Commit Graph

229 Commits

Author SHA1 Message Date
Binary Craft a7a709aaa9 Fixes #13893 - some standard library networking tests are failing on Windows 2023-03-01 02:54:43 -05:00
Andrew Kelley aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
Veikka Tuominen 7199d7c777 split @qualCast into @constCast and @volatileCast 2023-02-15 01:43:57 +02:00
Veikka Tuominen f16c10a86b implement @qualCast 2023-01-30 18:55:57 +02:00
Andrew Kelley cb9d00e1af Merge pull request #14402 from kcbanner/cbe_x86_fixes
CBE: x86 support and MSVC ABI fixes
2023-01-24 17:53:54 -05:00
Andrew Kelley ac28bedbee Merge pull request #14418 from ifreund/assume-sentinel-sux
std: eliminate pointless meta.assumeSentinel() usage
2023-01-23 21:01:54 -05:00
kcbanner 1aa2c32055 cbe: fixes for x86
- Emit calling convention
- Fix .Naked handling for msvc
- Add teb helper for x86
- Fix 128-bit shl implementation when rhs is >= 64
- Add 128-bit shl tests
2023-01-23 13:48:36 -05:00
Isaac Freund faf2fd18d3 std: eliminate pointless meta.assumeSentinel() usage
This fixes a bug in std.net caused during the introduction of
meta.assumeSentinel due to the unfortunate semantics of mem.span()

This leaves only 3 remaining uses of meta.assumeSentinel() in the
standard library, each of which could be a simple @ptrCast([*:0]T, foo)
instead. I think this function should likely be removed.
2023-01-23 12:19:53 +01:00
Jan Philipp Hafer 55e879d2ed std.os.windows: add possible error NETNAME_DELETED of ReadFile
Closes #13631
2023-01-23 02:07:12 -05:00
mlugg d3599ec73c std: implement os.mprotect on Windows 2023-01-20 03:33:35 +02:00
Andrew Kelley 86308ba1e1 std.net.getAddressList: call WSAStartup on Windows 2023-01-17 00:08:42 -07:00
star-tek-mb 1f9fa82235 windows root certificate scanning 2023-01-17 00:08:42 -07:00
kcbanner 58e558822a windows: unexpectedStatus/unexpectedError start the stack trace at the caller 2023-01-08 23:51:55 -05:00
kcbanner 461fb499f3 windows: rework DebugInfo to use less file operations and fix some memory management issues 2023-01-08 20:28:42 -05:00
Casey Banner 09ff03a57a debug: replace RtlCaptureStackBackTrace (which was spuriously failing) with a new implementation which uses RtlVirtualUnwind instead (#12740)
windows: add RtlCaptureContext, RtlLookupFunctionEntry, RtlVirtualUnwind and supporting types
windows: fix alignment of CONTEXT structs to match winnt.h as required by RtlCaptureContext (fxsave instr)
windows aarch64: fix __chkstk being defined twice if libc is not linked on msvc

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2023-01-04 14:54:49 -05:00
Andrew Kelley 72560b8db5 add some comments to explain workarounds 2023-01-02 14:08:50 -07:00
kcbanner ccf0ab0ef6 cbe: use callconv(.C) for zig.g stub functions, use zig.h function for windows teb instead of syscall 2023-01-02 13:56:11 -07:00
kcbanner 7fb3683c32 cbe: more msvc compatibility work
- Add .StaticInitializer to ValueRenderLocation to indicate that the emitted values
must be constant expressions (no function calls, struct casting).
- Add new path for special float types (nan, inf) that works in constant expressions
- Implement windows.teb() using a syscall for .stage2_c because x64 MSVC
doesn't support any kind of inline asm
2023-01-01 16:44:28 -05:00
Ganesan Rajagopal 4172c29166 Fix typo (#14149) 2023-01-01 15:57:05 +00:00
Ryan Liptak e9c48e6631 spawnWindows: Improve worst-case performance considerably
The name of the game here is to avoid CreateProcessW calls at all costs,
and only ever try calling it when we have a real candidate for execution.
Secondarily, we want to minimize the number of syscalls used when checking
for each PATHEXT-appended version of the app name.

An overview of the technique used:
- Open the search directory for iteration (either cwd or a path from PATH)
- Use NtQueryDirectoryFile with a wildcard filename of `<app name>*` to
  check if anything that could possibly match either the unappended version
  of the app name or any of the versions with a PATHEXT value appended exists.
- If the wildcard NtQueryDirectoryFile call found nothing, we can exit early
  without needing to use PATHEXT at all.

This allows us to use a <open dir, NtQueryDirectoryFile, close dir> sequence
for any directory that doesn't contain any possible matches, instead of having
to use a separate look up for each individual filename combination (unappended +
each PATHEXT appended). For directories where the wildcard *does* match something,
we only need to do a maximum of <number of supported PATHEXT extensions> more
NtQueryDirectoryFile calls.

---

In addition, we now only evaluate the extensions in PATHEXT that we know we can handle (.COM, .EXE, .BAT, .CMD) and ignore the rest.

---

This commit also makes two edge cases match Windows behavior:

- If an app name has the extension .exe and it is attempted to be executed, that is now treated as unrecoverable and InvalidExe is immediately returned no matter where the .exe is (cwd or in the PATH). This matches the behavior of the Windows cmd.exe.
- If the app name contains more than just a filename (e.g. it has path separators), then it is excluded from PATH searching and only does a cwd search. This matches the behavior of Windows cmd.exe.
2022-12-18 02:48:34 -08:00
Ryan Liptak 3ee8c49582 windows: Map EXE_MACHINE_TYPE_MISMATCH to InvalidExe
Seems to happen if the command trying to be executed has the extension .exe and it's an invalid executable.
2022-12-18 02:31:34 -08:00
Ryan Liptak 6e22b63edb windows: Extract RtlEqualUnicodeString usage into to a helper function 2022-12-17 22:06:47 -08:00
Ryan Liptak 5843b7987e Add error.InvalidExe to CreateProcessW error set and handle it in ChildProcess.spawnWindows 2022-12-17 03:36:45 -08:00
Andrew Kelley dd4ca88ca7 std: fix compile error bitrot
These were revealed in an earlier commit in this branch that removed a
workaround disabling Windows std lib files from being tested.
2022-12-11 12:48:17 -07:00
Andrew Kelley 50eb7983cd remove most conditional compilation based on stage1
There are still a few occurrences of "stage1" in the standard library
and self-hosted compiler source, however, these instances need a bit
more careful inspection to ensure no breakage.
2022-12-06 20:38:54 -07:00
Andrew Kelley 44ee1c885f std.os.windows.ReadLink: add missing alignment of local data buffer 2022-11-30 12:55:23 -07:00
Jakub Konka d3b1cdf508 Merge pull request #13659 from ziglang/arm-win-cpu-features
windows: add native CPU and features detection for Armv8 chips
2022-11-28 21:36:56 +01:00
Ryan Liptak 4e078941d0 os.windows.OpenFile: Add USER_MAPPED_FILE as a possible error
Ran into this when using a program that uses CreateFileMapping and then trying to call `std.fs.createFile` on the mapped file. More info can be found here:

https://stackoverflow.com/questions/41844842/when-error-1224-error-user-mapped-file-occurs

Before:

```
error.Unexpected NTSTATUS=0xc0000243
C:\Users\Ryan\Programming\Zig\zig\lib\std\os\windows.zig:138:40: 0x7ff74e957466 in OpenFile (test.exe.obj)
        else => return unexpectedStatus(rc),
                                       ^
```

After:

```
FAIL (AccessDenied)
C:\Users\Ryan\Programming\Zig\zig\lib\std\os\windows.zig:137:30: 0x7ff7f5b776ea in OpenFile (test.exe.obj)
        .USER_MAPPED_FILE => return error.AccessDenied,
                             ^
```
2022-11-28 18:56:11 +01:00
Jakub Konka d64d7aaac7 windows: drive the registry helper with actual value set for reg entries 2022-11-28 17:07:34 +01:00
Jakub Konka 57bda6524b windows: make registry helper generic over value types 2022-11-28 17:07:34 +01:00
Jakub Konka f348fbc024 windows: revert changes to definition of HKEY 2022-11-28 17:07:34 +01:00
Jakub Konka 7ea2c7fbcd windows: use RtlQueryRegistryValues to query reg in a single syscall 2022-11-28 17:07:34 +01:00
Jakub Konka 153afed877 windows: impl some primitives for getting registry keys 2022-11-28 17:07:34 +01:00
Jakub Konka e74b6f0a4b windows: detect couple more aarch64 CPU features 2022-11-28 17:07:34 +01:00
Jakub Konka 6edf9127fe windows: add missing enum values for ProcessorFeatures enumeration 2022-11-28 17:07:34 +01:00
Jakub Konka 625415d738 windows: add zig impl of IsProcessorFeaturePresent syscall 2022-11-28 17:07:34 +01:00
Jakub Konka 1eac3c57ec windows: add processor feature enumeration 2022-11-28 17:07:33 +01:00
Ali Chraghi fca776f8f5 os: windows: fix unhandled error 2022-11-19 22:48:32 +02:00
Ali Chraghi f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
Ryan Liptak db80225a97 fs: Some NAME_MAX/MAX_NAME_BYTES improvements 2022-10-29 14:30:46 -07:00
Ryan Liptak 33fdc43714 std.fs: Add MAX_NAME_BYTES
Also add some NAME_MAX or equivalent definitions where necessary
2022-10-29 14:30:43 -07:00
Andrew Kelley 9ee4530b9b std.os.windows.OpenFile: handle INVALID_HANDLE ntstatus 2022-10-18 16:52:43 -07:00
Ryan Liptak 8bb2e96ac3 std.os.windows: Change HKEY to *opaque {}
The definition of HKEY__ as a struct with an unused int field is only the case in the Windows headers when `STRICT` is defined. From https://learn.microsoft.com/en-us/windows/win32/winprog/enabling-strict:

> When STRICT is defined, data type definitions change as follows:
>
> -  Specific handle types are defined to be mutually exclusive; for example, you will not be able to pass an HWND where an HDC type argument is required. Without STRICT, all handles are defined as HANDLE, so the compiler does not prevent you from using one type of handle where another type is expected.

Zig's `opaque {}` already gives this benefit to us, so the usage of a struct with an unused field is unnecessary, and it was causing HKEY to have an alignment of 4, which is a problem because there are HKEY constants like HKEY_LOCAL_MACHINE (0x80000002) that are not 4-byte aligned. Without this change, the compiler would not allow something like HKEY_LOCAL_MACHINE to be defined since it enforces pointer alignment.
2022-10-14 15:23:13 -04:00
zooster db5562deb0 std.os.windows: fix HANDLER_ROUTINE callconv 2022-10-03 13:05:38 +03:00
ominitay 295451dfe5 std: Replace use of stage1 function pointers 2022-09-29 21:45:30 +03:00
Andrew Kelley 445b33cfc0 fix std.os.windows.PathSpace.span
it was returning a pointer to a parameter.
2022-08-19 16:45:16 -07:00
Andrew Kelley a82d7c2063 std: add missing error to windows.WriteFile
I encountered this error today when testing the self-hosted compiler on
Windows.
2022-08-11 06:22:05 -04:00
Ali Chraghi 0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
Andrew Kelley 76b7f56725 std.os.windows: upgrade to new function pointer semantics 2022-05-02 22:14:17 -07:00
protty 963ac60918 std.Thread: Mutex and Condition improvements (#11497)
* Thread: minor cleanups

* Thread: rewrite Mutex

* Thread: introduce Futex.Deadline

* Thread: Condition rewrite + cleanup

* Mutex: optimize lock fast path

* Condition: more docs

* Thread: more mutex + condition docs

* Thread: remove broken Condition test

* Thread: zig fmt

* address review comments + fix Thread.DummyMutex in GPA

* Atomic: disable bitRmw x86 inline asm for stage2

* GPA: typo mutex_init

* Thread: remove noalias on stuff

* Thread: comment typos + clarifications
2022-04-23 19:35:56 -05:00