How does WINE handle call stack alignment for MacOS?

Questions about Wine on macOS.
Locked
blueshogun96
Newbie
Newbie
Posts: 1
Joined: Sat Jan 21, 2017 9:02 pm

How does WINE handle call stack alignment for MacOS?

Post by blueshogun96 »

I'm quite stumped on how WINE handles this (likely because I haven't tried hard enough) for MacOS. How do you (the devs) handle the difference in the call stack alignment? For Windows, it's typically 4-byte aligned. But for MacOS, it's 16-byte aligned, which would make things a bit trickier. I was hoping to find out how the devs managed to work around this issue.

If you want to know why I'm asking, it's because I'm working on a somewhat hacky/improper VM so to speak. Since WINE cannot run binaries that require a base address of 0x10000, it's not as simple as running WINE to get the results I need. Let me illustrate what I mean and what I am doing:

Code: Select all

void macbox_install_wrapper( void* function_addr, void* wrapper_addr )
{
    uint8_t* func = (uint8_t*) function_addr;
    
    *(uint8_t*) &func[0] = 0xE9;    // JMP rel32 (quick and easy)
    *(uint32_t*)&func[1] = (uint32_t) wrapper_addr - (uint32_t) function_addr;
}
Yes, this is 32-bit code and it needs to be in i386 mode for it to work. This works just fine for Windows, but when calling a wrapper function from a Mac app, the stack alignment gets misaligned and chaos happens.

I have tried changing the alignment settings in XCode (I forgot exactly what I did, it's been a few months) but that did not appear to work. I also tried defining CALLBACK myself this way:

Code: Select all

#define CALLBACK __attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__)) __attribute__((aligned(4)))
This also does not appear to work either. The codebase in WINE is a bit large so I haven't been able to find for myself exactly how this is handled. So any hints would be helpful.

Thanks,

Shogun
User avatar
dimesio
Moderator
Moderator
Posts: 13205
Joined: Tue Mar 25, 2008 10:30 pm

Re: How does WINE handle call stack alignment for MacOS?

Post by dimesio »

You should probably ask this on the developer's mailing list. Most developers don't read the user's forum.
Locked