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                 pgd_clear(swapper_pg_dir + i);
  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->cs = USER_CS;
  57         regs->ds = regs->es = regs->ss = regs->fs = regs->gs = USER_DS;
  58         regs->eip = eip;
  59         regs->esp = esp;
  60 }
  61 
  62 /*
  63  * Free current thread data structures etc..
  64  */
  65 void exit_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  66 {
  67         /* forget local segments */
  68         __asm__ __volatile__("mov %w0,%%fs ; mov %w0,%%gs ; lldt %w0"
  69                 : /* no outputs */
  70                 : "r" (0));
  71         current->tss.ldt = 0;
  72         if (current->ldt) {
  73                 void * ldt = current->ldt;
  74                 current->ldt = NULL;
  75                 vfree(ldt);
  76         }
  77 }
  78 
  79 void flush_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  80 {
  81         int i;
  82 
  83         if (current->ldt) {
  84                 free_page((unsigned long) current->ldt);
  85                 current->ldt = NULL;
  86                 for (i=1 ; i<NR_TASKS ; i++) {
  87                         if (task[i] == current)  {
  88                                 set_ldt_desc(gdt+(i<<1)+
  89                                              FIRST_LDT_ENTRY,&default_ldt, 1);
  90                                 load_ldt(i);
  91                         }
  92                 }       
  93         }
  94 
  95         for (i=0 ; i<8 ; i++)
  96                 current->debugreg[i] = 0;
  97 }
  98 
  99 #define IS_CLONE (regs->orig_eax == __NR_clone)
 100 
 101 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] */
 102 {
 103         int i;
 104         struct pt_regs * childregs;
 105 
 106         p->tss.es = KERNEL_DS;
 107         p->tss.cs = KERNEL_CS;
 108         p->tss.ss = KERNEL_DS;
 109         p->tss.ds = KERNEL_DS;
 110         p->tss.fs = USER_DS;
 111         p->tss.gs = KERNEL_DS;
 112         p->tss.ss0 = KERNEL_DS;
 113         p->tss.esp0 = p->kernel_stack_page + PAGE_SIZE;
 114         p->tss.tr = _TSS(nr);
 115         childregs = ((struct pt_regs *) (p->kernel_stack_page + PAGE_SIZE)) - 1;
 116         p->tss.esp = (unsigned long) childregs;
 117         p->tss.eip = (unsigned long) ret_from_sys_call;
 118         *childregs = *regs;
 119         childregs->eax = 0;
 120         p->tss.back_link = 0;
 121         p->tss.eflags = regs->eflags & 0xffffcfff;      /* iopl is always 0 for a new process */
 122         if (IS_CLONE) {
 123                 if (regs->ebx)
 124                         childregs->esp = regs->ebx;
 125                 clone_flags = regs->ecx;
 126                 if (childregs->esp == regs->esp)
 127                         clone_flags |= COPYVM;
 128         }
 129         p->tss.ldt = _LDT(nr);
 130         if (p->ldt) {
 131                 p->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE);
 132                 if (p->ldt != NULL)
 133                         memcpy(p->ldt, current->ldt, LDT_ENTRIES*LDT_ENTRY_SIZE);
 134         }
 135         set_tss_desc(gdt+(nr<<1)+FIRST_TSS_ENTRY,&(p->tss));
 136         if (p->ldt)
 137                 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,p->ldt, 512);
 138         else
 139                 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,&default_ldt, 1);
 140         p->tss.bitmap = offsetof(struct thread_struct,io_bitmap);
 141         for (i = 0; i < IO_BITMAP_SIZE+1 ; i++) /* IO bitmap is actually SIZE+1 */
 142                 p->tss.io_bitmap[i] = ~0;
 143         if (last_task_used_math == current)
 144                 __asm__("clts ; fnsave %0 ; frstor %0":"=m" (p->tss.i387));
 145         return clone_flags;
 146 }
 147 
 148 /*
 149  * fill in the user structure for a core dump..
 150  */
 151 void dump_thread(struct pt_regs * regs, struct user * dump)
     /* [previous][next][first][last][top][bottom][index][help] */
 152 {
 153         int i;
 154 
 155 /* changed the size calculations - should hopefully work better. lbt */
 156         dump->magic = CMAGIC;
 157         dump->start_code = 0;
 158         dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
 159         dump->u_tsize = ((unsigned long) current->mm->end_code) >> 12;
 160         dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> 12;
 161         dump->u_dsize -= dump->u_tsize;
 162         dump->u_ssize = 0;
 163         for (i = 0; i < 8; i++)
 164                 dump->u_debugreg[i] = current->debugreg[i];  
 165 
 166         if (dump->start_stack < TASK_SIZE)
 167                 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> 12;
 168 
 169         dump->regs = *regs;
 170 
 171 /* Flag indicating the math stuff is valid. We don't support this for the
 172    soft-float routines yet */
 173         if (hard_math) {
 174                 if ((dump->u_fpvalid = current->used_math) != 0) {
 175                         if (last_task_used_math == current)
 176                                 __asm__("clts ; fnsave %0": :"m" (dump->i387));
 177                         else
 178                                 memcpy(&dump->i387,&current->tss.i387.hard,sizeof(dump->i387));
 179                 }
 180         } else {
 181                 /* we should dump the emulator state here, but we need to
 182                    convert it into standard 387 format first.. */
 183                 dump->u_fpvalid = 0;
 184         }
 185 }
 186 
 187 /*
 188  * sys_execve() executes a new program.
 189  */
 190 asmlinkage int sys_execve(struct pt_regs regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 191 {
 192         int error;
 193         char * filename;
 194 
 195         error = getname((char *) regs.ebx, &filename);
 196         if (error)
 197                 return error;
 198         error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, &regs);
 199         putname(filename);
 200         return error;
 201 }

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