Commit graph

6754 commits

Author SHA1 Message Date
Adrian Delgado
d6ad69d40a workaround bootstrapping limitations 2023-03-22 13:22:25 -05:00
Adrian Delgado
f34aa2d14f std.math: port int log10 from Rust 2023-03-22 12:03:11 -05:00
Frank Denis
d61ac0db8c
TLS: Favor ChaCha over AES-based ciphers on CPUs without AES support (#15034)
On CPUs without AES support, ChaCha is always faster and safer than
software AES.

Add `crypto.core.aes.has_hardware_support` to represent whether
AES acceleration is available or not, and in `tls.Client`, favor
AES-based ciphers only if hardware support is available.

This matches what BoringSSL is doing.
2023-03-22 17:58:24 +01:00
Frank Denis
84b89d7cfe
crypto.hmac: set the recommended key size to the block size (#15031)
HMAC supports arbitrary key sizes, and there are no practical reasons
to use more than 256 bit keys.

It still makes sense to match the security level, though, especially
since a distinction between the block size and the key size can be
confusing.

Using HMAC.key_size instead of HMAC.mac_size caused our TLS
implementation to compute wrong shared secrets when SHA-384 was
used. So, fix it directly in `crypto.hmac` in order to prevent
other misuses.
2023-03-22 06:17:52 +00:00
Roman Frołow
0787b11f19
naming: mid for index and mid_item for item 2023-03-21 15:12:13 +02:00
Veikka Tuominen
5e161c102d
Merge pull request #14841 from squeek502/is-cygwin-pty-stuff
`os.isCygwinPty`: Fix a bug, replace kernel32 call, and optimize
2023-03-21 15:03:33 +02:00
Marcus Ramse
1e087d3a64 std.json: support tuples 2023-03-21 15:01:45 +02:00
Veikka Tuominen
cd3575b0f0
Merge pull request #14848 from r00ster91/json
std.json: fix 2 TODOs
2023-03-21 15:00:47 +02:00
Frank Denis
dff4bbfd24
Remove Gimli and Xoodoo from the standard library (#14928)
These are great permutations, and there's nothing wrong with them
from a practical security perspective.

However, both were competing in the NIST lightweight crypto
competition.

Gimli didn't pass the 3rd selection round, and is not much used
in the wild besides Zig and libhydrogen. It will never be
standardized and is unlikely to get more traction in the future.

Xoodyak, that Xoodoo is the permutation of, was a finalist.

It has a lot of advantages and *might* be standardized without NIST.
But this is too early to tell, and too risky to commit to it
in a standard library.

For lightweight crypto, Ascon is the one that we know NIST will
standardize and that we can safely rely on from a usage perspective.

Switch to a traditional ChaCha-based CSPRNG, with an Ascon-based one
as an option for constrained systems.

Add a RNG benchmark by the way.

Gimli and Xoodoo served us well. Their code will be maintained,
but outside the standard library.
2023-03-21 04:54:10 +00:00
Andrew Kelley
626a75bbc2 std.Build.RunStep: fix control flow with qemu+glibc logic 2023-03-20 17:14:48 -04:00
KOUNOIKE Yuusuke
5df31f3ef3
add wasm-simd support for suggestVectorSizeForCpu (#14992) 2023-03-20 17:45:12 +01:00
Veikka Tuominen
0c16912733 std: improve error for formatting a function body type
Closes #14915
2023-03-20 17:29:43 +02:00
Reuben Dunnington
30427ff794
Fix GetFileInformationByHandle compile error (#14829)
* Fix GetFileInformationByHandle compile error

The wrapper function was mistakenly referencing ntdll.zig when the actual function is declared in kernel32.zig.

* delete GetFileInformationByHandle since it's not used by the stdlib
2023-03-19 23:23:05 +00:00
Jakub Konka
9a203fa789
Merge pull request #14986 from ziglang/macos-hcs
Upstream macOS hot-code swapping PoC
2023-03-19 21:22:40 +01:00
Ryan Liptak
2fce991d2a Remove std.os.windows.QueryInformationFile (a wrapper of NtQueryInformationFile)
This function is unused, and the current implementation contains a few footguns:

- The current wrapper treats all possible errors as unexpected, even likely ones like BUFFER_OVERFLOW (which is returned if the size of the out_buffer is too small to contain all the variable-length members of the requested info, which the user may not actually care about)
- Each caller may need to handle errors differently, different errors might be possible depending on the FILE_INFORMATION_CLASS, etc, and making a wrapper that handles all of those different use-cases nicely seems like it'd be more trouble than it's worth (FILE_INFORMATION_CLASS has 76 different possible values)

If a wrapper for NtQueryInformationFile is wanted, then it should probably have wrapper functions per-use-case, like how QueryObjectName wraps NtQueryObject for the `ObjectNameInformation` class
2023-03-19 17:33:25 +01:00
Luuk de Gram
c26cbd561c
Merge pull request #14998 from Luukdegram/shared-mem
wasm-linker: Implement shared-memory
2023-03-19 15:43:06 +01:00
Andrew Kelley
8f481dfc3c fix std.Build.OptionsStep
* use the same hash function as the rest of the steps
 * fix race condition due to a macOS oddity.
 * fix race condition due to file truncation (rename into place instead)
 * integrate with marking Step.result_cached. check if the file already
   exists with fs.access before doing anything else.
 * use a directory so that the file basename can be "options.zig"
   instead of a hash digest.
 * better error reporting in case of file system failures.
2023-03-19 00:39:29 -04:00
Jakub Konka
6f15eedff1 darwin: put posix spawn constants in POSIX_SPAWN struct 2023-03-18 21:54:05 +01:00
Jakub Konka
37192bcdcb macos: HCS PoC working 2023-03-18 21:53:36 +01:00
Jakub Konka
f1e25cf43e macho: add hot-code swapping poc 2023-03-18 21:53:26 +01:00
Jakub Konka
266c81322e darwin: resurrect posix_spawn wrappers 2023-03-18 21:53:15 +01:00
Jakub Konka
a23ef3783b os.zig: expose ptrace wrapper for darwin and linux 2023-03-18 21:52:40 +01:00
Luuk de Gram
09d6938df9
wasm: add atomics opcodes and refactoring
This adds the atomic opcodes for the Threads proposal to the
WebAssembly specification: https://github.com/WebAssembly/threads

PrefixedOpcode has been renamed to MiscOpcode as there's multiple
types of prefixed opcodes. This naming is similar to other tools
such as LLVM. As we now use the 0xFE prefix, we moved the
function_index MIR instruction as it was occupying the same value.
This commit includes renaming all related opcodes.
2023-03-18 20:13:30 +01:00
Luuk de Gram
09abd53da7
wasm-linker: refactor Limits and add flags
Rather than adding the flags "on-demand" during limits writing,
we now properly parse them and store the flags within the limits
itself. This also allows us to store whether we're using shared-
memory or not. Only when the correct flag is set will we set the
max within `Limits` or else we will leave it `undefined`.
2023-03-18 20:13:29 +01:00
Nicolas Sterchele
49d37e2d17 build-step: remove latest LogStep ref
LogStep was removed during the build parallel enhancement made in this
commit 58edefc6d1
2023-03-18 15:08:53 -04:00
hequn
f56f3c5824
Enable IPv4 mapped address conversion in linux version getAddressList (#14916)
It seems like the original code of setsockopt is not effective because
i catch the EINVAL branch when uncomment this code, it should call
setsockopt before the bind call.

This should fix issue #14900.

Co-authored-by: Qun He <hawkbee@qq.com>
2023-03-17 15:58:02 -04:00
Motiejus Jakštys
9f2aa3fbee Build.zig_exe: make it sentinel-aware
This is useful for tests that want to `execve` zig directly. The string
is already null-terminated, so this will just expose it as such,
removing an extra allocation from the test.

Will be used in #14462
2023-03-17 15:54:09 -04:00
Bas Westerbaan
2089b3f193
tls: use post-quantum secure key exchange (#14920) 2023-03-17 17:51:24 +01:00
Motiejus Jakštys
e0dd20b02e
add BoundedArrayAligned (#14580)
This is useful for creating byte buffers of actually-different-things.
Copied the argument order from `Allocator.alignedAlloc`

I noted that `ArrayListAligned` is going out of it's way to not set the
alignment at comptime when it is not specified. However, I was not able
to do that the same way here, and good people on IRC, @ifreund in
particular (thanks!) assured me that

    [N]T align(@alignOf(T))

is equivalent to

    [N]T
2023-03-17 17:50:25 +01:00
Jacob Young
cfcd6698cd main: add debug option to dump unoptimized llvm ir 2023-03-17 01:57:14 -04:00
Andrew Kelley
68c7261e1d disable bad std lib tests
see tracking issue #14968
2023-03-16 18:25:59 -07:00
Evin Yulo
b3af5d076c Fix #14901: parseFloat parsing 0x successfully 2023-03-16 19:36:06 +02:00
mllken
da0509750a std.os: handle EPERM errno for bind 2023-03-16 17:41:58 +02:00
Jakub Konka
e1e414e62a std: move os/darwin.zig and related to c/darwin.zig
Move to c/darwin.zig as they really are libSystem/libc imports/wrappers.

As an added bonus, get rid of the nasty `usingnamespace`s which are now
unneeded.

Finally, add `os.ptrace` but currently only implemented on darwin.
2023-03-16 11:42:30 +01:00
Andrew Kelley
cdda395590 std lib tests: avoid cwd races by using std.testing.tmpDir 2023-03-15 10:48:15 -07:00
Andrew Kelley
a1058dd27b fix std.fs unit test to not be racey 2023-03-15 10:48:15 -07:00
Andrew Kelley
4aa5895d32 std.Build: fix invalid assumption about fifos
Previously this code asserted that a fifo's readable length was greater
than or equal to the length of its readable slice, which was an invalid
assertion.

This code avoids making that assumption.
2023-03-15 10:48:15 -07:00
Andrew Kelley
4f1382e581 add std.LinearFifo.readableSliceOfLen 2023-03-15 10:48:15 -07:00
Andrew Kelley
6d6f6a4ac6 std.os.windows.OpenFile: handle DELETE_PENDING
This error means that there *was* a file in this location on the file
system, but it was deleted. However, the OS is not finished with the
deletion operation, and so this CreateFile call has failed. There is not
really a sane way to handle this other than retrying the creation after
the OS finishes the deletion.
2023-03-15 10:48:15 -07:00
Andrew Kelley
717e2c8718 std.Build.Cache: make unit tests not depend on cwd
This makes them more resilient to being run multiple times by multiple
different processes at the same time.
2023-03-15 10:48:15 -07:00
Andrew Kelley
363d4a107d add compile log output to build runner 2023-03-15 10:48:15 -07:00
Andrew Kelley
37a7d2c78d std.Build.RunStep: fix handling spawn failure
The error was caught and created a Step failure rather than bubbling up
so that the interpreter logic could handle it. Fixes hundreds of test
failures on Windows.
2023-03-15 10:48:15 -07:00
Andrew Kelley
11de55d0dd std.Build.Cache: handle ENOENT on createFile race
Companion commit to 628fec41593a2d2eca8b504e4fe90de9823aeded
2023-03-15 10:48:15 -07:00
Andrew Kelley
63bd0fe58e use DEC graphics instead of Unicode for box drawing 2023-03-15 10:48:15 -07:00
Andrew Kelley
3e328c89b7 std.Build.CompileStep: remove setNamePrefix and add setName 2023-03-15 10:48:15 -07:00
Andrew Kelley
22d94eaf32 disable std lib unit tests that hard code port numbers
See tracking issue #14907
2023-03-15 10:48:15 -07:00
Andrew Kelley
2b0929929d std.Build.Cache: handle ENOENT on createFile race
There are no dir components, so you would think that this was
unreachable, however we have observed on macOS two processes racing
to do openat() with O_CREAT manifest in ENOENT.
2023-03-15 10:48:15 -07:00
Andrew Kelley
0f88ad8c72 std.Build.CompileStep: proper step dependency on headers
Rather than calling make() from within make().
2023-03-15 10:48:15 -07:00
Andrew Kelley
e098b287e1 std.fs.File.writevAll: fix behavior for 0-length vectors
The OS layer expects pointer addresses to be inside the application's
address space even if the length is zero. Meanwhile, in Zig, slices may
have undefined pointer addresses when the length is zero. So this
function now modifies the iov_base fields when the length is zero.

This is a companion commit to b4893eb05565b2cb033c6ed88617d73faf878455.
2023-03-15 10:48:15 -07:00
Andrew Kelley
a26a2e1a17 build runner: fix compilation errors on windows 2023-03-15 10:48:15 -07:00