2

I have calculated the value of a parameter in user space and would like to pass the integer value to kernel space. I know that I have to use get_user(x, ptr), but I'm not sure how to provide the pointer to the kernel module.

I have an integer variable in my user space code and I can find the pointer to it. However, I should know the pointer beforehand so that I can use it in my kernel code. Do I need to allocate a specific memory location (i.e. 0x...) to the integer variable so that I can use it in both codes or there's another workaround?

I want this data transfer to have the minimum possible overhead.

Matt
  • 796
  • 12
  • 25
  • What system call are you using to get to that `get_user` call? That's the key to know how to pass user info to kernel. User and kernel spaces use different virtual address spaces, so that's the reason of havin `copy_to_user()` and `copy_from_user()` functions. Please **edit your question** showing some code or explaining how did you get executing kernel code from user space if not a system call. – Luis Colorado Aug 31 '15 at 09:49
  • I'm trying to create an entry in /proc and read its contents from user space and execute `get_user` there. I'm stuck in creating the entry for now. I'll update my question soon. – Matt Aug 31 '15 at 16:12
  • ok, so you are going to pass the information via read(2) system call in text format, right? – Luis Colorado Aug 31 '15 at 20:55
  • I created the /proc entry and I'm doing `cat myproc` to test the read operation. It works with copy_to_user but not with put_user – Matt Aug 31 '15 at 21:57
  • How did you create an entry in `/proc`? Are you programming in kernel side or in user side? What's the problem with using `copy_to_user` instead of `put_user`? – Luis Colorado Sep 01 '15 at 08:54
  • 1
    I kinda figured out how to solve this problem. I created a proc entry in my kernel module and defined my read and write functions. Then, I call `put_user` and `get_user` in read and write functions, respectively. Thanks a lot for your help. – Matt Sep 01 '15 at 22:00
  • So perhaps I have helped you without even have to write a response... :) – Luis Colorado Sep 02 '15 at 09:25

0 Answers0