Skip to content

Commit

Permalink
macho: refactor logic for setting __DATA_CONST as READ_ONLY
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Feb 24, 2024
1 parent 79a9b8e commit e94c94c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/MachO.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1773,13 +1773,11 @@ fn initSegments(self: *MachO) !void {
const segname = header.segName();
if (self.getSegmentByName(segname) == null) {
const prot = getSegmentProt(segname);
const flags: u32 = if (mem.startsWith(u8, segname, "__DATA_CONST")) 0x10 else 0; // TODO usee macho.SG_READ_ONLY once upstreamed
try self.segments.append(gpa, .{
.cmdsize = @sizeOf(macho.segment_command_64),
.segname = makeStaticString(segname),
.maxprot = prot,
.initprot = prot,
.flags = flags,
});
}
}
Expand Down Expand Up @@ -1855,6 +1853,11 @@ fn initSegments(self: *MachO) !void {
self.pagezero_seg_index = self.getSegmentByName("__PAGEZERO");
self.text_seg_index = self.getSegmentByName("__TEXT").?;
self.linkedit_seg_index = self.getSegmentByName("__LINKEDIT").?;

if (self.getSegmentByName("__DATA_CONST")) |seg_id| {
const seg = &self.segments.items[seg_id];
seg.flags |= macho.SG_READ_ONLY;
}
}

fn allocateSections(self: *MachO) !void {
Expand Down

0 comments on commit e94c94c

Please sign in to comment.