Copying blocks from kernel space to user space

Hugo Varotto (hvarotto@cs.pitt.edu)
Wed, 24 Mar 1999 14:05:32 -0500


Hi,

I'm trying to copy a block of data from kernel space to user space. In
particular, I'm trying to implement a syscall that will give me a subset
of the list of processes ( PID, CPU assigned, has_cpu flag, last_cpu
flag ). I'm interested in this info for some scheduling experiments in
our group.

I've already created syscalls that receive parameters from user space,
but this is my first implementation geting results from the syscal (
previously I've been modifiying the /proc filesystem, but it's my
understanding that it's faster to get the data from the syscall ).

I based my syscall in the stat function, so I created a function

----------------------------------------
int
rk_return_process_table ( long *ret_process_table )
{
long my_process_table[ PIDHASH_SZ*5 + 2];
int nr;

/* I'm returning 5 long items/flags for every */
/* process and 2 more indicating with */
/* nr_running and nr_tasks */

/* do data copying ot my_process_table .... */
/* and return it to the user */

return copy_to_user( ret_process_table,
my_process_table,sizeof(my_process_table)) ? -EFAULT : 0;

}
-----------------------------------------

I've also create the sys_return_process_table wrapper for the syscall
that will
call the function. I also updated the entry.S file to contain the new
syscall ( has id 208 after several new syscalls that I added ), and
defined __NR_rk_return_process_table in the file "unistd.h"

I then created a small test program that will call the new syscall,
basically

-----------------------------
#include <unistd.h>

void main( void )
{
long proc_table[256+2];

syscall( 208, proc_table );

printf( "nr_tasks[%ld]\n", proc_table[0] );
printf( "nr_running[%ld]\n", proc_table[1] );
}
-----------------------------

supposedly, in the first 2 places in the array I'm returning nr_running
and nr_tasks, but the syscall is returning me garbage ( I used a couple
of printk's in the rk_return_process_table function and the data is
correctly inserted in the table ).

Could somebody please give me some advice to where I'm making a mistake,
or some advice to what I'm doing wrong ? I'll really appreciate it
'cause I'm stuck at this point. Don't hesitate to tell me even if it's a
stupid error, 'cause I cannot find it ( maybe to little sleep ).

Thanks in advance

Hugo

--
Hugo Varotto
Computer Science Dept.
University of Pittsburgh
hvarotto@cs.pitt.edu

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/