summaryrefslogtreecommitdiff
path: root/libusb/os/windows_nt_common.c
Commit message (Collapse)AuthorAgeFilesLines
* Windows: Fix detection of Windows 10 when manifest declares supportAxel Gembe2019-08-091-1/+2
| | | | | | | | | | | | | | | | | | On Windows 10 GetVersionEx will return version 10.0 when the running application has a manifest that declares Windows 10 compatibility. https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests#supportedOS When no such manifest is found, the call will report version 6.2, which is Windows 8. The 6.4 version is returned by early Windows 10 Insider Previews and Windows Server 2017 Technical Preview 1. Closes #604 Signed-off-by: Axel Gembe <derago@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Add missing structure entry to avoid erroneous shift of following itemswinterrace2019-01-301-0/+1
| | | | | | Closes #526 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Windows: Fix MinGW build warnings/errorsChris Dickens2018-01-081-1/+2
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Enable dynamic selection between WinUSB and UsbDk backendsChris Dickens2018-01-081-111/+500
| | | | | | | | | | | | | This commit unifies the two Windows backends into a single project and enables the user to switch to the UsbDk backend, if available, using the libusb_set_option() function. All contexts will use the WinUSB backend by default for backwards compatibility. With this change, the UsbDk-specific projects are no longer required. Closes #309 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Rework poll() emulation to a much simpler and effective designChris Dickens2018-01-061-16/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous poll() implementation worked okay but had some issues. It was inefficient, had a large footprint, and there were simply some use cases that didn't work (e.g. a synchronous transfer that completes when no other event or transfer is pending would not be processed until the next poll() timeout). This commit introduces a new, simpler design that simply associates an OVERLAPPED structure to an integer that acts as a file descriptor. The poll() emulation now solely cares about the OVERLAPPED structure, not transfers or HANDLEs or cancelation functions. These details have been moved up into the higher OS-specific layers. For Windows NT environments, several deficiencies have been addressed: 1) It was previously possible to successfully submit a transfer but fail to add the "file descriptor" to the pollfd set. This was silently ignored and would result in the user never seeing the transfer being completed. 2) Synchronously completed transfers would previously not be processed unless another event (such as a timeout or other transfer completion) was processed. 3) Canceling any one transfer on an endpoint would previously result in *all* transfers on that endpoint being canceled, due to the use of the AbortPipe() function. This commit addresses all of these issues. In particular, run-time detection of the CancelIoEx() function will allow the user to cancel a single outstanding transfer without affecting any others still in process. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Add check for ERROR_FILE_NOT_FOUND, which means device removedChris Dickens2018-01-061-0/+4
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Improve locking in threading abstractionChris Dickens2018-01-031-1/+1
| | | | | | | | | | | | | | | | | Convert the usbi_mutex_t type to a CRITICAL_SECTION object. There are numerous advantages including lower resource usage and a better fast-path (doesn't require entering kernel space). Simplify the condition variable implementation by not associating a wait structure with a particular thread ID. This is not needed and causes an unnecessary search through the linked list of any available wait structures when the real optimization is just reusing an already created event object. Also, while here remove all the checks for NULL pointers because we don't do such a silly thing inside the library. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Clean up unnecessary variable initializationChris Dickens2017-01-121-1/+1
| | | | | | | Don't zero out variables that already are zero (calloc'ed) and don't set variables that aren't read before being set again. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows/WinCE: Improvements to windows_error_str() functionChris Dickens2017-01-121-18/+18
| | | | | | | | | | | | | | 1) Add FORMAT_MESSAGE_IGNORE_INSERTS to flags for security. 2) Optimize removal of CR/LF terminators 3) Switch to use snprintf() Windows-specific: 1) Don't waste time converting debug messages to unicode WinCE-specific: 1) Get rid of TCHAR code Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Hash table improvementsChris Dickens2017-01-121-55/+33
| | | | | | | | | | | | 1) The current implementation was not entirely thread-safe. The hash table was read outside of the mutex, which in some cases could lead to improper hashing. 2) The hash creation function accepted a size parameter that was hard-coded. Eliminating this saves time because we can ensure that the pre-defined size is a prime number instead of requiring code to calculate a prime number. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Remove use of gettimeofday()Chris Dickens2017-01-121-5/+8
| | | | | | | | | | | | | | | | | Prior to this commit, gettimeofday() was being used for timestamps in debug messages. This function has been marked as deprecated in the latest POSIX specification and furthermore is not supported on Windows, thus requiring our own implementation as usbi_gettimeofday(). This commit changes the logging code to obtain timestamps using the clock_gettime() function provided by the backend. The implementation of usbi_gettimeofday() for Windows was actually equivalent to that of the USBI_CLOCK_REALTIME implementation for clock_gettime(), so this eliminates code duplication. In addition, the USBI_CLOCK_REALTIME implementation has been updated for Windows to leverage the timespec_get() function available in VS 2015 and later. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* winnt: Do not differ between cancel / timeout ourselvesHans de Goede2016-08-171-9/+7
| | | | | | | | | | | | | (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
* core: Remove POSIX threads influence from synchronization codeChris Dickens2016-02-241-1/+1
| | | | | | | | | | | | | | This commit changes the signatures of the synchronization functions to reflect the needs of the library rather than the signature of the pthreads API. The mutex and condition variable attributes parameters have been removed as no part of the core library makes use of them. In addition, the condition variable timed-wait function has been modified to accept the relative time passed in via libusb_wait_for_event(). This allows the implementation-specific code to handle conversion to absolute time as necessary, rather than forcing this to occur. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows/WinCE: Improve the run-time dynamic linking schemeChris Dickens2016-01-281-6/+14
| | | | | | | | | | | | | | | Prior to this commit, the Windows and WinCE backends had a specific shortcoming when loading DLLs, that being that once loaded they were never unloaded. This commit improves this by providing a means to unload the DLLs during cleanup. Note that the use of GetModuleHandle() has been removed in favor of the exclusive use of LoadLibrary(). This was done to ensure that a reference count is taken against the loaded DLL, which guards against some other part of the application unloading the DLL that libusb is currently using. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix some minor issues in windows_nt_common.cChris Dickens2016-01-281-8/+8
| | | | | | | 1) Address a few more stylistic discrepancies 2) Add appropriate type casts for printf functions Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Minor improvements to windows_nt_common.cChris Dickens2016-01-271-3/+5
| | | | | | | | 1) Possible memory leak is avoided if htab_create() is called while a hash table is already allocated 2) Error handling is simplified in windows_handle_events() Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Replace open-coded string alloc + copy with _strdup()Chris Dickens2016-01-271-2/+1
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Source file cleanupChris Dickens2016-01-261-376/+363
| | | | | | | | | | | | This commit addresses a few different issues: 1) Whitespace made consistent with the rest of the library source 2) Formatting of function and variable declarations made consistent with the rest of the library source 3) Functions and variables made static where possible 4) Definitions in header files moved if not used publicly Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* windows: Move common definitions to a separate fileDmitry Fleytman2016-01-231-0/+616
New files windows_nt_common.h/c introduced. Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com> Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>