// segments - do zapisania // sections - sekcje tego samego typy (te same flagi) // rel_sections - wektor wszystkich sekcji z pliku rel // offset_map - mapa, index_sekcji -> offset sekcji // segments_flag - flagi void addNewSegment(Context& ctx, headerT& header, vector& segments, const vector>& sections, vector& rel_sections, unordered_map& offset_map, int segment_flags) { if (sections.size()) { segmentT p; int size = 0; int new_off = header.e_shoff; if (new_off % constants::kPageSize != 0) { new_off += constants::kPageSize - (new_off % constants::kPageSize); } for (auto& s : sections) { if (size % s.second.sh_addralign != 0) { size += s.second.sh_addralign - (size % s.second.sh_addralign); }; offset_map[s.first] = new_off + size; size += s.second.sh_size; } if (size != 0) { p.p_type = PT_LOAD; p.p_flags = segment_flags; p.p_offset = new_off; p.p_vaddr = new_off + ctx.base_address; p.p_paddr = new_off + ctx.base_address; p.p_filesz = size; p.p_memsz = size; p.p_align = constants::kPageSize; ctx.last_segment += size; segments.emplace_back(p); header.e_phnum++; header.e_shoff += size; } } }