summaryrefslogtreecommitdiffstats
path: root/adb/sysdeps_win32.cpp
Commit message (Collapse)AuthorAgeFilesLines
* adb: "support" O_CLOEXEC in adb_open on Windows.Josh Gao2019-02-071-0/+3
| | | | | | | | | Previously, we were rejecting the flag and failing with EINVAL. File handles aren't inherited by default, so just ignore the flag. Bug: http://b/123753498 Test: adb install --streaming foo.apk Change-Id: I17401fcdd58024956d47a5c4c0c57b06831d9817
* Merge "adb: win32: improve console output on Windows 10"Josh Gao2019-01-231-11/+67
|\
| * adb: win32: improve console output on Windows 10Spencer Low2018-11-061-11/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use Windows 10's improved virtual terminal emulation to handle more terminal sequences, to fix console resize artifacts, and to fix issues with the last column. `top' and `more' work well now. Use a sensible default TERM value of xterm-256color. Test: manual on Windows 10 Bug: https://issuetracker.google.com/issues/37081235 Change-Id: If6612f3bb7db1ecaaa4b7930c9e54075ba7abb3f Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
* | adb: switch unix_open to string_view.Josh Gao2018-12-211-3/+4
|/ | | | | | | | Test: test_adb.py Test: test_device.py Test: $ANDROID_HOST_OUT/nativetest64/adb_test/adb_test Test: adb shell /data/nativetest64/adbd_test/adbd_test Change-Id: Ieecc9b1b7f2111f4da45d4bbd1b7703535fe7d4d
* adb: don't use <error.h>.Elliott Hughes2018-10-221-21/+0
| | | | | | | | | | | This should fix the bloody Mac build, which doesn't have <error.h>. Since we weren't entirely happy with error(3) anyway, switch to the toybox style of error_exit and perror_exit, which are slightly briefer and quite a bit more intention-revealing. Bug: N/A Test: builds Change-Id: Ic8e411906c363af51657da5ce947b25a0b6bb1f3
* adb: rationalize fatal/error logging.Elliott Hughes2018-10-191-15/+29
| | | | | | | | | | | | | | | | | | | Let's use LOG(FATAL)/PLOG(FATAL) for actual fatal stuff. Add a Windows error(3) and move folks who didn't really mean "abort" fatal over to it. Also get rid of syntax_error which wasn't adding a lot of value, and most of the places it was adding "usage: " didn't seem entirely appropriate anyway. In particular, we seemed to have confused fastdeploy.cpp into aborting in most user error cases, and none of the reviewers noticed. Clearly we'd all lost track of far too many options. (I've also cleaned up a few random instances of fprintf(3) + exit(2).) Bug: N/A Test: manual Change-Id: I3e8440848a24e30d928de9eded505916bc324786
* Merge changes from topic "windows-libcxx"Pirama Arumuga Nainar2018-10-111-0/+4
|\ | | | | | | | | | | | | * changes: Do not enable -Wold-style-cast for Windows Add sys/types.h in utf8.h Adapt to switch to libc++ for Windows
| * Adapt to switch to libc++ for WindowsPirama Arumuga Nainar2018-09-211-0/+4
| | | | | | | | | | | | | | | | | | | | | | Bug: http://b/91353691 - libcxx has ETXTBSY for Windows - adb/sysdeps/memory.h is no longer needed Test: Build and test Windows binaries under Wine. Change-Id: I9c27087d46c49cb25b391c4adae8d9e24724784d
* | Support > 2GiB seeks in adb_lseek.Elliott Hughes2018-09-261-16/+10
|/ | | | | | | | | | Also stop using size_t (which will be 32-bit on Win32) for offsets in adb_sideload_host, and stop truncating large file sizes in our "sideload-host" messages. Bug: http://b/112003354 Test: builds Change-Id: If5b7cc9d1fc7ff7ca6eaebd20418f7b061846203
* adb: win32: set thread namesSpencer Low2018-09-031-0/+23
| | | | | | | | | | | | | Use a new Windows 10 API, SetThreadDescription(). Background info from a Chrome developer: https://randomascii.wordpress.com/2015/10/26/thread-naming-in-windows-time-for-something-better/ Test: Win10, Vista, adb shell Test: Ran windbg -pn adb.exe, used .dump /ma to create a dump, ran `dx -g @$curprocess.Threads' on the dump and it showed the thread names. Change-Id: I14ea7121605cb3fa45ce7b59e2ba5882a215b59f Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
* [adb] Modernize codebase by replacing NULL with nullptrYi Kong2018-07-131-21/+21
| | | | | | | | Fixes -Wzero-as-null-pointer-constant warning. Test: m Bug: 68236239 Change-Id: Ia8c4deacafed2f3b7dbc3d4c3c77c6c632e3de81
* Simplify __attribute__((__printf__)) use.Elliott Hughes2018-06-261-3/+2
| | | | | | | | We don't need this now everyone's using clang... Bug: http://b/69933068 Test: ran tests Change-Id: I88f0cf03981ade47e210387fd6f3a2706dfeb9b8
* adb: win32: cleanup winsock initialization.Josh Gao2018-04-111-20/+9
| | | | | | | Instead of doing it in 3 arbitrary functions, do it at startup always. Test: wine adb_test.exe Change-Id: Ida272d218aee6c331471250edce64d512d3b628a
* adb: win32: properly set EBADF in some functions.Josh Gao2018-04-111-0/+4
| | | | | Test: treehugger Change-Id: If3f29f9ee586e29652e9709b3f594a1376ed4bb3
* adb: partially clang-format sysdeps_win32.cpp.Josh Gao2018-04-111-63/+53
| | | | | | | | clang-format some functions that I'm about to touch, but do it in a separate commit to avoid making the actual changes unreadable. Test: treehugger Change-Id: I7dc5258d9ecc1c091d42311149d9e18ae483715b
* adb: implement adb_writev.Josh Gao2018-04-111-40/+115
| | | | | | Change-Id: I55258c155d7b07368ebb45577b2e01ca804cf258 Test: adb_test Test: python test_device.py
* adb: fix FdeventTest.invalid_fd on Windows.Josh Gao2018-03-291-1/+7
| | | | | | | | | Bail out immediately in our poll emulation if we have any invalid file descriptors, instead of actually calling WSAPoll (which might block forever). Test: wine adb_test.exe Change-Id: I06ccca305783ee7a1721b1585ddf73e022bd02d7
* adb: fix windows test build.Josh Gao2018-03-231-5/+4
| | | | | | | | | | The switch over to soong unintentionally turned off building the Windows tests (and there's a bug preventing them from being turned on). Preemptively fix the build breakages that'll happen when we turn them back on. Test: mma with Android.bp 's/cc_test_host/cc_binary_host' hacks Change-Id: I6582cfc61b96052537d50d8ba90533dbb66e3e1d
* adb: bump the local socket backlog to the maximum.Josh Gao2018-03-211-3/+1
| | | | | | | | | | | The listen backlog seems to be more meaningful on Darwin than on Linux, resulting in connections failing with ECONNRESET. Bump it up to the maximum supported value to make this less likely. 128 pending connections ought to be enough for anybody. Bug: http://b/74616284 Test: python test_device.py Change-Id: I5fe0205924188cf18ca1fc1204f923ab5523eeb2
* Revert "adb: check our socketpair ends in our win32 emulation."Josh Gao2017-03-301-27/+2
| | | | | | | | | | This reverts commit 5990191c4e4802567881db2f19db4adbddc64e1e. Some Windows users are seeing mismatches between the two ends. Bug: https://code.google.com/p/android/issues/detail?id=258400 Test: mma Change-Id: Ie3a121a2754332608ff64b3b016adcb4258d41f3
* Make ADB over mDNS work on WindowsCasey Dahlin2017-03-071-6/+11
| | | | | | | | Test: Verified ADB over mDNS on a Windows machine Bug: 30482671 (cherry picked from 9fdd77101f49d03ff29342e12e23edf241f68522) Change-Id: If955ca304db71a5b08c5a9654f1e27ab74af9af8
* Revert "Revert "adb: move adb_strerror to sysdeps/win32/errno.cpp.""Josh Gao2016-12-051-76/+1
| | | | | | | This reverts commit 43c02b27cd50a75f0fecb44e56a9bf32c6923aef. Test: mma Change-Id: I6b22ead8a4b964973ee2fdb8deba42bea74880cf
* Revert "adb: move adb_strerror to sysdeps/win32/errno.cpp."Josh Gao2016-12-051-1/+76
| | | | This reverts commit 4fba3d2638ecec0f87fe8d8913490bfbd7234d19.
* adb: move adb_strerror to sysdeps/win32/errno.cpp.Josh Gao2016-11-301-76/+1
| | | | | | Bug: none Test: mma Change-Id: I9df4d6faf9883a78f50ca6b2b7c35f095d06ae20
* adb: kill adb_mutex_t, adb_cond_t.Josh Gao2016-09-211-47/+35
| | | | | | | | | | | | Now that we have support for std::mutex and std::condition_variable on Windows, remove our mutex compatibility layer in favor of the C++ one. Bug: http://b/31653591 Test: mma && $ANDROID_HOST_OUT/nativetest64/adb_test/adb_test && \ python test_adb.py && python test_device.py (also on Windows) Change-Id: I5b7ed9c45cc2a32edcf4e77b56dc28e441f15f34
* adb: check our socketpair ends in our win32 emulation.Josh Gao2016-08-241-2/+27
| | | | | | | | In our Win32 socketpair emulation, check that the ends are properly connected before returning. Change-Id: I33d356fd9ebcac89fc6a89a5200e926032220383 Test: no additional failing tests in adb_test.exe
* std::unqiue_ptr<..., decltype(&fn)> seems to be the preferred idiom.Elliott Hughes2016-08-081-1/+1
| | | | | | This is the only decltype(fn)* outside aapt2 in the whole tree. Change-Id: I2e19d2031b56fdb808c62c2c07ca6080c9ec6fe3
* adb: fix stat on Windows.Josh Gao2016-08-011-24/+0
| | | | | | | | | | | | | stat on Windows fails with ENOENT when passed a path with a trailing slash or backslash, regardless of whether the target is actually a directory. Emulate the correct POSIX behavior by stripping trailing path separators and then checking if the target is a directory if successful. Bug: http://b/30481559 Bug: https://code.google.com/p/android/issues/detail?id=214633 Change-Id: I1d398d19a9bce1ecb3fdc4aabc31aa98c82c3f93 Test: Relevant adb_tests pass on Linux and Windows 10.
* Kill load_file.Elliott Hughes2016-05-271-56/+0
| | | | Change-Id: I6c332f7d8e94d513605295b3d4d32c4e1cf878dc
* adb: support forwarding TCP port 0.David Pursell2016-05-091-14/+24
| | | | | | | | | | | | | | | | | | | | | | | | | This CL adds support to forward or reverse TCP port 0 to allow the system to automatically select an open port. The resolved port number will be printed to stdout: $ adb forward tcp:0 tcp:8000 12345 $ adb reverse tcp:0 tcp:9000 23456 This allows testing to be more robust by not hardcoding TCP ports which may already be in use. Forwarding port 0 is a host-only change and will work with any device, but reversing port 0 requires the device to be updated with a new adbd binary. This CL also does a little bit of cleanup such as moving the alistener class out of adb.h, and adds some error checking and additional tests. Bug: 28051746 Test: python -m unittest discover Test: adb_test Test: `adb forward` and `adb reverse` with tcp:0 Change-Id: Icaa87346685b403ab5da7f0e6aa186aa091da572
* adb: increase the FD table size on Win32.Josh Gao2016-04-181-1/+1
| | | | | | | | | | 128 maximum FDs is a pretty low limit, which can easily be exhausted by port forwarding. Bump the maximum up to 2048, and add a test that checks whether we can actually use a few hundred sockets. Bug: https://code.google.com/p/android/issues/detail?id=12141 Bug: http://b/28246942 Change-Id: Ia4a2ff776e8e58ec13378756f19d80392679ece9
* adb: use TCP keepalive.David Pursell2016-02-231-0/+27
| | | | | | | | | | | | | | | | Currently adb only realizes a TCP transport has gone away when it tries to send a packet, which caused problems in particular for `adb reboot` since no packets are sent, leading to the client hanging until Ctrl+C. This CL turns on TCP keepalive packets to send 1 packet every second, allowing up to 10 failures before disconnecting. Using built-in TCP functionality turns out to be much cleaner in this case than trying to implement our own keepalive packets at the application layer, and should be more lightweight since it's all done in the TCP stack. Bug: http://b/23093474 Change-Id: Ifb41cbb85b9752a9f394e1eed3c6ac4da47a4e4d
* adb: add fd exhaustion test, fix errno reporting in sysdeps_win32.Josh Gao2016-02-191-73/+76
| | | | | | | Add a test for FD exhaustion, and fix cases where we weren't properly setting errno. Change-Id: I486055bb9ead31089ce76b210c11de9e973f3256
* adb: move win32 fd base to 2048, fix fd allocation.Josh Gao2016-02-191-13/+11
| | | | | | | | | | Windows has a maximum fd limit of 2048, so we can avoid collision with real file descriptors by starting from there. Also, fds would be previously be allocated by a linear walk from the last allocated FD, instead of the lowest available FD, as required by POSIX. Keep track of the lowest available file descriptor to make things feel more familiar. Change-Id: Id6ac1c54f4f7964a6cdfa8d3f4f96262e4881964
* adb: don't emulate fdevent or socketpair on Windows.Josh Gao2016-02-191-1350/+126
| | | | Change-Id: I16cf7d4427eb79f36db39e91f85402a268fa72f5
* Merge "adb: win32: handle incomplete UTF-8 in console output, other fixes"David Pursell2016-02-011-31/+134
|\
| * adb: win32: handle incomplete UTF-8 in console output, other fixesSpencer Low2016-01-281-31/+134
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the various adb_printf, adb_fwrite, etc. functions did not correctly handle the case of the passed buffer ending with an incomplete UTF-8 sequence. This is fixed by buffering up incomplete UTF-8 sequences in g_console_output_buffer (protected by the mutex g_console_output_buffer) and outputting it later once the full sequence is available. A unittest for the main worker function, ParseCompleteUTF8(), was added to adb_test. Other fixes: - Fix the return value of number-of-chars written to be number of UTF-8 bytes instead of number of UTF-16 characters. - Don't overwrite errno in success cases of various adb_printf, etc. functions. This might be excessive, but might be useful in the case when these functions are used for debugging/tracing. - Add missing UTF-8 stdio functions that aren't currently used by adb, but might be in the future: vprintf, putc, putchar, puts. - stdin_raw_init: If we can't get the console handle, don't call SetConsoleMode(). Not a big deal, but this will prevent erroneous trace output. Change-Id: I8730e8af92882c42b884ad921b39a17b54465085 Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
* | base: add SystemErrorCodeToString() function.David Pursell2016-02-011-60/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | Pulls the Windows error string generation out of adb into libbase so that it can be used by fastboot as well. Also makes a Unix equivalent that just wraps strerror() so that upcoming fastboot error reporting code can be platform-independent. The intent here is just to provide a portable way to report an error to the user. More general cross-platform error handling is out of scope. Bug: http://b/26236380 Change-Id: I5a784a844775949562d069bb41dcb0ebd13a32bc
* | adb: SIGWINCH support for WindowsSpencer Low2016-01-281-5/+21
|/ | | | | | | | | | | | | | | | | - Introduces unix_read_interruptible() which is like unix_read() except that it can return EINTR. - The big idea is that the Windows ReadConsoleInput() API will return an event on window resize and then we return EINTR from unix_read_interruptible() just like Unix. - Only handles horizontal resize since Windows doesn't seem to give an event for vertical resize when no special screen buffer is used. This should be sufficient for the primary use case of adb on Windows (people are not running vi in the first place). Change-Id: Id8d1710b559834c8098f2d7fbecedf2d0ade4b88 Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
* adb: tag fatal, fatal_errno with printf attribute.Josh Gao2016-01-151-2/+5
| | | | | | | Also, fix bugs that this uncovered. In particular, the sysdeps_win32 FATAL macro would only print __FUNCTION__. Change-Id: I6307ec9749edec21b4fee192e135a86ec445c84b
* Track rename of base/ to android-base/.Elliott Hughes2015-12-041-4/+4
| | | | Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
* adb: win32: remove widen()/narrow() in favor of UTF8ToWide()/WideToUTF8()Spencer Low2015-11-121-116/+113
| | | | | | | | | | | | | | Now that we have a more standardized API (also available in Chromium), switch to it. Another benefit is real error handling instead of just killing the process on invalid Unicode. Make UTF8ToWide()/WideToUTF8() set errno to EILSEQ on bad input. This is the same error code that wcsrtombs(3) uses. Update the unittest to check for EILSEQ. Change-Id: Ie92acf74d37adaea116cf610c1bf8cd433741e16 Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
* Merge changes Ic124ecb9,I94de55d2Josh Gao2015-11-121-2/+2
|\ | | | | | | | | | | * changes: libbase: remove exit-time destructors. adb: remove exit-time destructors.
| * adb: remove exit-time destructors.Josh Gao2015-11-121-2/+2
| | | | | | | | | | | | | | | | | | On exit, these destructors get invoked while other threads might still be using them, potentially causing a crash, and definitely causing tsan to report a race condition. Bug: http://b/23384853 Change-Id: I94de55d22f97f4edd1d7cc1f34e8c1f8dfd56a5a
* | Revert "Revert "adb/base: fix adb push of Unicode filenames on Win32""Elliott Hughes2015-11-111-80/+45
|/ | | | | | | | | This reverts commit cc8cd59456ca485a51cd6fd388c8bcb1af4a8f9b. With the dependency on libcutils (for gettid for non-bionic) removed, this no longer breaks the build. Change-Id: I645bd6876e2502ddc1535b69af1e645c0df9d178
* adb: win32: fix adb shellSpencer Low2015-11-111-86/+36
| | | | | | | | | | | | | | | | | 28416d6d33267f92768116e269966d61eac01db9 broke adb shell on Windows because it was calling unix_read() with a buffer size of 1 byte which wasn't supported by unix_read()/_console_read(). This change makes _console_read() support such a small buffer by maintaining an internal input buffer. This lets us simplify the existing code that was already maintaining a cached INPUT_RECORD. Also eliminate some duplicate code in the big switch statement. Change-Id: I8f0aed4fb9f6f2f5b9a6b68ce60d2e368fec81c7 Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
* Revert "adb/base: fix adb push of Unicode filenames on Win32"Elliott Hughes2015-11-111-45/+80
| | | | | | | | This reverts commit ac9514a4524f98b2029dbcda9326a763d25492b1. The new gettid dependency caused other breakage. Change-Id: I74a75e40c30a45beb275f9dd38eb5c7beac15fbd
* adb/base: fix adb push of Unicode filenames on Win32Spencer Low2015-11-101-80/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | ae5a6c06cdd9ae1a0a7cdc42711f0a5594e54dcd made adb push use android::base::ReadFileToString() for small files, but that API did not support UTF-8 filenames on Windows, until this fix which does the following: - Add android::base::{WideToUTF8,UTF8ToWide}() which are only available on Windows. The signatures are based on Chromium's APIs of the same name. - Add the namespace android::base::utf8 which has versions of APIs that take UTF-8 strings. To use this, make sure your code is in a namespace and then do "using namespace android::base::utf8;". On Windows, this will make calls to open() call android::base::utf8::open(), and on other platforms, it will just call the regular ::open(). - Make ReadFileToString() and WriteStringToFile() use utf8::open() and utf8::unlink(). - Adapt unittests from Chromium. - fastboot needs to link with libcutils because it links with libbase which depends on libcutils for gettid() for logging. Change-Id: I1aeac40ff358331d7a1ff457ce894bfb17863904 Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
* adb shell SIGWINCH support.Elliott Hughes2015-11-041-36/+33
| | | | | Bug: http://b/19734542 Change-Id: Ic9404a132cb9c42cb6a378bcd4b3dea9188d0a44
* adb: create unix_isatty() function.David Pursell2015-11-021-53/+45
| | | | | | | | | | | Our Windows code has several different ways it checks whether an FD is a console or not, some of which aren't exactly correct as they may treat character devices (e.g. NUL) as consoles. This CL disallows using the builtin isatty() function and provides unix_isatty() instead which correctly checks these corner cases. Change-Id: I6d551c745dae691c7eb3446b585265d62c1e62fa