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

Loading x64 libraries from arm64 code #1273

Open
Rosentti opened this issue Feb 20, 2024 · 4 comments
Open

Loading x64 libraries from arm64 code #1273

Rosentti opened this issue Feb 20, 2024 · 4 comments

Comments

@Rosentti
Copy link

Hi. I make an application (OpenSteamClient), which is build with dotnet and C#.
This supports being natively compiled for arm64, x64 and lots of platforms. However an underlying library is only available as 64-bit or 32-bit (works the same regardless).

Can box64/box86 be used with a native app to load a non-native library and have it work?

Sorry if this has been asked before, couldn't find anything on the topic.

@ptitSeb
Copy link
Owner

ptitSeb commented Feb 20, 2024

It can, but not directly. Create a special wrapper for a lib is possible, as long as you now the API.
It's not straightforward for now, but if you have the libs in question and it's API to wrap, I can work on that, OpenSteamClient looks like an interesting project.

@Rosentti
Copy link
Author

Well that might be a problem. We don't know it's api 100%, and all the interop is done through C#. Are there docs for that feature anywhere?

@ptitSeb
Copy link
Owner

ptitSeb commented Feb 20, 2024

No, no doc.

Basicaly, the idea is to build box64 as a library that expose the needed API, and wrapped calls to execute the underlying x86_64 code.
If the API is C (and not C++), that can be done. If the API get enriched later by other function call, that's not an issue, but it would need code change and new build. I still need to create the mecanism, but never did it becasue I never had a concrete lib to wrap...

@Rosentti
Copy link
Author

So libbox64 (as a library, let's call it libbox64 for now), could expose, say:

  • dlopen
  • dlsym
  • dlclose

If it's possible, that'd effectively be enough for our use case.

The first function we call from the lib is called CreateInterface (via dlsym/dlopen), which returns a pointer to a C++ class with a specified name (as const char*).

The actual calling of the functions in the C++ class is done with some math to calculate each function's offset in the vtable, so no problem there with box64?

The second one is a callback system (also retrieved with dlsym), called rapidly every ~5ms. This returns a struct to some callback data. I presume this is also not an issue with box64, since the data comes from the lib.

I know one possible problem area though, the lib spawns other x64 (and in some cases x86) processes for some (optional) features, like shader management.

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

2 participants