Making a Linux system call

This is a discussion on Making a Linux system call within the Linux Programming forums, part of the Platform Specific Boards category; I'm having trouble passing a variable (specifically an integer) from user mode to kernel mode. This is my code for ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    3

    Making a Linux system call

    I'm having trouble passing a variable (specifically an integer) from user mode to kernel mode. This is my code for my system call:
    Code:
    #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!

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,208
    You never pass procnumk to the function, you are passing the pointer to procnum each time. Try
    Code:
    #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);
    }

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    Quote Originally Posted by Shakti View Post
    You never pass procnumk to the function, you are passing the pointer to procnum each time. Try
    Code:
    #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

  4. #4
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Show the rest of the code. That isn't where the problem is.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    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);

  6. #6
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    1) What do you think asmlinkage does?

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C: system call
    By Dedalus in forum C Programming
    Replies: 6
    Last Post: 06-22-2009, 09:45 AM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 06:18 AM
  3. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  4. Multiple types in lists, vectors or arrays.
    By megatron09 in forum C++ Programming
    Replies: 20
    Last Post: 08-31-2006, 01:54 PM
  5. Replies: 4
    Last Post: 06-13-2005, 09:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21