Message-ID: <4ILWf2$zf8@newsmth.org>
Subject: ACM Online Judge�诤�����系统���么���
Date: Fri, 27 May 2005 03:44:50 +0000
From: star55@newsmth.net-SPAM.no (���说���)
Path: news.cnusenet.org!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-cn.bbs.comp.unix.development.kernel.mbox.zip!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!newsfeed.icl.net!newsfeed00.sul.t-online.de!t-online.de!tsicnews.teliasonera.com!news.banetele.no!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!bandi.nntp.kabelfoon.nl!news.bylinux.net!news.newsmth.org!NEWSMTH
Newsgroups: cn.bbs.comp.unix.development.kernel
Organization: 水木����
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: KernelTech/x/M.1117165490.D0
Lines: 214
Xref: news.cnusenet.org cn.bbs.comp.unix.development.kernel:28921
为ACM�����交系统�陌�全,���潜�������一些系统���貌����没�����.
���诘�����系统一直没�法�业����希���税�写�玫��诤�模����公������,�������院������方������倩�一些时��.
����什么�������MAIL�医���.tiebang55@163.com
/*
* FJNU Online Judge System,System call filter Module:system_filter.c
*
* Copyright (C) 2005 qicheng chen.
*/
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#include <linux/config.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
#ifdef CONFIG_SMP
#define __SMP__
#endif
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/times.h>
#include <asm/uaccess.h>
#include <linux/proc_fs.h> /* Necessary because we use the proc fs */
struct proc_dir_entry *Our_Proc_File;
struct idtr{
unsigned short limit;
unsigned int base;
} __attribute__ ((packed)) idtr;
struct idt{
unsigned short off_low;
unsigned short sel;
unsigned char none,flags;
unsigned short off_hight;
} __attribute__ ((packed)) idt;
struct my_data{
int pid;
int memory;
int time;
};
struct my_data p_data[10];
int my_count=0;
struct idtr idt_r;
struct idt *p;
unsigned long new_syscall;
unsigned long old_syscall;
extern asmlinkage void new_stub();
ssize_t procfile_read(char *, char **, off_t, int, int *, void *);
static int init_module()
{
int rv = 0;
asm("sidt %0" : "=m" (idt_r));
p=(struct idt *)(idt_r.base+8*0x80);
old_syscall=(p->off_hight << 16 ) | p->off_low;
new_syscall=(unsigned long) &new_stub;
p->off_low=(unsigned short)(new_syscall & 0x0000ffff);
p->off_hight=(unsigned short)((new_syscall >> 16) & 0x0000ffff);
/*Create proc file*/
Our_Proc_File = create_proc_entry("JudgeOnline", 0644, NULL);
Our_Proc_File->read_proc = procfile_read;
Our_Proc_File->owner = THIS_MODULE;
Our_Proc_File->mode = S_IFREG | S_IRUGO;
Our_Proc_File->uid = 0;
Our_Proc_File->gid = 0;
Our_Proc_File->size = 37;
printk(KERN_INFO "Trying to create /proc/JudgeOnline:\n");
if (Our_Proc_File == NULL) {
rv = -ENOMEM;
remove_proc_entry("JudgeOnline", &proc_root);
printk(KERN_INFO "Error: Could not initialize /proc/JudgeOnline\n");
} else {
printk(KERN_INFO "Success!\n");
}
return rv;
}
static void cleanup_module()
{
p->off_low=(unsigned short)(old_syscall & 0x0000ffff);
p->off_hight=(unsigned short)((old_syscall >> 16) & 0x0000ffff);
printk("Clean System Call Fitler Module\n");
remove_proc_entry("JudgeOnline", &proc_root);
printk(KERN_INFO "/proc/JudgeOnline removed\n");
}
/*�����������为0,��止1*/
int syscall_status[261]={0,
/*1 2 3 4 5 6 7 8 9 10*/
......
};
asmlinkage int filter(int eax,int ebx,int ecx,int edx)
{
if(eax==260){
current->flags^=0x10000000;
return 0;
}
if(current->flags&0xF0000000){
if(syscall_status[eax]==1){
if(eax==5&&(current->flags&0x20000000)) return 1;
notify_parent(current,35);
return 0;
}
if(eax==1||eax==252){
p_data[my_count].pid=current->pid;
p_data[my_count].memory=current->mm->mm_stat.rss;
p_data[my_count].time=current->times.tms_utime;
my_count++;
my_count%=10;
}
}
return 1;
}
void new_int80()
{
asm("
.globl new_stub
.align 4,0x90
new_stub:
pushl %%es;
pushl %%ds;
pushl %%ebp;
pushl %%edi;
pushl %%esi;
pushl %%edx;
pushl %%ecx;
pushl %%ebx;
pushl %%eax;
pushl %%edx;
pushl %%ecx;
pushl %%ebx;
pushl %%eax;
call *%1;
addl $0x10, %%esp;
testl %%eax,%%eax;
popl %%eax;
jnz next
movl $260,%%eax;
next:
popl %%ebx;
popl %%ecx;
popl %%edx;
popl %%esi;
popl %%edi;
popl %%ebp;
popl %%ds;
popl %%es;
jmp *%0;
" :
: "m" (old_syscall),"m" (&filter) );
}
ssize_t
procfile_read(char *buffer,
char **buffer_location,
off_t offset, int buffer_length, int *eof, void *data)
{
int len = 0; /* The number of bytes actually used */
int length=0;
int i;
if (offset > 0) {
*eof = 1;
return len;
}
/*
* Fill the buffer and get its length
*/
for(i=0;i<10;i++){
length = sprintf(buffer+len,"%d %d %d ",p_data[i].pid,p_data[i].time,p_data[i].memory);
len+=length;
}
/*
* Return the length
*/
return len;
}
--
���牡����
�不知��为什么要����,却一直要���蔚幕���,������要���伟�,��
[m[31m�� ��源:��水木���� http://newsmth.net��[FROM: 218.5.5.*][m