I have change linux kernul to add this function (after adding new faild called my_field of type long):
asmlinkage long sys_set_weight(long weight) {
if (weight < 0)
{
return -EINVAL; // -22
}
current->my_field = weight;
return 0;
}
in syscall_64.tbl I have:
334 common set_weight sys_set_weight
and in syscalls.h I have:
asmlinkage long sys_set_weight(long weight);
in C when I wrote:
int set_weight(int weight) {
long r = syscall(334, weight);
return r;
}
int main () {
int x = set_weight(-3);
cout << "set_weight returns: " << x << endl;
return 0;
}
But I see the following printed:
set_weight returns: 0
why is that? I am retuning -EINVAL
not 0
When you call syscall
, you are passing through ...
. You pass an int
through ...
, but the function expects a long
.
I'm not sure why you made set_weight
accept an int
when the call expects a long
, but you have no prototype that converts it to a long
before passing it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.