i386: remove dependency on <sys/mman.h>
This defines memory-protection flags specifically for the GDT.
This commit is contained in:
parent
96eafeac45
commit
f39779e810
|
@ -7,7 +7,6 @@
|
|||
#ifndef UKERNEL_ARCH_I386_GDT_H
|
||||
# define UKERNEL_ARCH_I386_GDT_H
|
||||
|
||||
# include <sys/mman.h>
|
||||
# include <sys/types.h>
|
||||
# include <stdint.h>
|
||||
|
||||
|
@ -70,6 +69,10 @@ typedef struct _TSS
|
|||
|
||||
|
||||
/* constants */
|
||||
# define GDT_PROT_READ 0x1
|
||||
# define GDT_PROT_WRITE 0x2
|
||||
# define GDT_PROT_EXEC 0x4
|
||||
|
||||
# define GDT_SYSTEM_TYPE_LDT 0x2
|
||||
# define GDT_SYSTEM_TYPE_TSS 0x9
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@
|
|||
/* GDT: 4GB flat memory setup */
|
||||
static const GDTTable _gdt_4gb[2] =
|
||||
{
|
||||
{ 0x00000000, 0xffffffff, PROT_READ | PROT_EXEC },
|
||||
{ 0x00000000, 0xffffffff, PROT_READ | PROT_WRITE }
|
||||
{ 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_EXEC },
|
||||
{ 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_WRITE }
|
||||
};
|
||||
|
||||
static const IDT _idt[] =
|
||||
|
|
|
@ -139,9 +139,9 @@ int gdt_append(GDT * gdt, vaddr_t base, size_t size, unsigned int prot)
|
|||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
if(prot != PROT_READ
|
||||
&& prot != (PROT_READ | PROT_WRITE)
|
||||
&& prot != (PROT_READ | PROT_EXEC))
|
||||
if(prot != GDT_PROT_READ
|
||||
&& prot != (GDT_PROT_READ | GDT_PROT_WRITE)
|
||||
&& prot != (GDT_PROT_READ | GDT_PROT_EXEC))
|
||||
{
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
|
@ -157,13 +157,13 @@ int gdt_append(GDT * gdt, vaddr_t base, size_t size, unsigned int prot)
|
|||
else
|
||||
limit = size - 1;
|
||||
/* access */
|
||||
if(prot == (PROT_READ | PROT_EXEC))
|
||||
if(prot == (GDT_PROT_READ | GDT_PROT_EXEC))
|
||||
/* code segment */
|
||||
access |= GDT_ACCESS_PROT_RW | GDT_ACCESS_PROT_X;
|
||||
else if(prot == (PROT_READ | PROT_WRITE))
|
||||
else if(prot == (GDT_PROT_READ | GDT_PROT_WRITE))
|
||||
/* data segment (read/write) */
|
||||
access |= GDT_ACCESS_PROT_RW;
|
||||
else if(prot == PROT_READ)
|
||||
else if(prot == GDT_PROT_READ)
|
||||
/* data segment (read-only) */
|
||||
access |= GDT_ACCESS_SET;
|
||||
return _gdt_append_entry(gdt, base, limit, access, flags);
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
/* GDT: 4GB flat memory setup */
|
||||
static const GDTTable _gdt_4gb[2] =
|
||||
{
|
||||
{ 0x00000000, 0xffffffff, PROT_READ | PROT_EXEC },
|
||||
{ 0x00000000, 0xffffffff, PROT_READ | PROT_WRITE }
|
||||
{ 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_EXEC },
|
||||
{ 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_WRITE }
|
||||
};
|
||||
|
||||
|
||||
|
|
10
tests/gdt.c
10
tests/gdt.c
|
@ -54,17 +54,17 @@ int main(int argc, char * argv[])
|
|||
/* flat 4 GB */
|
||||
printf("Flat 4 GB:\n");
|
||||
gdt = gdt_init();
|
||||
gdt_append(gdt, 0x00000000, 0xffffffff, PROT_READ | PROT_EXEC);
|
||||
gdt_append(gdt, 0x00000000, 0xffffffff, PROT_READ | PROT_WRITE);
|
||||
gdt_append(gdt, 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_EXEC);
|
||||
gdt_append(gdt, 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_WRITE);
|
||||
gdt_append_system(gdt, &tss, sizeof(tss), GDT_SYSTEM_TYPE_TSS);
|
||||
gdt_apply(gdt);
|
||||
|
||||
/* 4 MB code + 4 MB data (read-write) + 4 MB data (read-only) */
|
||||
printf("\n4 MB (rx) + 4 MB (rw) + 4 MB (ro):\n");
|
||||
gdt = gdt_init();
|
||||
gdt_append(gdt, 0x00400000, 0x00400000, PROT_READ | PROT_EXEC);
|
||||
gdt_append(gdt, 0x00800000, 0x00400000, PROT_READ | PROT_WRITE);
|
||||
gdt_append(gdt, 0x00c00000, 0x00400000, PROT_READ);
|
||||
gdt_append(gdt, 0x00400000, 0x00400000, GDT_PROT_READ | GDT_PROT_EXEC);
|
||||
gdt_append(gdt, 0x00800000, 0x00400000, GDT_PROT_READ | GDT_PROT_WRITE);
|
||||
gdt_append(gdt, 0x00c00000, 0x00400000, GDT_PROT_READ);
|
||||
gdt_append_system(gdt, &tss, sizeof(tss), GDT_SYSTEM_TYPE_TSS);
|
||||
gdt_apply(gdt);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user