I am currently trying to call a system call by passing a char*
buffer as a parameter. However, I am not able to write any data to the char*
buffer nor read from the char*
buffer. I tried allocating data to a char x = 'a'
and then using copy_to_user
and vice versa using copy_from_user
, but nothing works out and no values are copied. I have been trying since way too long and not getting headway. Can someone please help me with this issue or point out where I am going wrong.
The system call is:
static void generate_Tasklist(char*,int);
static void generate_Tasklist(char *buffer,int size)
{
printk("\nINSIDE THE FUNCTION\n");
char x;
x = 'a';
int res = access_ok(VERIFY_WRITE,buffer,size);
printk("The return value of access_ok is %d\n",res);
int res1 = copy_to_user(buffer,&x,1);
printk("\nTHE RESULT AFTER copy_to_user IS %d\n",res1);
int res2 = copy_from_user(x,buffer,1);
printk("---------%c\n",x);
printk("\nTHE RESULT AFTER copy_from_user IS %d\n",res2);
}
asmlinkage long sys_syscall(char __user *buffer,int size) {
printk("\nThis is the system call to list processes!!!!!!!!!!!!!!!!!!!!!!!!\n");
generate_Tasklist(buffer,size);
return 0;
}
The user space program is :
int main(int argc, char *argv[]) {
char *bytes = (char *) malloc( sizeof( struct task_info ) * 3 );
int size = sizeof( struct task_info ) * 3;
for (int i=0; i < size; i++)
{
*(bytes + i) = 'x';
}
long int output = syscall(__NR_hello,1,bytes,size);
printf("\nThe value is %c\n",bytes[0]);
//print(bytes);
free( (void *) bytes );
printf ("The listprocess_syscall() returned %ld\n", output);
return 0;
}
So what I'm trying to do is overwrite the default value of 'x
' in the buffer by 'a
' for the first byte which is not happening. The value returned by copy_from_user
and copy_to_user
is 1
. Any suggestions on what I can do?