Files
android_development/host/windows/usb
Spencer Low 487b1deae9 AdbWinUsbApi.dll: fix race condition crash in WinUsb.dll
There is a race condition in AdbWinUsbApi.dll where AdbCloseHandle() of an
interface would clobber the WinUsb handles, causing a concurrent
Adb{Read,Write}EndpointSync() to crash.

The fix is to make AdbCloseHandle(endpoint) set a flag to prevent future IOs
from starting up, abort any pending IOs, and wait for the pending IOs to abort.
Adb{Read,Write}EndpointSync() participates in this scheme.

There is still a race condition if the caller calls AdbCloseHandle(interface)
before calling AdbCloseHandle(endpoint). No AOSP code does this and assuming
that this never happens simplifies the fix.

This fix also ignores Adb{Read,Write}EndpointAsync() (the async APIs) since
those APIs are unused by AOSP.

This fix should not affect devices whose vendor supplies Windows USB drivers
that use a 'legacy kernel driver'. This causes AdbWinApi.dll to call a 'legacy
kernel driver' instead of AdbWinUsbApi.dll (which uses WinUsb.dll which uses a
kernel driver included with Windows). The source code for the 'legacy kernel
driver' was deleted from AOSP over 4 years ago, so it is probably deprecated
(I don't know the official status of it). Even so, I wouldn't be surprised if
some modern 3rd party devices were still using the legacy driver or a similar
driver derived from the original source code.

Also in this change:

 - Added a test case to adb_winapi_test that reproduces the race condition and
   verifies the fix.

 - adb_winapi_test misc: more strictly check return values and error codes,
   symbolize some dumped data to make things more readable, disable old test
   code that looked for specific hardware, test AdbGetInterfaceName() the same
   way adb uses it, fix dumping of initial "handshake".

 - Increased AdbWinUsbApi.dll file version info from 2.0.0.0 to 2.0.0.1.

 - Update AdbWinUsbApi.dll in prebuilt tree.

 - Include AdbWinUsbApi.pdb (debugging symbols) so the DLL can be debugged in
   the future (or at least so crash addresses can be manually symbolized).

 - Update AdbWinApi.dll, AdbWinUsbApi.dll, adb_winapi_test.exe build
   environments to WDK 7.1.0, which seems to be the publicly available closest
   version to what built the last version of these files.

   This entailed modifying SOURCES files to use USE_NATIVE_EH=1 instead of
   USER_C_FLAGS=/EHsc, removing /Wp64, manually setting DLL base addresses to
   the old address, using DEBUG_CRTS=1 to pickup the debug ATL for checked
   builds.

 - Update BUILDME.TXT files with up-to-date instructions.

 - For source files that are already majority CRLF, make the whole file CRLF.

 - Update SOURCES to explicitly set Windows Vista as the target. This means
   that future rebuilders don't need to worry as much about their build
   environment.

Bug: https://code.google.com/p/android/issues/detail?id=161890

Change-Id: I30a4e2ff3919929001c2319c4bb80354f7bcfda0
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-12 14:14:52 -07:00
..

android_winusb.inf file contained in this folder must be used to install
WinUsb framework on customers machines. In order to build installation
package that is compliant with android_winusb.inf, you need to create
the following tree:

Root of the installation folder must contain:
  * File android_winusb.inf - Installation file
  * File androidwinusb86.cat - Signed catalog for 32-bit package
  * File androidwinusba64.cat - Signed catalog for AMD 64-bit package
  * Subfolder i386 containing files for 32-bit installation:
    * WdfCoInstaller01007.dll
    * WinUSBCoInstaller.dll
    * WUDFUpdate_01007.dll
  * Subfolder amd64 containing files for AMD 64-bit installation:
    * WdfCoInstaller01007.dll
    * WinUSBCoInstaller.dll
    * WUDFUpdate_01007.dll

File contained in i386 and amd64 subfolders are Microsoft distributives needed
to install WinUsb framework. These files can be obtained from WDK 'redist'
folder, respectively to the OS: copy x86 files to i386 subfolder, and amd64
files to amd64 subfolder.

android_winusb.inf file can be modified in order to provide support for the
devices that were not available when Android SDK was shipped. To do that,
modify [Google.NTx86], [Google.NTamd64], and [Strings] sections of .inf
file to add descriptions for new devices and interfaces. Note that when .inf
file is modified, .cat files must be rebuilt and resigned in order to keep
integrity of the installation. Failure to rebuild and resign .cat files will
not break the installation, but it will cause security warnings (that can be
dismissed) to pop up at the installation time.

As an alternative to modification, android_winusb.inf file can be used as a
template to create new .inf file for new devices. Note that you also need
to build and sign new .cat files for that custom .inf file of yours.

The simplest way to create .cat files would be using inf2cat.exe utility,
available in WDK at bin\SelfSign folder. To use this utility you will need to
create an installation folder a sdesribed at the beginning of this document,
and run inf2cat.exe on .inf file at the root of installation folder.