| ▲ | Windows: Prefer the Native API over Win32(codeberg.org) |
| 52 points by nikbackm 4 days ago | 34 comments |
| |
|
| ▲ | qq66 6 minutes ago | parent | next [-] |
| > Comparing the comprehensive Win32 API reference against the incidentally documented Native APIs, its clear which one Microsoft would prefer you use. The native API is treated as an implementation detail, whilst core parts of Windows' backwards compatibility strategy are implemented in Windows subsystem. > A general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software. Zig clearly doesn't actually care that much about building robust and reusable software if they're going to forgo Microsoft's decades-long backwards compatibility functionality for the dubious gains of using bare-metal APIs. |
|
| ▲ | cmovq 20 minutes ago | parent | prev | next [-] |
| >> Microsoft are free to change the Native API at will, and you will be left holding both pieces when things break. > [...] the worst case scenario is really mild: A new version of windows comes out, breaking ntdll compatibility. Zig project adds a fix to the std lib. Application developer recompiles their zig project from source, and ships an update to their users. That assumes the application developer will continue to maintain it until the end of time. Also "the fix" would mean developers wanting to support earlier Windows versions would need to use an older std library? Or is the library going to have runtime checks to see what Windows build its running on? |
| |
| ▲ | eps 13 minutes ago | parent [-] | | > Microsoft are free to change the Native API at will,... But they won't, because if there is one thing that Microsoft has always been extremely good at and cared for is backward compatibility. And changing Native API will break a ton of existing software, because even though undocumented it is very widely used. | | |
| ▲ | blibble a minute ago | parent [-] | | you are confusing the ntdll interface (which is undocumented and subject to change), and win32 (which is stable, mostly) they tell you not to use ntdll, and say they will change it whenever they want and they have in the past (they have had to modify this policy with "containers" but it's still what they say) |
|
|
|
| ▲ | roelschroeven an hour ago | parent | prev | next [-] |
| > > Won't this get flagged by anti-virus scanners as suspicious? > Unfortunately, yes. We consider this a problem for the anti-virus scanners to solve. I don't think the anti-virus scanners consider Zig important enough, or even know about. They will not be the ones experiencing problems. Having executables quarantined and similar problems will fall on Zig developers and users of their software. That seems like a major drawback for using Zig. |
| |
| ▲ | monocasa 44 minutes ago | parent [-] | | Yeah, I had this problem when shipping go binaries on Windows. Antivirus vendors really do not care that your program regularly shows up as a false positive due to their crappy heuristics, even if you have millions of users. | | |
| ▲ | anfragment 42 minutes ago | parent [-] | | Have you tried code-signing with an EV certificate? If so, did it help? Asking for a friend. | | |
|
|
|
| ▲ | cmovq an hour ago | parent | prev | next [-] |
| Is there an official stance on whether ntdll is stable? Obviously they're not going to change things arbitrarily since applications depend on it, but I'm wondering if there is a guarantee like the linux syscall interface or how you can run a win32 application compiled in 2004 on Win11. |
| |
|
| ▲ | boje 28 minutes ago | parent | prev | next [-] |
| Honestly, this sounds like a future headache that would otherwise go unnoticed unless the programmer is dealing with porting or binding over source code meant for older Windows systems to Zig (or supporting older systems in general). Eventually it might result in a bunch of people typing out blogposts venting their frustrations, and the creation of tutorials and shims for hooking to Win32 instead of the Zig standard library with varying results. Which is fine, I suppose. Legacy compiler targets are a thing. This is already a problem with Linux binaries for systems that don't have a recent enough Glibc (unless the binaries themselves don't link to it and do syscalls directly). |
|
| ▲ | bob1029 43 minutes ago | parent | prev | next [-] |
| Why not use both DLLs? Prefer win32 wherever possible and use the lower level APIs only if absolutely necessary. Benchmark after you have figured this out. Performance is probably not a thing at this level of abstraction. |
| |
| ▲ | nvme0n1p1 16 minutes ago | parent [-] | | What makes you think they haven't benchmarked? Here's one fun example from following development on Zulip: advapi.dll loads bcrypt.dll, which loads bcryptprimitives.dll. bcryptprimitives.dll runs an internal test suite every time it's loaded into any process. So if you can avoid loading advapi.dll, your process will start faster. |
|
|
| ▲ | self_awareness 7 minutes ago | parent | prev | next [-] |
| For me this is too much. I wish Zig all the best, but decisions like this make me want to jump off this sinking ship. |
|
| ▲ | lostmsu an hour ago | parent | prev | next [-] |
| Fool's errand. Apps built with this will have to be maintained forever (vs the apps from Win 9x which still work in Windows 11). |
|
| ▲ | pseudohadamard 3 days ago | parent | prev | next [-] |
| For people not familiar with Windows development, another name for the NT native API is "the API that pretty much every document on Windows programming tells you not to use". It's like coding to the Linux syscall interface instead of libc. |
| |
| ▲ | HexDecOctBin an hour ago | parent | next [-] | | Linux syscall interface is actually stable and can easily be targeted. It’s BSDs (and Mac OS) that force everyone to link to only libc. | | | |
| ▲ | eps 6 minutes ago | parent | prev | next [-] | | "Every document" notwithstanding, Native API is very widely used in practice and generally considered stable. If in doubt, try and find examples of its breakage, semantic changes, etc. | |
| ▲ | kvemkon an hour ago | parent | prev | next [-] | | > It's like ... Considering the level of the API. But it is total opposite comparing a bit deeper. Linux has a famous rule "WE DO NOT BREAK USERSPACE!" e.g. [1]. [1] https://news.ycombinator.com/item?id=44611692 | | |
| ▲ | dunder_cat an hour ago | parent [-] | | One thing that is amusing about the prevalence of advanced anti-cheat in Windows gaming is it's actually causing said API/ABIs to undergo ossification. A good data point is the invention of Syscall User Dispatch^1 on Linux which would allow a program to basically install a syscall handler when they originate from various regions of memory. I do not know how usable this is in practice, admittedly -- but I think the fact it was contributed at all speaks to the growing need. ^1 https://docs.kernel.org/admin-guide/syscall-user-dispatch.ht... |
| |
| ▲ | nullpoint420 an hour ago | parent | prev | next [-] | | Yeah, I know go has had issues because they subvert libc themselves in similar fashion. I wonder how this will turn out. | | |
| ▲ | wrs an hour ago | parent | next [-] | | Go backed out of their strategy on MacOS and started using libc (libsystem?), because when Apple says something is internal and may change without notice, they really mean it. It may be a better risk with Microsoft, but it’s still a risk. | |
| ▲ | LoganDark an hour ago | parent | prev [-] | | I think they had to revert back to libc on macOS/iOS because those have syscall interfaces that truly are not stable (and golang found that out the hard way). I wonder if they had to do the same on BSDs because of syscall filtering. |
| |
| ▲ | pjmlp 40 minutes ago | parent | prev | next [-] | | Except unlike Linux syscall interface and like almost every other OS out there, ABI compatibility is an accident, not a guarantee. | |
| ▲ | koakuma-chan an hour ago | parent | prev [-] | | > It's like coding to the Linux syscall interface instead of libc. The right thing to do? I don't see why I would want to use libc. | | |
| ▲ | pjmlp 38 minutes ago | parent | next [-] | | Nope, in UNIX proper syscalls and libc overlap, that is how C and UNIX eventually evolved side by side, in a way one could argue UNIX is C's runtime, and hence why most C deployments also expect some level of compatibility with UNIX/POSIX. Linux is the exception offering its guts to userspace with guarantees of stability. | |
| ▲ | delta_p_delta_x an hour ago | parent | prev | next [-] | | On Windows, the stability guarantees are opposite to that of Linux. The kernel ABI is not guaranteed to be stable, whereas the Win32 ABI is. And frankly, the Windows way is better. On Linux, the 'ABI' for nearly all user-mode programs is not the kernel's ABI but rather glibc's (plus the variety of third-party libraries, because Win32 has a massive surface area and is an all-in-one API). Now, glibc's ABI constantly changes, so linking against a newer glibc (almost certainly the 'host' glibc, because it is almost impossible to supply a different 'target' glibc without Docker) will result in a program that doesn't run on older glibc. So much for Torvalds' 'don't break userspace'. Not so for a program compiled for 'newer' Win32; all that matters are API compatibilities. If one only uses old-hat interfaces that are documented to be present on Windows 2000, one can write and compile one's code on Windows 11, and the executable will run on the former with no issues. And vice versa, actually. | | |
| ▲ | monocasa 38 minutes ago | parent [-] | | A lot of the native API is considered stable these days. The actual signals aren't, but the wrappers in ntdll are. |
| |
| ▲ | usrnm 37 minutes ago | parent | prev [-] | | > I don't see why I would want to use libc To make your code portable? Linux-only software is even worse than Windows-only | | |
| ▲ | koakuma-chan 3 minutes ago | parent [-] | | Let me narrow down the scope here. I am a Rust developer, developing software that will run on my Linux server. Why would I want to use libc? Why does Rust standard library use libc? Zig, for example, doesn't. |
|
|
|
|
| ▲ | dblohm7 34 minutes ago | parent | prev [-] |
| This is a terrible idea! _Maybe_, _maybe_ using only the documented APIs with only the documented parameters. Unfortunately it makes too many false assumptions about interoperability between Win32 and the underlying native API that aren't true. For example (and the Go runtime does this, much to my chagrin), querying the OS version via the native API always gives you "accurate" version information without needing to link a manifest into your application. Unfortunately that lack of manifest will still cause many Win32 APIs above the native layer to drop into a compatibility mode, creating a fundamental inconsistency between what the application thinks the OS capabilities are versus which Win32 subsystem behaviours the OS thinks it should be offering. |