zig icon indicating copy to clipboard operation
zig copied to clipboard

Windows: Rework kernel32 apis

Open The-King-of-Toasters opened this issue 1 year ago • 1 comments

To facilitate https://github.com/ziglang/zig/issues/1840, this commit slims std.windows.kernel32 to only have the functions needed by the standard library. Since this will break projects that relied on these, I offer these solutions:

  • Make an argument as to why certain functions should be added back in. Note that they may just be wrappers around ntdll APIs, which would go against https://github.com/ziglang/zig/issues/1840.

    If necessary I'll add them back in and make wrappers in std.windows for it.

  • Maintain your own list of APIs. This is the option taken by bun, where they wrap functions with tracing.

  • Use zigwin32.

I've also added TODO comments that specify which functions can be reimplemented using ntdll APIs in the future.

Other changes:

  • Group functions into groups (I/O, process management etc.).
  • Synchronize definitions against Microsoft documentation to use the proper parameter types/names.
  • Break all functions with parameters over multiple lines.

The-King-of-Toasters avatar Apr 13 '24 05:04 The-King-of-Toasters

I've added fleshed out the comments on the remaining APIs. I've categorised them into three groups:

  • Forwarders: The function puts the arguments into place and jumps directly into the ntdll function.
  • Wrappers: The function sets up local variables and calls the ntdll function. Typically OBJECT_ATTRIBUTES or UNICODE_STRING, but can be more involved.
  • Unnamed: Functions that are too hard to simply replace.

The-King-of-Toasters avatar Apr 19 '24 14:04 The-King-of-Toasters

@andrewrk This pr has been open for a couple months now, since then a couple Windows API changes have been made. I've kept this branch up-to-date but I'd like it to be merged before I do any more changes (specifically, adding a linkat implementation). I think it would also help future contributors who want to tackle #1840.

Do you have any objections to these changes?

The-King-of-Toasters avatar Jul 18 '24 09:07 The-King-of-Toasters

Sorry for the delay, I hadn't seen it until now. Looks good! Thanks for your patience on the merge.

andrewrk avatar Jul 18 '24 18:07 andrewrk