Skip to content

Instantly share code, notes, and snippets.

@punmechanic
Created October 28, 2017 13:49
Show Gist options
  • Save punmechanic/2d104dff0e8dd024eca90fd5646d83f7 to your computer and use it in GitHub Desktop.
Save punmechanic/2d104dff0e8dd024eca90fd5646d83f7 to your computer and use it in GitHub Desktop.
struct size_t {
};
int do_read_from_somewhere(size_t* output) {
size_t out;
*output = out;
return 0;
}
int main() {
size_t buffer;
do_read_from_somewhere(&buffer);
return 0;
}
.file "main.cpp"
.text
.globl _Z22do_read_from_somewhereP6size_t
.def _Z22do_read_from_somewhereP6size_t; .scl 2; .type 32; .endef
.seh_proc _Z22do_read_from_somewhereP6size_t
_Z22do_read_from_somewhereP6size_t:
.LFB0:
pushq %rbp
.seh_pushreg %rbp
movq %rsp, %rbp
.seh_setframe %rbp, 0
subq $16, %rsp
.seh_stackalloc 16
.seh_endprologue
movq %rcx, 16(%rbp)
movl $0, %eax
addq $16, %rsp
popq %rbp
ret
.seh_endproc
.def __main; .scl 2; .type 32; .endef
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
main:
.LFB1:
; push the current value of rbp onto the stack. this is done to preserve the existing value when we pop it later
pushq %rbp
.seh_pushreg %rbp
; move the current stack pointer to rbp
movq %rsp, %rbp
.seh_setframe %rbp, 0
; subtract 48 from the stack pointer - used for SEH
subq $48, %rsp
.seh_stackalloc 48
.seh_endprologue
; invoke __main, whatever this is
call __main
; wat?
leaq -1(%rbp), %rax
; wat wat?
movq %rax, %rcx
; call our function
call _Z22do_read_from_somewhereP6size_t
; set the eax value to 0 - This is the main's return value.
movl $0, %eax
; restore 48 bytes to the stack pointer (remember this is for SEH?)
addq $48, %rsp
; pop the previous value of rbp, restoring it to the original value when we pushed it at the start of .LFB1.
popq %rbp
ret
.seh_endproc
.ident "GCC: (Rev3, Built by MSYS2 project) 5.2.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment