Hey everyone. I am new to kernel programming and have been learning quite a lot of interesting things recently.
My questions are about the functions:
access_ok(type, addr, size);
copy_to_user(void __user * to, const void * from, unsigned long n);
access_ok is now used instead of the deprecated verify_area function. I just want to make sure my understanding is right (assume type is VERIFY_WRITE).. does access_ok check only if the address pointed to by addr and extending to address+size fall is writable?
I am trying to create the pedagogictime system call as in the exercise by Gary Nutt in `Kernel Projects For Linux'. It takes two arguments, an integer flag and a struct timespec pointer cur_time. Through a call by reference, it writes the values of the xtime structure (also struct timespec) to the given pointer in user space.
Ok, so once I know that access_ok(VERIFY_WRITE, cur_time, sizeof(cur_time)) returns true (non-zero int) then I can write to the user space pointed to by cur_time.
Is this done as follows...
Code:
struct timespec tmp_time;
/* disable interrupts, read values, enable interrupts */
local_irq_disable();
tmp_time.tv_sec = xtime.tv_sec;
tmp_time.tv_usec = xtime.tv_nsec;
local_irq_enable();
int len_to_write;
/* copy tmp_time variable in kernel space to user space variable cur_time */
len_to_write = copy_to_user(cur_time, tmp_xtime, sizeof(cur_time));
if (len_to_write == 0) {
; // writing succesful
} else {
; // unsuccesful, do stuff
}
... I haven't yet actually tried it out. I know, I probably should before asking. But I want to make sure of the accuracy before having to go throught the whole recompile+reboot steps
Also, I am not sure where access_ok() and copy_to_user() are defined.. if anyone knows, please tell me
Thanks in advance,
James