flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Linux ccall

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 08 Nov 2019, 13:17
why "and esp,0FFFFFFF0h" outer of block - according to calling convention first param should be paragraph alignment, if no param so there is nothing to align, isn`t so?
Code:
if size
        sub     esp,size
end if    


ccall should be:
Code:
macro ccall proc*,[arg]
{
    common
        local size,count
        mov     ebp,esp
        if size
                sub     esp,size
                and     esp,not $F
        end if
        
        count = 0
        if ~ arg eq
    forward
        mov     dword [esp+count*4],arg
        count = count + 1
    common
        end if
        size = count*4
        call    proc
        mov     esp,ebp
}    


and why not so? Why linuxers dislike push?:
Code:
macro ccall proc*,[arg]
{
    common
        local size,count
        mov     ebp,esp
        if ~ arg eq
                count = 0
                sub     esp,size
                and     esp,not $F
                add     esp,size      
    reverse
                pushd arg
                count = count + 1
                match =double any,arg \{ count = count + 1 \} ; why double couldn`t be in linux calls too?
    common
                size = count*4
        end if
        call    proc
        mov     esp,ebp
}    


That one produce absolutely same stack content, plus don`t create redundant alignment, and more flexible ("push mem" exists while "mov mem,mem" - don`t exist).

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 08 Nov 2019, 13:17
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20423
Location: In your JS exploiting you and your system
revolution 08 Nov 2019, 13:24
Where is the "Linux ccall" macro that you are referring to?

32-bit Linux, the OS, uses int 0x80 with register parameters. 64-bit Linux uses syscall.

If you are interfacing to one of the C libraries or linking to some C sources then I thought 32-bit code didn't need any stack alignment.
Post 08 Nov 2019, 13:24
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 08 Nov 2019, 13:47
fasmg source import32.inc - definitions of ccall & cinvoke.
Isn`t *.SO files linux analog of *.DLL? they not have exports?
for example X-window system used via int $80 & syscalls or via cinvoke?

Actualy at the very begining of meeting with Linux windows-users expect to see how to interact with X-windows system, and only later how to interact with OS.


Last edited by ProMiNick on 08 Nov 2019, 14:04; edited 1 time in total
Post 08 Nov 2019, 13:47
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 08 Nov 2019, 13:56
These macros have been simply copied from the libc version, which targets not just Linux and therefore needs to fullfill expectations of some other systems as well. I did not pay much attention to this specific use being Linux-only.
Post 08 Nov 2019, 13:56
View user's profile Send private message Visit poster's website Reply with quote
st



Joined: 12 Jul 2019
Posts: 49
Location: Russia
st 09 Nov 2019, 07:58
I suppose the alignment depends on data passed to functions.

Quote:
SYSTEM V APPLICATION BINARY INTERFACE Intel386 Architecture Processor Supplement Fourth Edition (March 19, 1997)

Registers and the Stack Frame
...
The stack is word aligned. Although the architecture does not require any
alignment of the stack, software convention and the operating system
requires that the stack be aligned on a word boundary.
http://www.sco.com/developers/devspecs/abi386-4.pdf

Quote:
System V Application Binary Interface Intel386 Architecture Processor Supplement Version 1.0 (February 3, 2015)

2.2.2 The Stack Frame
...
The end of the input argument area shall be aligned on a 16 (32, if __m256 is
passed on stack) byte boundary. In other words, the value (%esp + 4) is always
a multiple of 16 (32) when control is transferred to the function entry point
.
https://www.uclibc.org/docs/psABI-i386.pdf

However I do don think this is of actual interest nowadays as Linux tends to drop IA32 mode support.

ProMiNick wrote:
Actualy at the very begining of meeting with Linux windows-users expect to see how to interact with X-windows system, and only later how to interact with OS.

As to me, I did not. I see no practical reason to program X with assembly when Fedora Gnome comes with Wayland. While I have implemented in asm an experimental memory manager with garbage collection, because I was doubt how to do some tricks in C.
Post 09 Nov 2019, 07:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.