Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for position independent executables #206

Merged
merged 9 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"tests/test_kernels/default_settings",
"tests/test_kernels/map_phys_mem",
"tests/test_kernels/higher_half",
"tests/test_kernels/pie",
]
exclude = [
"examples/basic",
Expand Down
11 changes: 8 additions & 3 deletions src/binary/level_4_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ impl UsedLevel4Entries {
/// Initializes a new instance from the given ELF program segments.
///
/// Marks the virtual address range of all segments as used.
pub fn new<'a>(segments: impl Iterator<Item = ProgramHeader<'a>>) -> Self {
pub fn new<'a>(
segments: impl Iterator<Item = ProgramHeader<'a>>,
virtual_address_offset: u64,
) -> Self {
let mut used = UsedLevel4Entries {
entry_state: [false; 512],
};

used.entry_state[0] = true; // TODO: Can we do this dynamically?

for segment in segments {
let start_page: Page = Page::containing_address(VirtAddr::new(segment.virtual_addr()));
let start_page: Page = Page::containing_address(VirtAddr::new(
segment.virtual_addr() + virtual_address_offset,
));
let end_page: Page = Page::containing_address(VirtAddr::new(
segment.virtual_addr() + segment.mem_size(),
segment.virtual_addr() + virtual_address_offset + segment.mem_size(),
));

for p4_index in u64::from(start_page.p4_index())..=u64::from(end_page.p4_index()) {
Expand Down
Loading