aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLAN-TW <lantw44@gmail.com>2013-03-29 17:21:53 +0800
committerLAN-TW <lantw44@gmail.com>2013-03-29 17:21:53 +0800
commit1965cda478ea73e786a796b1960be3194923e391 (patch)
tree321ba57b505b7958ff4dfe600b687a13a55337df
parentc5d5d4f4e04734a1a746c87f5800fae6bd524405 (diff)
downloadtaiwan-online-judge-lantw44-broken-20130310.tar.gz
taiwan-online-judge-lantw44-broken-20130310.tar.zst
taiwan-online-judge-lantw44-broken-20130310.zip
Sync with upstream - 20130329broken-20130310
-rw-r--r--toj/center/src/Makefile5
-rw-r--r--toj/center/src/center.h4
-rw-r--r--toj/center/src/center_manage.cpp2
-rw-r--r--toj/center/src/event_exec.cpp (renamed from toj/php/event_exec.cpp)0
-rw-r--r--toj/center/src/event_exec.h (renamed from toj/php/event_exec.h)0
-rw-r--r--toj/center/src/hyperio/Makefile13
-rw-r--r--toj/center/src/hyperio/hyperio_mod.c58
-rw-r--r--toj/center/src/hyperio/hyperio_mod.h21
-rw-r--r--toj/center/src/hyperio/judgk_hyperio.c416
-rw-r--r--toj/center/src/hyperio/judgk_hyperio.h52
-rw-r--r--toj/center/src/hyperio/test.cpp173
-rw-r--r--toj/center/src/judgm_lib.h4
12 files changed, 744 insertions, 4 deletions
diff --git a/toj/center/src/Makefile b/toj/center/src/Makefile
index dcfab80..0ad79aa 100644
--- a/toj/center/src/Makefile
+++ b/toj/center/src/Makefile
@@ -2,13 +2,13 @@ ifneq ($(KERNELRELEASE),)
judgk-objs := judgk_mod.o judgk_proc.o judgk_syscall.o judgk_syscall_asm.o judgk_security.o judgk_hyperio.o
obj-m := judgk.o
else
- KERNEL_SOURCE := /usr/lib/modules/$(shell uname -r)/build
+ KERNEL_SOURCE := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
${MAKE} -C ${KERNEL_SOURCE} M=${PWD} modules
mv judgk.ko ../judge/
- g++ -rdynamic -fvisibility=hidden -O2 center_server.cpp center_manage.cpp center_judge.cpp pack.cpp /srv/http/toj/php/event_exec.cpp -ldl -lpq -ltar -lbz2 -ljson -lcurl -pthread -o center_server
+ g++ -rdynamic -fvisibility=hidden -O2 center_server.cpp center_manage.cpp center_judge.cpp pack.cpp event_exec.cpp -ldl -lpq -ltar -lbz2 -ljson -lcurl -pthread -o center_server
g++ -O2 judge_server.cpp pack.cpp -ldl -lbz2 -ltar -pthread -o judge_server
mv center_server ../
mv judge_server ../judge/
@@ -20,6 +20,7 @@ default:
mv jmod_test_line.so ../jmod/jmod_test/
mv jmod_test_check.so ../jmod/jmod_test/
tar -jcvf ../tmp/jmodpack/jmod_test.tar.bz2 -C ../jmod/jmod_test .
+
clean:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
endif
diff --git a/toj/center/src/center.h b/toj/center/src/center.h
index a143df0..18147c3 100644
--- a/toj/center/src/center.h
+++ b/toj/center/src/center.h
@@ -38,15 +38,17 @@ public:
center_jmod_info *jmod_info;
center_pro_info *pro_info;
int lang;
+ bool rejudge_flag;
char *param;
void *jmod_manage_data;
- center_submit_info(int subid,int uid,center_jmod_info *jmod_info,center_pro_info *pro_info,int lang,char *param){
+ center_submit_info(int subid,int uid,center_jmod_info *jmod_info,center_pro_info *pro_info,int lang,bool rejudge_flag,char *param){
this->subid = subid;
this->uid = uid;
this->jmod_info = jmod_info;
this->pro_info = pro_info;
this->lang = lang;
+ this->rejudge_flag = rejudge_flag;
this->param = param;
this->jmod_manage_data = NULL;
}
diff --git a/toj/center/src/center_manage.cpp b/toj/center/src/center_manage.cpp
index 1155ab0..f5f7210 100644
--- a/toj/center/src/center_manage.cpp
+++ b/toj/center/src/center_manage.cpp
@@ -15,7 +15,7 @@
#include<string>
#include"tpool.h"
-#include"/srv/http/toj/php/event_exec.h"
+#include"event_exec.h"
#include"center.h"
#include"judge_def.h"
#include"judgm_manage.h"
diff --git a/toj/php/event_exec.cpp b/toj/center/src/event_exec.cpp
index af258c0..af258c0 100644
--- a/toj/php/event_exec.cpp
+++ b/toj/center/src/event_exec.cpp
diff --git a/toj/php/event_exec.h b/toj/center/src/event_exec.h
index aec1acb..aec1acb 100644
--- a/toj/php/event_exec.h
+++ b/toj/center/src/event_exec.h
diff --git a/toj/center/src/hyperio/Makefile b/toj/center/src/hyperio/Makefile
new file mode 100644
index 0000000..655e473
--- /dev/null
+++ b/toj/center/src/hyperio/Makefile
@@ -0,0 +1,13 @@
+ifneq ($(KERNELRELEASE),)
+ hyperio-objs := hyperio_mod.o judgk_hyperio.o
+ obj-m := hyperio.o
+else
+ KERNEL_SOURCE := /usr/lib/modules/$(shell uname -r)/build
+ PWD := $(shell pwd)
+default:
+ ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
+
+ g++ -O2 test.cpp -o test
+clean:
+ ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
+endif
diff --git a/toj/center/src/hyperio/hyperio_mod.c b/toj/center/src/hyperio/hyperio_mod.c
new file mode 100644
index 0000000..a188b14
--- /dev/null
+++ b/toj/center/src/hyperio/hyperio_mod.c
@@ -0,0 +1,58 @@
+#include<linux/module.h>
+#include<linux/kernel.h>
+#include<linux/kdev_t.h>
+#include<linux/device.h>
+#include<linux/cdev.h>
+#include<linux/fs.h>
+
+#include"../judgk.h"
+#include"../judgk_com.h"
+#include"hyperio_mod.h"
+
+static int __init mod_init(){
+ alloc_chrdev_region(&mod_dev,0,1,"hyperio");
+ mod_class = class_create(THIS_MODULE,"chardev");
+ device_create(mod_class,NULL,mod_dev,NULL,"hyperio");
+ cdev_init(&mod_cdev,&mod_fops);
+ cdev_add(&mod_cdev,mod_dev,1);
+
+ judgk_hyperio_init();
+
+ pr_alert("hyperio:Init\n");
+ return 0;
+}
+static void __exit mod_exit(){
+ judgk_hyperio_exit();
+
+ cdev_del(&mod_cdev);
+ device_destroy(mod_class,mod_dev);
+ class_destroy(mod_class);
+ unregister_chrdev_region(mod_dev,1);
+
+ pr_alert("hyperio:Exit\n");
+}
+module_init(mod_init);
+module_exit(mod_exit);
+MODULE_LICENSE("Dual BSD/GPL");
+
+static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg){
+ long ret;
+
+ ret = 0;
+ switch(cmd){
+ case IOCTL_HYPERIO_ADD:
+ ret = judgk_hyperio_add(filp);
+ break;
+ case IOCTL_HYPERIO_READ:
+ ret = judgk_hyperio_read(filp,arg);
+ break;
+ case IOCTL_HYPERIO_WRITE:
+ ret = judgk_hyperio_write(filp,arg);
+ break;
+ case IOCTL_HYPERIO_DEL:
+ ret = judgk_hyperio_del(filp);
+ break;
+ }
+
+ return ret;
+}
diff --git a/toj/center/src/hyperio/hyperio_mod.h b/toj/center/src/hyperio/hyperio_mod.h
new file mode 100644
index 0000000..3d75b68
--- /dev/null
+++ b/toj/center/src/hyperio/hyperio_mod.h
@@ -0,0 +1,21 @@
+static int __init mod_init(void);
+static void __exit mod_exit(void);
+
+static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg);
+
+static dev_t mod_dev;
+static struct cdev mod_cdev;
+static struct class *mod_class;
+extern int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma);
+static struct file_operations mod_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = mod_ioctl,
+ .mmap = judgk_hyperio_mmap
+};
+
+extern int judgk_hyperio_init(void);
+extern int judgk_hyperio_exit(void);
+extern int judgk_hyperio_add(struct file *filp);
+extern int judgk_hyperio_read(struct file *filp,size_t len);
+extern int judgk_hyperio_write(struct file *filp,size_t len);
+extern int judgk_hyperio_del(struct file *filp);
diff --git a/toj/center/src/hyperio/judgk_hyperio.c b/toj/center/src/hyperio/judgk_hyperio.c
new file mode 100644
index 0000000..9194e29
--- /dev/null
+++ b/toj/center/src/hyperio/judgk_hyperio.c
@@ -0,0 +1,416 @@
+#include<linux/fs.h>
+#include<linux/tty.h>
+#include<linux/slab.h>
+#include<linux/mm.h>
+#include<linux/wait.h>
+#include<linux/sched.h>
+#include<asm/atomic.h>
+#include<asm/mman.h>
+
+#include"../judgk.h"
+#include"../judgk_com.h"
+#include"judgk_hyperio.h"
+
+int judgk_hyperio_init(){
+ int i;
+ struct hyperio_info *info;
+
+ hyperio_filp_ht = (struct hlist_head*)kmalloc(sizeof(struct hlist_head) * HYPERIO_FILP_HTSIZE,GFP_KERNEL);
+ for(i = 0;i < HYPERIO_FILP_HTSIZE;i++){
+ INIT_HLIST_HEAD(&hyperio_filp_ht[i]);
+ }
+
+ hyperio_table = (struct hyperio_info*)kmalloc(sizeof(struct hyperio_info) * HYPERIO_MAXNUM,GFP_KERNEL);
+ for(i = 0;i < HYPERIO_MAXNUM;i++){
+ info = &hyperio_table[i];
+
+ atomic_set(&info->ref_count,0);
+ info->filp = NULL;
+ info->create_flag = false;
+ info->end_flag = false;
+ info->hook_fops = NULL;
+ info->old_fops = NULL;
+
+ atomic64_set(&info->read_remain,JUDGK_COM_HYPERIO_BUFSIZE);
+ info->read_off = 0;
+ info->read_buf = NULL;
+ init_completion(&info->read_rwait);
+ init_completion(&info->read_wwait);
+
+ atomic64_set(&info->write_remain,JUDGK_COM_HYPERIO_BUFSIZE);
+ info->write_off = 0;
+ info->write_buf = NULL;
+ init_completion(&info->write_rwait);
+ init_completion(&info->write_wwait);
+ }
+
+ hyperio_tty_drv = tty_alloc_driver(HYPERIO_MAXNUM,TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV);
+ hyperio_tty_drv->owner = THIS_MODULE;
+ hyperio_tty_drv->driver_name = "judgk_tty";
+ hyperio_tty_drv->name = "jtty";
+ hyperio_tty_drv->type = TTY_DRIVER_TYPE_SYSTEM;
+ hyperio_tty_drv->subtype = SYSTEM_TYPE_TTY;
+ hyperio_tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+ hyperio_tty_drv->init_termios = tty_std_termios;
+ hyperio_tty_drv->init_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
+ hyperio_tty_drv->init_termios.c_oflag &= ~OPOST;
+ hyperio_tty_drv->init_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
+ hyperio_tty_drv->init_termios.c_cflag &= ~(CSIZE | PARENB);
+ hyperio_tty_drv->init_termios.c_cflag |= CS8;
+ tty_set_operations(hyperio_tty_drv,&hyperio_tops);
+
+ tty_register_driver(hyperio_tty_drv);
+
+ return 0;
+}
+int judgk_hyperio_exit(){
+ int i;
+
+ for(i = 0;i < HYPERIO_MAXNUM;i++){
+ if(hyperio_table[i].create_flag == true){
+ tty_unregister_device(hyperio_tty_drv,i);
+ hyperio_table[i].create_flag = false;
+ }
+ }
+ tty_unregister_driver(hyperio_tty_drv);
+
+ return 0;
+}
+int judgk_hyperio_add(struct file *filp){
+ int idx;
+ struct hyperio_info *info;
+
+ info = NULL;
+ for(idx = 0;idx < HYPERIO_MAXNUM;idx++){
+ if(atomic_cmpxchg(&hyperio_table[idx].ref_count,0,1) == 0){
+ info = &hyperio_table[idx];
+ break;
+ }
+ }
+ if(info == NULL){
+ return -1;
+ }
+
+ filp->private_data = info;
+
+ info->filp = NULL;
+ if(info->create_flag == false){
+ tty_register_device(hyperio_tty_drv,idx,NULL);
+ info->create_flag = true;
+ }
+ info->end_flag = false;
+ if(info->hook_fops == NULL){
+ info->hook_fops = (struct file_operations*)kmalloc(sizeof(struct file_operations),GFP_KERNEL);
+ }
+
+ atomic64_set(&info->read_remain,JUDGK_COM_HYPERIO_BUFSIZE);
+ info->read_off = 0;
+ if(info->read_buf == NULL){
+ info->read_buf = kmalloc(JUDGK_COM_HYPERIO_BUFSIZE,GFP_KERNEL);
+ }
+ memset(info->read_buf,0,JUDGK_COM_HYPERIO_BUFSIZE);
+ init_completion(&info->read_rwait);
+ init_completion(&info->read_wwait);
+
+ atomic64_set(&info->write_remain,JUDGK_COM_HYPERIO_BUFSIZE);
+ info->write_off = 0;
+ if(info->write_buf == NULL){
+ info->write_buf = kmalloc(JUDGK_COM_HYPERIO_BUFSIZE,GFP_KERNEL);
+ }
+ memset(info->write_buf,0,JUDGK_COM_HYPERIO_BUFSIZE);
+ init_completion(&info->write_rwait);
+ init_completion(&info->write_wwait);
+
+ return idx;
+}
+int judgk_hyperio_read(struct file *filp,size_t len){
+ struct hyperio_info *info;
+ bool wait_flag;
+ size_t remain;
+
+ if((long)len >= 0){
+ wait_flag = true;
+ }else{
+ wait_flag = false;
+ len = -(long)len;
+ }
+
+ info = (struct hyperio_info*)filp->private_data;
+
+ remain = atomic64_read(&info->write_remain);
+ if(unlikely(len > (JUDGK_COM_HYPERIO_BUFSIZE - remain))){
+ return -EINVAL;
+ }
+
+ if(unlikely(len > 0 && (remain = atomic64_add_return(len,&info->write_remain)) == len)){
+ complete(&info->write_wwait);
+ }
+ if(wait_flag == true){
+ while(unlikely(remain == JUDGK_COM_HYPERIO_BUFSIZE)){
+ if(info->end_flag == true){
+ remain = atomic64_read(&info->write_remain);
+ break;
+ }
+ wait_for_completion_interruptible(&info->write_rwait);
+ remain = atomic64_read(&info->write_remain);
+ }
+ }
+
+ return JUDGK_COM_HYPERIO_BUFSIZE - remain;
+}
+int judgk_hyperio_write(struct file *filp,size_t len){
+ struct hyperio_info *info;
+ bool wait_flag;
+ size_t remain;
+
+ if((long)len >= 0){
+ wait_flag = true;
+ }else{
+ wait_flag = false;
+ len = -(long)len;
+ }
+
+ info = (struct hyperio_info*)filp->private_data;
+
+ remain = atomic64_read(&info->read_remain);
+ if(unlikely(len > remain)){
+ return -EINVAL;
+ }
+
+ if(unlikely(len > 0 && (remain = atomic64_sub_return(len,&info->read_remain)) == (JUDGK_COM_HYPERIO_BUFSIZE - len))){
+ complete(&info->read_rwait);
+ }
+ if(wait_flag == true){
+ while(unlikely(remain == 0)){
+ if(info->end_flag == true){
+ remain = atomic64_read(&info->read_remain);
+ break;
+ }
+ wait_for_completion_interruptible(&info->read_wwait);
+ remain = atomic64_read(&info->read_remain);
+ }
+ }
+
+ return remain;
+}
+int judgk_hyperio_del(struct file *filp){
+ struct hyperio_info *info;
+
+ info = (struct hyperio_info*)filp->private_data;
+ info->end_flag = true;
+ complete(&info->read_rwait);
+ complete(&info->read_wwait);
+ complete(&info->write_rwait);
+ complete(&info->write_wwait);
+
+ atomic_dec(&info->ref_count);
+ return 0;
+}
+int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma){
+ unsigned long size;
+ unsigned long off;
+ void *buf;
+
+ size = vma->vm_end - vma->vm_start;
+ off = vma->vm_pgoff << PAGE_SHIFT;
+ if((size + off) > JUDGK_COM_HYPERIO_BUFSIZE){
+ return -EINVAL;
+ }
+ if((vma->vm_flags & VM_READ) != 0 && (vma->vm_flags & VM_WRITE) != 0){
+ return -EINVAL;
+ }
+ if((vma->vm_flags & VM_READ) == 0 && (vma->vm_flags & VM_WRITE) == 0){
+ return -EINVAL;
+ }
+
+ if((vma->vm_flags & VM_READ) != 0){
+ buf = ((struct hyperio_info*)filp->private_data)->write_buf;
+ }else{
+ buf = ((struct hyperio_info*)filp->private_data)->read_buf;
+ }
+ remap_pfn_range(vma,
+ vma->vm_start,
+ virt_to_phys(buf + off) >> PAGE_SHIFT,
+ size,
+ vma->vm_page_prot);
+
+ return 0;
+}
+
+static inline struct hyperio_info* hyperio_filp_lookup(struct file *filp){
+ struct hlist_node *node;
+ struct hyperio_info *info;
+
+ rcu_read_lock();
+
+ info = NULL;
+ hlist_for_each_entry_rcu(info,node,&hyperio_filp_ht[(unsigned long)filp % HYPERIO_FILP_HTSIZE],node){
+ if((unsigned long)info->filp == (unsigned long)filp){
+ break;
+ }
+ info = NULL;
+ }
+
+ rcu_read_unlock();
+
+ return info;
+}
+static int hyperio_tty_open(struct tty_struct *tty, struct file *filp){
+ struct hyperio_info *info;
+ struct file_operations *hook_fops;
+
+ tty->low_latency = 1;
+
+ info = &hyperio_table[tty->index];
+ atomic_inc(&info->ref_count);
+ info->filp = filp;
+
+ hook_fops = info->hook_fops;
+ info->old_fops = filp->f_op;
+ memcpy(hook_fops,filp->f_op,sizeof(struct file_operations));
+
+ hook_fops->read = hyperio_tty_filpread;
+ hook_fops->write = hyperio_tty_filpwrite;
+
+ filp->f_op = hook_fops;
+
+ spin_lock(&hyperio_filp_htlock);
+
+ hlist_add_head_rcu(&info->node,&hyperio_filp_ht[(unsigned long)info->filp % HYPERIO_FILP_HTSIZE]);
+
+ spin_unlock(&hyperio_filp_htlock);
+
+ return 0;
+}
+static void hyperio_tty_close(struct tty_struct *tty, struct file *filp){
+ struct hyperio_info *info;
+
+ info = &hyperio_table[tty->index];
+
+ spin_lock(&hyperio_filp_htlock);
+
+ hlist_del_rcu(&info->node);
+
+ spin_unlock(&hyperio_filp_htlock);
+
+ filp->f_op = info->old_fops;
+
+ info->end_flag = true;
+ complete(&info->read_rwait);
+ complete(&info->read_wwait);
+ complete(&info->write_rwait);
+ complete(&info->write_wwait);
+
+ atomic_dec(&info->ref_count);
+}
+static int hyperio_tty_write(struct tty_struct *tty,const unsigned char *buf,int count){
+ return count;
+}
+static int hyperio_tty_write_room(struct tty_struct *tty){
+ return JUDGK_COM_HYPERIO_BUFSIZE;
+}
+static ssize_t hyperio_tty_filpread(struct file *filp,char __user *buf,size_t count,loff_t *off){
+ struct hyperio_info *info;
+ size_t buf_len;
+ off_t buf_off;
+ size_t remain;
+ size_t read_len;
+ off_t read_off;
+
+ if(unlikely(count < 0)){
+ return -EINVAL;
+ }
+
+ info = hyperio_filp_lookup(filp);
+ if(unlikely(info == NULL)){
+ return -EIO;
+ }
+
+ buf_len = count;
+ buf_off = 0;
+ while(likely(buf_len > 0)){
+ while(unlikely((remain = atomic64_read(&info->read_remain)) == JUDGK_COM_HYPERIO_BUFSIZE)){
+ if(unlikely(info->end_flag == true)){
+ return -EIO;
+ }
+ if(likely(buf_off > 0)){
+ return buf_off;
+ }
+ wait_for_completion_interruptible(&info->read_rwait);
+ }
+ if(unlikely(buf_len > (JUDGK_COM_HYPERIO_BUFSIZE - remain))){
+ read_len = JUDGK_COM_HYPERIO_BUFSIZE - remain;
+ }else{
+ read_len = buf_len;
+ }
+
+ read_off = info->read_off;
+ if(likely((read_len + read_off) < JUDGK_COM_HYPERIO_BUFSIZE)){
+ copy_to_user(buf + buf_off,info->read_buf + read_off,read_len);
+ info->read_off = read_len + read_off;
+ }else{
+ copy_to_user(buf + buf_off,info->read_buf + read_off,JUDGK_COM_HYPERIO_BUFSIZE - read_off);
+ copy_to_user(buf + buf_off + (JUDGK_COM_HYPERIO_BUFSIZE - read_off),info->read_buf,(read_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE);
+ info->read_off = (read_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE;
+ }
+
+ if(unlikely(atomic64_add_return(read_len,&info->read_remain) == read_len)){
+ complete(&info->read_wwait);
+ }
+ buf_len -= read_len;
+ buf_off += read_len;
+ }
+
+ return count;
+}
+static ssize_t hyperio_tty_filpwrite(struct file *filp,const char __user *buf,size_t count,loff_t *off){
+ struct hyperio_info *info;
+ size_t buf_len;
+ off_t buf_off;
+ size_t remain;
+ size_t write_len;
+ off_t write_off;
+
+ if(unlikely(count < 0)){
+ return -EINVAL;
+ }
+
+ info = hyperio_filp_lookup(filp);
+ if(unlikely(info == NULL)){
+ return -EIO;
+ }
+
+ buf_len = count;
+ buf_off = 0;
+ while(likely(buf_len > 0)){
+ while(unlikely((remain = atomic64_read(&info->write_remain)) == 0)){
+ if(unlikely(info->end_flag == true)){
+ return -EIO;
+ }
+ wait_for_completion_interruptible(&info->write_wwait);
+ }
+ if(unlikely(buf_len > remain)){
+ write_len = remain;
+ }else{
+ write_len = buf_len;
+ }
+
+ write_off = info->write_off;
+ if(unlikely((write_len + write_off) >= JUDGK_COM_HYPERIO_BUFSIZE)){
+ copy_from_user(info->write_buf + write_off,buf + buf_off,JUDGK_COM_HYPERIO_BUFSIZE - write_off);
+ copy_from_user(info->write_buf,buf + buf_off + (JUDGK_COM_HYPERIO_BUFSIZE - write_off),(write_len + write_off) - JUDGK_COM_HYPERIO_BUFSIZE);
+ info->write_off = (write_len + write_off) - JUDGK_COM_HYPERIO_BUFSIZE;
+ }else{
+ copy_from_user(info->write_buf + write_off,buf + buf_off,write_len);
+ info->write_off = write_len + write_off;
+ }
+
+ if(unlikely(atomic64_sub_return(write_len,&info->write_remain) == (JUDGK_COM_HYPERIO_BUFSIZE - write_len))){
+ complete(&info->write_rwait);
+ }
+ buf_len -= write_len;
+ buf_off += write_len;
+ }
+
+ return count;
+}
diff --git a/toj/center/src/hyperio/judgk_hyperio.h b/toj/center/src/hyperio/judgk_hyperio.h
new file mode 100644
index 0000000..1c0a31f
--- /dev/null
+++ b/toj/center/src/hyperio/judgk_hyperio.h
@@ -0,0 +1,52 @@
+#define HYPERIO_MAXNUM 256
+#define HYPERIO_FILP_HTSIZE 1009
+
+struct hyperio_info{
+ atomic_t ref_count;
+ struct hlist_node node;
+ struct file *filp;
+
+ bool create_flag;
+ bool end_flag;
+ struct file_operations *hook_fops;
+ const struct file_operations *old_fops;
+
+ atomic64_t read_remain;
+ off_t read_off;
+ char *read_buf;
+ struct completion read_rwait;
+ struct completion read_wwait;
+
+ atomic64_t write_remain;
+ off_t write_off;
+ char *write_buf;
+ struct completion write_rwait;
+ struct completion write_wwait;
+};
+
+static inline struct hyperio_info* hyperio_filp_lookup(struct file *filp);
+static int hyperio_tty_open(struct tty_struct * tty, struct file * filp);
+static void hyperio_tty_close(struct tty_struct * tty, struct file * filp);
+static int hyperio_tty_write(struct tty_struct *tty,const unsigned char *buf,int count);
+static int hyperio_tty_write_room(struct tty_struct *tty);
+static ssize_t hyperio_tty_filpread(struct file *filp,char __user *buf,size_t count,loff_t *off);
+static ssize_t hyperio_tty_filpwrite(struct file *filp,const char __user *buf,size_t count,loff_t *off);
+
+static struct tty_driver *hyperio_tty_drv;
+static struct tty_operations hyperio_tops = {
+ .open = hyperio_tty_open,
+ .close = hyperio_tty_close,
+ .write = hyperio_tty_write,
+ .write_room = hyperio_tty_write_room
+};
+static struct hyperio_info *hyperio_table;
+static struct hlist_head *hyperio_filp_ht;
+static DEFINE_SPINLOCK(hyperio_filp_htlock);
+
+int judgk_hyperio_init(void);
+int judgk_hyperio_exit(void);
+int judgk_hyperio_add(struct file *filp);
+int judgk_hyperio_read(struct file *filp,size_t len);
+int judgk_hyperio_write(struct file *filp,size_t len);
+int judgk_hyperio_del(struct file *filp);
+int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma);
diff --git a/toj/center/src/hyperio/test.cpp b/toj/center/src/hyperio/test.cpp
new file mode 100644
index 0000000..18e536b
--- /dev/null
+++ b/toj/center/src/hyperio/test.cpp
@@ -0,0 +1,173 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include<unistd.h>
+#include<fcntl.h>
+#include<time.h>
+#include<limits.h>
+#include<math.h>
+#include<termios.h>
+#include<sys/ioctl.h>
+#include<sys/types.h>
+#include<sys/mman.h>
+#include<sys/wait.h>
+
+#include"../judge_def.h"
+#include"../judgm_lib.h"
+
+int fd;
+/*char *rbuf;
+off_t roff = 0;
+
+int judgm_hyperio_compare(char *buf,size_t len){
+ int flag;
+ size_t remain;
+ off_t off;
+ size_t data_len;
+ size_t cmp_len;
+
+ flag = 0;
+ remain = len;
+ off = 0;
+ data_len = 0;
+ cmp_len = 0;
+ while(remain > 0 && flag == 0){
+ if(data_len == 0){
+ if((data_len = ioctl(fd,IOCTL_READ,cmp_len)) <= 0){
+ return -1;
+ }
+ }
+ if(remain < data_len){
+ cmp_len = remain;
+ }else{
+ cmp_len = data_len;
+ }
+
+ if((roff + cmp_len) < BUF_SIZE){
+ flag |= memcmp(rbuf + roff,buf + off,cmp_len);
+ roff += cmp_len;
+ }else{
+ flag |= memcmp(rbuf + roff,buf + off,BUF_SIZE - roff);
+ flag |= memcmp(rbuf,buf + off + (BUF_SIZE - roff),(cmp_len + roff) - BUF_SIZE);
+ roff = (cmp_len + roff) - BUF_SIZE;
+ }
+ remain -= cmp_len;
+ off += cmp_len;
+ }
+ if(cmp_len > 0){
+ ioctl(fd,IOCTL_READ,-(long)cmp_len);
+ }
+
+ if(flag == 0){
+ return 0;
+ }else{
+ return -1;
+ }
+}*/
+
+int main(){
+ int i,j;
+ char *buf;
+ int idx;
+ int pid;
+ char str[4096];
+ int a,b;
+ int l;
+
+ judgm_hyperio *hyperio;
+
+ fd = open("/dev/judgk",O_RDWR);
+ hyperio = new judgm_hyperio(fd);
+
+ printf("%d\n",hyperio->tty_idx);
+
+ if((pid = fork()) == 0){
+ int outfd;
+
+ outfd = judgm_hyperio::get_ttyfd(0);
+
+ //dup2(fd,0);
+ dup2(outfd,1);
+
+ printf("Hello World\n");
+ char *argv[] = {NULL,NULL};
+ char *envp[] = {NULL};
+
+ execve("/srv/http/toj/center/judge/tmp/run/1/test",argv,envp);
+ exit(0);
+ }
+
+ printf("%d\n",hyperio->compare("Hello World\n",12));
+
+ waitpid(pid,NULL,0);
+
+ getchar();
+ delete hyperio;
+ close(fd);
+
+ /*flag = 0;
+ roff = 0;
+ woff = 0;
+ srand(23);
+ for(i = 0;i < 1000000;i++){
+ a = rand() % 65536;
+ b = rand() % 65536;
+
+ snprintf(str,sizeof(str),"%d %d\n",a,b);
+ l = strlen(str);
+ j = l;
+ len = 0;
+ while(j > 0){
+ len = ioctl(fd,IOCTL_WRITE,len);
+ if(j < len){
+ len = j;
+ }
+
+ if((len + woff) < BUF_SIZE){
+ memcpy(wbuf + woff,str + (l - j),len);
+ woff += len;
+ }else{
+ memcpy(wbuf + woff,str + (l - j),BUF_SIZE - woff);
+ memcpy(wbuf,str + (l - j) + (BUF_SIZE - woff),(len + woff) - BUF_SIZE);
+ woff = (len + woff) - BUF_SIZE;
+ }
+
+ j -= len;
+ }
+ ioctl(fd,IOCTL_WRITE,-len);
+
+ snprintf(str,sizeof(str),"%d\n",a + b);
+ l = strlen(str);
+ j = l;
+ len = 0;
+ while(j > 0){
+ len = ioctl(fd,IOCTL_READ,len);
+ if(len <= 0){
+ flag = 1;
+ break;
+ }
+ if(j < len){
+ len = j;
+ }
+
+ if((roff + len) < BUF_SIZE){
+ flag |= memcmp(rbuf + roff,str + (l - j),len);
+ roff += len;
+ }else{
+ flag |= memcmp(rbuf + roff,str + (l - j),BUF_SIZE - roff);
+ flag |= memcmp(rbuf,str + (l - j) + (BUF_SIZE - roff),(len + roff) - BUF_SIZE);
+ roff = (len + roff) - BUF_SIZE;
+ }
+
+ j -= len;
+ }
+ ioctl(fd,IOCTL_READ,-len);
+
+ if(flag != 0){
+ printf("WA\n");
+ break;
+ }
+ }*/
+
+ return 0;
+}
diff --git a/toj/center/src/judgm_lib.h b/toj/center/src/judgm_lib.h
index 4aa02fa..f3324c0 100644
--- a/toj/center/src/judgm_lib.h
+++ b/toj/center/src/judgm_lib.h
@@ -65,6 +65,10 @@ private:
limit.rlim_max = limit.rlim_cur;
prlimit(pid,RLIMIT_NOFILE,&limit,NULL);
+ limit.rlim_cur = 70368744177664L;
+ limit.rlim_max = limit.rlim_cur;
+ prlimit(pid,RLIMIT_STACK,&limit,NULL);
+
com_proc_add.run_path[0] = '\0';
strncat(com_proc_add.run_path,run_path,sizeof(com_proc_add.run_path));
com_proc_add.pid = pid;