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

Wrapping fopencookie #787

Closed
ksco opened this issue May 15, 2023 · 2 comments · Fixed by #788
Closed

Wrapping fopencookie #787

ksco opened this issue May 15, 2023 · 2 comments · Fixed by #788

Comments

@ksco
Copy link
Collaborator

ksco commented May 15, 2023

This function is used by an old game running on ScummVM, and it takes a struct cookie_io_functions_t as an argument.

typedef struct {
   cookie_read_function_t  *read;
   cookie_write_function_t *write;
   cookie_seek_function_t  *seek;
   cookie_close_function_t *close;
} cookie_io_functions_t;

FILE *fopencookie(void *restrict cookie, const char *restrict mode,
                  cookie_io_functions_t io_funcs);

IIUC, A struct of this size will be directly passed through the stack, and it needs to be reconstructed on the fly when calling the native libs. The callback functions also need to be properly wrapped (i.e. GOM). Wrapper infra doesn't have support for this kind of function it seems.

A simple program for testing this function: https://ksco.cool/SAi4

@ptitSeb
Copy link
Owner

ptitSeb commented May 15, 2023

Mmmm, I need to think about this, but a signature like "pFEppV" should work. You than create

EXPORT void* my_fopencookie(x64emu_t* emu, vpod* cookie, void* mode, my_cookie_io_function_t* s)

That should work, as V will gives a pointer to pointing at the stack directly.

@ksco
Copy link
Collaborator Author

ksco commented May 15, 2023

Oh! Indeed! Let me try it.

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

Successfully merging a pull request may close this issue.

2 participants