| ... | @@ -839,58 +839,42 @@ pub fn padToIdeal(actual_size: anytype) @TypeOf(actual_size) { | ... | @@ -839,58 +839,42 @@ pub fn padToIdeal(actual_size: anytype) @TypeOf(actual_size) { |
| 839 | math.maxInt(@TypeOf(actual_size)); | 839 | math.maxInt(@TypeOf(actual_size)); |
| 840 | } | 840 | } |
| 841 | | 841 | |
| 842 | // fn detectAllocCollision(self: *Coff, start: u64, size: u64) ?u64 { | 842 | fn detectAllocCollision(self: *Coff, start: u64, size: u64) ?u64 { |
| 843 | // const headers_size = self.getSizeOfHeaders(); | 843 | const headers_size = self.getSizeOfHeaders(); |
| 844 | // if (start < headers_size) | 844 | if (start < headers_size) |
| 845 | // return headers_size; | 845 | return headers_size; |
| 846 | | 846 | |
| 847 | // const end = start + padToIdeal(size); | 847 | const end = start + padToIdeal(size); |
| 848 | | 848 | |
| 849 | // for (self.sections.items(.header)) |header| { | 849 | for (self.sections.items(.header)) |header| { |
| 850 | // const increased_size = padToIdeal(section.sh_size); | 850 | const increased_size = padToIdeal(header.size_of_raw_data); |
| 851 | // const test_end = section.sh_offset + increased_size; | 851 | const test_end = header.pointer_to_raw_data + increased_size; |
| 852 | // if (end > section.sh_offset and start < test_end) { | 852 | if (end > header.pointer_to_raw_data and start < test_end) { |
| 853 | // return test_end; | 853 | return test_end; |
| 854 | // } | 854 | } |
| 855 | // } | 855 | } |
| 856 | // for (self.program_headers.items) |program_header| { | 856 | |
| 857 | // const increased_size = padToIdeal(program_header.p_filesz); | 857 | return null; |
| 858 | // const test_end = program_header.p_offset + increased_size; | 858 | } |
| 859 | // if (end > program_header.p_offset and start < test_end) { | 859 | |
| 860 | // return test_end; | 860 | pub fn allocatedSize(self: *Coff, start: u64) u64 { |
| 861 | // } | 861 | if (start == 0) |
| 862 | // } | 862 | return 0; |
| 863 | // return null; | 863 | var min_pos: u64 = std.math.maxInt(u64); |
| 864 | // } | 864 | for (self.sections.items(.header)) |header| { |
| 865 | | 865 | if (header.pointer_to_raw_data <= start) continue; |
| 866 | // // pub fn allocatedSize(self: *Coff, start: u64) u64 { | 866 | if (header.pointer_to_raw_data < min_pos) min_pos = header.pointer_to_raw_data; |
| 867 | // // if (start == 0) | 867 | } |
| 868 | // // return 0; | 868 | return min_pos - start; |
| 869 | // // var min_pos: u64 = std.math.maxInt(u64); | 869 | } |
| 870 | // // if (self.shdr_table_offset) |off| { | 870 | |
| 871 | // // if (off > start and off < min_pos) min_pos = off; | 871 | pub fn findFreeSpace(self: *Coff, object_size: u64, min_alignment: u32) u64 { |
| 872 | // // } | 872 | var start: u64 = 0; |
| 873 | // // if (self.phdr_table_offset) |off| { | 873 | while (self.detectAllocCollision(start, object_size)) |item_end| { |
| 874 | // // if (off > start and off < min_pos) min_pos = off; | 874 | start = mem.alignForwardGeneric(u64, item_end, min_alignment); |
| 875 | // // } | 875 | } |
| 876 | // // for (self.sections.items) |section| { | 876 | return start; |
| 877 | // // if (section.sh_offset <= start) continue; | 877 | } |
| 878 | // // if (section.sh_offset < min_pos) min_pos = section.sh_offset; | | |
| 879 | // // } | | |
| 880 | // // for (self.program_headers.items) |program_header| { | | |
| 881 | // // if (program_header.p_offset <= start) continue; | | |
| 882 | // // if (program_header.p_offset < min_pos) min_pos = program_header.p_offset; | | |
| 883 | // // } | | |
| 884 | // // return min_pos - start; | | |
| 885 | // // } | | |
| 886 | | | |
| 887 | // pub fn findFreeSpace(self: *Coff, object_size: u64, min_alignment: u32) u64 { | | |
| 888 | // var start: u64 = 0; | | |
| 889 | // while (self.detectAllocCollision(start, object_size)) |item_end| { | | |
| 890 | // start = mem.alignForwardGeneric(u64, item_end, min_alignment); | | |
| 891 | // } | | |
| 892 | // return start; | | |
| 893 | // } | | |
| 894 | | 878 | |
| 895 | inline fn getSizeOfHeaders(self: Coff) usize { | 879 | inline fn getSizeOfHeaders(self: Coff) usize { |
| 896 | const msdos_hdr_size = msdos_stub.len + 8; | 880 | const msdos_hdr_size = msdos_stub.len + 8; |