ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have a similar question, and it is part of my homework assignment. I'm coming here only as a last resort as the professor won't discuss this with the students and refers us to the TA, who is nice, but barely speaks English and doesn't understand our questions. Our assignment was to add a system call to the linux 2.6.30 kernel, then make a user program that calls the new system call we created. The professor detailed everything extremely well, so we got that running fine.
For the second part, we need to figure out what happens when a null pointer is passed to copy_from_user() for the userspace address. Here is how I thought about approaching the problem: create another system call that takes in 1 parameter and pass it to uses copy_from_user(). Then, after we compile the new system call into our uml kernel, we run a usermode program that is supposed to call our system call, but pass in a null value.
Is this the most efficient way to solve this question? If so, how do I pass in variables to copy_from_user() for a system call?
You can do it that way. Why not? As for how to load up copy_from_user, the syntax is copy_from_user(*dest,src,size) and the return value is the number of bytes NOT copied. Just set src = 0x0 and see what happens.
You have to kmalloc the destination buffer in the kernel, or else have it statically assigned, and the source is a userspace memory pointer, in the context of the process that has invoked your command. Size is the number of bytes to copy.
#define __NR_copycall 336
int ret = 0;
ret = syscall(__NR_copycall);
printf("ret = %d \n",ret);
When I run this program, it prints "ret = 1" to the screen, then exits. I thought by not passing anything to the function, it would be the same thing as passing null. I also don't know how to pass a variable to the function since I don't know which register to modify and how to modify it right before the system call. Could someone please tell me what I need to change to get this figured out?
When I run this program, it prints "ret = 1" to the screen, then exits
What would you expect to have happen? You told your kernel routine to return 1. That is what it did. Any error messages will be in /var/log/messages. Look there.
I thought by not passing anything to the function, it would be the same thing as passing null.
Why would you think that? The registers are saved when you make your syscall, but they are not cleared. You want a 0x0 in a register, you have to put it there.
Look at /usr/src/linux/kernel/sys.c
Also look at sys_call.S which may have some other name on your system (on my workstation it is /usr/src/linux/arch/um/sys-i386/sys_call_table.S).
Registers are modified in the following order as specified by the order of the arguments in the syscall() invocation: %eax is the syscall number; %ebx, %ecx, %edx, %esi, %edi and %ebp are the registers used as arguments 0 to 5.