LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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


Reply
  Search this Thread
Old 08-13-2006, 08:44 AM   #1
jamie_barrow
Member
 
Registered: Jul 2003
Location: Gauteng, South Africa
Distribution: Windows XP, yup :D Will be back onto Ubuntu probably someday
Posts: 107

Rep: Reputation: 15
Question Kernel Programming - copy_to_user


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

Last edited by jamie_barrow; 08-13-2006 at 08:52 AM.
 
Old 08-13-2006, 09:31 AM   #2
jamie_barrow
Member
 
Registered: Jul 2003
Location: Gauteng, South Africa
Distribution: Windows XP, yup :D Will be back onto Ubuntu probably someday
Posts: 107

Original Poster
Rep: Reputation: 15
k, i found out where it is, its in

linux/include/asm-i386/uaccess.h

so #include <asm/uaccess.h>
 
  


Reply

Tags
call, kernel, system



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
copy_to_user within module. maheshstms Linux - Kernel 5 02-11-2014 05:04 AM
Difference between Userland programming and Kernel Programming.. meetsagittarian Programming 1 02-20-2006 12:26 AM
Kernel Programming misbahuddin Linux - Software 1 01-04-2006 05:15 PM
kernel programming help Pratik H Pandya Red Hat 4 09-02-2005 11:54 PM
in what library is "copy_to_user"? hesher Programming 4 04-16-2004 05:21 PM

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

All times are GMT -5. The time now is 09:36 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