diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2023-11-15 15:20:33 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2023-11-15 15:20:33 +0100 |
| commit | 9e35b66510af4e9a1ad7f3bd490a9de52c2612ff (patch) | |
| tree | dd31af66a3bba6c9a5bc890808908a4a20a7db07 /src | |
| parent | 713458ac81144be3284221740e53c007547cbece (diff) | |
| download | box64-9e35b66510af4e9a1ad7f3bd490a9de52c2612ff.tar.gz box64-9e35b66510af4e9a1ad7f3bd490a9de52c2612ff.zip | |
[ELFLOADER] Small improvment to have correct R/W attribute set on elf memory
Diffstat (limited to 'src')
| -rw-r--r-- | src/elfs/elfloader.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index 80533f96..97de8a49 100644 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -242,7 +242,7 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin) head->multiblocks[n].paddr = e->p_paddr + offs; head->multiblocks[n].size = e->p_filesz; head->multiblocks[n].align = e->p_align; - uint8_t prot = PROT_READ|PROT_WRITE|((e->p_flags & PF_X)?PROT_EXEC:0); + uint8_t prot = ((e->p_flags & PF_R)?PROT_READ:0)|((e->p_flags & PF_W)?PROT_WRITE:0)|((e->p_flags & PF_X)?PROT_EXEC:0); #if defined(PAGE8K) || defined(PAGE16K) || defined(PAGE64K) head->multiblocks[n].p = NULL; if(e->p_filesz) { @@ -272,7 +272,7 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin) (void*)head->multiblocks[n].paddr, head->multiblocks[n].size, prot, - MAP_PRIVATE|MAP_FIXED, + MAP_PRIVATE|MAP_FIXED, //((prot&PROT_WRITE)?MAP_SHARED:MAP_PRIVATE)|MAP_FIXED, head->fileno, e->p_offset ); @@ -292,7 +292,7 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin) void* p = mmap64( (void*)paddr, asize, - prot, + prot|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0 @@ -315,6 +315,8 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin) return 1; } } + if(!(prot&PROT_WRITE)) + mprotect((void*)paddr, asize, prot); } #endif //PAGE4K #ifdef DYNAREC |