Skip to content

syscall: implement sys_mmap/sys_munmap/sys_mprotect for dlopen support#48

Open
eplondke wants to merge 3 commits into
masterfrom
dev/ejp/dlopen
Open

syscall: implement sys_mmap/sys_munmap/sys_mprotect for dlopen support#48
eplondke wants to merge 3 commits into
masterfrom
dev/ejp/dlopen

Conversation

@eplondke

Copy link
Copy Markdown

Add a malloc+read based mmap implementation in libs/syscall/angel/src/sys_mmap.c to support BSD libdl's dlopen loading position-independent shared objects under hexagon-sim.

MAP_ANON non-fixed allocations use memalign(4096) to reserve a contiguous aligned block that serves as the rtld base address. MAP_FIXED calls write directly into the already-allocated block via sys_seek+sys_read (file-backed) or memset (anonymous/BSS), placing each PT_LOAD segment at the correct relative offset. munmap is a no-op since dlclose is not yet supported. mprotect is a no-op since the simulator does not enforce page permissions.

The previous UNSUPPORTED stubs in libs/qurt/src/qurt_mmap.c are removed. The new file is auto-included by the angel Makefile's $(wildcard src/*.c) rule.

Add a malloc+read based mmap implementation in libs/syscall/angel/src/sys_mmap.c
to support BSD libdl's dlopen loading position-independent shared objects under
hexagon-sim.

MAP_ANON non-fixed allocations use memalign(4096) to reserve a contiguous aligned
block that serves as the rtld base address. MAP_FIXED calls write directly into the
already-allocated block via sys_seek+sys_read (file-backed) or memset (anonymous/BSS),
placing each PT_LOAD segment at the correct relative offset. munmap is a no-op since
dlclose is not yet supported. mprotect is a no-op since the simulator does not enforce
page permissions.

The previous UNSUPPORTED stubs in libs/qurt/src/qurt_mmap.c are removed. The new file
is auto-included by the angel Makefile's $(wildcard src/*.c) rule.

Signed-off-by: Erich Plondke <erich.plondke@oss.qualcomm.com>
Signed-off-by: Erich Plondke <erich@qti.qualcomm.com>
@eplondke eplondke requested a review from bryanb-h2 June 10, 2026 05:10
@eplondke

Copy link
Copy Markdown
Author

Make sure if you're trying this out you don't have the old qurt file .o in your artifacts directory!

eplondke added 2 commits June 10, 2026 19:58
Dynamic ELF binaries have two string tables: .dynstr (for .dynsym) and
.strtab (for .symtab).  The old section scan picked the first SHT_STRTAB
it found by type, which is .dynstr in dynamic binaries since it precedes
.strtab in section order.  Using .dynstr to decode .symtab symbol names
causes all strcmp lookups to fail, so no special symbols (end, __boot_*,
etc.) are found when loading a --force-dynamic binary.

Fix: after locating SHT_SYMTAB, use pSymhdr->sh_line (h2_elf.h's name
for the standard ELF sh_link field) as the index of the associated string
table rather than scanning for the first SHT_STRTAB by type.

Signed-off-by: Erich Plondke <erich.plondke@oss.qualcomm.com>
Signed-off-by: Erich Plondke <erich@qti.qualcomm.com>
Signed-off-by: Erich Plondke <erich@qti.qualcomm.com>
@eplondke

Copy link
Copy Markdown
Author

Yay, all checks passed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant