This fixes an issue where an error that occurred in thread #X will create a false
error message stating that thread #X+1 did not discover the correct number of devices
Closes#1447
- Sometimes just change a type to match where it's coming from
- Sometimes add an explicit cast (but only if it's guaranteed correct,
like a previous check that a signed value is positive before casting to
unsigned)
- For libusb_bulk_transfer() add an assert to be certain that the signed
return value is never negative.
Update API documentation to underline this fact.
Add similar assert in usbi_handle_transfer_completion().
- darwin: For parsing OS version, change scanf to use %u instead of %i
- xusb: Add additional range checks before casting
- xusb: Reverse some backwards count and size arguments to calloc, not
that it really matters
Closes#1414
Some device descriptor fields are hard-coded by the HID backend, so they
will often not match. It is complicated to narrow this down to HID
devices, so we simply ignore these fields on Windows wholesale.
Hopefully we will fix the HID backend later, and this workaround can
then be reverted.
References #1360
References #1378
Signed-off-by: Tormod Volden <[email protected]>
Depending on the devices or drivers, open() may return
LIBUSB_ERROR_ACCESS
LIBUSB_ERROR_NOT_FOUND
LIBUSB_ERROR_NOT_SUPPORTED
for devices "out of reach" to libusb.
References #1360
Signed-off-by: Tormod Volden <[email protected]>
Instead of assuming there will always be some devices detected (when not
using LIBUSB_OPTION_NO_DEVICE_DISCOVERY), let the test pass but print a
warning to the user if there is none. This is to allow automated build
tests on restricted build environments without USB devices.
References #1374Closes#1379
In case num_devices equals 0, LIBUSB_EXPECT() calls
LIBUSB_TEST_CLEAN_EXIT(), which calls libusb_exit() on test_ctx which
has just been freed a few lines above by a call to libusb_exit(). This
might cause a SEGFAULT or SIGBUS depending on the system.
Fixes that by assigning NULL to test_ctx just after calling
libusb_exit() like it is done elsewhere in the file.
Closes#1374
Fixes the following warning from automake:
tests/Makefile.am:3: warning: 'LDFLAGS' is a user variable, you should not override it;
tests/Makefile.am:3: use 'AM_LDFLAGS' instead
Also, since stress_mt_LDFLAGS is set (even in a conditional), AM_LDFLAGS
will not be applied for stress_mt unless added explicitly.
Closes#1371
Signed-off-by: Tormod Volden <[email protected]>
According to https://gcc.gnu.org/wiki/StaticAnalyzer the
-Wanalyzer-malloc-leak and -Wanalyzer-file-leak options came in GCC 10.
When building with GCC 9 there would be warnings:
CC umockdev-umockdev.o
../../libusb-git/tests/umockdev.c:37:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]
37 | #pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
| ^~~~~~~~~~~~~~~~~~~~~~~~
../../libusb-git/tests/umockdev.c:38:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]
38 | #pragma GCC diagnostic ignored "-Wanalyzer-file-leak"
| ^~~~~~~~~~~~~~~~~~~~~~
Closes#1369
Signed-off-by: Tormod Volden <[email protected]>
- Added long-awaited support for multithreading. Since WebUSB still
doesn't support accessing same device from multiple threads, this works
by proxying I/O operations to the main thread as discussed on the
original issue. For applications that run on the main thread nothing
changes and they will continue to access WebUSB via Asyncify like
before, while other threads will use blocking mechanism until an
asynchronous response is available from the main thread.
- Rewrote notification mechanism to use atomic waiting via sync Wasm
instructions or `Atomics.waitAsync` depending on the thread. This
results in simpler and faster notifications than the previous
`postMessage`-based approach (which was used because
`Atomics.waitAsync` wasn't yet available), as well as allows to send
notifications across threads for multithreading scenario described
above.
- Fixed notification access to only wait/notify on the event we're
interested instead of using a global lock.
- Rewrote descriptor reading to query device for raw device &
configuration descriptors instead of re-serializing them from
JavaScript object representation. This incurs slight extra cost for the
initial device opening, but fixes number of issues with information
that is not yet exposed via WebUSB and allows to read supplementary
descriptors such as string and BOS which were previously not supported.
- Fixed listing only one alternate instead of all the available ones.
- Fixed device closing & re-opening which could previously error out
with "device busy" error.
- Added mandatory Emscripten-specific linking flags to the generated
pkgconfig.
- Added device speed inference. This is not yet exposed via WebUSB, but
we can at least make a best effort guess based on USB version and
packet size, like some other backends already do.
- Simplified & fixed device session ID generation which is now
guaranteed to be truly unique, whereas previously it could clash with
other devices of the same type.
- Prepare code to support building for the Web without mandatory
multithreading (which is costly on the Web) in the future. For now
those `#ifdef`s are defunct as libusb is always compiled with
`-pthread`, but some upcoming changes on the Emscripten side will allow
to leverage those codepaths for smaller Wasm binaries.
- Require explicit `--host=wasm32-unknown-emscripten` as we might want
to add non-Emscripten WebAssembly backends in the future.
- Various smaller fixes and improvements.
Note that this requires Emscripten 3.1.48 or newer to build for some of
the features used here, namely `co_await` support for JavaScript values
(without it code would be both more complex and slower) and some
proxying APIs. It shouldn't be a big deal in practice as most users
retrieve Emscripten via the official emsdk installer or Docker images.
Closes#1339
This commit adds a new unit test that verifies that the interface
interface and device interface versions are as expected. The unit test
relies on new testonly symbols to get details about the implementation.
The commit also adds a sanity check on the versions to ensure that
libusb_init fails if a supported version can not be found.
In addition to the new tests this commit also updates the tests to
use the static version of libusb. This provides them access to any
hidden symbol including testonly symbols (which should never be
exported in the shared library).
Signed-off-by: Nathan Hjelm <[email protected]>
automake has built-in support for running unit test with make check. This commit
sets the TESTS variable in tests/Makefile.am to enable this support and updates
the CI script to use make check instead of hard-coded test names.
Closes#1361
Signed-off-by: Nathan Hjelm <[email protected]>
Verify that you can open a device, do some transfer (a device descriptor
control transfer was chosen as it should succeed with any connected
device), and close a device from multiple threads in parallel as well.
Print a warning if a device is readonly.
Consistently add thread flags to the build.
Closes#1347
set_option.c gave warnings and init_context.c would fail to build on
Windows.
Tested with configure options --disable-log and --enable-debug-log
Signed-off-by: Tormod Volden <[email protected]>
This commit effectively deprecates libusb_set_log_cb by adding support for
setting the callback in either libusb_set_option or libusb_init_context. Since
the libusb_set_log_cb is already in use we can not easily deprecate it without
first incrementing the major version. We may do that in the future.
Closes#1265
Signed-off-by: Nathan Hjelm <[email protected]>
The behavior of libusb_set_option was not matching the documentation
when the log level was set in the environment. This has been fixed but a
regression test is needed to ensure the behavior does not deviate. This
commit adds a set of unit tests to cover some of the functionality of
libusb_set_option.
Closes#1245
Signed-off-by: Nathan Hjelm <[email protected]>
[Xiaofan: Add Windows setenv/unsetenv wrappers]
Signed-off-by: Xiaofan Chen <[email protected]>
[Tormod: Fix test_no_discovery() build on Linux, add msvc build]
Signed-off-by: Tormod Volden <[email protected]>
This commit updates all test and example code to use the newer
libusb_init_context() function instead of libusb_init().
Signed-off-by: Nathan Hjelm <[email protected]>
[Tormod: Update umockdev.c as well]
Signed-off-by: Tormod Volden <[email protected]>
Thanks to Ilya Averyanov for initial version.
This test detects issues like #1124.
Adaptation to Windows threads is on the wishlist (#1128).
References #1124
References #1128Closes#1189
Signed-off-by: Tormod Volden <[email protected]>
There was a behaviour change in libusb 1.0.25 which triggers issues when
the API is misused. This caused for instance gutenprint to crash, see
https://bugzilla.redhat.com/show_bug.cgi?id=2055504
This seems to affect several applications "out in the wild".
For now, work around this by installing an implicit default. But, change
the code to log an error in case this "feature" is being used.
This will allow some grace time for developers to fix their
applications, before we at a later point revert to the stricter
behaviour.
Fixes#1089
Add some basic umockdev tests. The setup in this case is all in one
process, but umockdev in principle could also work between processes.
This is just a start, more tests would make sense.
This commit updates libusb_set_option to save the options if setting them on the default
context. This ensures the options 1) can be set before libusb_init(NULL, ...), and 2)
are honored even if the default context is destroyed and re-created.
Signed-off-by: Nathan Hjelm <[email protected]>
There are certain games played in the examples and tests source to
account for differences in build environments and target platforms. This
can be simplified by including config.h and using the definitions there.
To that end, move the printf function attribute definition from
libusbi.h to config.h and leverage it where it is used in the examples
and tests.
Signed-off-by: Chris Dickens <[email protected]>
The type of list_size is ssize_t.
First idea was to use "%zd" printf format specifier.
But that is not supported by Visual Studio 2013.
Use "%ld" + cast list_size to long.
Closes#751
Suggested-by: Chris Dickens <[email protected]>
Signed-off-by: Uri Lublin <[email protected]>
Signed-off-by: Chris Dickens <[email protected]>
C11 compiler support has been available for many years now. It is not
unreasonable to require this now, and doing so allows some cleanup to
the configure script. It is no longer necessary to check for compiler
support of the '-fvibility' flag because any compiler that supports C11
will support this flag as well.
Fix up the way that compiler and linker flags are passed down to the
various makefiles. The compiler flags should be shared by all, but the
linker flags and libraries should be separated between the library and
the examples/tests. The visibility flag is only relevant for the
library and the thread flags are only relevant for sources using thread
constructs, so provide them as needed.
Rearrange configure.ac to group similar functionality and consolidate
where possible.
Based on these changes, update the Travis configuration file to include
newer versions of test platforms to ensure proper C11 compiler support.
Signed-off-by: Chris Dickens <[email protected]>
There appears to be no need for the WinCE backend anymore, and it is
increasingly difficult to keep healthy as the rest of the library
changes.
Require at least Visual Studio 2013 to compile. This simplifies matters
as there is some semblance of C99 support there.
Signed-off-by: Chris Dickens <[email protected]>
This new function allows more flexibility in extending the library to
support more user-configurable options. It is intended to provide a
single API that can support a wide variety of needs and eliminates the
need for new API functions to set future options.
The function is introduced with a single option (LIBUSB_OPTION_LOG_LEVEL)
that replaces the libusb_set_debug() function. Documentation relating to
libusb_set_debug() and the uses of this function in the examples and
tests have been updated accordingly.
Signed-off-by: Chris Dickens <[email protected]>
If fdopen(3) fails then ctx->output_file is NULL and should not be used
in cleanup_test_output() called next.
Problem detected by the Coverity tool
CID 1042543 (#1 of 1): Dereference after null check (FORWARD_NULL)9.
var_deref_model: Passing "ctx" to function
"cleanup_test_output(libusbx_testlib_ctx *)", which dereferences null
"ctx->output_file".
* fxload sample provenance
* No need for <sys/types.h> in samples as already in libusb.h
* Don't bother about sscanf_s in xusb
* Use HAVE_### and rely on config.h where possible
* Formal inclusion of <winsock.h> in libusb.h for WinCE and WDK
* Cleanup of Windows' config.h
* Avoid ENAMETOOLONG and ENOTEMPTY conflict between errno.h and winsock.h for WinCE
* Additional newlines & braces cleanup
* cleanup_test_output() produced an assertion error when compiled with MSVC
due to closing ctx->output_file
* set ctx->output_file to stdout by default