diff --git a/sortix/elf.cpp b/sortix/elf.cpp index ac00d3eb..998077db 100644 --- a/sortix/elf.cpp +++ b/sortix/elf.cpp @@ -36,6 +36,25 @@ namespace Sortix { namespace ELF { + int ToProgramSectionType(int flags) + { + switch ( flags & (PF_X | PF_R | PF_W) ) + { + case 0: + return SEG_NONE; + case PF_X: + case PF_X | PF_R: + case PF_X | PF_W: + case PF_X | PF_R | PF_W: + return SEG_TEXT; + case PF_R: + case PF_W: + case PF_R | PF_W: + default: + return SEG_DATA; + } + } + addr_t Construct32(Process* process, const void* file, size_t filelen) { if ( filelen < sizeof(Header32) ) { return 0; } @@ -83,7 +102,7 @@ namespace Sortix if ( segment == NULL ) { return 0; } segment->position = mapto; segment->size = Page::AlignUp(mapbytes); - segment->type = SEG_DATA; // TODO: BUG + segment->type = ToProgramSectionType(pht->flags); if ( segment->Intersects(process->segments) ) { @@ -163,7 +182,7 @@ namespace Sortix if ( segment == NULL ) { return 0; } segment->position = mapto; segment->size = Page::AlignUp(mapbytes); - segment->type = SEG_DATA; // TODO: BUG + segment->type = ToProgramSectionType(pht->flags); if ( segment->Intersects(process->segments) ) { diff --git a/sortix/elf.h b/sortix/elf.h index b5c8c515..8c6c2ab2 100644 --- a/sortix/elf.h +++ b/sortix/elf.h @@ -162,6 +162,10 @@ namespace Sortix const uint32_t PT_LOPROC = 0x70000000; const uint32_t PT_HIPROC = 0x7FFFFFFF; + const uint32_t PF_X = (1<<0); + const uint32_t PF_W = (1<<1); + const uint32_t PF_R = (1<<2); + // Reads the elf file into the current address space and returns the // entry address of the program, or 0 upon failure. addr_t Construct(Process* process, const void* file, size_t filelen); diff --git a/sortix/process.h b/sortix/process.h index f45ed068..24f3237a 100644 --- a/sortix/process.h +++ b/sortix/process.h @@ -34,10 +34,11 @@ namespace Sortix struct ProcessSegment; const size_t DEFAULT_STACK_SIZE = 64*1024; - const int SEG_TEXT = 0; - const int SEG_DATA = 1; - const int SEG_STACK = 2; - const int SEG_OTHER = 3; + const int SEG_NONE = 0; + const int SEG_TEXT = 1; + const int SEG_DATA = 2; + const int SEG_STACK = 3; + const int SEG_OTHER = 4; struct ProcessSegment {