Skip to content

Commit

Permalink
Windows: Rework kernel32 apis
Browse files Browse the repository at this point in the history
To facilitate ziglang#19037, 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#19037.
  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.
  • Loading branch information
The-King-of-Toasters committed Apr 13, 2024
1 parent bf3a54c commit a5390c4
Show file tree
Hide file tree
Showing 2 changed files with 425 additions and 323 deletions.
2 changes: 1 addition & 1 deletion lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ pub const DebugInfo = struct {
@memcpy(name_buffer[0..4], &[_]u16{ '\\', '?', '?', '\\' });

const process_handle = windows.kernel32.GetCurrentProcess();
const len = windows.kernel32.K32GetModuleFileNameExW(
const len = windows.kernel32.GetModuleFileNameExW(
process_handle,
module.handle,
@ptrCast(&name_buffer[4]),
Expand Down
Loading

0 comments on commit a5390c4

Please sign in to comment.