calling-convention

Is garbage allowed in high bits of parameter and return value registers in x86-64 SysV ABI?

爷,独闯天下 提交于 2020-01-27 04:26:19
问题 The x86-64 SysV ABI specifies, among other things, how function parameters are passed in registers (first argument in rdi , then rsi and so on), and how integer return values are passed back (in rax and then rdx for really big values). What I can't find, however, is what the high bits of parameter or return value registers should be when passing types smaller than 64-bits. For example, for the following function: void foo(unsigned x, unsigned y); ... x will be passed in rdi and y in rsi , but

Is garbage allowed in high bits of parameter and return value registers in x86-64 SysV ABI?

那年仲夏 提交于 2020-01-27 04:26:07
问题 The x86-64 SysV ABI specifies, among other things, how function parameters are passed in registers (first argument in rdi , then rsi and so on), and how integer return values are passed back (in rax and then rdx for really big values). What I can't find, however, is what the high bits of parameter or return value registers should be when passing types smaller than 64-bits. For example, for the following function: void foo(unsigned x, unsigned y); ... x will be passed in rdi and y in rsi , but

Windows32 API: “mov edi,edi” on function entry?

我怕爱的太早我们不能终老 提交于 2020-01-24 17:33:48
问题 I'm stepping through Structured Error Handling recovery code in Windows 7 (e.g, what happens after SEH handler is done and passes back "CONTINUE" code). Here's a function which is called: 7783BD9F mov edi,edi 7783BDA1 push ebp 7783BDA2 mov ebp,esp 7783BDA4 push 1 7783BDA6 push dword ptr [ebp+0Ch] 7783BDA9 push dword ptr [ebp+8] 7783BDAC call 778692DF 7783BDB1 pop ebp 7783BDB2 ret 8 I'm used to the function prolog of "push ebp/mov ebp,esp". What's the purpose of the "mov edi,edi"? 回答1: Raymond

variadic arguements and x64

笑着哭i 提交于 2020-01-20 08:39:26
问题 Well I've found something that interests me and I didn't manage to find an answer for it.... how does the va_arg \ va_start \ va_list \ va_end macros work under the hood in x64? calling convention in i386 passes parameters on the stack hence the macro just increments some pointer that points to the stack base and forwards it however in x64 all parameters are passed by registers.... so what happens there? how does the called function know which registers were used to pass arguments and doesn't

Weird MSC 8.0 error: “The value of ESP was not properly saved across a function call…”

只愿长相守 提交于 2020-01-18 21:32:52
问题 We recently attempted to break apart some of our Visual Studio projects into libraries, and everything seemed to compile and build fine in a test project with one of the library projects as a dependency. However, attempting to run the application gave us the following nasty run-time error message: Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function pointer declared with a different calling convention. We

Run-Time Check Failure #0: Using C-exports from MinGW dll in VC++ (or: Using libclang MinGW build in VC++ application)

依然范特西╮ 提交于 2020-01-17 04:54:05
问题 This question is about using C-Functions from a MinGW dll in a VC++ project, which fails with the following error: Run-Time Check Failure #0 . I successfully build clang and more importantly libclang using MinGW (to have a libclang.dll that uses the MinGW standard library). My application previously used a VC++-build of libclang, that I now want to exchange with the MinGW build. To do that, I created a def-file and afterwards an import library from the MinGW dll file: dlltool -z libclang.def

x86 Assembly - Why is [e]bx preserved in calling conventions?

耗尽温柔 提交于 2020-01-13 10:04:36
问题 I've noticed that a lot of calling conventions insist that [e]bx be preserved for the callee. Now, I can understand why they'd preserve something like [e]sp or [e]bp, since that can mess up the callee's stack. I can also understand why you might want to preserve [e]si or [e]di since that can break the callee's string instructions if they aren't particularly careful. But [e]bx? What on earth is so important about [e]bx? What makes [e]bx so special that multiple calling conventions insist that

Calling convention on x64

依然范特西╮ 提交于 2020-01-10 02:57:18
问题 I saw in several places that Microsoft calling conventions for x64 platforms were narrowed down to just one: Caller cleans stack ( cdecl ), and parameters are passed in a combination of stack and registers (I am not going into the exact details here). I assume that if this is the calling convention of the OS, then probably all other compilers targeting Windows (e.g. mingw-w64) follow it, too. Is this calling convention true also on other major platforms ( x64 Linux, etc.)? Or does Linux still

What are callee and caller saved registers?

荒凉一梦 提交于 2020-01-09 03:01:10
问题 I'm having some trouble understanding the difference between caller and callee saved registers and when to use what. I am using the MSP430 : procedure: mov.w #0,R7 mov.w #0,R6 add.w R6,R7 inc.w R6 cmp.w R12,R6 jl l$loop mov.w R7,R12 ret the above code is a callee and was used in a textbook example so it follows the convention. R6 and R7 are callee saved and R12 is caller saved. My understanding is that the callee saved regs aren't "global" in the sense that changing its value in a procedure

Segfault while calling C function (printf) from Assembly

守給你的承諾、 提交于 2020-01-07 04:36:30
问题 I am using NASM on linux to write a basic assembly program that calls a function from the C libraries (printf). Unfortunately, I am incurring a segmentation fault while doing so. Commenting out the call to printf allows the program to run without error. ; Build using these commands: ; nasm -f elf64 -g -F stabs <filename>.asm ; gcc <filename>.o -o <filename> ; SECTION .bss ; Section containing uninitialized data SECTION .data ; Section containing initialized data text db "hello world",10 ;