Commit graph

766 commits

Author SHA1 Message Date
Yabin Cui
b584572213 Add test for pthread types alignment check.
Bug: 19249079
Change-Id: I83c4f0d11ec5d82a346ae0057d02a92bb1d519e8
2015-03-20 17:42:09 -07:00
Yabin Cui
bbb0432a33 Return EINVAL when calling pthread_detach for joined thread.
Change-Id: I717015132187e087e0ad485284a13c8801e25e77
2015-03-19 16:48:19 -07:00
Dmitriy Ivanov
52393a5633 Move open from zip tests to dlext
To avoid building them for glibc.

 Also replace snprintf with std::string

Change-Id: I12e1d2e4ab46ff5af6c05453da67842e0d838fc5
2015-03-18 22:50:01 -07:00
Dmitriy Ivanov
618f1a36f8 Implement lookup by DT_SONAME
This CL also fixes SEARCH_NAME hack and resolves
  https://code.google.com/p/android/issues/detail?id=6670
  once and for all.

Bug: https://code.google.com/p/android/issues/detail?id=6670
Change-Id: I9b8d6a672cd722f30fbfbb40cdee8d9b39cfe56e
2015-03-18 18:14:30 -07:00
Elliott Hughes
c6fbbb42e6 Merge "Hide statfs/fstatfs' ST_VALID flag from userspace." 2015-03-18 23:11:52 +00:00
Elliott Hughes
fa495d51b0 Hide statfs/fstatfs' ST_VALID flag from userspace.
Spotted while debugging the strace 4.10 upgrade.

Change-Id: I1af1be9c9440151f55f74a835e1df71529b0e4fe
2015-03-18 15:46:48 -07:00
Dimitry Ivanov
c0eaa73284 Merge "Support loading shared libraries from zip files" 2015-03-18 17:25:33 +00:00
Daniel Micay
ee7649c5ac set errno to ENOENT in getauxval per glibc 2.19
Bionic's getauxval(...) implementation returns zero when entries are
missing. Zero can be a valid value, so there is no unambiguous way of
detecting an error. Since glibc 2.19, errno is set to ENOENT when an
entry is missing to make it possible to detect this. Bionic should match
this behavior as code in the Linux ecosystem will start relying on it to
check for the presence of newly added entries.

Change-Id: Ic1efe29bc45fc87489274c96c4d2193f3a7b8854
Signed-off-by: Daniel Micay <danielmicay@gmail.com>
2015-03-17 19:50:55 -04:00
Yabin Cui
5490bebd7c Merge "Remove duplication in pthread_mutex.cpp." 2015-03-17 18:12:32 +00:00
Simon Baldwin
aef719510a Support loading shared libraries from zip files
Add code to support loading shared libraries directly from within
APK files.

Extends the linker's handling of LD_LIBRARY_PATH, DT_RUNPATH, etc
to allow elements to be either directories as normal, or ZIP
format files.  For ZIP, the ZIP subdirectory string is separated
from the path to file by '!'.

For example, if DT_NEEDED is libchrome.so and Chrome.apk is the
Android ARM APK then the path element

  /system/app/Chrome.apk!lib/armeabi-v7a

would cause the linker to load lib/armeabi-v7a/libchrome.so
directly from inside Chrome.apk.  For loading to succeed,
libchrome.so must be 'stored' and not compressed in Chrome.apk,
and must be page aligned within the file.

Motivation:
  Chromium tracking issue:
  https://code.google.com/p/chromium/issues/detail?id=390618

Bug: 8076853
Change-Id: Ic49046600b1417eae3ee8f37ee98c8ac1ecc19e7
2015-03-16 17:50:50 -07:00
Dmitriy Ivanov
cb0443c0fa Remove obsolete test_isolated wrapper function
We already run all of our tests in isolated mode.

Change-Id: I8236baa302b1026a9b4a1c33a4aa65e223771bc7
2015-03-16 14:20:57 -07:00
Yabin Cui
d3e2a207ff Merge "Hide content of pthread_cond_t in pthread_cond_internal_t." 2015-03-16 20:58:02 +00:00
Dmitriy Ivanov
b1ada3dd3f Fix typo
Change-Id: Ie6dad7d09873c88f6bbb2d45c2780e3b0c618bd6
2015-03-16 13:20:23 -07:00
Yabin Cui
32651b8e8e Hide content of pthread_cond_t in pthread_cond_internal_t.
Bug: 19249079
Change-Id: I6f55af30bcd6211ce71630c6cacbef0e1663dcee
2015-03-16 11:09:52 -07:00
Yabin Cui
64a9c4f697 Make gtest_main exit 1 when some test are failed.
This is the gtest behavior, which I think can make test status
judgement more convenient.

Change-Id: I7d3c210d1744b954a4148cd905dd5c353207fce8
2015-03-12 23:36:29 -07:00
Yabin Cui
5b8e7cd957 Remove duplication in pthread_mutex.cpp.
Also add unit tests about thread woken up by pthread_mutex_unlock.

Bug: 19216648

Change-Id: I8bde8105b00186c52a2f41d92458ae4a5eb90426
2015-03-12 21:54:41 -07:00
Yabin Cui
c6e5874a4c Loosen fchmodat AT_SYMLINK_NOFOLLOW test on symlink.
It has been reported in b2/19657449 and b2/19381040 that fchmodat
AT_SYMLINK_NOFOLLOW operation on symlink can succeed. It seems to be
controlled by kernel(version or configuration) or user configuration
whether chmod is allowed on symlinks. Unless we can disable chmod on
symlinks in bionic explicitly, we can not guarantee that the test can
pass. But it seems reasonable to allow chmod on symlink if kernel allows
to. So We prefer to loosen the test here, accepting both success and
failure when doing chmod operation on symlinks.

Bug: 19657449
Bug: 19381040
Change-Id: I780e84f0b50d0412fbac9f1c240d07e984892a28
2015-03-09 18:13:15 -07:00
Yabin Cui
24e8871faa Rename fortify_sprintf_warnings.cpp to fortify_compilation_test.cpp.
Bug: 19234260
Change-Id: Ife27ca13eeae317739eda25b40dd2a08606d6d6f
2015-03-05 00:46:18 -08:00
Yabin Cui
d9647594de Fix fortify compilation test in x86_64.
Change-Id: Ic243f6583e4f435899d01c7845dddacacbfc916e
2015-03-05 00:39:09 -08:00
Yabin Cui
94545eba37 Fix fortify compilation test on x86.
Change-Id: I9b88cbcec51b6f1dbac2780a9bf82851bd6cc87c
2015-03-04 22:35:13 -08:00
Yabin Cui
f3bd305b8f Fix fortify compilation test on mips.
Change-Id: Icff5b859ae58067bfa34430d3f5684335fe063b4
2015-03-04 21:43:14 -08:00
Yabin Cui
e1c0213be3 Merge "Switch pthread_rwlock_t to stdatomic." 2015-03-05 04:42:35 +00:00
Yabin Cui
08ee8d2030 Switch pthread_rwlock_t to stdatomic.
Bug: 19099838
Change-Id: Ie82967a60b5cec61a8bdd1e0e4a03738d01944f8
2015-03-04 18:16:20 -08:00
Yabin Cui
20f2268d61 Add fortify compile test.
Two parts of tests are added:
1. Compile time warnings for gcc checking built-in functions.
2. Compile time errors for each errordecl() in bionic.

Bug: 19234260
Change-Id: Iec6e4a8070c36815574fe9e0af9595d6143a4757
2015-03-04 13:10:38 -08:00
Christopher Ferris
cc9ca1051d Fix fread returning bad data.
Bug: 19172514
Change-Id: I05016577858a02aca7d14e75e6ec28abc925037c
2015-02-27 18:22:45 -08:00
Yabin Cui
f6237470a3 Make bionic gtest main be compatible with gtest output format for cts test.
Bug: 17589740
Change-Id: Ifab521da379a33bf0a7bf11c21386f936f0d494c
2015-02-26 19:03:54 -08:00
Yabin Cui
ea9c933f36 Make all output of child test go to parent process in gtest_main.
Change-Id: Iad460e89755051cdb99593cbf42c97d9a359f32b
2015-02-24 14:44:51 -08:00
Nick Kralevich
35778253a5 Fix "faccessat ignores flags"
The kernel system call faccessat() does not have any flags arguments,
so passing flags to the kernel is currently ignored.

Fix the kernel system call so that no flags argument is passed in.

Ensure that we don't support AT_SYMLINK_NOFOLLOW. This non-POSIX
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html)
flag is a glibc extension, and has non-intuitive, error prone behavior.

For example, consider the following code:

  symlink("foo.is.dangling", "foo");
  if (faccessat(AT_FDCWD, "foo", R_OK, AT_SYMLINK_NOFOLLOW) == 0) {
    int fd = openat(AT_FDCWD, "foo", O_RDONLY | O_NOFOLLOW);
  }

The faccessat() call in glibc will return true, but an attempt to
open the dangling symlink will end up failing. GLIBC documents this
as returning the access mode of the symlink itself, which will
always return true for any symlink on Linux.

Some further discussions of this are at:

  * http://lists.landley.net/pipermail/toybox-landley.net/2014-September/003617.html
  * http://permalink.gmane.org/gmane.linux.lib.musl.general/6952

AT_SYMLINK_NOFOLLOW seems broken by design. I suspect this is why this
function was never added to POSIX. (note that "access" is pretty much
broken by design too, since it introduces a race condition between
check and action). We shouldn't support this until it's clearly
documented by POSIX or we can have it produce intuitive results.

Don't support AT_EACCESS for now. Implementing it is complicated, and
pretty much useless on Android, since we don't have setuid binaries.
See http://git.musl-libc.org/cgit/musl/commit/?id=0a05eace163cee9b08571d2ff9d90f5e82d9c228
for how an implementation might look.

Bug: 18867827
Change-Id: I25b86c5020f3152ffa3ac3047f6c4152908d0e04
2015-02-24 13:40:43 -08:00
Elliott Hughes
be52e65817 Fix dup2 in the case where the two fds are equal.
dup3's behavior differs from dup2 in this case, so we need to paper
over that in the C library.

Change-Id: I313cd6f226db5e237f61866f324c5ecdd12bf762
2015-02-23 21:52:56 -08:00
Elliott Hughes
3cfb52aab2 Add GNU extensions mempcpy and wmemcpy.
Used by elfutils. On the bright side, they stopped using __mempcpy.

Bug: 18374026
Change-Id: Id29bbe6ef1c5ed5a171bb6c32182f129d8332abb
2015-02-18 22:02:56 -08:00
Christopher Ferris
54b61b7ca7 Merge "Accuracy tests for libm" 2015-02-17 21:41:41 +00:00
Elliott Hughes
fb48c68221 Merge "Fix memchr overflow." 2015-02-17 17:54:40 +00:00
Elliott Hughes
e1f9ddaf0d Regression test for NDK bug 80199.
Bionic never had this bug, but since the proposed fix is to remove the NDK's
broken code, we should add a regression test here.

Bug: https://code.google.com/p/android/issues/detail?id=80199
Change-Id: I4de21b5da9913cef990bc4d05a7e27562a71a02b
2015-02-14 14:11:50 -08:00
Elliott Hughes
41ef902379 Fix memchr overflow.
The overflow's actually in the generic C implementation of memchr.

While I'm here, let's switch our generic memrchr to the OpenBSD version too.

Bug: https://code.google.com/p/android/issues/detail?id=147048
Change-Id: I296ae06a1ee196d2c77c95a22f11ee4d658962da
2015-02-14 13:21:22 -08:00
Jingwei Zhang
56b2b2916b Accuracy tests for libm
This patch adds more tests for math functions to address coverage
issue of math functions discussed in:
https://android-review.googlesource.com/#/c/49653/
https://android-review.googlesource.com/#/c/94780/

These are data sets used in regression tests for the Intel the math library (libm). They were collected over a long period of testing various libm implementations.
The data sets contain function specific data (special and corner cases such as +/-0, maximum/minimum normalized numbers, +/-infinity, QNaN/SNaN, maximum/minimum denormal numbers, arguments that would produce close to overflow/underflow results, known hard-to-round cases, etc), implementation specific data (arguments close to table look-up values for different polynomial approximations, worst cases for range reduction algorithms) and other data with interesting bit patterns.
The reference values are computed with Maple and were converted into hexadecimal format.

Change-Id: I7177c282937369eae98f25d02134e4fc3beadde8
Signed-off-by: Jingwei Zhang <jingwei.zhang@intel.com>
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>
2015-02-14 00:56:46 +08:00
Elliott Hughes
7f925097e8 Fix our ftw tests.
SELinux denies access to some files in /sys, so we can't just trawl
through that asserting general truths. Instead, create a small known
tree.

Sadly neither ftw nor nftw takes user callback data, otherwise it would
be nice to assert that we visit all the expected nodes.

Bug: 19252748
Change-Id: Ib5309c38aaef53e6030281191a265a8d5a619044
2015-02-10 14:15:33 -08:00
Christopher Ferris
05d26211d8 Display errors instead of running infinitely.
When there is an error detected, the code runs forever and then times
out without any indication of what happened. Change it so that error
messages are printed and the test fails.

Change-Id: Id3160fc2f394984de0157356594fd8b40de66b4a
2015-02-06 18:05:58 -08:00
Yabin Cui
ead08148bd Add path separator in bionic-unit-tests program path.
Bug: 19220800
Change-Id: I4245b1270363544cd5f083fe7ea7d9b11b46cdc0
2015-02-05 10:39:37 -08:00
Yabin Cui
63826658f4 Merge "Add signal handling in bionic gtest main." 2015-02-05 04:21:03 +00:00
Yabin Cui
1d4c780a2e Add signal handling in bionic gtest main.
The two bugs are very closely related and code amount is very small,
So I think they may be fixed in one change.

Bug: 19128558
Bug: 19129994
Change-Id: I44a35398e64dfca7e9676428cb8f4026e8f6e488
2015-02-04 19:06:07 -08:00
Yabin Cui
17976019a1 Merge "Fix poll/ppoll fortify test to avoid hanging in failed fortify clang test." 2015-02-05 01:14:32 +00:00
Yabin Cui
f4fe6937aa Fix poll/ppoll fortify test to avoid hanging in failed fortify clang test.
Bug: 19220800
Change-Id: Ie75c640183c4a41a499556fefb4f824a134a5fb1
2015-02-04 12:27:06 -08:00
Yabin Cui
11829be3e1 Merge "Add test about pthread_mutex_t owner tid limit." 2015-02-03 22:28:56 +00:00
Yabin Cui
140f3678f0 Add test about pthread_mutex_t owner tid limit.
Bug: 19216648
Change-Id: I7b12955bdcad31c13bf8ec2740ff88ba15223ec0
2015-02-03 12:20:46 -08:00
Nick Kralevich
d80ec66121 Merge "Add fchmodat(AT_SYMLINK_NOFOLLOW) and fchmod O_PATH support" 2015-02-02 22:03:41 +00:00
Nick Kralevich
3cbc6c627f Add fchmodat(AT_SYMLINK_NOFOLLOW) and fchmod O_PATH support
Many libc functions have an option to not follow symbolic
links. This is useful to avoid security sensitive code
from inadvertantly following attacker supplied symlinks
and taking inappropriate action on files it shouldn't.
For example, open() has O_NOFOLLOW, chown() has
lchown(), stat() has lstat(), etc.

There is no such equivalent function for chmod(), such as lchmod().
To address this, POSIX introduced fchmodat(AT_SYMLINK_NOFOLLOW),
which is intended to provide a way to perform a chmod operation
which doesn't follow symlinks.

Currently, the Linux kernel doesn't implement AT_SYMLINK_NOFOLLOW.
In GLIBC, attempting to use the AT_SYMLINK_NOFOLLOW flag causes
fchmodat to return ENOTSUP. Details are in "man fchmodat".

Bionic currently differs from GLIBC in that AT_SYMLINK_NOFOLLOW
is silently ignored and treated as if the flag wasn't present.

This patch provides a userspace implementation of
AT_SYMLINK_NOFOLLOW for bionic. Using open(O_PATH | O_NOFOLLOW),
we can provide a way to atomically change the permissions on
files without worrying about race conditions.

As part of this change, we add support for fchmod on O_PATH
file descriptors, because it's relatively straight forward
and could be useful in the future.

The basic idea behind this implementation comes from
https://sourceware.org/bugzilla/show_bug.cgi?id=14578 , specifically
comment #10.

Change-Id: I1eba0cdb2c509d9193ceecf28f13118188a3cfa7
2015-02-02 13:17:17 -08:00
Elliott Hughes
d036e94bb3 Explicitly check that the reason fortify tests abort is fortify.
Change-Id: I95291e2febf7b497c1d9f37fd7fa9acdd21e86a4
2015-02-02 11:18:58 -08:00
Elliott Hughes
4674e3899a Fortify poll and ppoll.
And remove the test for FD_ZERO fortification, which never made much
sense anyway.

Change-Id: Id1009c5298d461fa4722189e8ecaf22f0c529536
2015-02-02 09:15:19 -08:00
Elliott Hughes
b6e3e800d2 Add the fortify tests back into the glibc tests.
Change-Id: I4426d0c7c1bfe3b0028a674f72d1c3b9d883d6af
2015-01-31 21:32:10 -08:00
Yabin Cui
11c4353cdd Add --gtest-filter as synonym for --gtest_filter in bionic gtest main.
Bug: 19130480
Change-Id: I0d3df70ee8f692581cc4b9b742c5f347259fd0d2
2015-01-28 14:28:14 -08:00