PDA

View Full Version : Making a Linux system call



ShamWow
03-28-2010, 12:12 PM
I'm having trouble passing a variable (specifically an integer) from user mode to kernel mode. This is my code for my system call:


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

asmlinkage int sys_processdisplay(int __user *procnum) {
int procnumk = 0;
copy_from_user(procnum, procnum, sizeof(int));
printk(KERN_EMERG "procnumk is: %d\n", procnumk);
return(1);
}

The problem is procnumk stays at 0. When I compile I get a weird message anytime I try to use copy_from_user or get_user that says "modpost: 3 mismatches found"

I appreciate any help. Thanks!

Shakti
03-28-2010, 12:48 PM
You never pass procnumk to the function, you are passing the pointer to procnum each time. Try


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

asmlinkage int sys_processdisplay(int __user *procnum) {
int procnumk = 0;
copy_from_user(&procnumk, procnum, sizeof(int));
printk(KERN_EMERG "procnumk is: %d\n", procnumk);
return(1);
}

ShamWow
03-28-2010, 01:27 PM
You never pass procnumk to the function, you are passing the pointer to procnum each time. Try


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

asmlinkage int sys_processdisplay(int __user *procnum) {
int procnumk = 0;
copy_from_user(&procnumk, procnum, sizeof(int));
printk(KERN_EMERG "procnumk is: %d\n", procnumk);
return(1);
}


I still get the modpost warning and 0 for procnumk

Kennedy
03-29-2010, 08:19 AM
Show the rest of the code. That isn't where the problem is.

ShamWow
03-29-2010, 10:21 AM
That is all the code, could it be how I made the system call? This is how I called it:
retval = syscall(__NR_processdisplay, 1);

Kennedy
03-29-2010, 10:59 AM
1) What do you think asmlinkage does?

2) Exactly how are you registering this as a system call?