Now that we are not setting fFragmented in VectorLength(), we can
reset it in SetVector based purely on the length of the newly set vectors.
We also need to set it in SetData, as SetVector does not call this.
This fixes an oversight in bc7fd43358.
In a few instances, we need to not wait for objects to become unbusy
during ID puts because we expect they still will be, e.g. in the case
of Control pipes with submitted transfers that are still running. There,
we need to put the ID, cancel transfers, and only then wait for the
object to become unbusy.
Technically, this is a functional change, but at least in practice
it will have little real-world effect, for two reasons:
1. The DefaultPipe's Busy flag is basically never updated (the Device's
busy flag is generally used instead), so it will virtually never be
"busy".
2. Most devices have no Control endpoints besides that default one.
Change-Id: I32ff4094effeac9ec74546c9643ea2025418e1c1
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4491
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This way, any endpoints or interfaces which are currently using the
default pipe for SetFeature/.../etc. will return immediately and
become unbusy.
Should fix the remaining KDLs in #16794 and #16969.
Change-Id: I6615fc03394a0c50eae1ca7da2fb43f243841613
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4490
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This mostly only matters for the Device DefaultPipe, which is still
accesible even after its USBID has been put, but it makes sense to
do this in general, too.
Change-Id: I6711f1ce8fe79dff54927e3b5e60dec15bb58b14
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4489
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Control pipes have internal structures to wait for queued requests.
When force-cancelling queued transfers, the callbacks will not be called,
and so such transfers would be left hanging until the timeout occurred
or the destructor destroys the semaphore and mutex.
This probably will not fix any hang-related tickets, though, as force
cancellation is pretty much only used during device/pipe teardown.
Change-Id: I41db7caf380cdd082bc3509e95262317489bf100
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4488
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
I was not actually aware that our USB stack already supported
breaking (bulk) transfers up into smaller units as necessary;
these APIs are not very well documented.
This makes #15569 occur far less often, though it is still
more than possible to trigger.
It did not return the length of the vectors, but only the current
fragment's worth of vectors. It also modified the fFragmented flag,
which really should have been set in SetVectors in the first place.
As everything seemed to call IsFragmented after VectorLength,
this is not a behavioral change.
This allows us to stop storing the package flags, which saves 4
bytes per package node (a value that really adds up when there
are thousands upon thousands of PackageNodes), at the cost of an extra
sizeof(int32) allocation for the WeakPointer object per-package (of
which there are are much fewer, of course.)
This also is safer overall, as now consumers of GetPackage() or VFSInit()
will now hit a NULL dereference if they have failed to check if the
package still exists, instead of a use-after-free.
Change-Id: Iea97ffcd491c6e2da7093730a7fa951b84dcefdf
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4478
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
This is both more correct, as we need to not read past the 'size'
position of the passed pointer, and much faster, in the case where
the passed pointer is into some very large block of memory.
This provides an unbelievable speedup to a microbenchmark posted on IRC
that makes heavy use of this function in tandem with some rather
large allocations. (Some variants of it go from multiple minutes
to under a second!)
It has been since 2019. It seems to be added to images anyway,
probably because something else depends on it, but for correctness,
it belongs outside the REGULAR section.
If the debug_output pointer is just a kernel_args_malloc'd structure,
then it is already mapped and we should not be re-mapping it; we only
need to do that if we are using a fixed-map ring.
Eventually, EFI should get support for the debug log ring_buffer
like bios_ia32 has for transparent handoffs, but this preserves
everything except for the pre-start MMU dump, which is an improvement.
Fixes#15455.
It was removed in hrev55422 as we never had declared it in any headers.
But it seems some software came to depend on it anyway. Reinstate it,
and add a declaration for it, behind _GNU_SOURCE.
This reverts and replaces hrev53141, hrev53200~1, and hrev53888.
Two years ago (in hrev53141), I added checks to validate that Devices
were not in the process of being torn down before using them, to fix
a race condition KDL. Further logic was added in hrev53200~1 and in
hrev53888 for Pipes.
Well, upon closer inspection following the reports of #16794 et al.,
it appears upon closer inspection there were still two more race
conditions lurking in there: the first between Get and InitCheck, and
the second between InitCheck and use.
To resolve both of these, a new atomic "busy" flag is added to objects,
which is incremented before unlocking the objects array, and then
waited on before actually proceeding with teardown.
The older checks about initialization status are now superfluous
and are removed in favor of an earlier PutUSBID() invocation in Device.
While #16794 was fixed by hrev55429, some of those or related KDLs
might have been caused by these races. This also re-resolves #15115,
along with #14949 and #15710.
Change-Id: Ifcae84945a81123af5ef4683a6e33dc1eec5b23c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4421
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This array was introduced by korli in hrev44089~1 (2012). It "mapped"
ports to slots using a device's HubPort, and then used this value in
FreeDevice() to locate the xhci_device struct in question.
Well, when there are non-root hubs in use, the HubPort values can
of course collide, leading us to tear down the wrong device in many
circumstances. This appears to have been the true cause of #16794,
and probably also #16878 and #17266, and maybe even some others.
In case any one message (or, more likely, importing the bootloader's
syslog buffer) is too large for our buffer, do not discard it, but
keep as much as we can, and print <TRUNC> at the beginning of it,
to distinguish from <DROP>. (Documentation already notes <TRUNC> as
a possible thing to find in the syslog.)
If keep_debug_output_buffer is true, then we reused the syslog buffer
the bootloader allocated (and which has just been re-mapped above),
so we do not need to write the buffer in again (and moreover doing so
is incorrect, as it contains a raw ring_buffer header, and will be
larger than the buffer.)
This fixes "<DROP>" appearing at the beginning of all syslogs (or at least,
ones that began with handoffs from the bootloader) spuriously when
the whole buffer was really present anyway.
* Destroy interfaces and endpoints before deleting the default pipe,
as all of these may actually use the default pipe at any time
while they are alive.
* Remove the default pipe and then ourselves from the stack before
deleting the default pipe, as it also may be used at any time.
May help with some of the open tickets about USB stack KDLs.
This fix is for ticket #9460 to enable -Werror for ext2.
- Unused functions are removed.
- The ASSERT macro was redefining a different ASSERT macro from the included files. Now it gets undefined first.
- One comparison side was cast to ptrdiff_t because X86_gcc2 complained about signed/unsigned comparison
Change-Id: Ib0caade2f83de34c04acc0fc6aa5ed50712daec4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4453
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Instead their IDs are indexes into the stack, and are used primarily
for TRACE*() printing, so move the getter function into a "protected"
block and rename the variable appropriately.
AllocateAddress() is the pre-USB3 way of doing things;
as we never use it anywhere else and it is specific to
each BusManager, we always just got 1, which is what
the root hub will always be anyway.
Additionally, clarify the logic in _InsertEndpointForPipe
that is special-casing the root hub.
No functional change intended.
glibc's hsearch and tree functions are old and rather slow.
While these APIs do not appear to be used very often, these
changes can make a big difference: in one benchmark I was sent,
this change is nearly a 10x speedup or more in some cases.
This is a source compatibility break from BeOS, but should not
be an ABI one (I checked, the symbols are identical.)
Also use "= {}" in the definitions of the fields. We use this
in plenty of places in the kernel, so it should be OK for GCC2.
Change-Id: Ibe05b2236d46024d7b4563ae16e1cc7140fed965
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4434
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Modifications made on hrev55413 removed UsageID from array Items,
but also (bug here) broke UsagePage, needed by KeyboardHandler
in order to recognize items as Keyboard ones.
Fixes#17263.
Change-Id: I4b73c69240f31d3c8c2aacf6bab0d270f2053387
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4458
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Follow-up for Alan Shearer's change. Useful when the buffer contains the
character "%".
Change-Id: Ia6771a2d71306ca97e7c03f0e986ad3cfe100684
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4459
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
the file position corresponds to the end of the buffer.
Change-Id: Ib67dcfe1f43d959777c2f6dbf84181f25a022a7c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4447
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>