Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any equivalent for stdcall in GCC?

I'm working on my own kernel using GCC, and when calling C functions from asm code, I have to do add esp,xx myself. After some searching I found that stdcall is a Microsoft invention and can't use it in GCC. Is there any handy way to do this work?

like image 525
babel92 Avatar asked Oct 26 '12 23:10

babel92


People also ask

What is difference between cdecl and Stdcall?

__cdecl is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it can do vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code.

What does __ Stdcall mean?

__stdcall is a calling convention: a way of determining how parameters are passed to a function (on the stack or in registers) and who is responsible for cleaning up after the function returns (the caller or the callee).

What calling convention does GCC use?

In Linux, GCC sets the de facto standard for calling conventions. Since GCC version 4.5, the stack must be aligned to a 16-byte boundary when calling a function (previous versions only required a 4-byte alignment). A version of cdecl is described in System V ABI for i386 systems.


Video Answer


1 Answers

Is there any equivalence of stdcall in linux?

my kernel in a linux environment

Wait, is this your own kernel, or the Linux kernel? Because if it's your own kernel, it's not Linux any more.

  1. If you're working on Linux, you'll want to stick with regular calling conventions and write your assembly to match.

  2. If you're working on your own kernel, you can do anything you want. GCC and Clang both support stdcall calling conventions on ix86 processors, e.g.,

     #define stdcall __attribute__((stdcall))
    

    See: Function Attributes (GCC manual)

like image 172
Dietrich Epp Avatar answered Oct 14 '22 13:10

Dietrich Epp