Program loader now sets the correct program segment type.
This commit is contained in:
parent
acf1eebc98
commit
7cd28f097c
|
@ -36,6 +36,25 @@ namespace Sortix
|
||||||
{
|
{
|
||||||
namespace ELF
|
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)
|
addr_t Construct32(Process* process, const void* file, size_t filelen)
|
||||||
{
|
{
|
||||||
if ( filelen < sizeof(Header32) ) { return 0; }
|
if ( filelen < sizeof(Header32) ) { return 0; }
|
||||||
|
@ -83,7 +102,7 @@ namespace Sortix
|
||||||
if ( segment == NULL ) { return 0; }
|
if ( segment == NULL ) { return 0; }
|
||||||
segment->position = mapto;
|
segment->position = mapto;
|
||||||
segment->size = Page::AlignUp(mapbytes);
|
segment->size = Page::AlignUp(mapbytes);
|
||||||
segment->type = SEG_DATA; // TODO: BUG
|
segment->type = ToProgramSectionType(pht->flags);
|
||||||
|
|
||||||
if ( segment->Intersects(process->segments) )
|
if ( segment->Intersects(process->segments) )
|
||||||
{
|
{
|
||||||
|
@ -163,7 +182,7 @@ namespace Sortix
|
||||||
if ( segment == NULL ) { return 0; }
|
if ( segment == NULL ) { return 0; }
|
||||||
segment->position = mapto;
|
segment->position = mapto;
|
||||||
segment->size = Page::AlignUp(mapbytes);
|
segment->size = Page::AlignUp(mapbytes);
|
||||||
segment->type = SEG_DATA; // TODO: BUG
|
segment->type = ToProgramSectionType(pht->flags);
|
||||||
|
|
||||||
if ( segment->Intersects(process->segments) )
|
if ( segment->Intersects(process->segments) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -162,6 +162,10 @@ namespace Sortix
|
||||||
const uint32_t PT_LOPROC = 0x70000000;
|
const uint32_t PT_LOPROC = 0x70000000;
|
||||||
const uint32_t PT_HIPROC = 0x7FFFFFFF;
|
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
|
// Reads the elf file into the current address space and returns the
|
||||||
// entry address of the program, or 0 upon failure.
|
// entry address of the program, or 0 upon failure.
|
||||||
addr_t Construct(Process* process, const void* file, size_t filelen);
|
addr_t Construct(Process* process, const void* file, size_t filelen);
|
||||||
|
|
|
@ -34,10 +34,11 @@ namespace Sortix
|
||||||
struct ProcessSegment;
|
struct ProcessSegment;
|
||||||
|
|
||||||
const size_t DEFAULT_STACK_SIZE = 64*1024;
|
const size_t DEFAULT_STACK_SIZE = 64*1024;
|
||||||
const int SEG_TEXT = 0;
|
const int SEG_NONE = 0;
|
||||||
const int SEG_DATA = 1;
|
const int SEG_TEXT = 1;
|
||||||
const int SEG_STACK = 2;
|
const int SEG_DATA = 2;
|
||||||
const int SEG_OTHER = 3;
|
const int SEG_STACK = 3;
|
||||||
|
const int SEG_OTHER = 4;
|
||||||
|
|
||||||
struct ProcessSegment
|
struct ProcessSegment
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue