Commit Graph
100 Commits
Author SHA1 Message Date
Augustin Cavalier f7fb846f5b Tracker: Store the correct time value in the thumbnail creation attribute.
We were storing real_time_clock_usecs() but comparing against
BStatable::GetModificationTime() which is just a time_t. The
values were thus displayed wrongly in the "Get Info" window,
but also thumbnails would not have been updated when the file was.

Should fix #18691 and possibly some other tickets.
2023-11-30 17:42:08 -05:00
Augustin Cavalier b6c24e6b40 network: Overhaul TUN/TAP subsystem.
* Rename the "tun" network device to "tunnel". FreeBSD calls theirs
   "tuntap" but speaks of both TUN and TAP devices as interfaces for
   tunnels. The other BSDs seem to do likewise.

 * Fold the "tun" driver into the "tunnel" network device. The
   network device now publishes entries in devfs when interfaces
   are created, and unpublishes them when interfaces are destroyed.

   This removes the need for the driver and device to communicate
   through a file descriptor, and thus allows the receive queue
   to be totally eliminated, massively simplifying that logic.

 * Use standard net-stack FIFOs instead of TCP BufferQueue, which is
   specialized to TCP's needs in far too many ways. Thanks to the
   previous commit adding support for interrupting semaphore waits,
   we can use the FIFO wait mechanisms, too.

 * Restructure the TAP logic, and generate MAC addresses more like
   Linux does.

 * Actually set type = IFT_TUN, and use the "loopback" frame handler
   instead of the "ethernet" frame handler. This allows significant
   cleanup of the header handling logic.

 * In TUN mode, reject packets that don't look like IP packets.

 * Delete "tunconfig"; it was mostly stubs and is now unnecessary.

TUN mode tested and confirmed as working by kallisti5 with OpenVPN.
TAP mode partially tested, but not yet confirmed as working.

Fixes #18673.

Change-Id: Ibd803139474e8db556a4f567901da15ee4083621
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7143
Reviewed-by: Alex von Gluck IV <[email protected]>
2023-11-30 20:44:44 +00:00
Augustin Cavalier daf1dd9c40 kernel/sem: Use "count" as thread_unblock status in B_RELEASE_ALL.
Previously, "count" did nothing for B_RELEASE_ALL. Now, if it is
< 0, it will be the error code returned by acquire_sem() of any
waiting threads.

As B_RELEASE_ALL is a Haiku extension, this change should not
cause any compatibility problems that we cannot fix.

This will be useful in implementing some features of TUN/TAP
with network FIFOs.

Change-Id: I2dbccedefac2024fe740b87543ff3b80f5257e20
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7163
Reviewed-by: waddlesplash <[email protected]>
2023-11-30 20:44:44 +00:00
Augustin Cavalier 255314f734 libroot: Make stpncpy compatible with GCC2. 2023-11-28 21:47:39 -05:00
Augustin Cavalier 611d3d7803 BSocket: Fix swapped parameters in Bind().
Spotted by X512.
2023-11-28 20:41:02 -05:00
Augustin Cavalier 15a3f4c540 libroot: Add stpncpy.
Imported from musl.

It is in POSIX.1-2017.
2023-11-28 20:37:15 -05:00
Augustin Cavalier 783aa308c3 network/stack: Clean up socket_receive.
* Reshuffle variable declarations, most are placed much
   closer to first usages now.

 * Turn a confusingly worded comment into an ASSERT(),
   and remove another one that was outdated.

 * Fix some minor code style problems.

 * Make the copying logic more consistent between first
   and then subsequent copies.

 * Make it possible for B_BAD_ADDRESS (EFAULT) to be
   returned. This is not listed in POSIX, but as per
   online sources, at least Linux does do this.

Change-Id: Idcfbed30531c1ab4796c4ee37f7f4ce8078e535b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7147
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2023-11-27 17:10:19 +00:00
Augustin Cavalier 2926dfaa3f network/stack: Fix handling of MSG_TRUNC in socket_receive.
This is a Linux extension (which at least FreeBSD has also
adopted.) It's used in the Haiku port of libpcap (where it's
a necessity) and wpa_supplicant (where it wasn't, and I
removed it.) It seems that we've had it for quite some time.

Fixes tcpdump following addition of flag checks.
2023-11-24 23:07:18 -05:00
Augustin Cavalier ceeea27b72 freebsd_wlan: Fix compilation of ieee80211_ioctl.h under GCC2 in C mode.
GCC2 tolerates [] FLAs in C++ mode but not in C mode, as discovered
when trying to build wpa_supplicant against R1/beta4. A workaround
was added there for now, but this is the more general solution.
2023-11-24 12:57:07 -05:00
Augustin Cavalier 459fa41f17 network/stack: Get rid of socket_readv and socket_writev.
These have not been used in years (maybe since the redesign of the
network stack?). Only socket_writev had an implementation, which was
mostly just an incomplete version of socket_send.

Scatter/gather I/O is already supported via msghdr's msg_iov/len fields,
so this is redundant anyway.

Change-Id: If41c4f4ee021856f6db49c7cb95422a9c1aa7700
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7127
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
2023-11-24 16:28:38 +00:00
Augustin Cavalier 5188904bfa loopback: Actually update device statistics.
ifconfig shows numbers other than 0 for the loopback interface now.
2023-11-23 15:03:21 -05:00
Augustin Cavalier 75874bab1a ethernet: Device statistics must be updated using atomic operations.
Both send and receive can be called concurrently, and there aren't
any locks protecting these fields, so they must be updated with atomics.
2023-11-23 15:02:45 -05:00
Augustin Cavalier 6461885e2e TUN: Remove redundant comments.
They only described things that the function names and parameters
already indicated. As per the Coding Guidelines, such excessive
commenting is to be removed.

Also fix some other (minor) code style issues while at it.
2023-11-23 14:27:40 -05:00
Augustin Cavalier c1f1032016 network/stack: Enumerate TUN after loopback. 2023-11-23 14:24:35 -05:00
Augustin Cavalier a1d837369f lgtm.yml: Delete.
"LGTM" code scanning was bought out and merged into GitHub Actions.
The code scanning setup there has a different mechanism for configuration,
and so this file is not useful anymore.
2023-11-23 13:46:19 -05:00
Augustin Cavalier e1480b40af ext2: Adjust short and pretty names to just be "ext" and not "ext2".
The filesystem name returned by read_fs_info will be correct (i.e.
returning "ext3" or "ext4" as appropriate), but some things just list
the filesystem driver's name, which can cause confusion.

Change-Id: Ic4acf497fc5db5c167131aeb323b45eeb78594d6
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7126
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
2023-11-23 18:20:04 +00:00
Augustin Cavalier 973f6d3320 network: Migrate SIGPIPE generation into the socket module.
This removes the burden of determining whether to and then
actually sending SIGPIPE from the protocol modules, meaning
the MSG_NOSIGNAL flag can now be implemented entirely in
the socket module and not even passed further down the chain.

Change-Id: I9ba976c4aff60d533cb4b390bbba1560c0de423f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7124
Reviewed-by: Jérôme Duval <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-11-23 06:51:39 +00:00
Augustin Cavalier da2f2c65b7 network/stack: Mask off MSG_NOSIGNAL at the top of socket_receive.
Fixes WebKitGTK spinning endlessly and spawning lots of
short-lived worker processes following the addition of
flag checks and EOPNOTSUPP to the various socket modules.

Change-Id: I6d944b4d0235eea9e8a9333645fcb531805f340f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7123
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-11-23 06:23:12 +00:00
Augustin Cavalier e7371da8b5 network/stack: Add back a #pragma mark. 2023-11-22 12:04:38 -05:00
Augustin Cavalier 407d3f1046 network/stack: De-templatize base_fifo methods.
Following the removal of the "Fifo" class, they
do not need to be templated anymore.
2023-11-22 12:00:02 -05:00
Augustin Cavalier 0b829b1151 network/stack: Remove unused "Fifo" class.
Its declarations were moved from another header to this file
in 2008, with a comment in the commit message and a TODO here
questioning whether it was needed for anything. In the 15 years
since then, nothing has used it.
2023-11-22 11:47:52 -05:00
Augustin Cavalier 4100480724 network/stack: Return EOPNOTSUPP when unhandled flags are specified.
This method is invoked directly in some protocols, e.g. L2cap (Bluetooth.)
2023-11-22 11:41:18 -05:00
Augustin Cavalier 73eb03214e net/ProtocolUtilities: Return EOPNOTSUPP when unhandled flags are specified.
Same as has already been done for UNIX domain sockets and TCP
(this is used in the implementation of UDP.)
2023-11-22 11:40:02 -05:00
Augustin Cavalier 42e4cb759a net/ProtocolUtilities: Correct implementation of MSG_DONTWAIT.
We don't want to restore the timeout from a restarted syscall
if MSG_DONTWAIT has been specified.
2023-11-22 11:39:29 -05:00
Augustin Cavalier fca1b0ec50 protocols/tcp: Return EOPNOTSUPP when unhandled flags are specified.
Same as was done for UNIX domain sockets in 74a44f5aed.
2023-11-21 23:36:07 -05:00
Augustin Cavalier 93a6528df8 protocols/tcp: Correct implementation of MSG_DONTWAIT.
Waiting for state changes correctly checked MSG_DONTWAIT,
but the overall data timeout only did in ReadData, not
SendData. This corrects that and makes the implementation
more consistent overall.
2023-11-21 23:34:59 -05:00
Augustin Cavalier f860cfc76c protocols/tcp: Correct implementation of MSG_NOSIGNAL.
The other send_signal invocation correctly checked NOSIGNAL already.
2023-11-21 23:34:33 -05:00
Augustin Cavalier 3bae07fc29 protocols/unix: Implement MSG_NOSIGNAL.
Same logic as in the TCP protocol module.

This fixes a regression from hrev57383: curl now works
again. (Perhaps it shouldn't be called a "regression",
though, but instead an uncovered bug / missing feature.)

Fixes #18666.
2023-11-16 12:08:47 -05:00
Augustin Cavalier 74a44f5aed protocols/unix: Return EOPNOTSUPP when unhandled flags are specified.
Fixes the "bug" part of #18653 (however the flags still need to
actually be implemented.)

Change-Id: Icd296af8b409416317ba3d02735504729949fd08
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7109
Reviewed-by: Niels Sascha Reedijk <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-11-15 16:33:38 +00:00
Augustin Cavalier eb4d2229f0 Debugger: Select "local" interface if none specified in MSG_DEBUG_THIS_TEAM.
The debug_server sends MSG_DEBUG_THIS_TEAM but of course it doesn't
have a way to specify the internal interface pointer. We should thus
assume the local one is implied.

Fixes #18645, which is not a regression but has been the case since
the initial host-interface refactors years ago, apparently.

Change-Id: I48078232f154f2f8f7cdf28792d39ae58471ce19
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7074
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2023-10-30 23:57:14 +00:00
Augustin Cavalier e8d328979c ICUTimeConversion: Fix buffer overflows and add more error handling.
* Declare databridge buffer lengths in LocaleBackend.
 * Use strcpy instead of strlcpy when writing to databridge buffers
   (this is the first fix for #18598.)
 * Check for overflows and error out when they happen.
 * Verify that ICU actually knows the timezone in question
   and fall back to GMT if it does not (this would also fix that crash.)

Fixes #18598.
2023-10-28 16:36:12 -04:00
Augustin Cavalier c199c568de DebugAnalyzer: Fix -Werror=mismatched-new-delete. 2023-10-28 14:20:31 -04:00
Augustin Cavalier bb2808d615 bootloader: Implement TSC calibration via hypervisor CPUID leaf.
While debugging some problems on the HaikuPorts build VMs, mmlr
noticed their clocks had an alarming amount of drift. This prompted
an investigation into TSC calibration mechanisms, and the discovery
that there is a VM-specific one which we did not implement.

This mechanism is more accurate than counting cycles on VMs where
cycles can be "stolen" (the probable cause of the aforementioned
clock drift.)

Tested in VMware (works out of the box) and on QEMU/KVM
(may need TSC frequency specified or a host with invariant TSC.)

Change-Id: I4ccfdb2e4e2621404ec9026e7106c02bf96faf18
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7063
Reviewed-by: waddlesplash <[email protected]>
2023-10-25 00:53:55 +00:00
Augustin Cavalier b8fbb723ea fs_shell: Use UINTPTR_MAX not LONG_MAX.
Fixes the build after the previous commit.
2023-10-24 19:16:19 -04:00
Augustin Cavalier 5c040b731c People: Fix buffer overflow in string handling.
Also move some variable declarations closer to their usages.

Fixes #18618.
2023-10-23 22:15:27 -04:00
Augustin Cavalier de9f473cda Terminal: Colors are stored using untranslated names.
The previous code did not work on non-English locales,
a problem readily detectable when running in Terminal
inside a Terminal session, e.g.:

PrefHandler::getRGB(Hintergrund) - key not found

Fixes #18614.
2023-10-23 21:29:12 -04:00
Augustin Cavalier 8764a29843 build/jam: Only add C++ header directories to include path for C++ code.
There are now some system headers (e.g. <stdatomic.h>) that have outright
different versions for C and C++ which are not compatible with each other.

Change-Id: Ibf797e0817f0fe4d5241424d7d06023b19888c02
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6991
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2023-10-13 16:18:47 +00:00
Augustin Cavalier 5c32c5ef2f condition_variable: Reorder members for optimal sizing.
Class size now 48 instead of 56 bytes (on x86_64.) No functional change.
2023-10-09 21:08:53 -04:00
Augustin Cavalier 788b1b12b6 Get rid of kernel_c++_structs mechanism.
This undoes fc7864091e.

It was only ever used by the FreeBSD compatibility layer,
only supported one structure, and created problems with
concurrent builds.
2023-10-09 20:26:21 -04:00
Augustin Cavalier 7a701128f1 drivers/network: Remove now-unneeded manual dependency declarations. 2023-10-09 20:21:23 -04:00
Augustin Cavalier 869de36dcd freebsd_network: Remove the need for <kernel_c++_structs.h>.
Use sizeof()+roundup() to build a char[] of the correct size,
and add a static_assert to ensure it stays so.

The <kernel_c++_structs.h> header needs to have its dependency
manually declared, and not all consumers of this file properly
declared it as such. This then fixes a concurrent build problem.

Fixes #17965 as this was the only consumer of this header.
2023-10-09 20:21:06 -04:00
Augustin Cavalier d8bca3564a Tracker: Check whether the default button is disabled on double-click.
The comment above this block specified the correct behavior: the
button's status is already updated elsewhere, so just check IsEnabled().
But the code did not actually do that.

It appears this has been incorrect all the way back to the initial
OpenTracker import in 2001.

Fixes #13721.
2023-09-23 17:05:19 -04:00
Augustin Cavalier 2d42fb1a9a Tracker: Adjust open button status when B_DIRECTORY_NODE is set.
In hrev51155, it was changed to be always enabled no matter what,
so that the current directory (without anything selected) could be opened.
But this means it would also be enabled for files, which is misleading.

Instead, remove the function, and adjust the logic detecting whether
to enable the button or not to take B_DIRECTORY_NODE into account.
2023-09-23 17:05:06 -04:00
Augustin Cavalier d95a9b63f7 iaxwifi200: Synchronize to OpenBSD trunk.
CVS revision(s) are in first-line comments.

Requires a new firmware package (from HaikuPorts). There are some
changes in here which may fix some of the odder issues, like failures
to connect to access points. There is also support for one new PCI ID.

Tested by PulkoMandy who reports it's still working.
2023-09-23 15:10:10 -04:00
Augustin Cavalier 76681bd900 kernel: Rewrite B_DEBUG_SPINLOCK_CONTENTION.
* Replace count_low/count_high with bigtime_t fields plus an int32.
   sizeof(spinlock) is now 32 bytes with the debug option enabled.

 * Adjust and clean up all spinlock code to use the new fields.

 * Fold DEBUG_SPINLOCK_LATENCIES into the new code. Remove the bootloader
   option and other flags for it (these were not compiled in by default.)

The new code should be much easier to understand and also more powerful.
However, the information transmitted to userland isn't as useful now;
the KDL command output will have the interesting information.

(Things could be reworked to transmit more interesting information to
userland again if desired, but as this code clearly hadn't been compiled
for many years, as it referred to global spinlocks that have been gone
for a very long time.)

Change-Id: I2cb34078bfdc7604f288a297b6cd1aa7ff9cc512
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6943
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2023-09-23 18:41:04 +00:00
Augustin Cavalier ef9e2f627b kernel/arch: Make arch_debug_get_caller() a macro implemented by a builtin.
Only the x86 and PPC implementations look like they would have worked,
while the builtin is available and will work across all architectures.
We already use it unconditionally in some parts of libroot.

Change-Id: I2dffb3b2c7cdd605092382b9d649151adb921bb4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6942
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-09-23 18:41:04 +00:00
Augustin Cavalier d0c34f9331 kernel/debug: Invoke cpu_pause in trap_cpu_in_kdl.
This is the loop that runs on all CPUs besides the one
actually running the kernel debugger. It's functionally
a spin-loop around a few different variables, and so it
should be safe to use cpu_pause() here, just as real
spinlocks do.

(cpu_pause() just runs a "pause" or equivalent instruction,
it doesn't use the CPU-idle modules, which indeed may be
unsafe to use in KDL.)

A glance at FreeBSD seems to indicate they also do this
when their kernel debugger is active.

Seriously improves power consumption while KDL is active:
even running in a VM with only a few cores, there would be
obvious fan spin-up when entering KDL. After this change,
there's barely any at all (while overall CPU usage % remains
basically identical.)
2023-09-23 14:07:17 -04:00
Augustin Cavalier f0a016dcb1 BBufferedDataIO: Fix Write().
I looked at this code as a reference when writing similar code in another
project, and realized then that this was broken to the point where I
don't think anyone could have actually used it:

1. Writes larger than the buffer should only return the amount written
by this Write() call, not the amount flushed beforehand.

2. fDirty was only set if there were bytes remaining after the first
write to the buffer. So, if you wrote small amounts of data, they
would be silently discarded most of the time!

3. When filling the buffer, we might as well flush simultaneously.
This allows the logic to be consolidated into a loop and remove the
duplicate memcpy. In case of failure, just return the bytes-written
as the write could be retried later.

4. Flush() should always return an error or 0, not bytes written.

While at it, add some basic tests for this class.

Change-Id: I2de01d0b31e3fe22863cef21dd7b0b62ed47121b
2023-09-22 19:56:04 -04:00
Augustin Cavalier 35bc8b401a ArchitectureRules: Disable autovectorization for the kernel (for now.)
See #18593.
2023-09-22 16:27:37 -04:00
Augustin Cavalier 55b2baf2f6 kernel: Use correct type for semaphore numbers.
It must be unsigned short, otherwise in some places we would use
negative offsets and wind up out-of-bounds.

Fixes #18586.
2023-09-21 22:28:55 -04:00
Augustin Cavalier 959d9cd069 kernel: Cleanups to the XSI message queue & semaphore implementations.
* Remove unused/unneeded parameters to Dequeue.
 * Make use of StackOrHeapArray.
 * Reorder syscall-entry checks for efficiency.
 * Inline the unlock-block method and unset variables in the process.
 * Reorder code for clarity and to reduce indentation.
2023-09-21 22:20:31 -04:00
Augustin Cavalier f759ab2733 headers/compatibility/bsd: Update headers to remove BSD advertising clause.
Rewrite link.h entirely.
2023-09-21 18:38:10 -04:00
Augustin Cavalier 2e0e70b5bb libroot: Delete some old private math headers.
These haven't been needed or used in a long time.
2023-09-21 18:31:22 -04:00
Augustin Cavalier d6b37ce996 packagefs: Fix missing unlocks in Volume package content node removal.
When breaking out of _RemovePackageContentRootNode() by encountering
a specified "endPackageNode", we need to unlock all directories.

This case is only possible to encounter when _AddPackageContentRootNode()
fails partway and invokes _Remove() to remove the just-added nodes.

Fixes a hang/deadlock encountered by Diver while testing some (disabled)
HaikuPorts recipes.
2023-09-21 14:53:06 -04:00
Augustin Cavalier 2903a69d4a network/ipv4: Fix NULL dereference in multicast-send.
Fixes the KDL in #18585.
While at it, add a missing NULL check and fix a leak.
2023-09-20 16:39:28 -04:00
Augustin Cavalier 75e1de3c23 libnetwork: Synchronize netresolv with NetBSD 9.3.
Some of the Haiku-specific modifications that were previously unmarked
are now clearly marked with #ifdef __HAIKU__.

BIND9-specific files containing private APIs never exposed in public
headers have been removed.

Tested with wget, curl, pkgman (Network Kit), WebPositive (WebKit/curl),
and Falkon (QtWebEngine/Chromium). All DNS-related operations seem
to still work just fine.

(One patch also imported from NetBSD trunk for GCC 12+ compatibility.)

Change-Id: I4a349577b24b4df008fd9cba5d3a322cd24397f1
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6879
Reviewed-by: waddlesplash <[email protected]>
2023-08-31 23:38:47 +00:00
Augustin Cavalier ac30bc0ef6 libnetwork: Remove lcl_sv.cpp.
This has not been included in the build for years, probably since the
initial NetResolv merge. Services are now returned via the "protocols"
file, and getservent() has no need for these utility functions.

Change-Id: If18bdd9593463b38a9aaedb7a621d0ddc15530e4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6878
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-08-31 23:38:47 +00:00
Augustin Cavalier 4dcc1ed654 kernel: Synchronize inet_addr.c to remove advertising clause.
Change-Id: I03665bcad679e3fddaea0d8a95663be12b003bd8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6877
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-08-31 23:38:47 +00:00
Augustin Cavalier 56241aab2f Zip-O-Matic: Fix and enable _SelectInTracker().
Based on a code example from humdinger.
2023-08-31 15:25:06 -04:00
Augustin Cavalier 711b36b44c Tracker: Merge SelectPosesListMode and SelectPosesIconMode.
There was a TODO comment about this, which dated all the way back
to the original OpenTracker import over 20 years ago.

There's still more cleanup needed, so I left another TODO.
2023-08-31 15:13:06 -04:00
Augustin Cavalier 46a6070b57 libroot: Replace strcspn and strchrnul with musl versions.
Removes the last BSD advertising clause from the "string" directory.
2023-08-31 15:10:19 -04:00
Augustin Cavalier bc328a435b libroot: Import a lot of changes to stdlib, string code from FreeBSD.
Includes licensing clause removal. Also deleted 2 files that are
not used in the build and are not referenced anywhere else.
2023-08-31 15:10:19 -04:00
Augustin Cavalier a573f9e4be libroot: Fix build of new time files under GCC2. 2023-08-30 22:46:36 -04:00
Augustin Cavalier a8e2f08853 libroot: Replace the old localtime fallback backend with musl code.
This allows for the deletion of quite a lot of ugly C89 code.
2023-08-30 22:32:58 -04:00
Augustin Cavalier b09c82377a libroot/locale: Minor fixes and expose internal POSIX locale.
* We can return early from duplocale() so set the "magic" flag early.
 * Initialize all fields up front.
 * Add an internal method __posix_locale_t() which returns a locale_t
   usable as a global C/POSIX locale type, and add the appropriate
   definition to the musl internal header.
2023-08-30 17:57:19 -04:00
Augustin Cavalier 2705bc6bdf libroot/locale: Fix indentation of locale_t.cpp.
Also adjust some braces. No functional change intended.
2023-08-30 17:55:04 -04:00
Augustin Cavalier efdfb84038 signal.h: Look for _DEFAULT_SOURCE not __USE_GNU for sighandler_t.
Our features.h does not define __USE_GNU, and so applications trying
to use this GNU-ism would have to define it for themselves, even if
_GNU_SOURCE had already been specified.
2023-08-30 17:31:31 -04:00
Augustin Cavalier 8e8c7a073f Tracker: Reimplement BSlowContextPopup as BPopUpNavMenu.
BSlowContextPopup was mostly a duplicate class of BNavMenu
only on top of BPopUpMenu instead of BMenu. Now, BPopUpNavMenu
just subclasses BNavMenu and adds the few features of BPopUpMenu
neccessary.

Drag-and-drop of files using the pop-up nav menu seems to still work fine.

Change-Id: Ic1f49c5bed60fff7a3076a22f74aebc6eba51d57
2023-08-30 17:04:24 -04:00
Augustin Cavalier 18ee9c8397 Tracker: Add some missing includes.
These were implicitly picked up thanks to SlowContextPopup,
but that is about to change.
2023-08-30 16:51:07 -04:00
Augustin Cavalier 6bde05aebd libs/bsd: Implement getentropy(2).
With generic_syscall to avoid using a FD.

Change-Id: Id1702118bb673f06a861e4f0ad3401ce3d45cbd0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/31
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
2023-08-29 19:42:27 +00:00
Augustin Cavalier d57510c0ff Tracker: Reduce differences between NavMenu and SlowContextPopup.
No functional change intended.

Change-Id: Iaa9b821462ec97b74de538aa2c489762bf413311
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6872
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2023-08-28 20:57:26 +00:00
Augustin Cavalier 20e18366d6 ShowImage: Use layouts for the main view area.
The main window itself is still not using them,
due to incompatibilities with the toolbar animation.

Fixes #18547.
2023-08-25 19:34:34 -04:00
Augustin Cavalier 692e2e45bb Debugger: Move line-info version check up and print a warning.
This way it will be clear why there is no line-info.
2023-08-25 16:57:57 -04:00
Augustin Cavalier 15969ccf84 Debugger: Downgrade a warning to a TRACE.
We don't need to know all the objects which have no
debug information; this just spams the console.
2023-08-25 16:57:57 -04:00
Augustin Cavalier b22fab9510 build_haiku_image: Fix type of MAIL:draft and MAIL:flags indexes.
Fixes #18503.
2023-08-25 14:53:50 -04:00
Augustin Cavalier 4024e5b6a4 ramfs: Do not advertise ourselves as a persistent filesystem.
The original change to fix ramfs appearance (hrev56642)
in Tracker and elsewhere said the reason for adding the
FS_IS_REMOVABLE flag instead of removing FS_IS_PERSISTENT
was because of problems encountered with writing/deleting
entries on ramfs mounts.

I was unable to reproduce those problems; writing and
deleting entries on RAMFS mounts still works just fine
in Tracker and elsewhere, even after removing the flag.
So it seems safe to remove; subsequent problems can be
addressed as they come up.

Fixes #18173.
2023-08-24 21:02:30 -04:00
Augustin Cavalier 4e145eadc6 BMenu: Lock the looper before calling _AddItem().
Otherwise, we could wind up in a state where the
list of items is being concurrently accessed,
which is invalid.

Hopefully fixes #18256.
2023-08-24 19:14:19 -04:00
Augustin Cavalier b89f11999a ramfs: Rewrite Query system to use the common Query parser-evaluator.
The common version was also derived from BFS' original implementation,
but was genericized during packagefs development, and has more recent
fixes and additions.

Only lightly tested, but arbitrary-attribute-indexed queries seem to be
working just fine.
2023-08-24 18:01:46 -04:00
Augustin Cavalier 7602588721 Screen: Make some manual edits to Vendors.h.
This data comes from the PNP registry, where deprecated entries
have "DO NOT USE". But those deprecated entries were often once used
in actual products, and we don't want to display "DO NOT USE" for them.
So remove such text, and replace it with the actual vendor name in a few places.
2023-08-18 22:09:40 -04:00
Augustin Cavalier cc6365c7aa bootloader: Don't issue warnings upon encountering PT_EH_FRAME.
The kernel already does the same thing.
2023-08-07 12:46:44 -04:00
Augustin Cavalier bfebd2b3c9 libroot: Acquire the process heap lock.
Upon further investigation, the global heap lock should actually
not need to be reset, but the process heap lock will.

Change-Id: Id1fd91cc0e7acecd5b4fd76cb82d4ed2ae3900ad
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6777
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-08-07 16:12:01 +00:00
Augustin Cavalier 77dd55aae5 libroot: Reinitialize global heap lock after fork.
The per-heap locks are reinitialized already by the routine which
invokes this one, but this global lock was previously missed.

May fix a deadlock reported by trungnt2910 to happen in the .NET port.
2023-08-04 15:19:41 -04:00
Augustin Cavalier 6d3065508f kernel/condition_variable: Adjust notified count and wait-status returning.
* If we received a wait status, always return with it.

 * Only count those entries for which we set the wait-status as
   having been notified.

In conjunction with the prior commit, this fixes some rare deadlocks
that could occur with timeouts or signals.
2023-08-04 15:19:41 -04:00
Augustin Cavalier 798b773393 kernel/user_mutex: Fix unset of locked flag if no entries were notified.
It turns out this code actually is possible to trigger, e.g. using
Git checkouts, where EINTR due to signals happens quite often.
However, even with this commit, it still does not work quite right,
due to an oversight in condition-variable notify accounting. That
will be addressed in the next commit.
2023-08-04 15:19:41 -04:00
Augustin Cavalier 2d43eebcab kernel: Store "next" pointer before notifying B_EVENT_INVALID.
Once B_EVENT_INVALID has been set, the select routine is free to
delete the select_info at any time. We therefore cannot access
the "next" pointer after notify_select_events returns.

May fix a KDL seen by trungnt2910.
2023-08-04 15:19:41 -04:00
Augustin Cavalier d8365e0f0f kernel/event_queue: Only set B_EVENT_INVALID with the lock held.
The dequeue routine expects that if B_EVENT_INVALID is set,
it is free to delete the object. So we must only set it with
the lock held, so that by the time the dequeue routine sees it,
we will be done with the event.
2023-08-04 15:19:41 -04:00
Augustin Cavalier 9b28ebf997 DoublyLinkedQueue: Rework Remove() function.
Equivalent to the changes done to DoublyLinkedList
(in 904e9f5512305dbc0eed9146e8a0b2d597269b71.)
2023-08-04 13:25:56 -04:00
Augustin Cavalier 74662b662d DoublyLinkedQueue: Adjust API to match that of DoublyLinkedList.
It appears nothing actually uses this method anyway.
2023-08-04 13:17:18 -04:00
Augustin Cavalier 5d8502cb2b bluetooth: DoublyLinkedQueue is not actually used. 2023-08-04 13:16:57 -04:00
Augustin Cavalier 65c74c6474 DoublyLinkedQueue: Adjust whitespace.
No functional change.
2023-08-04 13:11:52 -04:00
Augustin Cavalier 5590a8194b network/protocols/unix: Recheck fShutdown{Read|Write} before socket notify.
They may have changed, and we must not use the socket object if they
are set.

Related to #18535.
2023-08-04 12:59:15 -04:00
Augustin Cavalier 967ab75d8e network/protocols/unix: Fix UnixDatagramEndpoint::Close().
1. Set fShutdownRead & fShutdownWrite. This is necessary
because in Send(), there is a lock-unlock dance between the
source and target sockets which could potentially race with
some other thread closing the socket. The "shutdown" state
is checked before actually writing, and so we need to set it
here. Otherwise, the other thread could allocate a new receive
FIFO for us, which we do not want.

2. Don't return early when unbinding, but only if there's an
error (there shouldn't be.)

3. Merely ASSERT() in Free() that closing was already done
and nothing remains to be deallocated.

Should fix #18535.
unix_dgram_test still passes.
2023-08-03 17:10:56 -04:00
Augustin Cavalier 363e0cdf69 kernel/fd: deselect_select_infos must be called with io_mutex held.
When the select/deselect API consumers invoke deselect(), they
expect that when this function returns, no further references to
the select_infos will remain and they can be safely deleted.

In order for that to be true, we cannot remove the select_infos from
the list in one step and deselect them in another; we must do both
without releasing the lock in the middle.

Should hopefully fix a rare KDL seen while testing .NET and
the new event_queue.
2023-08-03 17:04:55 -04:00
Augustin Cavalier 904e9f5512 DoublyLinkedList: Rework Remove() function.
* Check fFirst/fLast instead of previous/next. Avoids
   list corruption when trying to remove already-removed
   elements, instead will cause null-dereference KDL.

 * Always set next/previous to NULL even when DEBUG is not
   enabled.
2023-08-03 13:18:26 -04:00
Augustin Cavalier 5ae1a17908 Revert "DoublyLinkedList: Add a RemoveAllBefore convenience function."
This reverts commit c6cd9b51a2.

This wound up being unnecessary for the event_queue implementation,
and furthermore is of dubious value in general.
2023-08-03 12:45:36 -04:00
Augustin Cavalier 4ae33413f2 kernel: Add errata patching for AMD "Zenbleed".
Part of #18525.

Change-Id: I6b5d73f6634d122dba13ad9544f340358ddef113
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6767
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2023-08-02 15:27:07 +00:00
Augustin Cavalier 13b7ddec87 NTFS: Fix potential memory leak. 2023-07-31 17:38:47 -04:00
Augustin Cavalier 4c47466fea fts: Roll up changes from FreeBSD.
Notable changes include:

 * fts: Stat things relative to the directory fd, if possible.
 * fts: Fix double-free with conflicting concurrent modifications.
 * fts: Don't abort if an empty pathname is given.
 * fts: Don't return FTS_SLNONE if it's not a symlink (if race).
 * fts_children: preserve errno after running close/fchdir
 * Use ANSI C prototypes. Eliminates -Wold-style-definition warnings.
 * fts: Fix a potential memory leak in error case
 * libc: Check for readdir(2) errors in fts(3)
2023-07-29 12:25:37 -04:00
Augustin Cavalier 3386b8b785 libbsd: Add a basic kqueue implementation.
It only supports file descriptors and processes (threads),
and a few flags (not all) to go with them.

This has been tested extensively against libuv.

Change-Id: I6fc5930fa7273698172c9c695965842b5df44f03
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6746
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
2023-07-29 15:53:15 +00:00
Augustin Cavalier f66d2b46a8 kernel: Add event queue implementation to wait for objects efficiently.
Based on hamishm's original patch from 2015, but heavily modified,
refactored, and reworked.

From the original commit message:

> When an object is deleted, a B_EVENT_INVALID event is delivered,
> and the object is unregistered from the queue.
>
> The special event flag B_EVENT_ONE_SHOT can be passed in when adding
> an object so that the object is automatically unregistered when an
> event is delivered.

Modifications to the original change include:

 * Removed the public interface (syscalls remain private for the moment)

 * Event list queueing/dequeueing almost entirely rewritten, including:
  - Clear events field when dequeueing.

  - Have B_EVENT_QUEUED actually indicate whether the event has been
    appended to the linked list (or not), based around lock state.
    The previous logic was prone to races and double-insertions.

  - "Modify" is now just "Deselect + Select" performed at once;
    previously it could cause use-after-frees.

  - Unlock for deselect only once at the end of dequeue.

  - Handle INVALID events still in the queue upon destruction,
    fixing memory leaks.

 * Deduplified code with wait_for_objects.

 * Use of C++ virtual dispatch instead of C-style enum + function calls,
   and BReferenceable plus destructors for teardown.

 * Removed select/modify/delete flags. Select/Modify are now the same
   operation on the syscall interface, and "Delete" is done when 0
   is passed for "events". Additionally, the events selected can be fetched
   by passing -1 for "events".

 * Implemented level-triggered mode.

 * Use of BStackOrHeapArray and other convenience routines in syscalls.

Change-Id: I1d2f094fd981c95215a59adbc087523c7bbbe40b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6745
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
2023-07-29 15:53:15 +00:00