How do I share data between kernel C programs and user level C programs? -
i using ubuntu 9.04 kernel 2.8.32. created simple system call counts number of clone , execve calls. when user/shell calls system call, pass user these 2 values. of using:
#include <linux/sched.h> #include <linux/asmlinkage> /* these 2 variables extern longs defined in sched.h , initialized in process_32.c */ total_execve; total_clones; long mycall* (int i){ int array[2]; array[0] = total_execve; array[1] = total_clones; return array; }
i not able compile undefined reference.
regarding returning array: new call able access array, won't array located in kernel memory?
answering last question first: array indeed in "kernel" memory, it's stack allocated means "go away" when mycall() function exits. function may appear work, may fail in cases memory gets re-used quickly.
to return multiple values, common pattern caller pass in pointers user-space memory, , have kernel routine fill them in. example, pass in 2 pointers 2 values, or define single struct contains values need , gets filled in kernel routine.
Comments
Post a Comment