Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wine wrapper for MacOS? #44

Open
mkarr opened this issue Oct 5, 2022 · 3 comments
Open

Wine wrapper for MacOS? #44

mkarr opened this issue Oct 5, 2022 · 3 comments

Comments

@mkarr
Copy link

mkarr commented Oct 5, 2022

HI, would it be possible to compile the wine wrapper for libusb for wine on Macos?

@radiomanV
Copy link
Owner

Hi, not a MacOs user here but i think yes if you can get it compiled for 32 bit. Can't give you directions of how do do this but from what a macos user told me some time ago there's a problem to compile it as 32 bit library under macos.

@d235j
Copy link

d235j commented Jan 10, 2023

macOS dropped 32-bit support in version 10.15. Most people running wine on macOS nowadays are using Crossover's 32on64 wine source, which uses thunking to call the 64-bit core libraries. However, to the best of my knowledge this does not provide winegcc or any mechanism to compile such a DLL.

Hopefully in the future, when 32on64 support lands upstream (it is a work-in-progress right now), an equivalent to winegcc will be available that supports thunking. But it's not here yet. So, for now you'll have to use wine on 32-bit Linux. This may be possible with Apple's Rosetta for Linux, but I haven't tried it so far.

@nanoant
Copy link

nanoant commented Jun 24, 2024

Hi all (@mkarr, @radiomanV, @d235j).
Wine 8.0 introduced WOW64 and with Wine 9.0 it is now considered stable. It is should be possible to make this wrapper compile both on 64-bit Linux and 64-bit only macOS without any 32-bit host compiler or any 32-bit host libraries.

It should be doable by splitting the DLL source code into:

  1. Windows part that is built with winegcc -b i686-w64-mingw32 into .dll and
  2. Unix part that is built with regular host $(CC) into .so

Then using wine/unixlib.h API shipped with Wine, 32-bit Windows DLL can call into 64-bit .so methods as soon as it calls __wine_init_unix_call, e.g.:

BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, void *reserved )
{
    switch (reason)
    {
    case DLL_PROCESS_ATTACH:
    {
        DisableThreadLibraryCalls( hinst );
        if (__wine_init_unix_call()) ERR( "No pcap support, expect problems\n" );
        else
        {
            char errbuf[PCAP_ERRBUF_SIZE];
            struct init_params params = { PCAP_CHAR_ENC_UTF_8, errbuf };
            BOOL is_wow64;

            if (PCAP_CALL( init, &params ) == PCAP_ERROR)
                WARN( "failed to enable UTF-8 encoding %s\n", debugstr_a(errbuf) );
            if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
            {
                params.opt = PCAP_MMAP_32BIT;
                if (PCAP_CALL( init, &params ) == PCAP_ERROR)
                    WARN( "failed to enable 32-bit mmap() %s\n", debugstr_a(errbuf) );
            }
        }
        break;
    }
    case DLL_PROCESS_DETACH:
        if (reserved) break;
        free_datalinks();
        free_tstamp_types();
        break;
    }
    return TRUE;
}

There are no tutorials on this (at least I found nothing) but, studying Wine source code like ws2_32 module, it should be relatively easy to implement. It requires some boiler plate as above, but this should be mostly copy paste effort.

On top of that we could also replace Linux specific udev with libusb_hotplug_register_callback API, this would make this module completely universal, running on any platform both Wine and libusb can run on.

I'd love to take this challange as I'd love to have native Xgecu software running on Mac, but I am not sure if I can find any time before October :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants