diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-03-20 03:16:23 +0100 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-03-20 03:16:23 +0100 |
commit | 4e871c9dd0418c4f6d33c83fd3338ad261f7dd3f (patch) | |
tree | b86c40b4dc1ad05b92eee8ad76615cf572bbf5b0 /03_hello_dynld/dynld.S | |
parent | ef6a411ce8ff615d65e2be105834c2fdbe557de1 (diff) | |
download | dynld-4e871c9dd0418c4f6d33c83fd3338ad261f7dd3f.tar.gz dynld-4e871c9dd0418c4f6d33c83fd3338ad261f7dd3f.zip |
added chapter 03 hello dynld
Diffstat (limited to '03_hello_dynld/dynld.S')
-rw-r--r-- | 03_hello_dynld/dynld.S | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/03_hello_dynld/dynld.S b/03_hello_dynld/dynld.S new file mode 100644 index 0000000..811fe2c --- /dev/null +++ b/03_hello_dynld/dynld.S @@ -0,0 +1,31 @@ +// Copyright (c) 2021 Johannes Stoelp + +#if !defined(__linux__) || !defined(__x86_64__) +# error "Only supported in linux(x86_64)!" +#endif + +#include <asm/unistd.h> + +.intel_syntax noprefix + +.section .text, "ax", @progbits +.global dl_start +dl_start: + // $rsp is guaranteed to be 16-byte aligned. + + // Clear $rbp as specified by the SysV AMD64 ABI. + xor rbp, rbp + + // Load pointer to process context prepared by execve(2) syscall as + // specified in the SysV AMD64 ABI. + // Save pointer in $rdi which is the arg0 (int/ptr) register. + lea rdi, [rsp] + + // Stack frames must be 16-byte aligned before control is transfered to the + // callees entry point. + call dl_entry + + // Call exit(1) syscall to indicate error, dl_entry should not return. + mov rdi, 1 + mov rax, __NR_exit + syscall |