finish the execve2 after the getdents and sleep

master
unknown 3 years ago
parent 8d2fb264ee
commit 6bb30a1101

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,41 @@
diff -Naur 0/linux/init/main.c 4/linux/init/main.c
--- 0/linux/init/main.c 2016-08-08 09:40:13.000000000 +0800
+++ 4/linux/init/main.c 2021-07-06 14:16:56.000000000 +0800
@@ -208,3 +208,9 @@
}
_exit(0); /* NOTE! _exit, not exit() */
}
+
+void print_nr(int sid)
+{
+ if (sid > 86)
+ printk(" --syscall: sid=%d, pid=%d\n", sid, current->pid);
+}
diff -Naur 0/linux/kernel/system_call.s 4/linux/kernel/system_call.s
--- 0/linux/kernel/system_call.s 2015-09-03 20:21:09.000000000 +0800
+++ 4/linux/kernel/system_call.s 2021-07-06 14:18:56.000000000 +0800
@@ -91,6 +91,11 @@
mov %dx,%es
movl $0x17,%edx # fs points to local data space
mov %dx,%fs
+
+ pushl %eax #by wyj
+ call print_nr
+ popl %eax
+
call sys_call_table(,%eax,4)
pushl %eax
movl current,%eax
diff -Naur 0/linux/mm/memory.c 4/linux/mm/memory.c
--- 0/linux/mm/memory.c 2015-09-04 15:24:20.000000000 +0800
+++ 4/linux/mm/memory.c 2021-07-06 14:21:45.000000000 +0800
@@ -370,6 +370,9 @@
unsigned long page;
int block,i;
+ if (current->pid > 5)
+ printk(" --do_no_page: address=%x, pid=%d\n", address, current->pid);
+
address &= 0xfffff000;
tmp = address - current->start_code;
if (!current->executable || tmp >= current->end_data) {

@ -357,3 +357,229 @@ exec_error1:
free_page(page[i]);
return(retval);
}
static inline volatile void oom(void)
{
printk("out of memory\n\r");
do_exit(SIGSEGV);
}
int do_execve2(unsigned long * eip,long tmp,char * filename,
char ** argv, char ** envp)
{
struct m_inode * inode;
struct buffer_head * bh;
struct exec ex;
unsigned long page[MAX_ARG_PAGES];
int i,argc,envc;
int e_uid, e_gid;
int retval;
int sh_bang = 0;
unsigned long p=PAGE_SIZE*MAX_ARG_PAGES-4;/*Save environment variables and parameters*/
if ((0xffff & eip[1]) != 0x000f)/*Check if it's a kernel code snippet*/
panic("execve called from supervisor mode");
for (i=0 ; i<MAX_ARG_PAGES ; i++) /* clear page-table */
page[i]=0;
if (!(inode=namei(filename))) /* get executables inode */
return -ENOENT;
argc = count(argv);
envc = count(envp);
restart_interp:
if (!S_ISREG(inode->i_mode)) { /* must be regular file */
retval = -EACCES;
goto exec_error2;
}
i = inode->i_mode;
e_uid = (i & S_ISUID) ? inode->i_uid : current->euid;
e_gid = (i & S_ISGID) ? inode->i_gid : current->egid;
if (current->euid == inode->i_uid)
i >>= 6;
else if (current->egid == inode->i_gid)
i >>= 3;
if (!(i & 1) &&
!((inode->i_mode & 0111) && suser())) {
retval = -ENOEXEC;
goto exec_error2;
}
if (!(bh = bread(inode->i_dev,inode->i_zone[0]))) {
retval = -EACCES;
goto exec_error2;
}
ex = *((struct exec *) bh->b_data); /* read exec-header */
if ((bh->b_data[0] == '#') && (bh->b_data[1] == '!') && (!sh_bang)) {
/*
* This section does the #! interpretation.
* Sorta complicated, but hopefully it will work. -TYT
*/
char buf[1023], *cp, *interp, *i_name, *i_arg;
unsigned long old_fs;
strncpy(buf, bh->b_data+2, 1022);
brelse(bh);
iput(inode);
buf[1022] = '\0';
if (cp = strchr(buf, '\n')) {
*cp = '\0';
for (cp = buf; (*cp == ' ') || (*cp == '\t'); cp++);
}
if (!cp || *cp == '\0') {
retval = -ENOEXEC; /* No interpreter name found */
goto exec_error1;
}
interp = i_name = cp;
i_arg = 0;
for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
if (*cp == '/')
i_name = cp+1;
}
if (*cp) {
*cp++ = '\0';
i_arg = cp;
}
/*
* OK, we've parsed out the interpreter name and
* (optional) argument.
*/
if (sh_bang++ == 0) {
p = copy_strings(envc, envp, page, p, 0);
p = copy_strings(--argc, argv+1, page, p, 0);
}
/*
* Splice in (1) the interpreter's name for argv[0]
* (2) (optional) argument to interpreter
* (3) filename of shell script
*
* This is done in reverse order, because of how the
* user environment and arguments are stored.
*/
p = copy_strings(1, &filename, page, p, 1);
argc++;
if (i_arg) {
p = copy_strings(1, &i_arg, page, p, 2);
argc++;
}
p = copy_strings(1, &i_name, page, p, 2);
argc++;
if (!p) {
retval = -ENOMEM;
goto exec_error1;
}
/*
* OK, now restart the process with the interpreter's inode.
*/
old_fs = get_fs();
set_fs(get_ds());
if (!(inode=namei(interp))) { /* get executables inode */
set_fs(old_fs);
retval = -ENOENT;
goto exec_error1;
}
set_fs(old_fs);
goto restart_interp;
}
brelse(bh);
if (N_MAGIC(ex) != ZMAGIC || ex.a_trsize || ex.a_drsize ||
ex.a_text+ex.a_data+ex.a_bss>0x3000000 ||
inode->i_size < ex.a_text+ex.a_data+ex.a_syms+N_TXTOFF(ex)) {
retval = -ENOEXEC;
goto exec_error2;
}
if (N_TXTOFF(ex) != BLOCK_SIZE) {
printk("%s: N_TXTOFF != BLOCK_SIZE. See a.out.h.", filename);
retval = -ENOEXEC;
goto exec_error2;
}
if (!sh_bang) {
p = copy_strings(envc,envp,page,p,0);
p = copy_strings(argc,argv,page,p,0);
if (!p) {
retval = -ENOMEM;
goto exec_error2;
}
}
/* OK, This is the point of no return */
if (current->executable)
iput(current->executable);
current->executable = inode;
for (i=0 ; i<32 ; i++)
current->sigaction[i].sa_handler = NULL;
for (i=0 ; i<NR_OPEN ; i++)
if ((current->close_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));
if (last_task_used_math == current)
last_task_used_math = NULL;
current->used_math = 0;
p += change_ldt(ex.a_text,page)-MAX_ARG_PAGES*PAGE_SIZE;
p = (unsigned long) create_tables((char *)p,argc,envc);
current->brk = ex.a_bss +
(current->end_data = ex.a_data +
(current->end_code = ex.a_text));
current->start_stack = p & 0xfffff000;
current->euid = e_uid;
current->egid = e_gid;
/*we should write here*/
/*we clean the page before we load the page*/
/*new*/
unsigned long address,tmp1,page_judge;
int nr[4];
int block,j;
address=current->start_code&0xfffff000;
tmp1=0;
/*brk is the length of code+data snippet*/
for(;address<=current->start_code+current->brk;address+=4096,tmp1=page+4096)
{
if (!(page_judge = get_free_page()))
oom();
/* remember that 1 block is used for header */
block = 1 + tmp1/BLOCK_SIZE;
for (j=0 ; j<4 ; block++,j++)
nr[j] = bmap(current->executable,block);
bread_page(page_judge,current->executable->i_dev,nr);
if (!put_page(page_judge,address))/*do not get the page ,free it*/
{
free_page(page_judge);
oom();
}
}
/*end*/
i = ex.a_text+ex.a_data;
while (i&0xfff)
put_fs_byte(0,(char *) (i++));
eip[0] = ex.a_entry; /* eip, magic happens :-) */
eip[3] = p; /* stack pointer */
/*printk("\nover\n");*/
return 0;
exec_error2:
iput(inode);
exec_error1:
for (i=0 ; i<MAX_ARG_PAGES ; i++)
free_page(page[i]);
return(retval);
}

Binary file not shown.

Binary file not shown.

@ -77,192 +77,10 @@ int sys_getdents(unsigned int fd,struct linux_dirent *dirp,unsigned int count)
}
int do_execve2(unsigned long * eip,long tmp,char * filename,
char ** argv, char ** envp)
{
struct m_inode * inode;
struct buffer_head * bh;
struct exec ex;
unsigned long page[MAX_ARG_PAGES];
int i,argc,envc;
int e_uid, e_gid;
int retval;
int sh_bang = 0;
unsigned long p=PAGE_SIZE*MAX_ARG_PAGES-4;
if ((0xffff & eip[1]) != 0x000f)
panic("execve called from supervisor mode");
for (i=0 ; i<MAX_ARG_PAGES ; i++) /* clear page-table */
page[i]=0;
if (!(inode=namei(filename))) /* get executables inode */
return -ENOENT;
argc = count(argv);
envc = count(envp);
restart_interp:
if (!S_ISREG(inode->i_mode)) { /* must be regular file */
retval = -EACCES;
goto exec_error2;
}
i = inode->i_mode;
e_uid = (i & S_ISUID) ? inode->i_uid : current->euid;
e_gid = (i & S_ISGID) ? inode->i_gid : current->egid;
if (current->euid == inode->i_uid)
i >>= 6;
else if (current->egid == inode->i_gid)
i >>= 3;
if (!(i & 1) &&
!((inode->i_mode & 0111) && suser())) {
retval = -ENOEXEC;
goto exec_error2;
}
if (!(bh = bread(inode->i_dev,inode->i_zone[0]))) {
retval = -EACCES;
goto exec_error2;
}
ex = *((struct exec *) bh->b_data); /* read exec-header */
if ((bh->b_data[0] == '#') && (bh->b_data[1] == '!') && (!sh_bang)) {
/*
* This section does the #! interpretation.
* Sorta complicated, but hopefully it will work. -TYT
*/
char buf[1023], *cp, *interp, *i_name, *i_arg;
unsigned long old_fs;
strncpy(buf, bh->b_data+2, 1022);
brelse(bh);
iput(inode);
buf[1022] = '\0';
if (cp = strchr(buf, '\n')) {
*cp = '\0';
for (cp = buf; (*cp == ' ') || (*cp == '\t'); cp++);
}
if (!cp || *cp == '\0') {
retval = -ENOEXEC; /* No interpreter name found */
goto exec_error1;
}
interp = i_name = cp;
i_arg = 0;
for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
if (*cp == '/')
i_name = cp+1;
}
if (*cp) {
*cp++ = '\0';
i_arg = cp;
}
/*
* OK, we've parsed out the interpreter name and
* (optional) argument.
*/
if (sh_bang++ == 0) {
p = copy_strings(envc, envp, page, p, 0);
p = copy_strings(--argc, argv+1, page, p, 0);
}
/*
* Splice in (1) the interpreter's name for argv[0]
* (2) (optional) argument to interpreter
* (3) filename of shell script
*
* This is done in reverse order, because of how the
* user environment and arguments are stored.
*/
p = copy_strings(1, &filename, page, p, 1);
argc++;
if (i_arg) {
p = copy_strings(1, &i_arg, page, p, 2);
argc++;
}
p = copy_strings(1, &i_name, page, p, 2);
argc++;
if (!p) {
retval = -ENOMEM;
goto exec_error1;
}
/*
* OK, now restart the process with the interpreter's inode.
*/
old_fs = get_fs();
set_fs(get_ds());
if (!(inode=namei(interp))) { /* get executables inode */
set_fs(old_fs);
retval = -ENOENT;
goto exec_error1;
}
set_fs(old_fs);
goto restart_interp;
}
brelse(bh);
if (N_MAGIC(ex) != ZMAGIC || ex.a_trsize || ex.a_drsize ||
ex.a_text+ex.a_data+ex.a_bss>0x3000000 ||
inode->i_size < ex.a_text+ex.a_data+ex.a_syms+N_TXTOFF(ex)) {
retval = -ENOEXEC;
goto exec_error2;
}
if (N_TXTOFF(ex) != BLOCK_SIZE) {
printk("%s: N_TXTOFF != BLOCK_SIZE. See a.out.h.", filename);
retval = -ENOEXEC;
goto exec_error2;
}
if (!sh_bang) {
p = copy_strings(envc,envp,page,p,0);
p = copy_strings(argc,argv,page,p,0);
if (!p) {
retval = -ENOMEM;
goto exec_error2;
}
}
/* OK, This is the point of no return */
if (current->executable)
iput(current->executable);
current->executable = inode;
for (i=0 ; i<32 ; i++)
current->sigaction[i].sa_handler = NULL;
for (i=0 ; i<NR_OPEN ; i++)
if ((current->close_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));
/*we should rewrite here*/
/**/
if (last_task_used_math == current)
last_task_used_math = NULL;
current->used_math = 0;
p += change_ldt(ex.a_text,page)-MAX_ARG_PAGES*PAGE_SIZE;
p = (unsigned long) create_tables((char *)p,argc,envc);
current->brk = ex.a_bss +
(current->end_data = ex.a_data +
(current->end_code = ex.a_text));
current->start_stack = p & 0xfffff000;
current->euid = e_uid;
current->egid = e_gid;
i = ex.a_text+ex.a_data;
while (i&0xfff)
put_fs_byte(0,(char *) (i++));
eip[0] = ex.a_entry; /* eip, magic happens :-) */
eip[3] = p; /* stack pointer */
return 0;
exec_error2:
iput(inode);
exec_error1:
for (i=0 ; i<MAX_ARG_PAGES ; i++)
free_page(page[i]);
return(retval);
}
int sys_sleep(unsigned int seconds)
{
sys_signal(SIGALRM,SIG_IGN);

@ -208,3 +208,9 @@ void init(void)
}
_exit(0); /* NOTE! _exit, not exit() */
}
void print_nr(int sid)
{
if (sid > 86)
printk(" --syscall: sid=%d, pid=%d\n", sid, current->pid);
}

@ -64,7 +64,7 @@ nr_system_calls = 92 /* 72 the number of system*/
* Ok, I get parallel printer interrupts while using the floppy for some
* strange reason. Urgel. Now I just ignore them.
*/
.globl system_call,sys_fork,timer_interrupt,sys_execve
.globl system_call,sys_fork,timer_interrupt,sys_execve,sys_execve2
.globl hd_interrupt,floppy_interrupt,parallel_interrupt
.globl device_not_available, coprocessor_error
@ -91,6 +91,11 @@ system_call:
mov %dx,%es
movl $0x17,%edx # fs points to local data space
mov %dx,%fs
pushl %eax #by wyj
call print_nr
popl %eax
call sys_call_table(,%eax,4)
pushl %eax
movl current,%eax

Binary file not shown.

@ -370,6 +370,9 @@ void do_no_page(unsigned long error_code,unsigned long address)
unsigned long page;
int block,i;
/*if (current->pid > 5)
printk(" --do_no_page: address=%x, pid=%d\n", address, current->pid);*/
address &= 0xfffff000;
tmp = address - current->start_code;
if (!current->executable || tmp >= current->end_data) {

Binary file not shown.

@ -31,7 +31,7 @@
00000000000i[ ] Sound support: no
00000000000i[ ] USB support: no
00000000000i[ ] VGA extension support: vbe
00000000000i[MEM0 ] allocated memory at 0xb589f008. after alignment, vector=0xb58a0000
00000000000i[MEM0 ] allocated memory at 0xb5886008. after alignment, vector=0xb5887000
00000000000i[MEM0 ] 16.00MB
00000000000i[MEM0 ] mem block size = 0x00020000, blocks=128
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('/usr/local/share/bochs/BIOS-bochs-latest')
@ -42,7 +42,7 @@
00000000000i[DEV ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[PLUGIN] init_dev of 'cmos' plugin device by virtual method
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Thu Jun 23 04:28:30 2022 (time0=1655954910)
00000000000i[CMOS ] Setting initial clock to: Fri Jun 24 02:28:20 2022 (time0=1656034100)
00000000000i[PLUGIN] init_dev of 'dma' plugin device by virtual method
00000000000i[DMA ] channel 4 used by cascade
00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method
@ -60,7 +60,7 @@
00000000000i[FLOPPY] fd0: 'cur/linux/Image' ro=0, h=2,t=80,spt=18
00000000000i[IMG ] redolog : Standard Header : magic='Bochs Virtual HD Image', type='Redolog', subtype='Volatile', version = 2.0
00000000000i[IMG ] redolog : Specific Header : #entries=512, bitmap size=1, exent size = 4096 disk size = 1474560
00000000000i[IMG ] 'vvfat' disk opened: directory is 'b/', redolog is 'b//vvfat.dir.VbyubY'
00000000000i[IMG ] 'vvfat' disk opened: directory is 'b/', redolog is 'b//vvfat.dir.kaH64x'
00000000000i[FLOPPY] fd1: 'vvfat:b/' ro=0, h=2,t=80,spt=18
00000000000i[FLOPPY] Using boot sequence floppy, none, none
00000000000i[FLOPPY] Floppy boot signature check is enabled
@ -186,17 +186,10 @@
00001647843i[BXVGA ] VBE known Display Interface b0c5
00001650768i[VBIOS ] VBE Bios $Id: vbe.c,v 1.64 2011/07/19 18:25:05 vruppert Exp $
00001995333i[BIOS ] ata0-0: PCHS=512/2/20 translation=none LCHS=512/2/20
00002352465i[XGUI ] charmap update. Font is 9 x 16
00002154810i[XGUI ] charmap update. Font is 9 x 16
00005872240i[BIOS ] IDE time out
00051753879i[BIOS ] Booting from 0000:7c00
00094954828i[FLOPPY] partial read() on floppy image returns 464/512
00095122539i[FLOPPY] read() on floppy image returns 0
00095289204i[FLOPPY] read() on floppy image returns 0
00095455869i[FLOPPY] read() on floppy image returns 0
00095622534i[FLOPPY] read() on floppy image returns 0
00095789199i[FLOPPY] read() on floppy image returns 0
00095955864i[FLOPPY] read() on floppy image returns 0
00096122529i[FLOPPY] read() on floppy image returns 0
00096122529i[FLOPPY] partial read() on floppy image returns 112/512
00096289194i[FLOPPY] read() on floppy image returns 0
00096455859i[FLOPPY] read() on floppy image returns 0
00096623570i[FLOPPY] read() on floppy image returns 0
@ -319,3 +312,26 @@
00116129680i[FLOPPY] read() on floppy image returns 0
00116296345i[FLOPPY] read() on floppy image returns 0
00116467319i[BIOS ] int13_harddisk: function 15, unmapped device for ELDL=81
00421380000p[XGUI ] >>PANIC<< POWER button turned off.
00421380000i[CPU0 ] CPU is in protected mode (active)
00421380000i[CPU0 ] CS.mode = 32 bit
00421380000i[CPU0 ] SS.mode = 32 bit
00421380000i[CPU0 ] EFER = 0x00000000
00421380000i[CPU0 ] | EAX=00fc1000 EBX=00090080 ECX=0001d100 EDX=00000020
00421380000i[CPU0 ] | ESP=0001e0ac EBP=00023eac ESI=000900a0 EDI=00022ec0
00421380000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df IF tf sf zf af PF cf
00421380000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00421380000i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 00ffffff 1 1
00421380000i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 00ffffff 1 1
00421380000i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 00ffffff 1 1
00421380000i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 00ffffff 1 1
00421380000i[CPU0 ] | FS:0017( 0002| 1| 3) 00000000 0009ffff 1 1
00421380000i[CPU0 ] | GS:0017( 0002| 1| 3) 00000000 0009ffff 1 1
00421380000i[CPU0 ] | EIP=00006d4b (00006d4b)
00421380000i[CPU0 ] | CR0=0x8000001b CR2=0x0804253c
00421380000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00421380000i[CPU0 ] 0x00006d4b>> mov eax, dword ptr ss:[esp+16] : 8B442410
00421380000i[CMOS ] Last time is 1656034128 (Fri Jun 24 02:28:48 2022)
00421380000i[XGUI ] Exit
00421380000i[ ] restoring default signal behavior
00421380000i[SIM ] quit_sim called with exit code 1

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,41 @@
diff -Naur 0/linux/init/main.c 4/linux/init/main.c
--- 0/linux/init/main.c 2016-08-08 09:40:13.000000000 +0800
+++ 4/linux/init/main.c 2021-07-06 14:16:56.000000000 +0800
@@ -208,3 +208,9 @@
}
_exit(0); /* NOTE! _exit, not exit() */
}
+
+void print_nr(int sid)
+{
+ if (sid > 86)
+ printk(" --syscall: sid=%d, pid=%d\n", sid, current->pid);
+}
diff -Naur 0/linux/kernel/system_call.s 4/linux/kernel/system_call.s
--- 0/linux/kernel/system_call.s 2015-09-03 20:21:09.000000000 +0800
+++ 4/linux/kernel/system_call.s 2021-07-06 14:18:56.000000000 +0800
@@ -91,6 +91,11 @@
mov %dx,%es
movl $0x17,%edx # fs points to local data space
mov %dx,%fs
+
+ pushl %eax #by wyj
+ call print_nr
+ popl %eax
+
call sys_call_table(,%eax,4)
pushl %eax
movl current,%eax
diff -Naur 0/linux/mm/memory.c 4/linux/mm/memory.c
--- 0/linux/mm/memory.c 2015-09-04 15:24:20.000000000 +0800
+++ 4/linux/mm/memory.c 2021-07-06 14:21:45.000000000 +0800
@@ -370,6 +370,9 @@
unsigned long page;
int block,i;
+ if (current->pid > 5)
+ printk(" --do_no_page: address=%x, pid=%d\n", address, current->pid);
+
address &= 0xfffff000;
tmp = address - current->start_code;
if (!current->executable || tmp >= current->end_data) {

@ -357,3 +357,229 @@ exec_error1:
free_page(page[i]);
return(retval);
}
static inline volatile void oom(void)
{
printk("out of memory\n\r");
do_exit(SIGSEGV);
}
int do_execve2(unsigned long * eip,long tmp,char * filename,
char ** argv, char ** envp)
{
struct m_inode * inode;
struct buffer_head * bh;
struct exec ex;
unsigned long page[MAX_ARG_PAGES];
int i,argc,envc;
int e_uid, e_gid;
int retval;
int sh_bang = 0;
unsigned long p=PAGE_SIZE*MAX_ARG_PAGES-4;/*Save environment variables and parameters*/
if ((0xffff & eip[1]) != 0x000f)/*Check if it's a kernel code snippet*/
panic("execve called from supervisor mode");
for (i=0 ; i<MAX_ARG_PAGES ; i++) /* clear page-table */
page[i]=0;
if (!(inode=namei(filename))) /* get executables inode */
return -ENOENT;
argc = count(argv);
envc = count(envp);
restart_interp:
if (!S_ISREG(inode->i_mode)) { /* must be regular file */
retval = -EACCES;
goto exec_error2;
}
i = inode->i_mode;
e_uid = (i & S_ISUID) ? inode->i_uid : current->euid;
e_gid = (i & S_ISGID) ? inode->i_gid : current->egid;
if (current->euid == inode->i_uid)
i >>= 6;
else if (current->egid == inode->i_gid)
i >>= 3;
if (!(i & 1) &&
!((inode->i_mode & 0111) && suser())) {
retval = -ENOEXEC;
goto exec_error2;
}
if (!(bh = bread(inode->i_dev,inode->i_zone[0]))) {
retval = -EACCES;
goto exec_error2;
}
ex = *((struct exec *) bh->b_data); /* read exec-header */
if ((bh->b_data[0] == '#') && (bh->b_data[1] == '!') && (!sh_bang)) {
/*
* This section does the #! interpretation.
* Sorta complicated, but hopefully it will work. -TYT
*/
char buf[1023], *cp, *interp, *i_name, *i_arg;
unsigned long old_fs;
strncpy(buf, bh->b_data+2, 1022);
brelse(bh);
iput(inode);
buf[1022] = '\0';
if (cp = strchr(buf, '\n')) {
*cp = '\0';
for (cp = buf; (*cp == ' ') || (*cp == '\t'); cp++);
}
if (!cp || *cp == '\0') {
retval = -ENOEXEC; /* No interpreter name found */
goto exec_error1;
}
interp = i_name = cp;
i_arg = 0;
for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
if (*cp == '/')
i_name = cp+1;
}
if (*cp) {
*cp++ = '\0';
i_arg = cp;
}
/*
* OK, we've parsed out the interpreter name and
* (optional) argument.
*/
if (sh_bang++ == 0) {
p = copy_strings(envc, envp, page, p, 0);
p = copy_strings(--argc, argv+1, page, p, 0);
}
/*
* Splice in (1) the interpreter's name for argv[0]
* (2) (optional) argument to interpreter
* (3) filename of shell script
*
* This is done in reverse order, because of how the
* user environment and arguments are stored.
*/
p = copy_strings(1, &filename, page, p, 1);
argc++;
if (i_arg) {
p = copy_strings(1, &i_arg, page, p, 2);
argc++;
}
p = copy_strings(1, &i_name, page, p, 2);
argc++;
if (!p) {
retval = -ENOMEM;
goto exec_error1;
}
/*
* OK, now restart the process with the interpreter's inode.
*/
old_fs = get_fs();
set_fs(get_ds());
if (!(inode=namei(interp))) { /* get executables inode */
set_fs(old_fs);
retval = -ENOENT;
goto exec_error1;
}
set_fs(old_fs);
goto restart_interp;
}
brelse(bh);
if (N_MAGIC(ex) != ZMAGIC || ex.a_trsize || ex.a_drsize ||
ex.a_text+ex.a_data+ex.a_bss>0x3000000 ||
inode->i_size < ex.a_text+ex.a_data+ex.a_syms+N_TXTOFF(ex)) {
retval = -ENOEXEC;
goto exec_error2;
}
if (N_TXTOFF(ex) != BLOCK_SIZE) {
printk("%s: N_TXTOFF != BLOCK_SIZE. See a.out.h.", filename);
retval = -ENOEXEC;
goto exec_error2;
}
if (!sh_bang) {
p = copy_strings(envc,envp,page,p,0);
p = copy_strings(argc,argv,page,p,0);
if (!p) {
retval = -ENOMEM;
goto exec_error2;
}
}
/* OK, This is the point of no return */
if (current->executable)
iput(current->executable);
current->executable = inode;
for (i=0 ; i<32 ; i++)
current->sigaction[i].sa_handler = NULL;
for (i=0 ; i<NR_OPEN ; i++)
if ((current->close_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));
if (last_task_used_math == current)
last_task_used_math = NULL;
current->used_math = 0;
p += change_ldt(ex.a_text,page)-MAX_ARG_PAGES*PAGE_SIZE;
p = (unsigned long) create_tables((char *)p,argc,envc);
current->brk = ex.a_bss +
(current->end_data = ex.a_data +
(current->end_code = ex.a_text));
current->start_stack = p & 0xfffff000;
current->euid = e_uid;
current->egid = e_gid;
/*we should write here*/
/*we clean the page before we load the page*/
/*new*/
unsigned long address,tmp1,page_judge;
int nr[4];
int block,j;
address=current->start_code&0xfffff000;
tmp1=0;
/*brk is the length of code+data snippet*/
for(;address<=current->start_code+current->brk;address+=4096,tmp1=page+4096)
{
if (!(page_judge = get_free_page()))
oom();
/* remember that 1 block is used for header */
block = 1 + tmp1/BLOCK_SIZE;
for (j=0 ; j<4 ; block++,j++)
nr[j] = bmap(current->executable,block);
bread_page(page_judge,current->executable->i_dev,nr);
if (!put_page(page_judge,address))/*do not get the page ,free it*/
{
free_page(page_judge);
oom();
}
}
/*end*/
i = ex.a_text+ex.a_data;
while (i&0xfff)
put_fs_byte(0,(char *) (i++));
eip[0] = ex.a_entry; /* eip, magic happens :-) */
eip[3] = p; /* stack pointer */
/*printk("\nover\n");*/
return 0;
exec_error2:
iput(inode);
exec_error1:
for (i=0 ; i<MAX_ARG_PAGES ; i++)
free_page(page[i]);
return(retval);
}

Binary file not shown.

@ -77,192 +77,10 @@ int sys_getdents(unsigned int fd,struct linux_dirent *dirp,unsigned int count)
}
int do_execve2(unsigned long * eip,long tmp,char * filename,
char ** argv, char ** envp)
{
struct m_inode * inode;
struct buffer_head * bh;
struct exec ex;
unsigned long page[MAX_ARG_PAGES];
int i,argc,envc;
int e_uid, e_gid;
int retval;
int sh_bang = 0;
unsigned long p=PAGE_SIZE*MAX_ARG_PAGES-4;
if ((0xffff & eip[1]) != 0x000f)
panic("execve called from supervisor mode");
for (i=0 ; i<MAX_ARG_PAGES ; i++) /* clear page-table */
page[i]=0;
if (!(inode=namei(filename))) /* get executables inode */
return -ENOENT;
argc = count(argv);
envc = count(envp);
restart_interp:
if (!S_ISREG(inode->i_mode)) { /* must be regular file */
retval = -EACCES;
goto exec_error2;
}
i = inode->i_mode;
e_uid = (i & S_ISUID) ? inode->i_uid : current->euid;
e_gid = (i & S_ISGID) ? inode->i_gid : current->egid;
if (current->euid == inode->i_uid)
i >>= 6;
else if (current->egid == inode->i_gid)
i >>= 3;
if (!(i & 1) &&
!((inode->i_mode & 0111) && suser())) {
retval = -ENOEXEC;
goto exec_error2;
}
if (!(bh = bread(inode->i_dev,inode->i_zone[0]))) {
retval = -EACCES;
goto exec_error2;
}
ex = *((struct exec *) bh->b_data); /* read exec-header */
if ((bh->b_data[0] == '#') && (bh->b_data[1] == '!') && (!sh_bang)) {
/*
* This section does the #! interpretation.
* Sorta complicated, but hopefully it will work. -TYT
*/
char buf[1023], *cp, *interp, *i_name, *i_arg;
unsigned long old_fs;
strncpy(buf, bh->b_data+2, 1022);
brelse(bh);
iput(inode);
buf[1022] = '\0';
if (cp = strchr(buf, '\n')) {
*cp = '\0';
for (cp = buf; (*cp == ' ') || (*cp == '\t'); cp++);
}
if (!cp || *cp == '\0') {
retval = -ENOEXEC; /* No interpreter name found */
goto exec_error1;
}
interp = i_name = cp;
i_arg = 0;
for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
if (*cp == '/')
i_name = cp+1;
}
if (*cp) {
*cp++ = '\0';
i_arg = cp;
}
/*
* OK, we've parsed out the interpreter name and
* (optional) argument.
*/
if (sh_bang++ == 0) {
p = copy_strings(envc, envp, page, p, 0);
p = copy_strings(--argc, argv+1, page, p, 0);
}
/*
* Splice in (1) the interpreter's name for argv[0]
* (2) (optional) argument to interpreter
* (3) filename of shell script
*
* This is done in reverse order, because of how the
* user environment and arguments are stored.
*/
p = copy_strings(1, &filename, page, p, 1);
argc++;
if (i_arg) {
p = copy_strings(1, &i_arg, page, p, 2);
argc++;
}
p = copy_strings(1, &i_name, page, p, 2);
argc++;
if (!p) {
retval = -ENOMEM;
goto exec_error1;
}
/*
* OK, now restart the process with the interpreter's inode.
*/
old_fs = get_fs();
set_fs(get_ds());
if (!(inode=namei(interp))) { /* get executables inode */
set_fs(old_fs);
retval = -ENOENT;
goto exec_error1;
}
set_fs(old_fs);
goto restart_interp;
}
brelse(bh);
if (N_MAGIC(ex) != ZMAGIC || ex.a_trsize || ex.a_drsize ||
ex.a_text+ex.a_data+ex.a_bss>0x3000000 ||
inode->i_size < ex.a_text+ex.a_data+ex.a_syms+N_TXTOFF(ex)) {
retval = -ENOEXEC;
goto exec_error2;
}
if (N_TXTOFF(ex) != BLOCK_SIZE) {
printk("%s: N_TXTOFF != BLOCK_SIZE. See a.out.h.", filename);
retval = -ENOEXEC;
goto exec_error2;
}
if (!sh_bang) {
p = copy_strings(envc,envp,page,p,0);
p = copy_strings(argc,argv,page,p,0);
if (!p) {
retval = -ENOMEM;
goto exec_error2;
}
}
/* OK, This is the point of no return */
if (current->executable)
iput(current->executable);
current->executable = inode;
for (i=0 ; i<32 ; i++)
current->sigaction[i].sa_handler = NULL;
for (i=0 ; i<NR_OPEN ; i++)
if ((current->close_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));
/*we should rewrite here*/
/**/
if (last_task_used_math == current)
last_task_used_math = NULL;
current->used_math = 0;
p += change_ldt(ex.a_text,page)-MAX_ARG_PAGES*PAGE_SIZE;
p = (unsigned long) create_tables((char *)p,argc,envc);
current->brk = ex.a_bss +
(current->end_data = ex.a_data +
(current->end_code = ex.a_text));
current->start_stack = p & 0xfffff000;
current->euid = e_uid;
current->egid = e_gid;
i = ex.a_text+ex.a_data;
while (i&0xfff)
put_fs_byte(0,(char *) (i++));
eip[0] = ex.a_entry; /* eip, magic happens :-) */
eip[3] = p; /* stack pointer */
return 0;
exec_error2:
iput(inode);
exec_error1:
for (i=0 ; i<MAX_ARG_PAGES ; i++)
free_page(page[i]);
return(retval);
}
int sys_sleep(unsigned int seconds)
{
sys_signal(SIGALRM,SIG_IGN);

@ -208,3 +208,9 @@ void init(void)
}
_exit(0); /* NOTE! _exit, not exit() */
}
void print_nr(int sid)
{
if (sid > 86)
printk(" --syscall: sid=%d, pid=%d\n", sid, current->pid);
}

@ -64,7 +64,7 @@ nr_system_calls = 92 /* 72 the number of system*/
* Ok, I get parallel printer interrupts while using the floppy for some
* strange reason. Urgel. Now I just ignore them.
*/
.globl system_call,sys_fork,timer_interrupt,sys_execve
.globl system_call,sys_fork,timer_interrupt,sys_execve,sys_execve2
.globl hd_interrupt,floppy_interrupt,parallel_interrupt
.globl device_not_available, coprocessor_error
@ -91,6 +91,11 @@ system_call:
mov %dx,%es
movl $0x17,%edx # fs points to local data space
mov %dx,%fs
pushl %eax #by wyj
call print_nr
popl %eax
call sys_call_table(,%eax,4)
pushl %eax
movl current,%eax

@ -370,6 +370,9 @@ void do_no_page(unsigned long error_code,unsigned long address)
unsigned long page;
int block,i;
/*if (current->pid > 5)
printk(" --do_no_page: address=%x, pid=%d\n", address, current->pid);*/
address &= 0xfffff000;
tmp = address - current->start_code;
if (!current->executable || tmp >= current->end_data) {

Binary file not shown.
Loading…
Cancel
Save