melih
melih

Reputation: 380

My system call is not working properly

I need to create 2 new system calls to set and get a property from a process by the given pid. I changed task_struct, added int z_value (this is what I need to set/get)

I also managed to set a default z_value (200) for every process created.

When I run get system call, I can see that default z_value correct. But when I try to set the z_value nothing happens.

No compiling errors, no segmentation fault etc.

Here is my set system call.

#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/uaccess.h>

asmlinkage void sys_set_z_value ( int user_value , pid_t pid )
{


    rcu_read_lock();

    struct task_struct *p = find_task_by_vpid(pid);  

    p->z_value = user_value;

    rcu_read_unlock();
}

Upvotes: 0

Views: 2298

Answers (3)

Chris Stratton
Chris Stratton

Reputation: 40357

Two suggestions:

1) Introduce an intentional error like some random characters in the source file and make sure your kernel build fails. Its amazing the number of problems that come down to the code you add not being built.

assuming that wasn't it

2) Load up your code with a lot of printk's so you can see what it's trying to do by either watching the console window or invoking dmesg after you've run it. Put them all over the place to check every assumption - that the code runs, that the variables are what you think, etc.

Upvotes: 0

Nicolas Viennot
Nicolas Viennot

Reputation: 3969

  • Your syscall should return a long type.
  • You should use the SYSCALL_DEFINE2() macros.
  • Your code should not compile without warnings (and declaring the p type in the middle of the function will trigger a warning)
  • If you get an invalid pid, your p variable will be NULL, and you should return -ESRCH

About this:

I also managed to set a default z_value (200) for every process created.

I hope that you took care of init_task too, it's a common mistake.

Upvotes: 2

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215259

Your call to copy_from_user makes no sense. There's no pointer to userspace memory involved. user_value is a value, not a pointer. (If you intended for it to be a pointer, you need to fix the types involved, but it looks like you're passing this int by value to the syscall.) Just assign p->z_value = user_value;.

Upvotes: 6

Related Questions