日期:2014-05-16 浏览次数:20802 次
unsigned int ctx;
p->ctx=0;
next->ctx++;
asmlinkage int sys_mycall(int num) { printk(KERN_INFO "success!\n"); return num; }
#define __NR_fanotify_mark 339 #define __NR_prlimit64 340 #define __NR_mycall 341 #ifdef __KERNEL__ #define NR_syscalls 342
.long sys_mycall
#include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/proc_fs.h> #define MODULE_VERSION "1.0" #define MODULE_NAME "proc_interface" #define FOOBAR_LEN 8 struct fb_data_t { char name[FOOBAR_LEN+1]; char value[FOOBAR_LEN+1]; }; static struct proc_dir_entry *example_dir,*foo_file, *bar_file,*jiffies_file,*symlink; struct fb_data_t foo_data,bar_data; static int proc_read_jiffies(char *page,char **start, off_t off,int count, int *eof,void *data) { int len; len=sprintf(page,"jiffies=%ld\n", jiffies); return len; } static int proc_read_foobar(char *page,char **start, off_t off,int count, int *eof,void *data) { int len; struct fb_data_t *fb_data=(struct fb_data_t *)data; len=sprintf(page,"%s='%s'\n", fb_data->name,fb_data->value); return len; } static int proc_write_foobar(struct file *file, const char *buffer, unsigned long count, void *data) { int len; struct fb_data_t *fb_data=(struct fb_data_t *)data; if(count>FOOBAR_LEN) len=FOOBAR_LEN; else len=count; if(copy_from_user(fb_data->value,buffer,len)){ return -EFAULT; } fb_data->value[len]='\0'; return len; } static int __init hello_init(void) { int rv=0; example_dir=proc_mkdir(MODULE_NAME,NULL); if(example_dir==NULL){ rv=-ENOMEM; goto out; } example_dir->owner=THIS_MODULE; jiffies_file=create_proc_read_entry("jiffies", 0444,example_dir, proc_read_jiffies, NULL); if(jiffies_file==NULL){ rv=-ENOMEM; goto no_jiffies; } jiffies_file->owner=THIS_MODULE; foo_file=create_proc_entry("foo",0644,example_dir); if(foo_file==NULL){ rv=-ENOMEM; goto no_foo; } strcpy(foo_data.name,"foo"); strcpy(foo_data.value,"foo"); foo_file->data=&foo_data; foo_file->read_proc=proc_read_foobar; foo_file->write_proc=proc_write_foobar; foo_file->owner=THIS_MODULE; bar_file=create_proc_entry("b