diff --git a/fs/exec.c b/fs/exec.c index 1ed1682f5d54f62ef446691908fb28fef141e12b..f839b6752a527f2c9c1efb2da13106ef42edab3c 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -11,6 +11,8 @@ #define MAX_ARG_PAGES 32 +extern int sys_close(int fd); + static unsigned long * create_tables(char * p,int argc,int envc) { unsigned long *argv,*envp; unsigned long * sp; @@ -199,6 +201,11 @@ int do_execve(unsigned long * eip,long tmp,char * filename, iput(current->executable); current->executable = inode; + for (i=0 ; iclose_on_exec>>i)&1) + sys_close(i); + current->close_on_exec = 0; + free_page_tables(get_base(current->ldt[1]),get_limit(0x0f)); free_page_tables(get_base(current->ldt[2]),get_limit(0x17)); diff --git a/fs/open.c b/fs/open.c index 0199bc240c4ffc91adb7a9a2ff5e77ddefc68185..999d4410dbeac3cfce94ac84a4426242f8a712c5 100644 --- a/fs/open.c +++ b/fs/open.c @@ -102,3 +102,19 @@ int sys_fstat() { return 0; } +int sys_close(unsigned int fd) { + struct file * filp; + if (fd >= NR_OPEN) + return -EINVAL; + current->close_on_exec &= ~(1<filp[fd])) + return -EINVAL; + current->filp[fd] = NULL; + if (filp->f_count == 0) + panic("Close: file count is 0"); + if (--filp->f_count) + return 0; + iput(filp->f_inode); + return 0; +} + diff --git a/include/linux/sys.h b/include/linux/sys.h index 13846cf43d01397943ee501127a781e7d9d471f0..5d663422b281366919483de6b4c15c7721ea3fb3 100644 --- a/include/linux/sys.h +++ b/include/linux/sys.h @@ -4,7 +4,7 @@ extern int sys_fork(); extern int sys_read(); extern int sys_write(); extern int sys_open(); -//extern int sys_close(); +extern int sys_close(); //extern int sys_waitpid(); //extern int sys_creat(); //extern int sys_link(); @@ -93,7 +93,7 @@ fn_ptr sys_call_table[] = { sys_read, sys_write, sys_open, - 0, /*sys_close,*/ + sys_close, 0, //sys_waitpid, 0, //sys_creat, 0, //sys_link, diff --git a/include/unistd.h b/include/unistd.h index a20220034d62e0da29eea09aef267ecfc47a3b0c..a805ffd5ed2a0178b25f5c3c6853cb5d237c4a86 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -151,7 +151,10 @@ __asm__ volatile("int $0x80\n\r"\ extern int errno; +int chdir(const char* pathname); +int close(int fildes); int dup(int fildes); +int execve(const char * filename, char ** argv, char ** envp); int fork(); int fstat(); int setup(void *BIOS); @@ -159,10 +162,8 @@ int sync(); int open(const char * filename, int flag, ...); int write(int fildes, const char * buf, off_t count); int read(int fildes, const char * buf, off_t count); -int execve(const char * filename, char ** argv, char ** envp); int rmdir(const char* pathname); -int chdir(const char* pathname); time_t time(time_t * tloc); diff --git a/lib/Makefile b/lib/Makefile index 331f5a525de47306a57b40f7f5bd5b069b106507..9618874db4ffc4be2e4282715d0de8e3ddee2c06 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,7 +2,7 @@ AR := ar LD := ld GCC := gcc CCFLAG := -m32 -I../include -nostdinc -ffreestanding -fno-pic -Wall -fomit-frame-pointer -fno-stack-protector -c -OBJS := ctype.o write.o string.o open.o dup.o execve.o +OBJS := ctype.o write.o string.o open.o dup.o execve.o close.o lib.a : $(OBJS) $(AR) rcs $@ $^ @@ -26,6 +26,9 @@ dup.o : dup.c execve.o : execve.c $(GCC) $(CCFLAG) -o $@ $< +close.o : close.c + $(GCC) $(CCFLAG) -o $@ $< + clean : -rm *.o -rm lib.a diff --git a/lib/close.c b/lib/close.c new file mode 100644 index 0000000000000000000000000000000000000000..0ba46778afd51a9f74c66e0baf70c3ad50faf7e9 --- /dev/null +++ b/lib/close.c @@ -0,0 +1,5 @@ +#define __LIBRARY__ +#include + +_syscall1(int,close,int,fd) +