root/fs/exec.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. core_dump
  2. sys_uselib
  3. create_tables
  4. count
  5. copy_strings
  6. change_ldt
  7. read_exec
  8. do_execve

   1 /*
   2  *  linux/fs/exec.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 /*
   8  * #!-checking implemented by tytso.
   9  */
  10 
  11 /*
  12  * Demand-loading implemented 01.12.91 - no need to read anything but
  13  * the header into memory. The inode of the executable is put into
  14  * "current->executable", and page faults do the actual loading. Clean.
  15  *
  16  * Once more I can proudly say that linux stood up to being changed: it
  17  * was less than 2 hours work to get demand-loading completely implemented.
  18  */
  19 
  20 #include <linux/fs.h>
  21 #include <linux/sched.h>
  22 #include <linux/kernel.h>
  23 #include <linux/mm.h>
  24 #include <linux/a.out.h>
  25 #include <linux/errno.h>
  26 #include <linux/signal.h>
  27 #include <linux/string.h>
  28 #include <linux/stat.h>
  29 #include <linux/fcntl.h>
  30 #include <linux/ptrace.h>
  31 #include <linux/user.h>
  32 
  33 #include <asm/segment.h>
  34 
  35 extern int sys_exit(int exit_code);
  36 extern int sys_close(int fd);
  37 
  38 /*
  39  * MAX_ARG_PAGES defines the number of pages allocated for arguments
  40  * and envelope for the new program. 32 should suffice, this gives
  41  * a maximum env+arg of 128kB !
  42  */
  43 #define MAX_ARG_PAGES 32
  44 
  45 /*
  46  * These are the only things you should do on a core-file: use only these
  47  * macros to write out all the necessary info.
  48  */
  49 #define DUMP_WRITE(addr,nr) \
  50 while (file.f_op->write(inode,&file,(char *)(addr),(nr)) != (nr)) goto close_coredump
  51 
  52 #define DUMP_SEEK(offset) \
  53 if (file.f_op->lseek) { \
  54         if (file.f_op->lseek(inode,&file,(offset),0) != (offset)) \
  55                 goto close_coredump; \
  56 } else file.f_pos = (offset)            
  57 
  58 /*
  59  * Routine writes a core dump image in the current directory.
  60  * Currently only a stub-function.
  61  *
  62  * Note that setuid/setgid files won't make a core-dump if the uid/gid
  63  * changed due to the set[u|g]id. It's enforced by the "current->dumpable"
  64  * field, which also makes sure the core-dumps won't be recursive if the
  65  * dumping of the process results in another error..
  66  */
  67 int core_dump(long signr, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  68 {
  69         struct inode * inode = NULL;
  70         struct file file;
  71         unsigned short fs;
  72         int has_dumped = 0;
  73         register int dump_start, dump_size;
  74         struct user dump;
  75 
  76         if (!current->dumpable)
  77                 return 0;
  78         current->dumpable = 0;
  79 /* See if we have enough room to write the upage.  */
  80         if (current->rlim[RLIMIT_CORE].rlim_cur < PAGE_SIZE)
  81                 return 0;
  82         __asm__("mov %%fs,%0":"=r" (fs));
  83         __asm__("mov %0,%%fs"::"r" ((unsigned short) 0x10));
  84         if (open_namei("core",O_CREAT | O_WRONLY | O_TRUNC,0600,&inode,NULL)) {
  85                 inode = NULL;
  86                 goto end_coredump;
  87         }
  88         if (!S_ISREG(inode->i_mode))
  89                 goto end_coredump;
  90         if (!inode->i_op || !inode->i_op->default_file_ops)
  91                 goto end_coredump;
  92         file.f_mode = 3;
  93         file.f_flags = 0;
  94         file.f_count = 1;
  95         file.f_inode = inode;
  96         file.f_pos = 0;
  97         file.f_reada = 0;
  98         file.f_op = inode->i_op->default_file_ops;
  99         if (file.f_op->open)
 100                 if (file.f_op->open(inode,&file))
 101                         goto end_coredump;
 102         if (!file.f_op->write)
 103                 goto close_coredump;
 104         has_dumped = 1;
 105 /* changed the size calculations - should hopefully work better. lbt */
 106         dump.magic = CMAGIC;
 107         dump.start_code = 0;
 108         dump.start_stack = regs->esp & ~(PAGE_SIZE - 1);
 109         dump.u_tsize = ((unsigned long) current->end_code) >> 12;
 110         dump.u_dsize = ((unsigned long) (current->brk + (PAGE_SIZE-1))) >> 12;
 111         dump.u_dsize -= dump.u_tsize;
 112         dump.u_ssize = 0;
 113         if (dump.start_stack < TASK_SIZE)
 114                 dump.u_ssize = ((unsigned long) (TASK_SIZE - dump.start_stack)) >> 12;
 115 /* If the size of the dump file exceeds the rlimit, then see what would happen
 116    if we wrote the stack, but not the data area.  */
 117         if ((dump.u_dsize+dump.u_ssize+1) * PAGE_SIZE >
 118             current->rlim[RLIMIT_CORE].rlim_cur)
 119                 dump.u_dsize = 0;
 120 /* Make sure we have enough room to write the stack and data areas. */
 121         if ((dump.u_ssize+1) * PAGE_SIZE >
 122             current->rlim[RLIMIT_CORE].rlim_cur)
 123                 dump.u_ssize = 0;
 124         dump.u_comm = 0;
 125         dump.u_ar0 = (struct pt_regs *)(((int)(&dump.regs)) -((int)(&dump)));
 126         dump.signal = signr;
 127         dump.regs = *regs;
 128 /* Flag indicating the math stuff is valid. We don't support this for the
 129    soft-float routines yet */
 130         if (hard_math) {
 131                 if ((dump.u_fpvalid = current->used_math) != 0) {
 132                         if (last_task_used_math == current)
 133                                 __asm__("clts ; fnsave %0"::"m" (dump.i387));
 134                         else
 135                                 memcpy(&dump.i387,&current->tss.i387.hard,sizeof(dump.i387));
 136                 }
 137         } else {
 138                 /* we should dump the emulator state here, but we need to
 139                    convert it into standard 387 format first.. */
 140                 dump.u_fpvalid = 0;
 141         }
 142         __asm__("mov %0,%%fs"::"r" ((unsigned short) 0x10));
 143 /* struct user */
 144         DUMP_WRITE(&dump,sizeof(dump));
 145 /* name of the executable */
 146         DUMP_WRITE(current->comm,16);
 147 /* Now dump all of the user data.  Include malloced stuff as well */
 148         DUMP_SEEK(PAGE_SIZE);
 149 /* now we start writing out the user space info */
 150         __asm__("mov %0,%%fs"::"r" ((unsigned short) 0x17));
 151 /* Dump the data area */
 152         if (dump.u_dsize != 0) {
 153                 dump_start = dump.u_tsize << 12;
 154                 dump_size = dump.u_dsize << 12;
 155                 DUMP_WRITE(dump_start,dump_size);
 156         };
 157 /* Now prepare to dump the stack area */
 158         if (dump.u_ssize != 0) {
 159                 dump_start = dump.start_stack;
 160                 dump_size = dump.u_ssize << 12;
 161                 DUMP_WRITE(dump_start,dump_size);
 162         };
 163 /* Finally dump the task struct.  Not be used by gdb, but could be useful */
 164         __asm__("mov %0,%%fs"::"r" ((unsigned short) 0x10));
 165         DUMP_WRITE(current,sizeof(*current));
 166 close_coredump:
 167         if (file.f_op->release)
 168                 file.f_op->release(inode,&file);
 169 end_coredump:
 170         __asm__("mov %0,%%fs"::"r" (fs));
 171         iput(inode);
 172         return has_dumped;
 173 }
 174 
 175 /*
 176  * Note that a shared library must be both readable and executable due to
 177  * security reasons.
 178  *
 179  * Also note that we take the address to load from from the file itself.
 180  */
 181 int sys_uselib(const char * library)
     /* [previous][next][first][last][top][bottom][index][help] */
 182 {
 183 #define libnum  (current->numlibraries)
 184         struct inode * inode;
 185         struct buffer_head * bh;
 186         struct exec ex;
 187         int error;
 188 
 189         if (!library || get_limit(0x17) != TASK_SIZE)
 190                 return -EINVAL;
 191         if ((libnum >= MAX_SHARED_LIBS) || (libnum < 0))
 192                 return -EINVAL;
 193         error = namei(library,&inode);
 194         if (error)
 195                 return error;
 196         if (!inode->i_sb || !S_ISREG(inode->i_mode) || !permission(inode,MAY_READ)) {
 197                 iput(inode);
 198                 return -EACCES;
 199         }
 200         if (!inode->i_op || !inode->i_op->bmap) {
 201                 iput(inode);
 202                 return -ENOEXEC;
 203         }
 204         if (!(bh = bread(inode->i_dev,bmap(inode,0),inode->i_sb->s_blocksize))) {
 205                 iput(inode);
 206                 return -EACCES;
 207         }
 208         if (!IS_RDONLY(inode)) {
 209                 inode->i_atime = CURRENT_TIME;
 210                 inode->i_dirt = 1;
 211         }
 212         ex = *(struct exec *) bh->b_data;
 213         brelse(bh);
 214         if (N_MAGIC(ex) != ZMAGIC || ex.a_trsize || ex.a_drsize ||
 215                 ex.a_text+ex.a_data+ex.a_bss>0x3000000 ||
 216                 inode->i_size < ex.a_text+ex.a_data+ex.a_syms+N_TXTOFF(ex)) {
 217                 iput(inode);
 218                 return -ENOEXEC;
 219         }
 220         current->libraries[libnum].library = inode;
 221         current->libraries[libnum].start = ex.a_entry;
 222         current->libraries[libnum].length = (ex.a_data+ex.a_text+0xfff) & 0xfffff000;
 223         current->libraries[libnum].bss = (ex.a_bss+0xfff) & 0xfffff000;
 224 #if 0
 225         printk("Loaded library %d at %08x, length %08x\n",
 226                 libnum,
 227                 current->libraries[libnum].start,
 228                 current->libraries[libnum].length);
 229 #endif
 230         libnum++;
 231         return 0;
 232 #undef libnum
 233 }
 234 
 235 /*
 236  * create_tables() parses the env- and arg-strings in new user
 237  * memory and creates the pointer tables from them, and puts their
 238  * addresses on the "stack", returning the new stack pointer value.
 239  */
 240 static unsigned long * create_tables(char * p,int argc,int envc)
     /* [previous][next][first][last][top][bottom][index][help] */
 241 {
 242         unsigned long *argv,*envp;
 243         unsigned long * sp;
 244 
 245         sp = (unsigned long *) (0xfffffffc & (unsigned long) p);
 246         sp -= envc+1;
 247         envp = sp;
 248         sp -= argc+1;
 249         argv = sp;
 250         put_fs_long((unsigned long)envp,--sp);
 251         put_fs_long((unsigned long)argv,--sp);
 252         put_fs_long((unsigned long)argc,--sp);
 253         current->arg_start = (unsigned long) p;
 254         while (argc-->0) {
 255                 put_fs_long((unsigned long) p,argv++);
 256                 while (get_fs_byte(p++)) /* nothing */ ;
 257         }
 258         put_fs_long(0,argv);
 259         current->arg_end = current->env_start = (unsigned long) p;
 260         while (envc-->0) {
 261                 put_fs_long((unsigned long) p,envp++);
 262                 while (get_fs_byte(p++)) /* nothing */ ;
 263         }
 264         put_fs_long(0,envp);
 265         current->env_end = (unsigned long) p;
 266         return sp;
 267 }
 268 
 269 /*
 270  * count() counts the number of arguments/envelopes
 271  */
 272 static int count(char ** argv)
     /* [previous][next][first][last][top][bottom][index][help] */
 273 {
 274         int i=0;
 275         char ** tmp;
 276 
 277         if ((tmp = argv) != 0)
 278                 while (get_fs_long((unsigned long *) (tmp++)))
 279                         i++;
 280 
 281         return i;
 282 }
 283 
 284 /*
 285  * 'copy_string()' copies argument/envelope strings from user
 286  * memory to free pages in kernel mem. These are in a format ready
 287  * to be put directly into the top of new user memory.
 288  *
 289  * Modified by TYT, 11/24/91 to add the from_kmem argument, which specifies
 290  * whether the string and the string array are from user or kernel segments:
 291  * 
 292  * from_kmem     argv *        argv **
 293  *    0          user space    user space
 294  *    1          kernel space  user space
 295  *    2          kernel space  kernel space
 296  * 
 297  * We do this by playing games with the fs segment register.  Since it
 298  * it is expensive to load a segment register, we try to avoid calling
 299  * set_fs() unless we absolutely have to.
 300  */
 301 static unsigned long copy_strings(int argc,char ** argv,unsigned long *page,
     /* [previous][next][first][last][top][bottom][index][help] */
 302                 unsigned long p, int from_kmem)
 303 {
 304         char *tmp, *pag = NULL;
 305         int len, offset = 0;
 306         unsigned long old_fs, new_fs;
 307 
 308         if (!p)
 309                 return 0;       /* bullet-proofing */
 310         new_fs = get_ds();
 311         old_fs = get_fs();
 312         if (from_kmem==2)
 313                 set_fs(new_fs);
 314         while (argc-- > 0) {
 315                 if (from_kmem == 1)
 316                         set_fs(new_fs);
 317                 if (!(tmp = (char *)get_fs_long(((unsigned long *)argv)+argc)))
 318                         panic("argc is wrong");
 319                 if (from_kmem == 1)
 320                         set_fs(old_fs);
 321                 len=0;          /* remember zero-padding */
 322                 do {
 323                         len++;
 324                 } while (get_fs_byte(tmp++));
 325                 if (p < len) {  /* this shouldn't happen - 128kB */
 326                         set_fs(old_fs);
 327                         return 0;
 328                 }
 329                 while (len) {
 330                         --p; --tmp; --len;
 331                         if (--offset < 0) {
 332                                 offset = p % PAGE_SIZE;
 333                                 if (from_kmem==2)
 334                                         set_fs(old_fs);
 335                                 if (!(pag = (char *) page[p/PAGE_SIZE]) &&
 336                                     !(pag = (char *) page[p/PAGE_SIZE] =
 337                                       (unsigned long *) get_free_page(GFP_USER))) 
 338                                         return 0;
 339                                 if (from_kmem==2)
 340                                         set_fs(new_fs);
 341 
 342                         }
 343                         *(pag + offset) = get_fs_byte(tmp);
 344                 }
 345         }
 346         if (from_kmem==2)
 347                 set_fs(old_fs);
 348         return p;
 349 }
 350 
 351 static unsigned long change_ldt(unsigned long text_size,unsigned long * page)
     /* [previous][next][first][last][top][bottom][index][help] */
 352 {
 353         unsigned long code_limit,data_limit,code_base,data_base;
 354         int i;
 355 
 356         code_limit = TASK_SIZE;
 357         data_limit = TASK_SIZE;
 358         code_base = data_base = 0;
 359         current->start_code = code_base;
 360         set_base(current->ldt[1],code_base);
 361         set_limit(current->ldt[1],code_limit);
 362         set_base(current->ldt[2],data_base);
 363         set_limit(current->ldt[2],data_limit);
 364 /* make sure fs points to the NEW data segment */
 365         __asm__("pushl $0x17\n\tpop %%fs"::);
 366         data_base += data_limit;
 367         for (i=MAX_ARG_PAGES-1 ; i>=0 ; i--) {
 368                 data_base -= PAGE_SIZE;
 369                 if (page[i])
 370                         put_dirty_page(current,page[i],data_base);
 371         }
 372         return data_limit;
 373 }
 374 
 375 /*
 376  * Read in the complete executable. This is used for "-N" files
 377  * that aren't on a block boundary, and for files on filesystems
 378  * without bmap support.
 379  */
 380 static int read_exec(struct inode *inode, unsigned long offset,
     /* [previous][next][first][last][top][bottom][index][help] */
 381         char * addr, unsigned long count)
 382 {
 383         struct file file;
 384         int result = -ENOEXEC;
 385 
 386         if (!inode->i_op || !inode->i_op->default_file_ops)
 387                 goto end_readexec;
 388         file.f_mode = 1;
 389         file.f_flags = 0;
 390         file.f_count = 1;
 391         file.f_inode = inode;
 392         file.f_pos = 0;
 393         file.f_reada = 0;
 394         file.f_op = inode->i_op->default_file_ops;
 395         if (file.f_op->open)
 396                 if (file.f_op->open(inode,&file))
 397                         goto end_readexec;
 398         if (!file.f_op || !file.f_op->read)
 399                 goto close_readexec;
 400         if (file.f_op->lseek) {
 401                 if (file.f_op->lseek(inode,&file,offset,0) != offset)
 402                         goto close_readexec;
 403         } else
 404                 file.f_pos = offset;
 405         result = file.f_op->read(inode, &file, addr, count);
 406 close_readexec:
 407         if (file.f_op->release)
 408                 file.f_op->release(inode,&file);
 409 end_readexec:
 410         return result;
 411 }
 412 
 413 /*
 414  * 'do_execve()' executes a new program.
 415  *
 416  * NOTE! We leave 4MB free at the top of the data-area for a loadable
 417  * library.
 418  */
 419 int do_execve(unsigned long * eip,long tmp,char * filename,
     /* [previous][next][first][last][top][bottom][index][help] */
 420         char ** argv, char ** envp)
 421 {
 422         struct inode * inode;
 423         char buf[128];
 424         unsigned long old_fs;
 425         struct exec ex;
 426         unsigned long page[MAX_ARG_PAGES];
 427         int i,argc,envc;
 428         int e_uid, e_gid;
 429         int retval;
 430         int sh_bang = 0;
 431         unsigned long p=PAGE_SIZE*MAX_ARG_PAGES-4;
 432         int ch;
 433 
 434         if ((0xffff & eip[1]) != 0x000f)
 435                 panic("execve called from supervisor mode");
 436         for (i=0 ; i<MAX_ARG_PAGES ; i++)       /* clear page-table */
 437                 page[i]=0;
 438         retval = namei(filename,&inode);        /* get executable inode */
 439         if (retval)
 440                 return retval;
 441         argc = count(argv);
 442         envc = count(envp);
 443         
 444 restart_interp:
 445         if (!S_ISREG(inode->i_mode)) {  /* must be regular file */
 446                 retval = -EACCES;
 447                 goto exec_error2;
 448         }
 449         if (IS_NOEXEC(inode)) {         /* FS mustn't be mounted noexec */
 450                 retval = -EPERM;
 451                 goto exec_error2;
 452         }
 453         if (!inode->i_sb) {
 454                 retval = -EACCES;
 455                 goto exec_error2;
 456         }
 457         i = inode->i_mode;
 458         if (IS_NOSUID(inode) && (((i & S_ISUID) && inode->i_uid != current->
 459             euid) || ((i & S_ISGID) && inode->i_gid != current->egid)) &&
 460             !suser()) {
 461                 retval = -EPERM;
 462                 goto exec_error2;
 463         }
 464         /* make sure we don't let suid, sgid files be ptraced. */
 465         if (current->flags & PF_PTRACED) {
 466                 e_uid = current->euid;
 467                 e_gid = current->egid;
 468         } else {
 469                 e_uid = (i & S_ISUID) ? inode->i_uid : current->euid;
 470                 e_gid = (i & S_ISGID) ? inode->i_gid : current->egid;
 471         }
 472         if (current->euid == inode->i_uid)
 473                 i >>= 6;
 474         else if (in_group_p(inode->i_gid))
 475                 i >>= 3;
 476         if (!(i & 1) &&
 477             !((inode->i_mode & 0111) && suser())) {
 478                 retval = -EACCES;
 479                 goto exec_error2;
 480         }
 481         memset(buf,0,sizeof(buf));
 482         old_fs = get_fs();
 483         set_fs(get_ds());
 484         retval = read_exec(inode,0,buf,128);
 485         set_fs(old_fs);
 486         if (retval < 0)
 487                 goto exec_error2;
 488         ex = *((struct exec *) buf);            /* exec-header */
 489         if ((buf[0] == '#') && (buf[1] == '!') && (!sh_bang)) {
 490                 /*
 491                  * This section does the #! interpretation.
 492                  * Sorta complicated, but hopefully it will work.  -TYT
 493                  */
 494 
 495                 char *cp, *interp, *i_name, *i_arg;
 496 
 497                 iput(inode);
 498                 buf[127] = '\0';
 499                 if ((cp = strchr(buf, '\n')) == NULL)
 500                         cp = buf+127;
 501                 *cp = '\0';
 502                 while (cp > buf) {
 503                         cp--;
 504                         if ((*cp == ' ') || (*cp == '\t'))
 505                                 *cp = '\0';
 506                         else
 507                                 break;
 508                 }
 509                 for (cp = buf+2; (*cp == ' ') || (*cp == '\t'); cp++);
 510                 if (!cp || *cp == '\0') {
 511                         retval = -ENOEXEC; /* No interpreter name found */
 512                         goto exec_error1;
 513                 }
 514                 interp = i_name = cp;
 515                 i_arg = 0;
 516                 for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
 517                         if (*cp == '/')
 518                                 i_name = cp+1;
 519                 }
 520                 while ((*cp == ' ') || (*cp == '\t'))
 521                         *cp++ = '\0';
 522                 if (*cp)
 523                         i_arg = cp;
 524                 /*
 525                  * OK, we've parsed out the interpreter name and
 526                  * (optional) argument.
 527                  */
 528                 if (sh_bang++ == 0) {
 529                         p = copy_strings(envc, envp, page, p, 0);
 530                         p = copy_strings(--argc, argv+1, page, p, 0);
 531                 }
 532                 /*
 533                  * Splice in (1) the interpreter's name for argv[0]
 534                  *           (2) (optional) argument to interpreter
 535                  *           (3) filename of shell script
 536                  *
 537                  * This is done in reverse order, because of how the
 538                  * user environment and arguments are stored.
 539                  */
 540                 p = copy_strings(1, &filename, page, p, 1);
 541                 argc++;
 542                 if (i_arg) {
 543                         p = copy_strings(1, &i_arg, page, p, 2);
 544                         argc++;
 545                 }
 546                 p = copy_strings(1, &i_name, page, p, 2);
 547                 argc++;
 548                 if (!p) {
 549                         retval = -ENOMEM;
 550                         goto exec_error1;
 551                 }
 552                 /*
 553                  * OK, now restart the process with the interpreter's inode.
 554                  */
 555                 old_fs = get_fs();
 556                 set_fs(get_ds());
 557                 retval = namei(interp,&inode);
 558                 set_fs(old_fs);
 559                 if (retval)
 560                         goto exec_error1;
 561                 goto restart_interp;
 562         }
 563         if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC) ||
 564                 ex.a_trsize || ex.a_drsize ||
 565                 ex.a_text+ex.a_data+ex.a_bss>0x3000000 ||
 566                 inode->i_size < ex.a_text+ex.a_data+ex.a_syms+N_TXTOFF(ex)) {
 567                 retval = -ENOEXEC;
 568                 goto exec_error2;
 569         }
 570         if (N_TXTOFF(ex) != BLOCK_SIZE && N_MAGIC(ex) != OMAGIC) {
 571                 printk("%s: N_TXTOFF != BLOCK_SIZE. See a.out.h.", filename);
 572                 retval = -ENOEXEC;
 573                 goto exec_error2;
 574         }
 575         if (!sh_bang) {
 576                 p = copy_strings(envc,envp,page,p,0);
 577                 p = copy_strings(argc,argv,page,p,0);
 578                 if (!p) {
 579                         retval = -ENOMEM;
 580                         goto exec_error2;
 581                 }
 582         }
 583 /* OK, This is the point of no return */
 584         current->dumpable = 1;
 585         for (i=0; (ch = get_fs_byte(filename++)) != '\0';)
 586                 if (ch == '/')
 587                         i = 0;
 588                 else
 589                         if (i < 15)
 590                                 current->comm[i++] = ch;
 591         current->comm[i] = '\0';
 592         if (current->executable) {
 593                 iput(current->executable);
 594                 current->executable = NULL;
 595         }
 596         i = current->numlibraries;
 597         while (i-- > 0) {
 598                 iput(current->libraries[i].library);
 599                 current->libraries[i].library = NULL;
 600         }
 601         if (e_uid != current->euid || e_gid != current->egid ||
 602             !permission(inode,MAY_READ))
 603                 current->dumpable = 0;
 604         current->numlibraries = 0;
 605         current->signal = 0;
 606         for (i=0 ; i<32 ; i++) {
 607                 current->sigaction[i].sa_mask = 0;
 608                 current->sigaction[i].sa_flags = 0;
 609                 if (current->sigaction[i].sa_handler != SIG_IGN)
 610                         current->sigaction[i].sa_handler = NULL;
 611         }
 612         for (i=0 ; i<NR_OPEN ; i++)
 613                 if (FD_ISSET(i,&current->close_on_exec))
 614                         sys_close(i);
 615         FD_ZERO(&current->close_on_exec);
 616         clear_page_tables(current);
 617         if (last_task_used_math == current)
 618                 last_task_used_math = NULL;
 619         current->used_math = 0;
 620         p += change_ldt(ex.a_text,page);
 621         p -= MAX_ARG_PAGES*PAGE_SIZE;
 622         p = (unsigned long) create_tables((char *)p,argc,envc);
 623         current->brk = ex.a_bss +
 624                 (current->end_data = ex.a_data +
 625                 (current->end_code = ex.a_text));
 626         current->start_stack = p;
 627         current->rss = (TASK_SIZE - p + PAGE_SIZE-1) / PAGE_SIZE;
 628         current->suid = current->euid = e_uid;
 629         current->sgid = current->egid = e_gid;
 630         if (N_MAGIC(ex) == OMAGIC) {
 631                 read_exec(inode, 32, (char *) 0, ex.a_text+ex.a_data);
 632                 iput(inode);
 633         } else if (!inode->i_op || !inode->i_op->bmap) {
 634                 read_exec(inode, 1024, (char *) 0, ex.a_text+ex.a_data);
 635                 iput(inode);
 636         } else
 637                 current->executable = inode;
 638         eip[0] = ex.a_entry;            /* eip, magic happens :-) */
 639         eip[3] = p;                     /* stack pointer */
 640         if (current->flags & PF_PTRACED)
 641                 send_sig(SIGTRAP, current, 0);
 642         return 0;
 643 exec_error2:
 644         iput(inode);
 645 exec_error1:
 646         for (i=0 ; i<MAX_ARG_PAGES ; i++)
 647                 free_page(page[i]);
 648         return(retval);
 649 }

/* [previous][next][first][last][top][bottom][index][help] */