高分求助:内核模块中的系统调用问题!
野草重新 2005-05-12 04:07:27 系统为redHat9.0,内核版本为2.4.20-8
程序文件为:
sys_call_read.c:
#define __KERNEL__
#define MODULE
#define __KERNEL_SYSCALLS__
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/unistd.h>
#include <linux/malloc.h>
#include <linux/vmalloc.h>
#include <asm-i386/uaccess.h>
#include <asm-i386/msr.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <asm/fcntl.h>
#include <asm/errno.h>
#include <linux/dirent.h>
#include <sys/mman.h>
#include <linux/string.h>
#include <linux/slab.h>
#include "params.h"
void ksys_print(char *name, unsigned long value)
{
printk("ksystime: %3li -- %s\n", value, name);
}
int init_module(void)
{
printk("hello,this is my own items\n");
mm_segment_t fs;
unsigned long ini, end, now, best, tsc;
int i;
char buffer[4];
#define measure_time(code) \
for (i = 0; i < NTRIALS; i++) { \
rdtscl(ini); \
code; \
rdtscl(end); \
now = end - ini; \
if (now < best) best = now; \
}
/* time rdtsc (i.e. no code) */
best = ~0;
measure_time( 0 );
tsc = best;
ksys_print("tsc", tsc);
/* time an empty read() */
fs=get_fs();
set_fs(get_ds());
best = ~0;
measure_time( read(0, buffer, 0) );
/* report data */
ksys_print("read()", best - tsc);
set_fs (fs);
return -EINVAL;
}
void cleanup_module(void)
{
}
params.h:
#ifndef NTRIALS
#define NTRIALS 100000
#endif
#ifndef READSIZE
#define READSIZE 128
#endif
#ifndef BUFSIZE
#define BUFSIZE 1024*1024
#endif
#ifndef FILENAME
#define FILENAME "/tmp/meg"
#endif
要实现的仅仅是在模块初始时候调用一个空的read()
编译总是出问题,请教