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

Windows: Rework kernel32 apis #19641

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

The-King-of-Toasters
Copy link
Contributor

@The-King-of-Toasters The-King-of-Toasters commented Apr 13, 2024

To facilitate #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 Prefer depending on NtDll rather than kernel32 or other higher level DLLs #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 The-King-of-Toasters changed the title QueryObjectName: Add error union Windows: Rework kernel32 apis Apr 13, 2024
@The-King-of-Toasters
Copy link
Contributor Author

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 The-King-of-Toasters force-pushed the windows-api-refactor branch 2 times, most recently from 3e99b86 to ab020f0 Compare April 20, 2024 03:38
lib/std/os/windows/kernel32.zig Outdated Show resolved Hide resolved
lib/std/os/windows/kernel32.zig Outdated Show resolved Hide resolved
lib/std/os/windows/kernel32.zig Outdated Show resolved Hide resolved
@The-King-of-Toasters The-King-of-Toasters force-pushed the windows-api-refactor branch 2 times, most recently from 60252bb to 7615944 Compare April 22, 2024 07:12
lib/std/os/windows.zig Outdated Show resolved Hide resolved
@The-King-of-Toasters The-King-of-Toasters force-pushed the windows-api-refactor branch 2 times, most recently from 57f8ff0 to 6fb865e Compare April 25, 2024 07:15
@The-King-of-Toasters The-King-of-Toasters force-pushed the windows-api-refactor branch 2 times, most recently from 3999adb to 98b3e14 Compare May 12, 2024 14:25
To facilitate ziglang#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 two 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 ziglang#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[1],
  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.
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 this pull request may close these issues.

None yet

2 participants