Commit Graph

14943 Commits

Author SHA1 Message Date
Feoramund
aaeae8bc7d mem: Remove trailing whitespace 2025-06-15 12:34:15 -04:00
Feoramund
47a54dd11a mem: Panic when passing invalid pointers to small stack free/resize
This is consistent with `Stack_Allocator`.
2025-06-15 12:34:15 -04:00
Feoramund
d7e98ba82a Add test for issue #2694 2025-06-15 12:34:15 -04:00
Feoramund
3261896790 mem: Correct wrong error message 2025-06-15 12:34:15 -04:00
Feoramund
aa41a77fc4 mem: Check if alignment matches on Small_Stack resize 2025-06-15 12:34:15 -04:00
Feoramund
3a02918efc mem: Make small_stack_resize* free if size is 0 2025-06-15 12:34:15 -04:00
Feoramund
a4771ce1b5 mem: Clarify what happens when you free out-of-order in a Small_Stack 2025-06-15 12:34:15 -04:00
Feoramund
21a17c1ae6 mem: Replace auto_cast 2025-06-15 12:34:15 -04:00
Feoramund
8f68c46467 mem: Don't unpoison the header of a Small_Stack allocation 2025-06-15 12:34:15 -04:00
Feoramund
5798151a0e mem: Poison unused memory more thoroughly 2025-06-14 13:21:15 -04:00
Feoramund
ae96b276c1 mem: Check if alignment matches on Stack_Allocator resize 2025-06-14 13:21:15 -04:00
Feoramund
837d8cf72c mem: Actually resize when resizing for Stack_Allocator
Changed the check from `bytes` to `err` for safety's sake, too.

This will prevent the potential bug of allocating non-zero memory, then
doing a zeroed resize, which will result in having garbage data in the
initial half.
2025-06-14 13:21:14 -04:00
Feoramund
f701aeffd5 mem: Correct wrong error message 2025-06-14 13:21:14 -04:00
Feoramund
7580dc2dd0 mem: Remove pointless check in Scratch_Allocator
The backup allocator is set at `init` which happens even if `Scratch` is
nil at the head of `scratch_alloc_bytes_non_zeroed`.
2025-06-14 13:21:14 -04:00
Feoramund
c4f6e973d9 mem: Don't change Scratch_Allocator's backup allocator
The backup allocator is set at `init` and must stay the same for the
lifetime of the Scratch allocator, as this allocator is used to free all
`leaked_allocations`. Changing it could lead to a situation where the
wrong allocator is used to free a leaked allocation.
2025-06-14 13:21:14 -04:00
Feoramund
62b0f71768 mem: Fix comment typo 2025-06-14 13:21:14 -04:00
Feoramund
890245c229 mem: Don't unpoison the header of a Stack allocation 2025-06-14 13:21:14 -04:00
Feoramund
79e5ddaa26 mem: Make stack_resize* free if size is 0
This will cause an error if the memory being resized was not the last
allocation, as should be expected according to the description that this
"acts just like stack_free."
2025-06-14 13:21:14 -04:00
Feoramund
179a8559f6 mem: Add guards against buggy allocators overlapping allocations 2025-06-14 13:21:14 -04:00
Feoramund
f627b55cf5 mem: Fix several issues in Scratch_Allocator
1. The size was being adjusted for the alignment which does not make any
   sense without the context of the base pointer. Now we just add the
   `alignment - 1` to the size if needed then adjust the pointer.

2. The root pointer of the last allocation is now stored in order to
   make the free operation more useful (and to cover the right memory
   region for ASan).

3. Resizing now only works on the last allocation instead of any address
   in a valid range, which resulted in overwriting allocations that had
   just been made.

4. `old_memory` is now re-poisoned entirely before the resized range is
   returned with the new range unpoisoned. This will guarantee that
   there are no unpoisoned gaps.

Fixes #2694
2025-06-14 12:35:16 -04:00
Feoramund
61f9fb7232 runtime: Remove unneeded max(0, ...)
`len` never returns negative numbers, so this was an overcautious
expression.
2025-06-13 12:09:10 -04:00
Jeroen van Rijn
fe9f74f7a2 Disable PR comments 2025-06-13 07:24:03 +02:00
Laytan
fc7fc4d5cd Merge pull request #5289 from JackMordaunt/jfm-sync_chan_refactor
Jfm sync chan refactor
2025-06-12 21:51:34 +02:00
Jack Mordaunt
3c3fd6e580 tests/core/sync/chan: move global state into test
While this state is not actually needed by more than one test, we can
just make it a static variable.
2025-06-12 16:14:52 -03:00
Jack Mordaunt
c1cd525d9d core/sync/chan.select_raw: call try_select_raw with deprecation warning
Eventually select_raw should be a blocking select operation, but for now
we need to migrate people away.
2025-06-12 16:14:52 -03:00
Jack Mordaunt
96b91849a9 core/sync/chan.try_select_raw: fix doc comment typo
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
2025-06-12 16:14:52 -03:00
Jack Mordaunt
4d7c182f7d tests/core/sync/chan: test harness for chan.try_select_raw
This test harness ensures consistent non-blocking semantics and
validates that we have solved the toctou condition.

The __global_context_for_test is a bit of a hack to fuse together the
test supplied proc and the executing logic in packaage chan.
2025-06-12 16:14:52 -03:00
Jack Mordaunt
faae81ba61 core/sync/chan.try_select_raw: test hook for testing the toctou
This is necessary because we need to allow the test guarantee against a
rare condition: where a third-party thread steals a value between the
validity checks can_{send,recv} and the channel operation
try_{send,recv}.
2025-06-12 16:14:52 -03:00
Jack Mordaunt
4043be8567 core/sync/chan.try_select_raw: skip nil input messages
This makes the proc easier and safer to call by letting the caller nil
out messages to skip sends.
2025-06-12 16:14:52 -03:00
Jack Mordaunt
fb39e5a2f8 core/sync/chan.try_select_raw: clarify loop control flow
Use a label to clarify the continue statements.
2025-06-12 16:14:52 -03:00
Jack Mordaunt
d5b7302ac0 core/sync.try_select_raw: fix TOCTOU
Fixes a TOCTOU where the channel could be used between the call to
can_{recv,send} and {recv,send} causing an unexpected blocking
operation.

To do this we use the non-blocking try_{recv,send} and retry the check
in a loop. This guarantees non-blocking select behaviour, at the cost of
spinning if the input channels are highly contended.

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
2025-06-12 16:14:52 -03:00
Jack Mordaunt
be873af003 core/sync.select_raw: rename to try_select_raw
This follows the convention where non-blocking operations are prefixed
with "try" to indicate as much.

Since select_raw in it's current form doesn't block, it should be
try_select_raw, and allow select_raw to name a blocking implementation.
2025-06-12 16:14:52 -03:00
Jack Mordaunt
7f9589922d core/sync.select_raw: return a useful index
This fixes a flaw in the original implementation: the returned index is
actually useless to the caller.

This is because the index returned refers to the internal "candidate"
list. This list is dynamic, and may not have all of the input channels
(if they weren't ready according to chan.can_{recv,send}). That means
the index is not guaranteed to mean anything to the caller.

The fix introduced here is to return the index into the input slice
(recvs,sends) and an enum to specify which input slice that is.

If no selection was made, then (-1, .None) is returned to communicate as
much.

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
2025-06-12 16:14:51 -03:00
Laytan Laats
0ed6cdc98e mem/tlsf: fix asan reporting poisoning of already poisoned region
free on tlsf poisons the entire block, while alloc might only unpoison a
part of it (cause it's size is aligned up). This causes free to
potentially poison an already poisoned portion, which is a
use-after-poison.

Because this is "fine" and intended, I opted to just
@no_sanitize_address it.
2025-06-12 19:37:24 +02:00
Jeroen van Rijn
74f70bfbcb Comment 2025-06-12 17:09:33 +02:00
Jeroen van Rijn
298bab99a4 Merge pull request #5326 from Kelimion/fix-5321
Revert changes to thread_unix.odin
2025-06-12 16:56:29 +02:00
Jeroen van Rijn
5aa377e64e Revert changes to thread_unix.odin 2025-06-12 16:36:40 +02:00
Jeroen van Rijn
b119ca0261 Merge pull request #5325 from Kelimion/fix-5321
Fix #5321
2025-06-12 16:14:01 +02:00
Jeroen van Rijn
59ba37f232 Remove transmute 2025-06-12 16:05:34 +02:00
Jeroen van Rijn
994b5a2a6c Remove c import 2025-06-12 16:01:31 +02:00
Jeroen van Rijn
caf41aa046 Fix #5321 2025-06-12 16:00:24 +02:00
Jeroen van Rijn
eb1b5f7d3a Merge pull request #5322 from Kelimion/fix-5321
Fix #5321 (on Windows)
2025-06-12 11:52:38 +02:00
Jeroen van Rijn
ac5f3746cf Fix #5321 2025-06-12 11:30:36 +02:00
Jeroen van Rijn
50ff3fabdc Merge pull request #5317 from Feoramund/fixup-container-queue
Tidy up `core:container/queue`
2025-06-12 00:00:34 +02:00
Jeroen van Rijn
a2be547dfd Merge exclude paths 2025-06-11 21:00:38 +02:00
Jeroen van Rijn
8a08edbdc7 Merge pull request #5319 from Kelimion/coverage
Add code coverage
2025-06-11 20:39:48 +02:00
Jeroen van Rijn
828d4c71d2 Now? 2025-06-11 20:33:12 +02:00
Jeroen van Rijn
921414aa74 Let's use the latest Ubuntu and a recent LLVM 2025-06-11 20:04:07 +02:00
Jeroen van Rijn
3965b2e4b4 kcov --version 2025-06-11 19:58:01 +02:00
Jeroen van Rijn
05cba0aca5 Change kcov url 2025-06-11 19:53:49 +02:00