LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 07-31-2018, 05:42 AM   #1
Phuti
LQ Newbie
 
Registered: Jul 2018
Posts: 4

Rep: Reputation: Disabled
Trying to copy data from kernel to user space using copy_to_user


I am trying to implement a system call for the Linux kernel as a way to learn kernel programming and I have this C file :

Code:
#include "myprocess.h"

SYSCALL_DEFINE2(get_info, struct pid_info *, info, int, pid)
{
        char *path;
        int err;
        ...
        
        ...
        //after finding the pid root path i am trying to copy it to user space
        err = copy_to_user(info->root_path, path, strlen(path));
        if (err)
                return -EFAULT;
        return 1;
}
Contents of myprocess header file :
Code:
...
struct pid_info {
        int pid;
        int state;
        char root[4096];
};
When trying to access the path from user program it has nothing inside. I know am doing something wrong or missing something and I just can't figure it out. Any help will be appreciated.
 
Old 07-31-2018, 12:42 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,266
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Please post your question only once. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a char driver. Sending from user space works, copy_to_user always 0 wedz Linux - Kernel 2 06-11-2013 09:37 PM
Sending data from kernel to user space ratbat Linux - Newbie 3 04-02-2013 02:33 AM
Linux kernel copy_to_user to user space display different result dennisdd Programming 7 04-12-2012 04:15 PM
[SOLVED] faster way to copy data to user space vdx Linux - Kernel 3 03-28-2012 04:02 AM
How to share data b/w user space and kernel space nandac Linux - Kernel 1 11-28-2006 10:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration