Skip to content

Commit

Permalink
Add read-only-data segment type
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed Apr 23, 2017
1 parent dea096a commit 1268717
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/process/include/process.hpp
Expand Up @@ -27,7 +27,11 @@ struct ProcessSymbol {
};

enum SectionType: uint8_t {
SectionTypeCode, SectionTypeData, SectionTypeBSS, SectionTypeStack,
SectionTypeCode,
SectionTypeData,
SectionTypeROData,
SectionTypeBSS,
SectionTypeStack
};

class Process {
Expand Down
1 change: 1 addition & 0 deletions src/process/process.cpp
Expand Up @@ -118,6 +118,7 @@ uintptr_t Process::addSection(SectionType type, size_t size) {
uint8_t flags = 4;
switch (type) {
case SectionTypeCode:
case SectionTypeROData:
break;
case SectionTypeData:
case SectionTypeBSS:
Expand Down
10 changes: 8 additions & 2 deletions src/readelf/readelf.cpp
Expand Up @@ -340,9 +340,15 @@ size_t readelf(Process *process, Stream *stream) {
goto err;
break;
case PT_LOAD:
type = SectionTypeData;
if (prog->flags & PF_X)
if (prog->flags & PF_X) {
if (prog->flags & PF_W) goto err;
type = SectionTypeCode;
} else {
if (prog->flags & PF_W)
type = SectionTypeData;
else
type = SectionTypeROData;
}
vaddr = process->addSection(type, prog->memsz);
if (prog->memsz > 0) {
offset_load = 0;
Expand Down

0 comments on commit 1268717

Please sign in to comment.