Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upProvide useful defaults for Android logcat output #21812
Conversation
highfive
commented
Sep 25, 2018
|
r? @paulrouget |
|
Sorry I lagged a bit, I’m about to submit a review with some code changes. |
|
For backtraces, maybe |
| #[allow(non_camel_case_types)] | ||
| type pthread_mutexattr_t = c_long; | ||
| #[allow(non_camel_case_types)] | ||
| type pthread_attr_t = c_void; // FIXME: wrong |
This comment has been minimized.
This comment has been minimized.
SimonSapin
Sep 26, 2018
Member
These types exist in the libc crate. android-rs-glue chooses not to depend on libc for some reason, but we already do. Let’s not redefine them?
| fn read(fd: c_int, buf: *mut c_void, count: usize) -> isize; | ||
| fn pthread_create(_: *mut pthread_t, _: *const pthread_attr_t, | ||
| _: extern fn(*mut c_void) -> *mut c_void, _: *mut c_void) -> c_int; | ||
| fn pthread_detach(thread: pthread_t) -> c_int; |
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| let mut thread = mem::uninitialized(); | ||
| let result = pthread_create(&mut thread, ptr::null(), logging_thread, |
This comment has been minimized.
This comment has been minimized.
SimonSapin
Sep 26, 2018
Member
I was wondering why this uses pthread rather than std::thread. rust-windowing/android-rs-glue#75 (comment) says:
At that time, trying to use Rust threads would lead to a crash because the Rust standard library needs to be initialized before being usable.
This initialization is generally automatically injected in _start by the compiler when you compile a regular binary. But here we are bypassing this mechanism.
@jdm, @paulrouget, do you know if this is also relevant to us?
This comment has been minimized.
This comment has been minimized.
|
|
||
| loop { | ||
| let result = read(descriptor, buf.as_mut_ptr().offset(cursor as isize) as *mut _, | ||
| buf.capacity() - 1 - cursor); |
This comment has been minimized.
This comment has been minimized.
SimonSapin
Sep 26, 2018
Member
I’ve convinced myself that this offset doesn’t overflow the buffer and that the substractions don’t underflow beyond zero, but it’s rather subtle.
cursor is always set to one of:
-
Zero
-
buf.capacity() - 1, which is 511 -
buf.len()which is set throughset_lentoresult + cursor, whereresultis number of bytes returned by a previousreadcall, which is at most equal to the third argument given toread,buf.capacity() - 1 - cursor -
buf.len() - last_newline_pos, which doesn’t underflow becauselast_newline_posis returned frombuf.iter().rposition(…)
I’d be much more comfortable if this code used much less unsafe pointer manipulation and more checked slicing, something like SimonSapin@a7dab4e
| cursor = buf.len(); | ||
| } | ||
| if cursor == buf.capacity() - 1 { | ||
| __android_log_write(3, tag, buf.as_ptr()); |
This comment has been minimized.
This comment has been minimized.
SimonSapin
Sep 26, 2018
Member
Unless I missed something I think this is missing a nul terminator. Something like *buf.get_unchecked_mut(cursor) = b'\0' as c_char; before this call should fix that.
This may be worth reporting upstream.
This comment has been minimized.
This comment has been minimized.
|
Setting RUST_BACKTRACE=1 tends to hit segfaults in libunwind when using NDK12. I'll give it a try as part of the NDK15 upgrade. |
|
I used your code changes unmodified except for fitting them in with the previous commit. |
|
@bors-servo r+ |
|
|
Provide useful defaults for Android logcat output These changes integrate the stdout/stderr redirection from https://github.com/tomaka/android-rs-glue/blob/0e80cfbcee362f207389dc2660525c3d74987f70/cargo-apk/injected-glue/lib.rs#L240-L303, and set up the default RUST_LOG filters so that useful JS errors and GL errors appear in the logcat output. I have verified that thread panics appear in output as well (without backtraces, sadly) by visiting https://acid3.acidtests.org. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21637 and fix #21783 - [x] These changes do not require tests because no tests for logcat. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21812) <!-- Reviewable:end -->
|
|
jdm commentedSep 25, 2018
•
edited by SimonSapin
These changes integrate the stdout/stderr redirection from https://github.com/tomaka/android-rs-glue/blob/0e80cfbcee362f207389dc2660525c3d74987f70/cargo-apk/injected-glue/lib.rs#L240-L303, and set up the default RUST_LOG filters so that useful JS errors and GL errors appear in the logcat output. I have verified that thread panics appear in output as well (without backtraces, sadly) by visiting https://acid3.acidtests.org.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is