summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* darwin: fix typov1.0.21-rc4Nathan Hjelm2016-09-122-2/+2
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* on to 1.0.21-rc4Nathan Hjelm2016-09-123-3/+6
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* darwin: do not use deprecated OSAtomicIncrement32Barrier in 10.12Nathan Hjelm2016-09-122-6/+20
| | | | | | | | | | 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>
* darwin: do not use objc_registerThreadWithCollector where deprecatedNathan Hjelm2016-09-072-2/+2
| | | | | | | 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>
* darwin: work around devices with buggy endpoint descriptorsNathan Hjelm2016-09-072-8/+25
| | | | | | | | | | 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>
* release: on to 1.0.21-rc3v1.0.21-rc3Nathan Hjelm2016-08-213-3/+5
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* core: Document why we drop the flying_transfers_lock before submit_transferHans de Goede2016-08-172-1/+5
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* linux_usbfs: Deal with receiving POLLERR before all transfers have completedHans de Goede2016-08-172-4/+8
| | | | | | | | | | | | | | | | | | | | | 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>
* core: Move calculate_timeout call to add_to_flying_transfersHans de Goede2016-08-171-8/+5
| | | | | | | 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>
* core: Fix unlocked access to timeout_flagsHans de Goede2016-08-172-2/+9
| | | | | | | | | | | | | | | | | 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>
* core: Fix do_close lockingHans de Goede2016-08-172-3/+3
| | | | | | | 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>
* core: Test for LIBUSB_SUCCESS instead of 0 in handle_timeout()Hans de Goede2016-08-172-2/+2
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* core: Do not arm timer-fd for transfers where the os handles timeoutHans de Goede2016-08-172-2/+2
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* core: Refactor code related to transfer flags and timeout handlingChris Dickens2016-08-175-99/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* winnt: Do not differ between cancel / timeout ourselvesHans de Goede2016-08-172-10/+8
| | | | | | | | | | | | | (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
* wince: Do not differ between cancel / timeout ourselvesHans de Goede2016-08-172-8/+3
| | | | | | | | | | | | (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
* core: Change event handling lock to traditional (non-recursive) typeChris Dickens2016-08-176-57/+34
| | | | | | | | | | | | | | | | | | | 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>
* Revert "io: Fix race condition in handle_timeout()"Hans de Goede2016-08-172-38/+21
| | | | | | | | | | 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>
* on to 1.0.21-rc2v1.0.21-rc2Nathan Hjelm2016-07-242-2/+2
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Updated TODO linkAnil Nair2016-07-242-2/+2
| | | | | | Closes #198 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* changelog: add entry for new solaris backendNathan Hjelm2016-07-242-1/+2
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Solaris backendLei Chen2016-07-248-4/+1401
| | | | | | Closes #177 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* changelog: add missing entryNathan Hjelm2016-07-222-1/+2
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* windows: use appropriate version for VS2015 solution filesPete Batard2016-07-222-3/+3
| | | | * Closes #193
* libusb 1.0.21-rc1v1.0.21-rc1Nathan Hjelm2016-07-213-3/+12
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* io: Fix race condition in handle_timeout()Joost Muller2016-07-212-21/+38
| | | | | | | | | | | | | | | | | 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>
* examples: add missing include to dpfp_threadedNathan Hjelm2016-07-212-1/+2
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* fix nanoNathan Hjelm2016-07-211-1/+1
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* examples: make dpfp_threaded work on OS XNathan Hjelm2016-07-212-8/+11
| | | | | | | 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>
* Examples: Ported testlibusb from libus-0.1 to libusb-1.0Anil Nair2016-07-213-2/+275
| | | | | | | | | 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>
* Add support for Intel Alpine Ridge USB 3.1 Controller on Windows 7.Jeffrey Nichols2016-05-292-3/+4
| | | | | | Closes #176 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Clean up referenced devices when memory allocation failsChris Dickens2016-05-292-9/+9
| | | | | | | | 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>
* Clean failure in discovered_devs_append.FTDI Dev2016-05-292-17/+25
| | | | | | Closes #161 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Misc: Fix usbi_os_backend structure initializationChris Dickens2016-05-297-1/+19
| | | | | | | Backends not using named initializers were broken by the recent addition of commit a283c3b5a3dce8f6f33331b9aa1d95d41c8f241c. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Misc: Add .amend to .gitignoreChris Dickens2016-05-293-1/+2
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Add support for persistent device memory.Steinar H. Gunderson2016-05-297-2/+110
| | | | | | | | | | | | | | | | | | | 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>
* Windows: Fix false assertion failure message during enumerationChris Dickens2016-05-293-10/+15
| | | | | | | | | | | | 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>
* AUTHORS: update my copyrightNathan Hjelm2016-03-201-1/+1
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* AppVeyor: add cygwin and minGW supporthacker24902016-03-194-1/+54
| | | | | | | | | | | | | | | - 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>
* fix nano versionNathan Hjelm2016-03-121-1/+1
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* autogen: remove --enable-maintainer-modeNathan Hjelm2016-03-122-2/+2
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* configure: bump autoconf version and remove obsolete AM_MAINTAINER_MODENathan Hjelm2016-03-113-3/+4
| | | | | | | | | | | | 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>
* core: re-add one more conditionalNathan Hjelm2016-03-062-4/+6
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* core: revert some of prior patchNathan Hjelm2016-03-061-16/+20
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* README.md: update AppVeyor badge (again)Ludovic Rousseau2016-03-062-2/+2
| | | | Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* free can handle NULL ptr.Gaurav2016-03-062-29/+19
| | | | | | | | free(NULL) is no operation. Contributed by @ya1gaurav. Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* AppVeyor: use a .bat file nowhacker24902016-03-062-1/+33
| | | | | | | | | | | - 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
* android: update READMEWilliam Skellenger2016-03-061-1/+3
| | | | | | Added other $ARCH Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* android: Fix typo in READMEWilliam Skellenger2016-03-062-2/+2
| | | | | | Remove the /sdcard copy and not the /system/lib copy Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* README.md: update AppVeyor badgeLudovic Rousseau2016-03-062-2/+2
| | | | Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>