Commit Graph
100 Commits
Author SHA1 Message Date
waddlesplash 14d9cf7417 Revert "bus_managers/pci: allow x86 systems to use VirtualBusMap"
This reverts commit 150e1c88e2.

Breaks interrupts on VMware and elsewhere, it seems (see #19517.)

Change-Id: I487de651d226e769f0ad5b07974a1c5079ad1714
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9176
Reviewed-by: waddlesplash <[email protected]>
2025-04-14 16:32:38 +00:00
Augustin Cavalier e6cd789248 libroot/malloc: Better handling of fragmented frees in PagesAllocator.
* Immediately free chunks that are from areas below a size threshold
   and which cover the whole area, or are in that area's head or tail.

 * Avoid unmapping just-freed chunks and any in the last area,
   if we can, while releasing memory. This should force smaller
   or not-needed chunks out of the caches more rapidly.

 * Drop the "single page cache clear" logic, as it isn't needed now;
   the "immediately free small areas" logic takes care of the same case
   in a more general way than for single pages.

Running a query for all files in Tracker, letting memory usage go
up to 200+MB, and then closing the query results window seemed to
test this logic pretty well. area_for+get_area_info were invoked
without a subsequent unmap ~12,000 times, vs. around ~3,600 that
the unmap path was taken. Other cases (web browsers) have lower
counts than that, at least in any given short window, from the
(admittedly brief) testing I did.

Hopefully will help with the huge amounts of areas seen in #19514.
2025-04-10 18:38:16 -04:00
Augustin Cavalier 5f8c94242b SplayTree: Add PreviousDontSplay to IteratableSplayTree. 2025-04-10 17:59:13 -04:00
Augustin Cavalier d45f85d19f libroot/musl: Use the correct toread and uflow for shgetc.
Should fix crashes with Python after the merge of the new wcstol.
2025-04-10 09:58:04 -04:00
Augustin Cavalier 0bd957f0e9 libroot: Update stubs. 2025-04-07 16:29:47 -04:00
Augustin Cavalier e2b1a054cd libroot: Update stubs for gcc2. 2025-04-07 16:23:49 -04:00
Augustin Cavalier 30cfbaf691 kernel: Move the BSD strto* implementations to kernel/lib from libroot.
The kernel is the only thing that uses them now.
2025-04-07 16:21:39 -04:00
Augustin Cavalier e192187bb2 libroot/glibc: Delete now-unused files. 2025-04-07 16:21:18 -04:00
Augustin Cavalier 7174197a8d libroot/posix: Switch to using musl's string-integer/float conversion routines.
Unlike glibc's, these don't take the current locale into account.
The POSIX specification says: "In other than the C and POSIX locales,
other implementation-defined subject sequences may be accepted."
Not accepting any other than the default seems to be more consistent
regardless.

This also makes things consistent between wchar_t and char, as we
were using the BSD implementations of strto*l for regular chars
but glibc's for wcsto*l before.
2025-04-07 16:20:36 -04:00
Augustin Cavalier e00903da0d libroot/musl: Define restrict in <features.h>.
Needed on GCC2.
2025-04-07 16:17:10 -04:00
Augustin Cavalier 9dcf5c5c88 stdio_ext.h: Add missing declaration for __fseterr.
Follow-up to #19479.
2025-04-07 14:48:23 -04:00
Augustin Cavalier 6b246eafbd BString: Add missing NULL checks in _MakeWritable().
Fixes crashes that can happen in out-of-memory conditions.
2025-04-02 14:24:20 -04:00
Augustin Cavalier 2fb23000eb libroot: Call thread exit hooks after __cxa_finalize.
This gives C++ destructors a chance to run before we tear down
the thread locale information (among other things.)

Should fix #19508.
2025-04-02 13:52:50 -04:00
Augustin Cavalier c6f736315a BSlider: Copy the UpdateText inside UpdateTextChanged.
We can't rely on it not changing between calls, especially as
MaxUpdateTextWidth() changes the value and re-gets it, and
that's called at the end of this method always. So we need to
keep our own copy rather than using the one that's owned by
the subclass.

Fixes a use-after-free uncovered by the guarded heap in VolumeSlider,
reported in #19493.
2025-03-21 11:54:37 -04:00
Augustin Cavalier aa2b9830e1 libroot/glibc: Zero-initialize the mbstate.
May fix #19493.
2025-03-21 11:52:00 -04:00
Augustin Cavalier a3fe8122be libroot/glibc: Delete even more unused stuff. 2025-03-20 17:22:10 -04:00
Augustin Cavalier 88b063d5e6 libroot/glibc: Delete now-uneeded locale files. 2025-03-20 16:45:53 -04:00
Augustin Cavalier 843c97b01f libroot: Make glibc use the native Haiku locale structs.
It accesses values through macros, so just write functions that
fetch the appropriate value from Haiku's structures.

Note that the values for multibyte digit characters are hardcoded.
As far as I can tell, we never set or updated these in glibc's
locale structures, so it always just used the default, so this
should not be a behavioral change from before.
2025-03-20 16:31:53 -04:00
Augustin Cavalier 910fdeee84 libroot/glibc: Delete more unused stuff.
Fixes more warnings.
2025-03-20 16:06:43 -04:00
Augustin Cavalier cf8410ca16 libroot/musl: Clean up x86_64 math Jamfile rules.
No functional change intended.
2025-03-20 16:06:43 -04:00
Augustin Cavalier cd7aab83d1 headers/posix: Drop commented-out strsep from string.h.
It's in the BSD header instead.
2025-03-20 14:00:48 -04:00
Augustin Cavalier 42adc340f4 libroot: Add missing files to arm64 Jamfiles to fix the build. 2025-03-20 14:00:31 -04:00
Augustin Cavalier 2ab23a1ade libroot/glibc: Fold needed declarations in stdlib/stdlib.h into include/stdlib.h.
Most aren't needed. This fixes quite a lot of compiler warnings.
2025-03-20 13:50:47 -04:00
Augustin Cavalier 55835d115b libroot/glibc: Add back cacos files to ARM sources. 2025-03-19 13:29:56 -04:00
Augustin Cavalier ac70aeab5b libroot/glibc: Remove some more unneeded stuff. 2025-03-19 13:29:41 -04:00
Augustin Cavalier a9f0038de7 libroot/musl: Add fpclassify to riscv64 & arm math sources.
Should fix the build there after recent changes.
2025-03-19 13:14:16 -04:00
Augustin Cavalier 91b06c1ca3 libroot: Replace most complex functions with musl's.
All compiled with the new GCC. Some where musl had TODOs/FIXMEs,
or where we would need the newer libgcc, the glibc versions are
left as-is.
2025-03-19 13:13:47 -04:00
Augustin Cavalier 42dcb9029f libroot/glibc: Delete more unused math files. 2025-03-19 11:46:56 -04:00
Augustin Cavalier 3ddb199a6e libroot: Replace s_ math routines from glibc with fully generic versions.
We define these as __builtins in math.h, but the compiler might
use out-of-line versions, and we need to export the symbols anyway.
musl implements the __fpclassify routines, so just use them.
2025-03-19 11:45:58 -04:00
Augustin Cavalier a5854d713e libroot/glibc: Add missing stdio_ext methods needed by gnulib.
Otherwise it needs to use libio internals to implement these,
which we don't want. musl also exports all these methods for
the same reason.

Implementations taken from glibc 2.15, current gnulib (5077f67), and
in a few cases tweaked for better Haiku support.

Should fix #19479.
2025-03-18 22:03:10 -04:00
Augustin Cavalier 0796aaabfc libroot: Clean up fpurge implementation.
* Take it from upstream glibc 2.15, much closer to the version we use.

 * Drop fpurge from stdio.h, it's nonstandard. Keep it around for
   ABI compatibility for now (BeOS didn't have it.) __fpurge is left
   in stdio_ext.h.
2025-03-18 22:03:10 -04:00
Augustin Cavalier 802a83e7ed libroot/glibc: Drop some unused stdio files. 2025-03-18 22:03:10 -04:00
Augustin Cavalier bb61eb2df3 libroot: Update stubs. 2025-03-18 19:51:24 -04:00
Augustin Cavalier e22463dc84 libroot: Update stubs for GCC2. 2025-03-18 19:45:46 -04:00
Augustin Cavalier d17f55ce84 libroot: Add R5 compatibility definition to OpenBSD malloc glue.
Only for GCC2.
2025-03-18 19:45:27 -04:00
Augustin Cavalier 13a3941b17 libroot/malloc: Don't export malloc_options.
It isn't needed.
2025-03-18 19:39:50 -04:00
Augustin Cavalier ee31ca9f7e libroot: Restore inadvertently removed mkstemps. 2025-03-18 19:30:58 -04:00
Augustin Cavalier a8b3a6b022 libroot: Replace tempfile functions with BSD or homegrown versions.
Same upstream commit as the mktemp file came from. Some modifications
to integrate better with Haiku.

FreeBSD has no tmpnam_r, so a new version implemented here
(inspired by FreeBSD's tmpnam implementation) that is fully
thread-safe.
2025-03-18 18:56:03 -04:00
Augustin Cavalier 8fadf59d1a headers: Move asprintf & vasprintf to stdio.h.
They're implemented in libroot, not libbsd, and they're now
in POSIX-2024 anyway.
2025-03-18 18:44:48 -04:00
Augustin Cavalier be5f87e9b9 libroot: Import most changes to mktemp from upstream FreeBSD.
From upstream dc36d6f9bb1.

Methods not declared for Haiku removed, and the old randomization
code is retained for now (but with getentropy() at least.)
2025-03-18 18:11:42 -04:00
Augustin Cavalier 0b27126820 libroot: Replace [efg]cvt implementations with musl's.
From latest musl release (1.2.5). This drops the _r versions,
which are nonstandard and are not present in our headers
(nor BeOS' headers.)
2025-03-18 18:01:03 -04:00
Augustin Cavalier 3d0e9319f6 libroot/glibc: Put wctype_t declaration inside second guard.
Should fix the build on GCC2.
2025-03-15 09:20:15 -04:00
Augustin Cavalier d95c04c2ee libroot/glibc: Remove some more unused files. 2025-03-15 08:11:49 -04:00
Augustin Cavalier 77dc532e76 libroot: Drop unused/uneeded empty tls.cpp. 2025-03-15 07:52:09 -04:00
Augustin Cavalier 20a6449385 kernel: Add thread setting to prevent page waits and use it in the file cache.
See inline comment: otherwise we could deadlock waiting for busy pages.

At the same time, make page_faults_allowed just an int16 and drop
atomics and extra checks, they aren't needed.

Fixes #19441.

Change-Id: I1b7cc06f66b44c3520fa36497c076ee5a6320706
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9120
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2025-03-14 18:34:06 +00:00
Augustin Cavalier c97ebaf1c7 MediaPlayer: Improvements to time tooltip.
* Make PositionToolTip update even when not attached to a window.

 * Always use the "hover" message to update the tooltip,
   never SetPosition.

 * Use BControl::Invoke so that hover messages are sent instantly.

 * Position the tooltip above the slider always.

Combined with the fixes to the Interface Kit, this provides a much
nicer experience for slider time tooltips.


Change-Id: Ib7f884ca91c253ed7e6639946fd2378166137d80
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9122
Haiku-Format: Haiku-format Bot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2025-03-14 17:50:43 +00:00
Augustin Cavalier acb9747e38 Interface Kit: Don't hide tooltip if we don't have any.
Ideally we would only hide our own tooltip and nobody else's, so
a TODO is added for that case.

This method is called for all mouse events if we get B_OUTSIDE_VIEW
or B_EXITED_VIEW as their "transit", but since tooltips themselves
get all mouse events and thus B_OUTSIDE_VIEW, this had the effect
of hiding all tooltips immediately instead of after the delay.
2025-03-14 13:47:54 -04:00
Augustin Cavalier d3009c305c Interface Kit: Always use the specified "where" in ShowTip.
It was previously ignored if the tooltip was already open.

Note that, combined with the previous commit, this means that
the "where" passed in will basically always be used (except for
"sticky" tooltips.) Applications or classes that use this private
API but pass in wrong or bogus positions will now need to be fixed.
2025-03-14 13:46:58 -04:00
Augustin Cavalier 6ac738b4de Interface Kit: Reset tooltip frames to their previous "where" on resize.
Instead of re-fetching the mouse position. This avoids tooltips "jumping"
when they may have resized by only a few pixels and don't need to be
repositioned.
2025-03-14 13:46:46 -04:00
Augustin Cavalier 30e5362d88 kernel/lib: Drop mergesort.
Nothing seems to use it.
2025-03-13 23:03:36 -04:00
Augustin Cavalier 546041c0ee libroot: Adjust stubs generator to work on Python 3. 2025-03-13 21:18:15 -04:00
Augustin Cavalier c23f4fec07 libroot/glibc: Update getopt to glibc 2.41.
Minor adaptations to integrate properly with Haiku libc.
2025-03-13 21:17:54 -04:00
Augustin Cavalier bbd93d522e libroot/glibc: Remove some unneeded files.
We can just use the system versions of these, or in the lc-
cases they didn't actually define any symbols.
2025-03-13 20:44:46 -04:00
Augustin Cavalier b989960b81 libroot/stdlib: Reinstate mistakenly removed UsePrivateHeaders. 2025-03-13 19:39:29 -04:00
Augustin Cavalier 705f9c114d libroot/stdlib: Define _DEFAULT_SOURCE for newer GCC.
So that we don't get warnings/errors about missing prototypes
for the non-standard sort functions.
2025-03-13 19:38:18 -04:00
Augustin Cavalier 95eee47cdc libroot/stdlib: Add qsort_r.
It's in POSIX-2024. Remove the libgnu implementation and just import
the changes from latest FreeBSD (dc36d6f9bb1753f3) instead.

While at it, put the non-standard sort functions behind
_DEFAULT_SOURCE.
2025-03-13 19:30:39 -04:00
Augustin Cavalier 194f7cff83 legacy stdc++: Delete all unused protected streambuf APIs that use IO_FILE directly.
Unfortunately there are some marked "public" that also use it,
so we can't just move the remainder to an internal file and then
drop libio.h from public consumption.

Delete all the unused portions of the public libio.h while at it.
2025-03-13 18:22:33 -04:00
Augustin Cavalier aa3a5e7698 headers: Drop _G_config.h from public headers.
Adjust the two legacy stdc++ headers that still included it;
it seems they didn't themselves depend on any of the definitions it
contained. However, streambuf.h actually did, so put that definition in
libio.h so that it's always present.

(The stdc++ implementation will get the 'real' _G_config.h from
libroot glibc.)
2025-03-13 17:23:44 -04:00
Augustin Cavalier 1799deddfd legacy stdc++: Drop <iostdio.h>.
It couldn't have been used anywhere, because "iolibio.h" is
available only in glibc includes in libroot, not in the
"headers" directories.
2025-03-13 16:36:09 -04:00
Augustin Cavalier 01a481d470 legacy stdc++: Make sure MTSAFE_IO is always enabled.
It's set in _G_config.h, but this file doesn't include that,
so in many cases the "unlocked" function was called instead.
(Most of the stdc++ .cc files did have it set, though.)
2025-03-13 16:35:23 -04:00
Augustin Cavalier 3b587ea361 legacy stdc++: Drop standard methods that are implemented in libroot.
sigsetmask is in libbsd.so, so keep the version here. All others
can just be dropped as the libroot implementations should suffice.
2025-03-13 16:16:54 -04:00
Augustin Cavalier 9769edfa33 headers: Get glibc <libio.h> out of the default include path.
It's needed by GCC2 stdc++, but we shouldn't be including it
for all consumers of <stdio.h>, which we were. Drop it,
and adjust all the things that were relying on <stdio_pre.h>'s
definition of __PRINTFLIKE to use the _PRINTFLIKE defined
in BeBuild.h instead.

Hopefully should not cause any breakage; the libroot
implementation of __freading depended on this, but
I didn't see anything else which did.
2025-03-13 15:57:25 -04:00
Augustin Cavalier 80f7969714 kernel/x86_64: Correct address mask in DebugGetReverseMappingInfo.
With how we currently use virtual address spaces, the old and
new computations should produce identical results even on LA57,
but this should be more correct if we ever do use more than just
48 bits of the address space.

Change-Id: I61915fceff8e7998032e0a9895010ef9c26b7b94
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9121
Haiku-Format: Haiku-format Bot <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2025-03-13 12:55:59 +00:00
Augustin Cavalier d68fa86ee1 libroot/unistd: dup3 should return EINVAL if oldFD == newFD.
As per POSIX-2024.

Fixes #19476.
2025-03-12 22:01:57 -04:00
Augustin Cavalier 0d73795fc9 libroot/malloc: Make the guarded heap handle bogus pointers better.
* Check if the area is a stack, and panic() if so.

 * Check names before accessing any area, and don't try
   to do anything with areas that we didn't create.

Makes frees pointing to stack data have much more useful
diagnostics than just "generic segfault".
2025-03-12 18:37:40 -04:00
Augustin Cavalier 3d196bd28c kernel/x86_64: Handle LA57 paging in VMTranslationMap page table walks.
Without this, we will fail to free the last level of page tables.
This bug has apparently been present since LA57 was originally
introduced years ago, however it was likely not a problem before
now because only the BIOS bootloader has support for it, while
systems that support LA57 are more likely to be booted via EFI.

While at it, fix the address mask for non-LA57 in
DebugGetReverseMappingInfo.

Should fix #19460.
2025-03-12 12:56:01 -04:00
Augustin Cavalier 92e002641e kernel/x86_64: Clear the lower half of the kernel PML4 in LA57 mode.
It also has an identity mapping that needs to be removed,
same as the PML5.
2025-03-12 12:20:27 -04:00
Augustin Cavalier ed8ca68825 ProcessController: Use more BString::SetToFormat. 2025-03-12 08:31:19 -04:00
Augustin Cavalier 139c35c9b9 ProcessController: Fix return type of UpdateSituation.
fWriteMemory is an int64.
2025-03-12 08:30:22 -04:00
Augustin Cavalier 282c3b6e08 kernel/slab: Set write protection on MemoryManager areas.
The MemoryManager maps and unmaps pages manually, so this isn't
strictly necessary, but it helps with memory accounting in e.g.
ProcessController.

Fixes the kernel_team disappearing from ProcessController's list
(and also having too-low memory amounts) as noticed in #19460.
2025-03-12 08:28:29 -04:00
Augustin Cavalier 70c25855f4 kernel: Move convertutf to utils.
No functional change.
2025-03-12 08:26:19 -04:00
Augustin Cavalier a97c4affc9 kernel: Rename basic "int" functions to "interrupt" (or at least "intr").
"int" of course is also an abbrevation for "integer", so having
two abbreviations is sometimes confusing. The BeOS functions
just use "interrupt" (e.g. "install_io_interrupt_handler"); it
seems we inherited the "int" abbreviation from NewOS.

The basic kernel methods and files related to interrupts are
here adjusted to drop the abbreviation and just use "interrupt(s)".
The architecture-specific functions ("arch_int_*") are mostly
moment left alone for now, though of course architecture-specific
usages of the generic kernel methods are adjusted.

Change-Id: Ic113ea1280a3c78e25f8ca3cc55b24ed5f594eae
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9119
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2025-03-12 01:58:33 +00:00
Augustin Cavalier ed5c4d8a2d file_systems: Add O_DIRECTORY checks to many filesystems that were missing them.
This doesn't get all the filesystems that were missing these checks
(e.g. I didn't adjust the more "WIP" filesystems like XFS and BTRFS)
but it does get most of them.
2025-03-10 23:30:07 -04:00
Augustin Cavalier 992f1401b2 ProcessController: Report kernel memory and fix some TODOs.
* Restore logic for excluding app_server side of bitmaps
   (though this may not work for server-cloned areas, only
   server-allocated ones.)

 * Leave TODO in place for media buffers.

 * Add all kernel-writable areas of the system (kernel) team
   to writable memory, but exclude the block_cache.

Fixes display of kernel memory information in ProcessController's
memory usage menu.
2025-03-10 22:35:55 -04:00
Augustin Cavalier e2ffc7fd31 kernel/vm: Don't report kernel protection to userland except for root.
And don't report other UIDs' area informations at all.

Fixes a TODO.
2025-03-10 22:34:17 -04:00
Augustin Cavalier e87593ae21 atheros813x: Merge changes from upstream FreeBSD.
Up through upstream commit 05a95d19cb248203acdd4e069d3eedfe597c3b49.

May fix #19471.
2025-03-10 22:27:53 -04:00
Augustin Cavalier ea0c6448f2 kernel/x86_64: Reset FPU state in x86_64_thread_entry.
Otherwise it won't be reset at all and we will begin with the
previous thread's FPU state, both for userland and kernel threads.

Also clear the FPU state in x86_return_to_userland, just like
in syscall exit.

Change-Id: Ie46d0e64a680c860c7fbff8dc57116625724eadd
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9092
Tested-by: Commit checker robot <[email protected]>
Haiku-Format: Haiku-format Bot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2025-03-11 02:13:26 +00:00
Augustin Cavalier 317307ff46 headers/x86[_64]: Name the "mxcsr_mask" fields properly.
These values aren't referenced anywhere at present however.

Change-Id: I870d6321c6d30f850f48f811213124276543a1a8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9091
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
2025-03-11 02:13:26 +00:00
Augustin Cavalier 6db4b42346 kernel/x86_64: Store FPU state from int_bottom_user in arch_thread always.
The XSAVE area can be quite large (1-2KB+), so rather than always
putting it on the kernel stack, just use the arch_thread FPU state.

Change-Id: Ie64c3ea3ca52cd8a4425ae1da69792588a69832a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9090
Reviewed-by: Jérôme Duval <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2025-03-11 02:13:26 +00:00
Augustin Cavalier bdb6d7db1a kernel/x86: Determine math/SIMD exception cause in exception handler.
Fixes a TODO.

Change-Id: I75e7f05bd72f1500234a7b43ed9da01d3a61ecf2
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9082
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2025-03-11 02:13:26 +00:00
Augustin Cavalier 4c76039f6f kernel/x86_64: Keep FPU and SSE control on context switch.
This reverts most of c7360f4b02.

Unlike the other floating-point registers, these values are callee-saved
(see "System V Application Binary Interface, AMD64 Architecture
Supplement" section 3.2.1.) So we need to preserve their values and not
reset defaults on context switch.

EMMS, as the previous changes used, does not suffice to clear
exceptions. We could use FNCLEX instead, but we need to reset
x87 state on context switch anyway, so use FNINIT. Do not
reinstate FNCLEX in the exception handler since it will
be executed on context switch anyway.

We also need to ensure a clean initial state, so take care of that
in arch_thread_init.

See also:
 * remarks in 396b74228e
 * as well as 53e2dc0f85

Fixes #19454 and #18624. Doesn't regress #18656 and #19063.
Doesn't seem to affect #19450.

Change-Id: I7179f1ec7304e7aed09ff80f6773e53d5dbdf5f9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9081
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2025-03-11 02:13:26 +00:00
Augustin Cavalier 848d379f5d strace: Handle area_id returns like status_t returns. 2025-03-08 14:57:37 -05:00
Augustin Cavalier cee5e4f57e strace: Don't check if status values are smaller than UINT32_MAX.
The type check suffices. Fixes printing ssize_t error names.
2025-03-08 14:57:18 -05:00
Augustin Cavalier 906623697e ram_disk: Do not use cache_get_pages in Trim().
cache_get_pages locks and unlocks the cache to wait for busy pages,
as well as after it's done, which creates a race where some other
thread may start waiting on a page that we have marked busy. But
as we are about to free those pages, that wait will deadlock.

Just loop through the cache's pages directly, skipping any busy ones
and freeing the others directly.

Fixes a deadlock observed with BFS on a ramdisk.
2025-03-08 10:16:02 -05:00
Augustin Cavalier 876171f588 ram_disk: Add missing DEBUG_PAGE_ACCESS_START.
This was removed from cache_get_pages, so we need to do it manually.

Fixes a KDL reported in the comments of #16951.
2025-03-08 09:42:28 -05:00
Augustin Cavalier bb6c8ca150 strace: Handle ssize_t differently than status_t.
It's 64-bit on 64-bit architectures and must be handled as such.

Fixes strace outputs seen in #16861.

Also clean up style a bit.
2025-03-08 00:12:43 -05:00
Augustin Cavalier fe70bb7f1e libroot/unistd: Fix write truncating return values of _kern_write.
ssize_t is 64-bit on 64-bit architectures, if we truncate to int
then values above 2GB will be seen as negative and errors instead
of the successes they are.

Seems to fix #16861.
2025-03-08 00:11:51 -05:00
Augustin Cavalier b3d011b90a kernel/locks: Assert in rw_lock_wait that we weren't spuriously unblocked.
May have caught #19458 earlier, depending on cause.

Change-Id: Ib5dd4ef72474f944946e1dae214c49fe440669bc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9086
Reviewed-by: waddlesplash <[email protected]>
2025-03-06 15:00:31 +00:00
Augustin Cavalier 0958031b24 kernel/fifo: Don't unlock before unblock.
Otherwise there is a race that can occur if the waiting thread is
interrupted (or hasn't slept yet) while the writing thread tries to
unblock it.

Instead, don't call SetNotified again if we unblocked with a status
of B_OK. This can only happen when we were notified by another thread
successfully.

Should help with #19458.

Change-Id: Iad46b26374a01539f8765231d259392c231c786a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9085
Reviewed-by: waddlesplash <[email protected]>
2025-03-06 15:00:31 +00:00
Augustin Cavalier 240f1a0e91 kernel/devfs: Check whether the node is a directory in devfs_open.
Same checks as other filesystems.

Fixes "cp file /dev/some/block/device".

Change-Id: Ic4bd04972247b94ac4eaa6e211fe6cb1c53f3975
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9084
Reviewed-by: waddlesplash <[email protected]>
2025-03-06 15:00:31 +00:00
Augustin Cavalier 16db148e63 kernel/x86: Replace homegrown memcpy & memset with NetBSD's.
FreeBSD also uses NetBSD's versions (with their own modifications,
however.) So it seems to make sense for us to adopt these, too;
they look to be better tuned than ours were (like handling
non-aligned addresses better, which was a TODO before.)
2025-03-05 14:25:56 -05:00
Augustin Cavalier 282bdf736c Overhaul generic memcpy and memset.
* Rewrite generic memcpy, with optimizations more like the common memcmp
   optimizations.

 * Rewrite generic memset, with a proper optimized implementation.

 * Name the files "generic_" like other files in the arch generics dirs.

 * Always use the generic versions in the bootloader, since it's
   complied with special flags.
2025-03-05 14:23:13 -05:00
Augustin Cavalier f33654d942 libroot/string: Put the misalignment check in memcmp() into a macro. 2025-03-05 13:43:02 -05:00
Augustin Cavalier a23e085678 m68k, arm: Rename arch_string.S to memcpy.S.
As it only contains a memcpy implementation.
2025-03-05 12:53:16 -05:00
Augustin Cavalier 62793934a1 x86, x86_64: Move (userland) memcpy, memset out of arch_string.S/.cpp.
Put the C++ versions in files with their own names, and
rename the assembly thunks to "commpage_string.S", as it
really just invokes the commpage versions.

The kernel x86 arch_string.S is left alone for the moment
as it will be replaced in the near future anyway.
2025-03-05 12:48:54 -05:00
Augustin Cavalier 8a86fccb1b arm64, riscv64: Drop arch_string.S.
It was empty and unused on these architectures.
2025-03-05 11:57:05 -05:00
Augustin Cavalier 1707ab1299 runtime_loader: Use posix_string_arch as built for libroot.
Instead of using individual files from it.
This will make changes to how it is built easier to make.
2025-03-05 11:55:27 -05:00
Augustin Cavalier 2b52ddef79 libroot/string: Use '==' and not '-' and '== 0' for all except the last comparison.
Should make the code clearer and save a branch in the loop.
Also add Haiku, Inc. to copyright notice.
2025-03-05 11:12:41 -05:00
Augustin Cavalier 5d46b254d4 libroot/string: Apply the same optimization to strncmp as in strcmp. 2025-03-05 10:45:55 -05:00
Augustin Cavalier 2e3af8f296 ralinkwifi: Import MT7601U driver from FreeBSD.
It's branded as a MediaTek device, but the firmware
copyright is Ralink.

From upstream b96864412700a2a5b5e9aaf5d6513ec062cfc96f.
Includes adaptations to make it compile on Haiku.
2025-03-03 16:46:01 -05:00