| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
|
|
|
|
| |
This commit fixes a warning introduced by macOS 10.12 Sierra when
using the OS atomics. These atomics have been deprecated in favor
of the ones provided by C11 (stdatomic.h). On older versions of
OS X we still use the OS atomics (now OSAtomicAdd32Barrier) and
on 10.12.0 and newer we use atomic_fetch_add.
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
|
| |
This commit updates the check around objc_registerThreadWithCollector
to enable the call only between 10.6 (introduced) and 10.8 (deprecated).
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
|
|
|
|
| |
This commit adds a workaround for devices that have buggy endpoint
descriptors but are otherwise functional. These devices will have
endpoints that fail the GetPipeProperties call. Since we only care
about the endpoint address we can read it from the descriptor
itself.
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The linux kernel will set its internal device state to USB_STATE_NOTATTACHED
as soon as it detects the disconnect, and then start a worker thread to
deal with the actual disconnection, kill outstanding urbs, etc.
The usbfs poll implementation will return POLL_ERR as soon as
ps->dev->state == USB_STATE_NOTATTACHED. The kernel will not wakeup
the poll until it is done with processing the disconnection. But if
we happen to call poll() between the state change and the disconnection
being fully processed, we may not be able to reap all outstanding transfers,
even on kernels with the USBFS_CAP_REAP_AFTER_DISCONNECT capability.
This commit deals with this by trying to reap as many transfers as possible
on disconnect on USBFS_CAP_REAP_AFTER_DISCONNECT capable kernels and then
calling usbi_handle_disconnect(handle) to deal with any remaining ones.
On USBFS_CAP_REAP_AFTER_DISCONNECT capable kernels this will be a no-op
unless we hit the race.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
|
|
|
| |
This cleans-up libusb_submit_transfer a bit by avoiding an error
exit path with unlock calls.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
There is a race between handle_timeout() and the completion functions.
When one thread is in handle_timeout() and another thread wakes
up from a poll(), there exists a window where the transfer has been
cancelled, but USBI_TRANSFER_TIMED_OUT is not yet set in timeout_flags.
Therefore, usbi_handle_transfer_completion() is sometimes called
with LIBUSB_TRANSFER_CANCELLED instead of the expected
LIBUSB_TRANSFER_TIMED_OUT.
timeout_flags is protected by the flying_transfers_lock, this commit
makes usbi_handle_transfer_cancellation() take that lock before
checking for USBI_TRANSFER_TIMED_OUT in timeout_flags, fixing this.
Reported-by: Joost Muller <joostmuller@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
|
|
|
| |
Put the lock / unlock calls around the part of the code which actually
checks the flags which the lock protect.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
| |
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
| |
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Commit a886bb02 sped up the library a bit by removing the serialization
of transfer submission with respect to the flying_transfers list, but
it introduced two separate issues.
1) A deadlock scenario is possible given the following sequence:
- Thread A submits transfer with very short timeout (say 1ms)
-> takes transfer->lock
-> adds transfer to flying_transfers list and arms timerfd
-> actually calls backend to submit transfer, but it fails
<context switch>
- Thread B is doing event handling and sees the timerfd trigger
-> takes ctx->flying_transfers_lock
-> finds the transfer above on the list
-> calls libusb_cancel_transfer() for this transfer
--> takes transfer->lock
<context switch>
- Thread A sees the transfer failed to submit
-> removes transfer from flying_transfers list
--> takes ctx->flying_transfers_lock (still holding transfer->lock)
** DEADLOCK **
2) The transfer state flags (e.g. submitting, in-flight) were protected
by transfer->flags_lock, but the timeout-related flags were OR'ed in
during timeout handling operations outside of the lock. This leads to
the possibility that transfer state might get overwritten.
This change corrects these issues and simplifies the transfer submission
code a bit by separating the state and timeout flags into their own flag
variables. The state flags are protected by the transfer lock. The timeout
flags are protected by the flying_transfers_lock.
The transfer submission code sheds some weight because it no longer needs
to worry about the timing of events that modify the transfer state flags.
These flags are always viewed and modified under the protection of the
transfer lock. Since libusb_submit_transfer() holds the transfer lock for
the entire duration of the operation, the other code paths that would
possibly touch the transfer (e.g. usbi_handle_disconnect() and
usbi_handle_transfer_completion()) have to wait for transfer submission
to fully complete. This eliminates any possible race conditions.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
[hdegoede@redhat.com: Reworked libusb_submit_transfer changes so that in
case both flying_transfer_lock and itransfer->lock are taken
flying_transfers_lock is always taken first]
[hdegoede@redhat.com: Removed some unrelated changes (will be submitted
as separate patches)]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(itransfer->flags & USBI_TRANSFER_TIMED_OUT) is already checked by
usbi_handle_transfer_cancellation(), make windows_transfer_callback()
call usbi_handle_transfer_cancellation() when
status == LIBUSB_TRANSFER_CANCELLED like all other os backends do, and
leave USBI_TRANSFER_TIMED_OUT handling up to the core, so that future
changes to timeout handling do no break winnt.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Note: untested
|
|
|
|
|
|
|
|
|
|
|
|
| |
(itransfer->flags & USBI_TRANSFER_TIMED_OUT) is already checked by
usbi_handle_transfer_cancellation(), which wince_transfer_callback()
will call when status == LIBUSB_TRANSFER_CANCELLED. Leave this up
to the core, so that future changes to timeout handling do no break
wince.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Note: untested
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The event handling lock was previously required to be of the recursive
type because the libusb_close() path requires the lock and may be
called by a thread that is handling events (e.g. from within a
transfer or hotplug callback). With commit 960a6e75, it is possible to
determine whether the current function is being called from an event
handling context, thus the recursive lock type is no longer necessary.
References:
* http://libusb.org/ticket/82
* 74282582cc879f091ad1d847411337bc3fa78a2b
* c775c2f43037cd235b65410583179195e25f9c4a
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
[hdegoede@redhat.com: rebase on top of current master]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
|
|
|
|
|
|
| |
This reverts commit bd8d5b5019b72b2dc2d074d96c9992e2f6e7e0b7.
Chris Dickens and me have been working on a patch-set refactoring
the transfer flag handling which fixes this differently. Revert
this commit so that the refactoring changes can be merged cleanly.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
| |
Closes #198
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
| |
Closes #177
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
* Closes #193
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
There is a race between handle_timeout() the completion functions.
When one thread is in handle_timeout() and another thread wakes
up from a poll(), there exists a window where the transfer has been
cancelled, but its USBI_TRANSFER_TIMED_OUT flag is not set yet.
Therefore, usbi_handle_transfer_completion() is sometimes called
with LIBUSB_TRANSFER_CANCELLED instead of the expected
LIBUSB_TRANSFER_TIMED_OUT.
This change adds transfer and flag locks to the handle_timeout()
function.
Closes #197
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
|
| |
OS X does not support unnamed semaphores so the example has been
updated to use a named semaphore instead.
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
|
|
|
| |
This commit is based on Nathan's branch
https://github.com/hjelmn/libusb-darwin/blob/master/examples/testlibusb1.c
Closes #178
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
| |
Closes #176
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
| |
Similar to commit adb6e39b68699b5d849836f9aaff7640b0f16173, drop the
use of usbi_reallocf() as the memory would be freed, thereby leaking
device references.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
| |
Closes #161
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
| |
Backends not using named initializers were broken by the recent
addition of commit a283c3b5a3dce8f6f33331b9aa1d95d41c8f241c.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
| |
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add a function to allocate memory belonging to a specific device,
so that the operating system can DMA straight into it for zerocopy,
and also avoid some clearing. Also, this allows up-front memory
allocation in the kernel at program startup; memory allocation is
otherwise done per-transfer, which can fail in a system where memory has become
fragmented over time).
This mirrors new functionality going into Linux' USB stack (recently
reviewed and acked upstream); only Linux is supported as a backend
currently.
[Chris Dickens] Modified to fix doxygen documentation, correct parameter
naming, reposition function declarations, and address a missing request
during the patch review process.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
Commit 1d54ee1b6687c532eca75925f56eb12e2a34ce42 addressed a device
reference leak but introduced a false warning message that occurs
for devices detected in early enumeration passes (e.g. hubs). The
assertion is meant to warn of a mismatch between parent devices but
fails to account for the fact that some devices that are allocated
early do not have a parent device assigned until the later
enumeration passes.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- Changes in platform configuration, x86 breaks the build
- Solution file does not contain platform for Any CPU, fixing it to Win32
- Added Multiple solutions to appveyor configuration file
- Added batch script for VS2010 builds
- Added fixes to appveyor.bat file and appveyor.yml
- Fixes for Platform and Configuration in appveyor.bat
- Fixed windows exit code, Appveyor reports exit on succesful build
- Multiple Builds in same platform and configuration, fixed it
- Added appveyor configuration to compile using MinGW 32-bit and 64-bits
- Minor Fixes for batch file and Added cygwin build script
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit bumps the minimum autoconf version to 2.69. This only
affects maintainers and will ensure libusb tarballs have up-to-date
configure scripts. At the same time we are removing the
AM_MAINTAINER_MODE macro as even its creator recommends against
using it.
Closes #122
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
| |
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
|
|
|
|
|
|
|
|
| |
free(NULL) is no operation.
Contributed by @ya1gaurav.
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
|
|
|
|
|
|
|
|
|
|
|
| |
- Changes in platform configuration, x86 breaks the build
- Solution file does not contain platform for Any CPU,fixing it to Win32
- Added Multiple solutions to appveyor configuration file
- Added batch script for VS2010 builds
- Added fixes to appveyor.bat file and appveyor.yml
- Fixes for Platform and Configuration in appveyor.bat
- Fixed windows exit code, Appveyor reports exit on succesful build
- Multiple Builds in same platform and configuration,fixed it
|
|
|
|
|
|
| |
Added other $ARCH
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
|
|
|
|
|
|
| |
Remove the /sdcard copy and not the /system/lib copy
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
|
|
|
|
| |
Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
|