calling-convention

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

此生再无相见时 提交于 2019-11-27 15:36:59
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 they are only 32-bits. Do the high 32-bits of rdi and rsi need to be zero? Intuitively, I would assume

Why not store function parameters in XMM vector registers?

≯℡__Kan透↙ 提交于 2019-11-27 14:03:43
I'm currently reading the book: "Computer Systems - A Programmers Perspective". I've found out that, on the x86-64 architecture, we are limited to 6 integral parameters which will be passed to a function in registers. The next parameters will be passed on the stack. And also, the first up-to-8 FP or vector args are passed in xmm0..7. Why not use float registers in order to store the next parameters, even when the parameters are not single/double precision variables? It would be much more efficient (as far as I understood) to store the data in registers, than to store it to memory, and then

how to specify vc11 lambda calling convention

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 14:00:57
I want to pass a lambda function pointer, which nested in a class, to the Windows API callback function. I found there is no place for me to specify the __stdcall keyword. Some people told me the compile only support __cdecl , but after I used nm command to dump the obj file, I found the compile will generate three helper function ( __stdcall , __cdecl , __fastcall ) concurrently. So my problem is, how can I specify the calling convention? Those following code are my test code. #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { auto func = [](){}; return 0; } 00000000 t ?<helper_func

Is “asmlinkage” required for a c function to be called from assembly?

痞子三分冷 提交于 2019-11-27 11:18:26
问题 I am writing a C function that will be invoked from assembly code. (Specifically, I want to do some checking job in the path of system call handling in linux kernel, so I will call the c function before a system call is dispatched in entry_32.S) I am confused with the "asmlinkage" modifier when defining my c function. I know asmlinkage is to tell the compiler that the parameters will be passed through stack. #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) Questions: (1) Is

Changing a C# delegate's calling convention to CDECL

て烟熏妆下的殇ゞ 提交于 2019-11-27 08:37:47
I have had this problem with C# when I was using DotNet1.1 The problem is this. I have an unmanaged dll, which has a function which takes a function pointer (among other arguments). When I declare the DLLImport in C# code, I pass a delegate. But the delegates in C# have stdcall calling convention whereas the unmanaged function expects a cdecl function pointer. Thus my naive approach resulted in crashes. Then I found the following: http://www.codeproject.com/KB/cs/cdeclcallback.aspx Some guy wrote an excellent library that enables changing calling convention of the delegate by, as I understood,

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

跟風遠走 提交于 2019-11-27 07:32:54
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 have never even specified calling conventions (__cdecl etc.) for our functions, leaving all the compiler

Where exactly is the red zone on x86-64?

血红的双手。 提交于 2019-11-27 06:35:45
问题 From Wikipedia: In computing, a red zone is a fixed-size area in a function's stack frame beyond the return address which is not preserved by that function. The callee function may use the red zone for storing local variables without the extra overhead of modifying the stack pointer. This region of memory is not to be modified by interrupt/exception/signal handlers. The x86-64 ABI used by System V mandates a 128-byte red zone, which begins directly after the return address and includes the

Can Scala call by reference?

跟風遠走 提交于 2019-11-27 05:44:39
问题 I know that Scala supports call-by-name from ALGOL, and I think I understand what that means, but can Scala do call-by-reference like C#, VB.NET, and C++ can? I know that Java cannot do call-by-reference, but I'm unsure if this limitation is solely due to the language or also the JVM. This would be useful when you want to pass an enormous data structure to a method, but you don't want to make a copy of it. Call-by-reference seems perfect in this case. 回答1: Java and Scala both use call by

How exactly does the callstack work?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 04:59:14
问题 I'm trying to get a deeper understanding of how the low level operations of programming languages work and especially how they interact with the OS/CPU. I've probably read every answer in every stack/heap related thread here on Stack Overflow, and they are all brilliant. But there is still one thing that I didn't fully understand yet. Consider this function in pseudo code which tends to be valid Rust code ;-) fn foo() { let a = 1; let b = 2; let c = 3; let d = 4; // line X doSomething(a, b);

What prevents the usage of a function argument as hidden pointer?

谁都会走 提交于 2019-11-27 04:49:24
问题 I try to understand the implication of System V AMD64 - ABI's calling convention and looking at the following example: struct Vec3{ double x, y, z; }; struct Vec3 do_something(void); void use(struct Vec3 * out){ *out = do_something(); } A Vec3 -variable is of type MEMORY and thus the caller ( use ) must allocate space for the returned variable and pass it as hidden pointer to the callee (i.e. do_something ). Which is what we see in the resulting assembler (on godbolt, compiled with -O2 ): use