root/arch/i386/kernel/process.c

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

DEFINITIONS

This source file includes following definitions.
  1. ret_from_sys_call
  2. start_thread
  3. exit_thread
  4. flush_thread
  5. copy_thread
  6. dump_thread
  7. sys_execve

   1 /*
   2  *  linux/arch/i386/kernel/process.c
   3  *
   4  *  Copyright (C) 1995  Linus Torvalds
   5  */
   6 
   7 /*
   8  * This file handles the architecture-dependent parts of process handling..
   9  */
  10 
  11 #include <linux/errno.h>
  12 #include <linux/sched.h>
  13 #include <linux/kernel.h>
  14 #include <linux/mm.h>
  15 #include <linux/stddef.h>
  16 #include <linux/unistd.h>
  17 #include <linux/ptrace.h>
  18 #include <linux/malloc.h>
  19 #include <linux/ldt.h>
  20 #include <linux/user.h>
  21 #include <linux/a.out.h>
  22 
  23 #include <asm/segment.h>
  24 #include <asm/system.h>
  25 
  26 asmlinkage void ret_from_sys_call(void) __asm__("ret_from_sys_call");
     /* [previous][next][first][last][top][bottom][index][help] */
  27 
  28 /*
  29  * The idle loop on a i386..
  30  */
  31 asmlinkage int sys_idle(void)
  32 {
  33         int i;
  34 
  35         if (current->pid != 0)
  36                 return -EPERM;
  37 
  38         /* Map out the low memory: it's no longer needed */
  39         for (i = 0 ; i < 768 ; i++)
  40                 swapper_pg_dir[i] = 0;
  41 
  42         /* endless idle loop with no priority at all */
  43         current->counter = -100;
  44         for (;;) {
  45                 if (hlt_works_ok && !need_resched)
  46                         __asm__("hlt");
  47                 schedule();
  48         }
  49 }
  50 
  51 /*
  52  * Do necessary setup to start up a newly executed thread.
  53  */
  54 void start_thread(struct pt_regs * regs, unsigned long eip, unsigned long esp)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         regs->eip = eip;
  57         regs->esp = esp;
  58 }
  59 
  60 /*
  61  * Free current thread data structures etc..
  62  */
  63 void exit_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  64 {
  65         /* forget local segments */
  66         __asm__ __volatile__("mov %w0,%%fs ; mov %w0,%%gs ; lldt %w0"
  67                 : /* no outputs */
  68                 : "r" (0));
  69         current->tss.ldt = 0;
  70         if (current->ldt) {
  71                 void * ldt = current->ldt;
  72                 current->ldt = NULL;
  73                 vfree(ldt);
  74         }
  75 }
  76 
  77 void flush_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  78 {
  79         int i;
  80 
  81         if (current->ldt) {
  82                 free_page((unsigned long) current->ldt);
  83                 current->ldt = NULL;
  84                 for (i=1 ; i<NR_TASKS ; i++) {
  85                         if (task[i] == current)  {
  86                                 set_ldt_desc(gdt+(i<<1)+
  87                                              FIRST_LDT_ENTRY,&default_ldt, 1);
  88                                 load_ldt(i);
  89                         }
  90                 }       
  91         }
  92 
  93         for (i=0 ; i<8 ; i++)
  94                 current->debugreg[i] = 0;
  95 }
  96 
  97 #define IS_CLONE (regs->orig_eax == __NR_clone)
  98 
  99 unsigned long copy_thread(int nr, unsigned long clone_flags, struct task_struct * p, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 100 {
 101         int i;
 102         struct pt_regs * childregs;
 103 
 104         p->tss.es = KERNEL_DS;
 105         p->tss.cs = KERNEL_CS;
 106         p->tss.ss = KERNEL_DS;
 107         p->tss.ds = KERNEL_DS;
 108         p->tss.fs = USER_DS;
 109         p->tss.gs = KERNEL_DS;
 110         p->tss.ss0 = KERNEL_DS;
 111         p->tss.esp0 = p->kernel_stack_page + PAGE_SIZE;
 112         p->tss.tr = _TSS(nr);
 113         childregs = ((struct pt_regs *) (p->kernel_stack_page + PAGE_SIZE)) - 1;
 114         p->tss.esp = (unsigned long) childregs;
 115         p->tss.eip = (unsigned long) ret_from_sys_call;
 116         *childregs = *regs;
 117         childregs->eax = 0;
 118         p->tss.back_link = 0;
 119         p->tss.eflags = regs->eflags & 0xffffcfff;      /* iopl is always 0 for a new process */
 120         if (IS_CLONE) {
 121                 if (regs->ebx)
 122                         childregs->esp = regs->ebx;
 123                 clone_flags = regs->ecx;
 124                 if (childregs->esp == regs->esp)
 125                         clone_flags |= COPYVM;
 126         }
 127         p->tss.ldt = _LDT(nr);
 128         if (p->ldt) {
 129                 p->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE);
 130                 if (p->ldt != NULL)
 131                         memcpy(p->ldt, current->ldt, LDT_ENTRIES*LDT_ENTRY_SIZE);
 132         }
 133         set_tss_desc(gdt+(nr<<1)+FIRST_TSS_ENTRY,&(p->tss));
 134         if (p->ldt)
 135                 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,p->ldt, 512);
 136         else
 137                 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,&default_ldt, 1);
 138         p->tss.bitmap = offsetof(struct thread_struct,io_bitmap);
 139         for (i = 0; i < IO_BITMAP_SIZE+1 ; i++) /* IO bitmap is actually SIZE+1 */
 140                 p->tss.io_bitmap[i] = ~0;
 141         if (last_task_used_math == current)
 142                 __asm__("clts ; fnsave %0 ; frstor %0":"=m" (p->tss.i387));
 143         return clone_flags;
 144 }
 145 
 146 /*
 147  * fill in the user structure for a core dump..
 148  */
 149 void dump_thread(struct pt_regs * regs, struct user * dump)
     /* [previous][next][first][last][top][bottom][index][help] */
 150 {
 151         int i;
 152 
 153 /* changed the size calculations - should hopefully work better. lbt */
 154         dump->magic = CMAGIC;
 155         dump->start_code = 0;
 156         dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
 157         dump->u_tsize = ((unsigned long) current->mm->end_code) >> 12;
 158         dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> 12;
 159         dump->u_dsize -= dump->u_tsize;
 160         dump->u_ssize = 0;
 161         for (i = 0; i < 8; i++)
 162                 dump->u_debugreg[i] = current->debugreg[i];  
 163 
 164         if (dump->start_stack < TASK_SIZE)
 165                 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> 12;
 166 
 167         dump->regs = *regs;
 168 
 169 /* Flag indicating the math stuff is valid. We don't support this for the
 170    soft-float routines yet */
 171         if (hard_math) {
 172                 if ((dump->u_fpvalid = current->used_math) != 0) {
 173                         if (last_task_used_math == current)
 174                                 __asm__("clts ; fnsave %0": :"m" (dump->i387));
 175                         else
 176                                 memcpy(&dump->i387,&current->tss.i387.hard,sizeof(dump->i387));
 177                 }
 178         } else {
 179                 /* we should dump the emulator state here, but we need to
 180                    convert it into standard 387 format first.. */
 181                 dump->u_fpvalid = 0;
 182         }
 183 }
 184 
 185 /*
 186  * sys_execve() executes a new program.
 187  */
 188 asmlinkage int sys_execve(struct pt_regs regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 189 {
 190         int error;
 191         char * filename;
 192 
 193         error = getname((char *) regs.ebx, &filename);
 194         if (error)
 195                 return error;
 196         error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, &regs);
 197         putname(filename);
 198         return error;
 199 }

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