Skip to content

Commit

Permalink
add DPL_USER constant
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Aug 8, 2007
1 parent f83f7ce commit b6dc618
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ process0()
// process to return to.
p0->tf = &tf;
memset(p0->tf, 0, sizeof(struct trapframe));
p0->tf->es = p0->tf->ds = p0->tf->ss = (SEG_UDATA << 3) | 3;
p0->tf->cs = (SEG_UCODE << 3) | 3;
p0->tf->es = p0->tf->ds = p0->tf->ss = (SEG_UDATA << 3) | DPL_USER;
p0->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p0->tf->eflags = FL_IF;
p0->tf->esp = p0->sz;

Expand Down
2 changes: 2 additions & 0 deletions mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct segdesc {
type, 1, dpl, 1, (uint) (lim) >> 16, 0, 0, 1, 0, \
(uint) (base) >> 24 }

#define DPL_USER 0x3 // User DPL

// Application segment type bits
#define STA_X 0x8 // Executable segment
#define STA_E 0x4 // Expand down (non-executable segments)
Expand Down
4 changes: 2 additions & 2 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ setupsegs(struct proc *p)
c->gdt[SEG_TSS] = SEG16(STS_T32A, (uint) &c->ts, sizeof(c->ts), 0);
c->gdt[SEG_TSS].s = 0;
if(p){
c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz, 3);
c->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz, 3);
c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz, DPL_USER);
c->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz, DPL_USER);
} else {
c->gdt[SEG_UCODE] = SEG_NULL;
c->gdt[SEG_UDATA] = SEG_NULL;
Expand Down
4 changes: 2 additions & 2 deletions trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tvinit(void)

for(i = 0; i < 256; i++)
SETGATE(idt[i], 0, SEG_KCODE << 3, vectors[i], 0);
SETGATE(idt[T_SYSCALL], 0, SEG_KCODE << 3, vectors[T_SYSCALL], 3);
SETGATE(idt[T_SYSCALL], 0, SEG_KCODE << 3, vectors[T_SYSCALL], DPL_USER);
}

void
Expand Down Expand Up @@ -56,7 +56,7 @@ trap(struct trapframe *tf)
// Force process exit if it has been killed and is in user space.
// (If it is still executing in the kernel, let it keep running
// until it gets to the regular system call return.)
if((tf->cs&3) == 3 && cp->killed)
if((tf->cs&3) == DPL_USER && cp->killed)
proc_exit();

// Force process to give up CPU and let others run.
Expand Down

0 comments on commit b6dc618

Please sign in to comment.