diff options
| author | rsc <rsc> | 2007-09-27 19:39:10 +0000 | 
|---|---|---|
| committer | rsc <rsc> | 2007-09-27 19:39:10 +0000 | 
| commit | 39c3fb1b157927058f24b72d43be6f15c1d422b7 (patch) | |
| tree | f02c00516eebdedd22e0ba59a2011c29398a5fc9 | |
| parent | 8c8b748a2f0f10188c1a58c529239fff3a3b1b01 (diff) | |
| download | xv6-labs-39c3fb1b157927058f24b72d43be6f15c1d422b7.tar.gz xv6-labs-39c3fb1b157927058f24b72d43be6f15c1d422b7.tar.bz2 xv6-labs-39c3fb1b157927058f24b72d43be6f15c1d422b7.zip  | |
overkill: use segments to catch stack overflow (delete before next year)
| -rw-r--r-- | proc.c | 6 | ||||
| -rw-r--r-- | proc.h | 5 | ||||
| -rw-r--r-- | swtch.S | 4 | 
3 files changed, 13 insertions, 2 deletions
@@ -73,7 +73,7 @@ setupsegs(struct proc *p)    splhi();    c = &cpus[cpu()]; -  c->ts.ss0 = SEG_KDATA << 3; +  c->ts.ss0 = SEG_PROCSTACK << 3;    if(p)      c->ts.esp0 = (uint)(p->kstack + KSTACKSIZE);    else @@ -84,12 +84,15 @@ setupsegs(struct proc *p)    c->gdt[SEG_KDATA] = SEG(STA_W, 0, 0xffffffff, 0);    c->gdt[SEG_TSS] = SEG16(STS_T32A, (uint)&c->ts, sizeof(c->ts)-1, 0);    c->gdt[SEG_TSS].s = 0; +  c->gdt[SEG_CPUSTACK] = SEG(STA_W|STA_E, 0, (uint)c->stack, 0);    if(p){      c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz-1, DPL_USER);      c->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz-1, DPL_USER); +    c->gdt[SEG_PROCSTACK] = SEG(STA_W|STA_E, 0, (uint)p->kstack, 0);    } else {      c->gdt[SEG_UCODE] = SEG_NULL;      c->gdt[SEG_UDATA] = SEG_NULL; +    c->gdt[SEG_PROCSTACK] = SEG_NULL;    }    lgdt(c->gdt, sizeof(c->gdt)); @@ -140,6 +143,7 @@ copyproc(struct proc *p)    memset(&np->context, 0, sizeof(np->context));    np->context.eip = (uint)forkret;    np->context.esp = (uint)np->tf; +  np->context.ss = SEG_PROCSTACK<<3;    // Clear %eax so that fork system call returns 0 in child.    np->tf->eax = 0; @@ -4,7 +4,9 @@  #define SEG_UCODE 3  #define SEG_UDATA 4  #define SEG_TSS   5  // this process's task state -#define NSEGS     6 +#define SEG_CPUSTACK 6 +#define SEG_PROCSTACK 7 +#define NSEGS     8  // Saved registers for kernel context switches.  // Don't need to save all the %fs etc. segment registers, @@ -22,6 +24,7 @@ struct context {    int esi;    int edi;    int ebp; +  int ss;  };  enum proc_state { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE }; @@ -16,10 +16,14 @@ swtch:    movl %esi, 20(%eax)    movl %edi, 24(%eax)    movl %ebp, 28(%eax) +  movl %ss, %ebx +  movl %ebx, 32(%eax)    # Load new registers    movl 4(%esp), %eax  # not 8(%esp) - popped return address above +  movl 32(%eax), %ebx +  movl %ebx, %ss    movl 28(%eax), %ebp    movl 24(%eax), %edi    movl 20(%eax), %esi  | 
