What system calls does
When using the
dlopen API -
dlclose - what syscalls does it use?
I wrote two programs to compare:
one which loads a function from a shared object,
and one which embeds the function in the main binary.
dtruss to log system calls, the dynamic-loading version does something like this:
void* start = 0x10EA52000; size_t pagesize = getpagesize(); struct stat64 stat; stat64("plugin.so", &stat); int fd = open("plugin.so", 0, 0); mmap(start+(0*pagesize), 6*pagesize, PROT_READ|PROT_EXEC, MAP_FIXED|MAP_PRIVATE, fd, 0*pagesize); mmap(start+(6*pagesize), 1*pagesize, PROT_READ|PROT_WRITE, MAP_FIXED|MAP_PRIVATE, fd, 1*pagesize); mmap(start+(7*pagesize), stat.off_t - 7*pagesize, PROT_READ, MAP_FIXED|MAP_PRIVATE, fd, 2*pagesize); close(fd); munmap(start+(0*pagesize), 4096); munmap(start+(6*pagesize), 4096); munmap(start+(7*pagesize), 4096);
It’s notable that this does not use any special syscalls. Instead, the program uses standard UNIX syscalls to put the file in memory.
The program knows the offsets of three sections of the file: one executable (containing functions), one read/writable (containing global variables), and one readable (the Mach-O headers, at the end of the file?). The program maps these into memory at fixed locations.
More by Jim
- The inception bar: a new phishing method
- The hacker hype cycle
- Project C-43: the lost origins of asymmetric crypto
- How Hacker News stays interesting
- My parents are Flat-Earthers
- The dots do matter: how to scam a Gmail user
- The sorry state of OpenSSL usability
- I hate telephones
- The Three Ts of Time, Thought and Typing: measuring cost on the web
- Granddad died today
- Your syntax highlighter is wrong
Tagged . All content copyright James Fisher 2017. This post is not associated with my employer. Found an error? Edit this page.