Commit Graph
100 Commits
Author SHA1 Message Date
Augustin Cavalier c6024e1bff kernel/thread: Assert that thread->pinned_to_cpu does not become negative.
May help with diagnosing #20100.
2026-05-18 11:45:33 -04:00
Augustin Cavalier 286eb01997 stdint.h: Declare SIZE_MAX using __SIZE_MAX__ if available.
Fixes the size_t part of #20079.
2026-05-11 14:36:10 -04:00
Augustin Cavalier 8b38e91f46 headers: Declare address and 64-bit limits using hexadecimal.
No functional change intended.
2026-05-11 14:32:27 -04:00
Augustin Cavalier fd09d924e6 headers: Drop nonstandard null.h and size_t.h.
They're holdovers from R5. <stddef.h> should just be included instead,
and ssize_t declared directly in sys/types.h.
2026-05-11 14:17:55 -04:00
Augustin Cavalier 60d0411454 headers: Move version constants to config/HaikuVersion.h.
They have been in BeBuild.h since BeOS days, but as this file
is included everywhere in the base system headers, it causes
a bunch of unnecessary POSIX namespace pollution. So, instead,
put them in a config header, and include it from SupportDefs.h,
which should only ever be included by Be/Haiku API headers.
2026-05-11 14:08:18 -04:00
Augustin Cavalier 414c41e7bf OS.h: Drop some unnecessary comments.
The first wasn't quite accurate, and the second seems to have been
copied from the R5 header.
2026-05-11 14:03:23 -04:00
Augustin Cavalier 56be32b772 Drop direct includes of size_t.h.
It's a non-standard header we inherited from BeOS. According to the
POSIX specification, size_t should be declared from including stddef.h
and/or sys/types.h, and ssize_t from sys/types.h.
2026-05-11 13:26:44 -04:00
Augustin Cavalier 29fcc40483 system: Move thread_creation_attributes.priority lower to avoid padding.
Note that this breaks syscall ABI.

Change-Id: I353049d67f5611fae87fe9e6193a64d51330c846
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5479
Reviewed-by: waddlesplash <[email protected]>
2026-05-11 17:24:24 +00:00
Augustin Cavalier e7cc89a038 kernel/x86: Use multibyte NOP constants in altcodepatch.
Follows up on a suggestion from the commits mailing list.
2026-05-04 15:27:11 -04:00
Augustin Cavalier facff75dd4 kernel/x86_64: Use VZEROALL to clear XMM/YMM/etc. registers when available.
It comes with AVX, so enable it if we've enabled AVX.

This also adjusts altcodepatch_replace to explicitly set NOPs
for the remainder of the patch area.

Change-Id: Ia07549851d86836ff5428635b580c751b4e5b2a3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10867
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-05-04 00:03:54 +00:00
Augustin Cavalier 009b56e781 kernel/x86_64: Move the stub functions to a stubs.S.
No functional change intended.

Change-Id: I5b52ec9cb401c9c2591ac87fe94c53edfbb7a3fa
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10866
Reviewed-by: waddlesplash <[email protected]>
Haiku-Format: Haiku-format Bot <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-05-04 00:03:54 +00:00
Augustin Cavalier ce845a52d4 freebsd_network: Set transfer type in usbd_transfer_setup.
This is necessary for the UE_BULK_INTR case.
2026-04-29 00:01:36 -04:00
Augustin Cavalier 35441396e7 zydwifi1211: Import (if_zyd from FreeBSD 15.)
Requested by a user on Discord. Untested, I don't have this hardware.
2026-04-28 14:10:08 -04:00
Augustin Cavalier b4f627e58b freebsd_network: Add UE_BULK_INTR.
Needed by if_zyd.
2026-04-28 14:08:33 -04:00
Augustin Cavalier a0452d3ac1 SoftwareUpdater: Implement automatic cleanup of admin directory.
Enabled by default, but can be disabled via a new settings window
option (which is saved and remembered across runs.)

Change-Id: Ifd49cd734dcf5e4a5e5b3625d23bc2778fa1fa55
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10850
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-04-28 06:57:18 +00:00
Augustin Cavalier 2964316995 kernel/smp: Make another variable static. 2026-04-27 16:31:55 -04:00
Augustin Cavalier 4dd45837e9 Package Kit & pkgman: Split cleanup operations into a "cleanup" command.
And only inform that some can be deleted at the end of install/uninstall.

As discussed in https://review.haiku-os.org/c/haiku/+/10711.
2026-04-27 16:29:33 -04:00
Augustin Cavalier 3a9a7e2188 libroot/riscv64: Fix TODO about using std::atomic for TLS.
As the comment noted, the same is done on x86_64 already.
2026-04-27 15:15:03 -04:00
Augustin Cavalier 747a839b95 kernel/smp: Move the per-CPU SMP message mailbox into cpu_ent.
Putting all the per-CPU messages in one array means they'll all
be on the same cache lines. The cpu_ent structure is cache-line-aligned,
so this means they'll be on separate cache lines.
2026-04-27 15:14:14 -04:00
Augustin Cavalier 99a4c6e757 network: Handle B_SELECT_DISCONNECTED in socket notifications.
TCPEndpoint::_NotifyReader() calls notify(READ, _AvailableData()),
which after a close will be negative, so this will set DISCONNECTED
in that case.

Drop the unnecessary duplication from TCPEndpoint::_HandleReset:
the net_socket layer sends READ|WRITE notifications in this case.

Fixes #19969.

Change-Id: I0e10c0280f3c84276b486b0375000153a117246d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10581
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-04-25 17:42:44 +00:00
Augustin Cavalier 6aa675a630 ltrace: Place stubs in exectable memory and improve efficiency.
* Implement the TODO about needing to place stubs in executable
   memory. This fixes basic ltrace operations.

 * Place traces behind a TRACE ifdef.

 * Get rid of the "patched table" and find the PatchEntry
   using fixed offsets, to improve efficiency.

 * Add a "bool trace" to PatchEntry. This paves the way for
   tracing only specific methods.

Using LD_PRELOAD_ADDONS=...ltrace_stub.so, trace entries are now
printed on x86_64. However, it seems that the trace stub is clobbering
something, as BWindows don't work correctly when traced.
2026-04-24 18:12:30 -04:00
Augustin Cavalier 28d23a2bbe bootloader: Increase kernel_args chunk size.
On a 64-bit nightly, it appears we're already using 16 out of the 20
slots for kernel_args ranges. On a 32-bit bootstrap build with symbols
enabled, we exhaust them (due to the network drivers that the bootstrap
build adds to the boot set).

The kernel_args are later freed by the kernel, so this shouldn't "leak"
any memory unnecessarily. With this size, we only need one chunk with
symbol loading disabled.
2026-04-24 12:53:45 -04:00
Augustin Cavalier 1c2f998214 bootloader: Avoid allocating the logo image in kernel_args space.
We never send it to the kernel but always free it. The kernel_args
allocator is very simple and can't handle frees besides the most recent
data, so this avoids "leaking" some kernel_args memory (it should all
be freed by the kernel later, though, so that only matters for
the bootloader itself.)
2026-04-24 12:48:48 -04:00
Augustin Cavalier c01840a306 Bump bootstrap package versions. 2026-04-23 16:55:49 -04:00
Augustin Cavalier cb72e7dc57 kernel/vm: Drop VMPageQueue::fName.
Nothing uses it (not even DEBUG_PAGE_QUEUE, it appears),
and it will need to be managed a different way for the
multiple ModifiedPageQueues, if we really do need it.
2026-04-23 16:38:13 -04:00
Augustin Cavalier 76e076b03b launch_daemon: Rework _GetSourceFileEnvironment logic.
Use strchrnul instead of strchr, and increment at the end of the loop.
This avoids needing to call _ParseExportVariable in two separate places.

The invocation of line.Append(chunk, bytesRead) was also incorrect,
as bytesRead would be past the end of chunk if chunk had been
incremented. But this wasn't really a problem because BString
does strnlen() on the passed arguments.

Inspired by a change seen in a fork of the Haiku repository on
GitHub.
2026-04-23 16:34:04 -04:00
Augustin Cavalier cb6c752887 HaikuPorts/arm64: Update with the newly rebootstrapped packages.
After this, a "stock" @minimum-mmc build can boot to the desktop
in QEMU without needing to do a local bootstrap!
2026-04-23 16:19:22 -04:00
Augustin Cavalier 2b1c4326ec MMCImage: Delete the temporary partition file after building.
AnybootImage does the same. Reduces confusion because the files
have quite similar names (we should probably fix that...)
2026-04-23 16:17:41 -04:00
Augustin Cavalier da093f807e Always include framebuffer and virtio_gpu in the build.
The virtio_gpu driver is included the "Haiku" package file,
so it logically makes sense to do the same for its accelerant.
2026-04-23 16:16:50 -04:00
Augustin Cavalier d32e4e0e00 3rdparty/unbootstrap.sh: Add _bootstrap to the package versions.
This makes it clear that the package was made by the bootstrap
process.

Also compress the packages with zlib, so that zstd isn't needed.
2026-04-23 15:54:03 -04:00
Augustin Cavalier 70d41befc2 HaikuBootstrap: Disable virtio_block, same as for the regular build. 2026-04-23 15:53:19 -04:00
Augustin Cavalier 920adf674e libroot/glibc: Fix the build for x86_64. 2026-04-15 23:50:23 -04:00
Augustin Cavalier c8a62a308c libroot/glibc: Properly split long double files and import 128-bit ones.
Also drop the long-double files from architectures where long-double
support is (currently) disabled in glibc config.h.

Should fix #19589 and other long-double related problems on
RISC-V and ARM64.

Change-Id: Ia33ce2791d812eb143b719fb61e69dbf8b70ce79
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10815
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Sam Roberts <[email protected]>
2026-04-15 19:13:54 +00:00
Augustin Cavalier a8fd01eb8e kernel/vm: Notify removed pages as not busy on removal.
We don't need to wait for them to be freed, as they're not
accessible once removed.
2026-04-14 13:40:07 -04:00
Augustin Cavalier 157e34f264 Tracker: Skip watch_node(B_STOP_WATCHING) if we aren't watching individual nodes.
Avoids unnecessary syscalls and saves time.
2026-04-13 18:59:59 -04:00
Augustin Cavalier 3dcdbf569c media: Delay starting the mixer until an output connects to the mixer.
Otherwise we just spends lots of CPU time sending silence.
This also paves the way for stopping the output when all
outputs disconnect, but that's not implemented just yet.

Since this forces a wait inside the mixer for the destination
to actually start, it may help with problems like #19074.
At least in testing, without that block, I got similar symptoms
and crashes, due to the initial 0 value being used to compute
the performance times, and winding up with very incorrect times.

Note that this changes the MultiAudioNode to not really start its
timesource when it gets a TIMESOURCE_START message. Instead it waits
until it gets a regular B_START (via StartNode) message to do that.

Change-Id: I1716e347537c88dcc76163a515e7fbb8c5ccdecb
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10643
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-04-13 19:27:55 +00:00
Augustin Cavalier ad37e9a395 BWindow: Use a SplayTree to store shortcuts.
This makes for much faster lookups, and avoids the need
to allocate an array.

sizeof(BWindow) is unchanged (on x86_64, 504; on x86, 376)
so this should not break ABI/API.

Quick benchmark in Tracker:
501 lookups, before: ~488 usec
501 lookups, after: ~284 usec

Change-Id: Ica2c728f0c5957380add53e14a826a4aade52df0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10720
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-04-13 19:24:34 +00:00
Augustin Cavalier fd2113c61a Tracker: Restore handling of B_DELETE key in KeyDown.
If the shortcut is not available (due to the menus not being active),
then this will make sure we handle the key regardless. If the shortcut
is active, then it'll get eaten by BWindow, and we won't get here.

Change-Id: Id6c3ae590f596481f9dfb720aa088238ccc6413c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10718
Haiku-Format: Haiku-format Bot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: John Scipione <[email protected]>
2026-04-13 19:24:15 +00:00
Augustin Cavalier 64d96af568 MIME Sniffer: Use memmem() to speed up matching.
This is now a POSIX method which was widely supported even before
its addition to POSIX, so using it here (including on the build
platform) should be OK.

This takes mimeset -F of the whole src/ hierarchy from around 2.8
seconds to around 2.1 (user time goes from ~1.2s to ~0.6s.) It seems
I/O is a lot of the remainder now.

Also drop the TODO comment; we don't want partial matching like that,
as the sniffing rules would not expect it.

All tests still pass.

Change-Id: Ibb190f6f9f5e73ed027e052ef665b177d3fd6f86
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10688
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-04-10 08:28:40 +00:00
Augustin Cavalier 14ea42a871 MIME Sniffer: Use memcmp instead of the mask setup where possible.
Another slight optimization. The time doesn't seem to decrease much,
but this paves the way for a much more optimized scan.

Change-Id: I0fb65544524fbc9606fd84ef521b706bd9dc4d02
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10687
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
2026-04-10 08:28:40 +00:00
Augustin Cavalier 3becbc68c4 MIME Sniffer: Propagate case-insensitivity down to patterns.
This will allow them to perform some more upfront optimizations.

Note that this change includes a slight compatibility breakage with
BeOS R5: it applies an "-i" flag in a disjunction to all patterns in
the disjunction, not just all patterns following the "-i" (I checked.)

However, as far as I can see, this feature of R5 was undocumented
(sniff rules are described in the "Release Notes" section of the Be Book
only, and "-i" isn't discussed there), and the only pattern on R5 that
appears to use them at all was the "text/html" pattern. The behavior to
apply case-insensitivity to all patterns seems unexpected, so I think
it should be OK to break compatibility in this slight way.

Change-Id: I0556d53e602bc68ae14ac21c9e226403061043a0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10686
Reviewed-by: Adrien Destugues <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-04-10 08:28:40 +00:00
Augustin Cavalier 46af16aa69 MIME Sniffer: Make RPattern a subclass of Pattern.
Avoids some unnecessary allocations.

Change-Id: I0435ed7a814a45739a03a62ba84a315d61bf23e3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10685
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Kacper Kasper <[email protected]>
2026-04-10 08:28:40 +00:00
Augustin Cavalier bc415d41f1 BFS: Send live-query rename/move notifications along with node monitor.
Otherwise, we send them out before the file is actually renamed,
and so we could send notifications with stale name values in them
(in the case of B_ENTRY_CREATED and B_ENTRY_REMOVED), or before
the file's name actually changed as visible in stat(). This way,
we send the notification only after updating the entries.
2026-04-09 15:21:46 -04:00
Augustin Cavalier da1768c354 StringForSize: Preinitialize the BNumberFormats.
I noticed when profiling the system with ActivityMonitor running
that most of ActivityMonitor's time was spent initializing these
for the Memory view. So, instead, cache the formatters to avoid
needing to reinitialize them so often.
2026-04-09 14:26:24 -04:00
Augustin Cavalier 816181bc95 fs_shell: Adjust to work with the new libroot_build errno setup.
I rebuilt fs_shell after the previous commit before pushing,
but it didn't fail then. I guess Jam failed to do an incremental
rebuild properly...
2026-04-09 14:14:00 -04:00
Augustin Cavalier 744616c074 libroot_build: Rework errno assignment.
With the old code, if the currentErrno hadn't changed, but was in
fact re-assigned more recently than the local errno was, then we
would wind up incorrectly return the local value instead of the
system value. This was the cause of the build mimeset not working
properly when run in recursive mode on Haiku.

So, instead, create a wrapper struct to make assignment of the
local errno always pass through to the system one, so they never
get out of sync in the first place.
2026-04-09 14:09:52 -04:00
Augustin Cavalier 95c8251d75 kernel tests: Fix TARGET_CC check.
$(architecture) isn't declared in this file.
2026-04-09 14:01:27 -04:00
Augustin Cavalier d693dd96fc Better handling for use of newer GCCs to build GCC2.
* Move the logic to build_cross_tools, as some scripts use this
   directly.

 * Use gnu89 standard instead of disabling specific warnings.

 * Reduce optimization level used to compile GCC, to try and stave
   off possible bugs.

 * Explain why 32-bit is used for GCC 2. (With some hacks,
   GCC 2 compiled in 64-bit mode can be used to build an image
   that does get to the desktop, though.)

Tested with GCC 14.2.
2026-04-08 00:29:33 -04:00
Augustin Cavalier 0cb8b2e3f6 MIME Sniffer: Include changes to appease GCC 2. 2026-04-07 23:38:30 -04:00
Augustin Cavalier 70bb9d9f1b MIME Sniffer: Pass the buffer all the way down and don't reallocate.
This avoids an allocation, copy, and deallocation every single
test of every single pattern, which was unbelievably inefficent
and one of the worst performance hits to the MIME sniffer.

Before this change, "mimeset -F src/" in the Haiku repository
took 20-40+ seconds. After this, it takes around 3 seconds.

All tests still pass (and indeed the tests caught some bugs in
the initial version of this change.)
2026-04-07 17:57:19 -04:00
Augustin Cavalier 18f8bc9d2d MIME Sniffer: De-indent Pattern::Sniff.
No functional change intended.
2026-04-07 17:57:19 -04:00
Augustin Cavalier 35df817840 MIME Sniffer: Apply haiku-format and new-style copyright headers.
Some changes done manually where it made sense.
2026-04-07 17:57:19 -04:00
Augustin Cavalier 2a001adfd1 MIME Sniffer: Move helper routines to the top of the file and make static. 2026-04-07 17:57:19 -04:00
Augustin Cavalier acaa509bf8 MIME Sniffer: Remove some dead code. 2026-04-07 17:57:19 -04:00
Augustin Cavalier 2168280fac Storage Kit: Streamline CharStream and make it use BString. 2026-04-07 17:57:19 -04:00
Augustin Cavalier 104eaabf01 Storage Kit: Move most MIME sniffer headers into src/.
There's no reason to keep these in the private headers directory
that I can see.
2026-04-07 17:57:19 -04:00
Augustin Cavalier 645c71a9a9 Devices: Fix typo. 2026-04-07 13:57:58 -04:00
Augustin Cavalier bc501624e2 configure: HDS now needs Python 3.10+.
3.9 is end-of-life as of 2025/10 anyway.
2026-04-07 13:51:33 -04:00
Augustin Cavalier 248735d5a2 kernel/vm: Split the page writer into its own file and queue subclass.
This paves the way for there being more than one modified queue,
e.g. for each KDiskDevice.
2026-04-06 22:23:26 -04:00
Augustin Cavalier 62b8be7e22 kernel/vm: DaemonCondition is really just a basic binary semaphore.
So split it off into its own file. This will make it easier to
split the page writer off into a separate file.
2026-04-06 22:23:26 -04:00
Augustin Cavalier f091a24ee2 AreaKeeper: Move to kernel/util.
This seems more consistent with how the directories are laid out.
2026-04-06 22:23:26 -04:00
Augustin Cavalier 2448a77520 kernel/vm: Move a number of init-related methods to a new vm_init.cpp.
This gets around 450 lines of code out of vm.cpp.

No behavioral change intended.
2026-04-06 22:23:26 -04:00
Augustin Cavalier 6e55e6942f pthread: PTHREAD_RECURSIVE_MUTEX_INITIALIZER is non-POSIX.
So add the _NP suffix like glibc does.

Pointed out by sortie.
2026-03-30 20:44:36 -04:00
Augustin Cavalier cc9cae1908 BString: memrchr is nonstandard and not available on macOS.
We use BString in the build platform, so we need it to work
everywhere. Add a fallback for non-Haiku targets (though glibc and
others do have memrchr and so could keep this, if we added some
more logic here.)
2026-03-30 19:21:33 -04:00
Augustin Cavalier d6c0df2394 kernel/guarded_heap: allocate_meta may fail with certain flags set.
May fix #20014.
2026-03-30 18:33:23 -04:00
Augustin Cavalier 75b91674e9 BString: Use memchr and memrchr to optimize two Find routines.
All BString tests are still passing.
2026-03-30 18:30:32 -04:00
Augustin Cavalier 53b69c0037 driver_settings: Use strchrnul to skip comments.
More optimized than just the simple loop.
2026-03-30 18:21:49 -04:00
Augustin Cavalier 40205ec46a kernel/cache: Add test for #18390 and related issues.
Change-Id: I873df21c54d4df4ea85904eabd186a36e55e13d9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10629
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 28e6329e8e kernel/vm: Add assert to VMCache::MarkPageUnbusy.
Change-Id: Iec29bdfa5f0a25d9f255c6eee1937bc7c9cc4c3a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10628
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 5554f0b829 kernel/vm: Fix a TODO about page I/O leaving pages in ACCESS state.
It turns out PAGE_ACCESS assertions could be tripped in other cases,
e.g. when resizing a cache while pages were being read in. So,
properly unset ACCESS (and just leave 'busy' set) in the places
where pages are read in, and re-enable the check.

Change-Id: I22ac5c8cb432c87613bb85e82703a0c1aeb55d86
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10627
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 05772630b8 kernel/file_cache: Recheck size in the do_cache_io loop.
Since we unlock the cache at various points in this loop,
we need to periodically recheck the size here, as otherwise
we might try to insert pages past the end.

This amends 4f8eaff87f. Re-tested
using the case described in that commit.

Change-Id: Id65e309f986a9b7f3e701d2b99c4f318a4eefbd3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10626
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier b37e0a513d kernel/vm: Clear busy_io along with the other page flags.
Change-Id: I796e6d01678e46eda9815c1c290b56975b6dbdfe
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10625
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 5eaf967479 kernel/cache: Use vm_page::busy_io in the file_cache.
This allows the VMCache to remove these pages pending the I/O
completion.

Combined with the following commits, confirmed to fix #18390.

Change-Id: I9630a00d70a9d6ac5b36e6de70475a6032390806
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10591
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 2b9d1bb9c2 kernel/vm: Rename vm_page::busy_writing to busy_io.
This way, it's clear that it can be used for more than just writing.

Change-Id: Ifd0928f0e8ec7b5eeb312795ceaae6e3fd266257
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10590
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier dcf4948bff kernel/vm: Add better handling for busy-writing pages on cache resizes.
Previously, busy-writing pages just stayed in the cache until
I/O finished. This wasn't right, as they should've been unmapped
(and removed) immediately, as a TODO in the PageWriteWrapper noted.

Now they are, and they're moved into a queue on the cache pending
the I/O completing.

This paves the way for fixing #18390.

Change-Id: I51778ba1cfc1d26f34dd44f1ee293381be59937f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8627
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier 15594f62fe DoublyLinkedList: Make DoublyLinkedListCLink more useful.
Before, it just used a hardcoded Element::link member. Now,
it uses whatever one is specified based on the template
arguments.

No source compatibility breakage intended.

Change-Id: I62128921766df0b705488eb64402f902334f2ed0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10589
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Haiku-Format: Haiku-format Bot <[email protected]>
2026-03-30 22:11:53 +00:00
Augustin Cavalier d22a7a3355 kernel/debug: Allow quotations to pass through early safemode settings.
The guarded heap override logic wants to see them at least.

Change-Id: I89c5c7a7b03e52f4bc42d71cba66775c213256e9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10597
Reviewed-by: waddlesplash <[email protected]>
2026-03-27 18:23:31 +00:00
Augustin Cavalier 2b3a46cc1b kernel/debug: Use strchrnul and memchr in parsing.
Slight efficiency improvement, and simplifies the code a bit too.

Change-Id: I502409a9aee260c3d0ad1c9003567e46c03b241b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10596
Reviewed-by: waddlesplash <[email protected]>
2026-03-27 18:23:31 +00:00
Augustin Cavalier e6d9dc2731 kqueue: Don't notify B_EVENT_INVALID for FDs.
It isn't sent at all on FreeBSD.

Found while testing #19969: the disconnection was reported twice.

Change-Id: Icaf7abef7c3c3a61fccf5eb9e827e0a6a0fa1228
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10580
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-27 01:13:34 +00:00
Augustin Cavalier 498d92cbd7 kernel/guarded_heap: Add an init comment. 2026-03-26 17:53:15 -04:00
Augustin Cavalier 34e74e0556 kernel/vm: Pages in the store should be in the commitment.
Otherwise we won't reserve memory/swap for swapped-out pages.
2026-03-26 17:49:56 -04:00
Augustin Cavalier 33dc47cb2c kernel/vm: Move committed_size to the cache implementations.
This fixes a long-standing TODO, and a major inconsistency
that for different caches, "commitment" reserves from different
pools, so any two aren't necessarily convertible.

The new system introduces a virtual method "TakeCommitmentFrom",
which allows the VM's cut_area routine to behave as it did
previously.
2026-03-26 17:36:27 -04:00
Augustin Cavalier 0a5cd96093 kernel/vm: Preparations for VMCache::committed_size removal.
Includes some cleanup to the organization of VMCache.h.
2026-03-26 17:25:05 -04:00
Augustin Cavalier 76af6f4c98 kernel/vm: Update/add some documentation comments and drop some old files.
They mostly contained descriptions of functions' operations, not
what they're for, so they weren't so useful. I've added some of
the remarks they had (or ones with a similar purpose) inline
as documentation comments, and deleted the rest.
2026-03-26 16:43:52 -04:00
Augustin Cavalier 222c477cf0 docs: Update the VM swap documentation.
It was mostly up-to-date technically; a few details have been
amended where things have changed, and the "personal" stuff
dropped.
2026-03-26 14:54:05 -04:00
Augustin Cavalier 030b7c1426 kernel/vm: Clarify locking of VMArea and drop old documentation.
The documentation file hadn't been updated in a very long time,
and referred to locks and paradigms that have long since been
dropped (e.g. sMappingLock was removed in 2010, in
afed2658f4ef3e3df5ff8390d1d7a51b5b897a9e.)

Add a few "protected by" comments in VMArea to clarify things,
but otherwise this document looks entirely obsolete (I went
through all of it.)
2026-03-26 14:11:23 -04:00
Augustin Cavalier b10415b7cc kernel/fs: Update comments in EntryCache.
Make the concurrency model slightly clearer.
2026-03-26 14:08:57 -04:00
Augustin Cavalier acde38ead3 freebsd_network: Update comment in kernel_malloc.
bus_dmamem_alloc doesn't need this behavior anymore.
2026-03-26 14:01:54 -04:00
Augustin Cavalier eb097f749b kernel/slab: Use (1 << x) to define cache flag bits.
No functional change intended.
2026-03-26 12:26:22 -04:00
Augustin Cavalier bb1c367a6d kqueue: Add a no-op EV_ENABLE definition.
EV_ADD implies ENABLE, so this isn't needed, but a lot of applications
try to specify it anyway. So this extends source compatibility.

If in the future we ever implement EV_DISABLE, we can just add a
real definition for it then, and since ADD implies ENABLE existing
applications shouldn't break.
2026-03-26 12:25:41 -04:00
Augustin Cavalier 5ac1c21e5f kernel/vm: Set the memory type on cloned device cache areas.
If the source area is now mapped write-combining, so will the
target area.

May fix some problems or slowness that occurred after the
framebuffers refactor commits.
2026-03-25 12:50:57 -04:00
Augustin Cavalier 7240f3762f kernel: Add mechanism to replace specific object caches with the guarded heap.
This allows the guarded heap to be used in a much more targeted way,
if it's suspected specific object_caches have problems.

Enabled by default for KDEBUG. The new safemode/kernel option is
"guarded_heap_for_object_caches". This accepts a comma-separated
list of quoted strings, optionally with * at beginning and/or end
(but not middle.) Examples:

mbufs*   # matches caches starting with "mbufs"
*jumbo9*	# matches caches containing "jumbo9"
"*jumbo9 chunks","mbufs*" # matches caches ending with "jumbo9 chunks"
                          # or starting with "mbufs"

This should help with diagnosing #19973, among others, without needing
to compile custom versions of drivers or anything like that.

Unfortunately it is not possible to use this mechanism to selectively
replace parts of the slab malloc. The slab malloc free() relies on
the MemoryManager to figure out what cache an object belongs to, which
doesn't work if objects of some size classes aren't known to the
MemoryManager at all.
2026-03-24 18:10:10 -04:00
Augustin Cavalier 90ac9e6538 kernel/vm: Overhaul swap cache commitments.
Before this commit, swap space was committed entirely orthogonally
from memory commitments. This was not handled at all correctly
when cutting areas (the area cutting logic tries to migrate commitments
between caches, but in the case of swapping caches, it didn't,
and couldn't, take the separate fCommittedSwapSize into account.)

Even without that problem, totally separate swap and memory commitments
caused other problems. For instance, suppose a setup with 4GB of RAM
and 4GB of swap. Many caches are created, and all 4GB of swap gets
reserved, but the caches with this swap reserved have no or few pages
in them. Then, all 4GB of RAM gets used up. The page daemon runs, and
looks for things to swap out, but it can't find anything because all
our swappable caches with pages have no swap reservations, so all it
can do is flush out cached pages, which just degrades performance.

Or, consider what would happen if the 4GB of swap was released, but
the 4GB of RAM was still in use, and then the kernel tried to
allocate memory. It would get OOM errors, because none of the
caches have swap commitments and so nothing can be written out.

Under this new system, the specific swap space reservation only happens
just before the page is first written out, so both these cases should
be handled smoothly, and swap should be used in a much more sensible
fashion overall.

This change seems to be more in line with what other OSes do (Windows
Task Manager's "Committed" clearly is RAM+swap, for instance.)

The only potential downside to this change is that swappable caches
may temporarily go over their commitment when reading or writing
out pages to swap, before the page daemon has a chance to come by
and free the page or the swap space. But as that is a temporary state
and should always be resolved by the page daemon, I think it's
probably an acceptable trade-off.

Change-Id: I928f4b4cacbec26ed6315179476eaff1a7f626c8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10305
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-24 14:02:52 +00:00
Augustin Cavalier 9be0e148a2 vesa & framebuffer: Clone the framebuffer instead of having it be user-accessible.
This begins paving the way for removal of user access to kernel
address space.

After the previous commits, BDirectWindow and BWindowScreen
still function properly.

Part of #19990.

Change-Id: I8477e43cd517ba67383755a4cb60b00bc117f5d7
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10559
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-03-24 14:01:11 +00:00
Augustin Cavalier 95ace7f374 kernel/vm: Introduce methods to change the cache of all an area's clones.
This will be useful in the case of cloned device caches based
around physical memory, e.g. for framebuffers.

Change-Id: If2b864208e86f436e91379b73c4b866b0bd5e1d7
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10558
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2026-03-24 14:01:11 +00:00
Augustin Cavalier 861f644f19 app_server & BWindowScreen: Do away with AS_GET_FRAME_BUFFER_CONFIG.
It can't work if the framebuffer is mapped per-application.
Instead, use the accelerant hook to get the framebuffer.

The BScreen methods this disables were deprecated and marked
private already, so no Haiku applications should be affected.
(If really necessary they could be reimplemented with BWindowScreen.)

Remove first _GetCardInfo in BWindowScreen; we invoke it
later, closer to where the buffer is actually used.

Tested with ParticlesII (which uses BWindowScreen) on VESA
with the new user-only-mapping accelerant.

Change-Id: I405bcfa8cb1eb2d0c346fafbc6233bef15196134
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10572
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-24 14:01:11 +00:00
Augustin Cavalier f6be811473 BDirectWindow: Clone the framebuffer from app_server, if necessary.
This paves the way for accelerants to map the framebuffer in
user memory, not kernel memory. It uses the ServerMemoryAllocator
in order to avoid mapping the framebuffer multiple times in
client applications.

While at it, clean up some names.

Tested with DirectWindowStars and GLTeapot, both work.

Change-Id: I4e0c003fae99891044af0a5e6e1d6a4506da6430
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10571
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2026-03-24 14:01:11 +00:00
Augustin Cavalier ede14380e5 kernel/slab: Run slab_object automatically when the 0xdeadbeef assert fails. 2026-03-23 23:11:40 -04:00
Augustin Cavalier a277043c1f kernel: Overhaul debug heaps system.
Instead of the kernel heap being a compile-time parameter, make it
a runtime parameter (if DEBUG_HEAPS is specified, at least; otherwise
we're hardwired to the slab heap as before.)

This is similar to what's done in userland: there LD_PRELOAD and
MALLOC_DEBUG control the heaps, here "kernel_malloc" and then
"guarded_heap_options" kernel settings control the heap.

While at it, apply fixes to the guarded and debug heaps to ensure
a minimum alignment of sizeof(void*), if no specific alignment
is requested.

Tested with a lot of build configurations (DEBUG_HEAPS 0, 1;
DEBUG_HEAPS_DEFAULT slab, guarded; USE_DEBUG_HEAPS_FOR_OBJECT_CACHE
0, 1) and with various parameters specified in the bootloader.
2026-03-23 23:01:26 -04:00
Augustin Cavalier 4fd16356e0 kernel: Move the debug heap to a separate file in the debug directory. 2026-03-23 23:01:26 -04:00