Commit graph

541 commits

Author SHA1 Message Date
Elliott Hughes
4ce902c30e Support 32-bit ARM vdso.
Linux 4.1 added this.

Bug: http://b/19198045
Change-Id: I28be802ff403a61dd6733a001411b3ff05fef5a5
2016-07-12 13:55:51 -07:00
Colin Cross
8428fb03c8 Merge "Remove deprecated Android.mk files" 2016-06-02 16:31:40 +00:00
Colin Cross
7510c33b61 Remove deprecated Android.mk files
These directories all have Android.bp files that are always used now,
delete the Android.mk files.

Change-Id: Ib0ba2d28bff88483b505426ba61606da314e03ab
2016-05-26 16:41:57 -07:00
Elliott Hughes
bdd8f896dd Improve diagnostics from the assembler __strcpy_chk routines.
Change-Id: Ib95b598f7f8338cc1a618c00232a4259dc4a6319
2016-05-26 16:38:34 -07:00
Elliott Hughes
c75da09f4f Improve diagnostics from the assembler __strcat_chk routines.
Change-Id: I44cbe5389c66de6618e581a6e302eea22c39d6fb
2016-05-26 14:55:00 -07:00
Elliott Hughes
382bd666e2 Stop including <machine/cpu-features.h>.
We're not looking at __ARM_ARCH__, because we don't support ARMv6.

Bug: http://b/18556103
Change-Id: I91fe096af697dc842a57e97515312e3530743678
2016-05-16 17:52:40 -07:00
Christopher Ferris
f5a9123d9f Add unwind information for r7 in arm syscalls.
It turns out that clang can emit code where the sp is saved in the r7
register on arm. Unfortunately, a lot of our syscalls overwrite that
value while the syscall is executing, so unwinding through that syscall
fails.

Update the syscall generation code to add unwinding information for
these uses.

Bug: 28411713
(cherry picked from commit 6e45d37dec)

Change-Id: Ib775effc44c4113735fe9032b0602b9d63e3e390
2016-04-27 20:34:47 -07:00
Elliott Hughes
eafad49bd6 Add <sys/quota.h>.
It turns out that at least the Nexus 9 kernel is built without CONFIG_QUOTA.
If we decide we're going to mandate quota functionality, I'm happy for us to
be a part of CTS that ensures that happens, but I don't want to be first, so
there's not much to test here other than "will it compile?". The strace
output looks right though.

Bug: http://b/27948821
Bug: http://b/27952303
Change-Id: If667195eee849ed17c8fa9110f6b02907fc8fc04
2016-04-06 11:06:09 -07:00
Elliott Hughes
7f72ad4d6c Add sync_file_range to <fcntl.h>.
Bug: http://b/27952303
Change-Id: Idadfacd657ed415abc11684b9471e4e24c2fbf05
2016-04-05 12:17:22 -07:00
Elliott Hughes
afe835d540 Move math headers in with the other headers.
Keeping them separate is a pain for the NDK, and doesn't help the platform.

Change-Id: I96b8beef307d4a956e9c0a899ad9315adc502582
2016-04-02 08:36:33 -07:00
Greg Hackmann
e2faf07d65 Add {get,set}domainname(2)
{get,set}domainname aren't in POSIX but are widely-implemented
extensions.

The Linux kernel provides a setdomainname syscall but not a symmetric
getdomainname syscall, since it expects userspace to get the domain name
from uname(2).

Change-Id: I96726c242f4bb646c130b361688328b0b97269a0
Signed-off-by: Greg Hackmann <ghackmann@google.com>
2016-03-25 14:16:58 -07:00
Josh Gao
19ca2fe82f Merge changes I17c22dc2,I9989e2ea
* changes:
  Add a checksum to jmp_buf on AArch64.
  Add a checksum to jmp_buf on ARM.
2016-03-03 22:02:37 +00:00
Josh Gao
a4c69137c6 Add a checksum to jmp_buf on ARM.
Make it easier to diagnose applications mucking with the contents of
jmp_buf by checksumming its contents.

Bug: http://b/27417786
Change-Id: I9989e2ea3979a36ae0bc4c9e1bacafddbacc731b
2016-03-03 12:45:08 -08:00
Elliott Hughes
01d5b946ac Remove optimized code for bzero, which was removed from POSIX in 2008.
I'll come back for the last bcopy remnant...

Bug: http://b/26407170
Change-Id: Iabfeb95fc8a4b4b3992e3cc209ec5221040e7c26
2016-03-02 17:21:07 -08:00
Elliott Hughes
784609317d Mandate optimized __memset_chk for arm and arm64.
This involves actually implementing assembler __memset_chk for arm64,
but that's easily done.

Obviously I'd like this for all architectures (and all the string functions),
but this is low-hanging fruit...

Change-Id: I70ec48c91aafd1f0feb974a2555c51611de9ef82
2016-03-02 11:58:41 -08:00
Elliott Hughes
3c6016f04a Improve diagnostics from the assembler __memcpy_chk routines.
Change-Id: Iec16c92ed80beee505cba2121ea33e3550197b02
2016-03-01 14:45:58 -08:00
Elliott Hughes
62e59646f8 Improve diagnostics from the assembler __memset_chk routines.
Change-Id: Ic165043ab8cd5e16866b3e11cfba960514cbdc57
2016-03-01 12:46:47 -08:00
Elliott Hughes
31adf6cd38 Merge "Improve FORTIFY failure diagnostics." 2016-02-28 00:30:31 +00:00
Elliott Hughes
b83d6747fa Improve FORTIFY failure diagnostics.
Our FORTIFY _chk functions' implementations were very repetitive and verbose
but not very helpful. We'd also screwed up and put the SSIZE_MAX checks where
they would never fire unless you actually had a buffer as large as half your
address space, which probably doesn't happen very often.

Factor out the duplication and take the opportunity to actually show details
like how big the overrun buffer was, or by how much it was overrun.

Also remove the obsolete FORTIFY event logging.

Also remove the unused __libc_fatal_no_abort.

This change doesn't improve the diagnostics from the optimized assembler
implementations.

Change-Id: I176a90701395404d50975b547a00bd2c654e1252
2016-02-26 22:06:17 -08:00
Dimitry Ivanov
19acb698e8 [MIPS] Add __popcountsi2 to libgcc_compat.c
Also removed outdated genlibgcc_compat.py script
and references to it.

Bug: http://b/27340856
Change-Id: I7eef362364078867c60a27e72abba515f08b6651
2016-02-25 14:28:45 -08:00
Elliott Hughes
5f26c6bc91 Really add adjtimex(2), and add clock_adjtime(2) too.
Change-Id: I81fde2ec9fdf787bb19a784ad13df92d33a4f852
2016-02-03 13:19:10 -08:00
Greg Hackmann
3f3f6c526b Add adjtimex
Change-Id: Ia92d35b1851e73c9f157a749dba1e98f68309a8d
Signed-off-by: Greg Hackmann <ghackmann@google.com>
2016-01-28 13:41:22 -08:00
Dimitry Ivanov
6d142bcf34 Move __aeabi* symbols to LIBC_N version
We had these symbols incorrectly versioned as LIBC_PRIVATE
in M release. This change moves __aeabi* symbols from LIBC
to LIBC_N and adds __gnu_Unwind_Find_exidx to the list

Bug: https://github.com/android-ndk/ndk/issues/1
Change-Id: I0b353012adeacb00ae29ea10c63b9d1cf1cadbe7
2016-01-08 10:13:16 -08:00
Dimitry Ivanov
6f72fdede8 Fix gcc+arm builds
gcc requires unique names of symbols for .symver

Bug: http://b/26391427
Change-Id: I6392e34a45a37245fd4e53fb54243be73f443313
2016-01-05 20:41:06 -08:00
Dimitry Ivanov
d90d067312 Export public __aeabi* symbols as LIBC_PRIVATE
But keep LIBC as default version for them

Bug: http://b/26391427
Bug: http://b/26410625
Change-Id: I819e354bbba482d1f983d9be15c23fcce10e5dd9
2016-01-05 18:18:33 -08:00
Daniel Micay
4200e260d2 fix the mremap signature
The mremap definition was incorrect (unsigned long instead of int) and
it was missing the optional new_address parameter.

Change-Id: Ib9d0675aaa098c21617cedc9b2b8cf267be3aec4
2015-11-06 13:14:43 -08:00
Dan Willemsen
5edf077c5b Merge "Switch to LOCAL_SRC_FILES_EXCLUDE" 2015-10-20 20:44:29 +00:00
Dan Willemsen
268a673bd1 Switch to LOCAL_SRC_FILES_EXCLUDE
This moves the generic arm/arm64/x86 settings into the main makefiles
and makes the rest of them derivatives. This better aligns with how
soong handles arch/cpu variants.

Also updates the Android.bp to make it consistent with the make
versions.

Change-Id: I5a0275d992bc657459eb6fe1697ad2336731d122
2015-10-20 11:58:28 -07:00
Josh Gao
b24d743f62 Remove deprecated use of ldm/stm in ARM setjmp.
ARM deprecates using the SP register in the register lists for ldm
and stm, which LLVM emits a warning for.

Bug: http://b/25017080
Change-Id: Ib427e3dfd5740e251f1ad91ebb66534e0d7b72a9
2015-10-19 17:13:51 -07:00
Christopher Ferris
ad157a3c33 Merge "Add a no dwarf version of assembler macros." 2015-09-30 23:18:32 +00:00
Christopher Ferris
8f8308c974 Add a no dwarf version of assembler macros.
For the __release and __release_rt functions, the previous macros
would add a dwarf cfi entry for the function with no values. This works
with libunwind since it always tries the arm unwind information first.

This change removes those entries by creating a no dwarf version of the
assembler macro.

Change-Id: Ib93e42fff5a79b8d770eab0071fdee7d2afa988d
2015-09-30 15:32:15 -07:00
Brent DeGraaf
1d0268c6b8 libc: krait: Use performance version of memcpy
Change-Id: Iaa52635240da8b8746693186b66b69778e833c32
2015-09-30 20:59:36 +00:00
Christopher Ferris
931e1399f1 Merge "Add cortex-a53.a57 target for 32 bit big/little." 2015-09-25 16:29:33 +00:00
Christopher Ferris
fdfcfce7c6 Fix over read in strcpy/stpcpy/strcat.
This bug will happen when these circumstances are met:

- Destination address & 0x7 == 1, strlen of src is 11, 12, 13.
- Destination address & 0x7 == 2, strlen of src is 10, 11, 12.
- Destination address & 0x7 == 3, strlen of src is 9, 10, 11.
- Destination address & 0x7 == 4, strlen of src is 8, 9, 10.

In these cases, the dest alignment code does a ldr which reads 4 bytes,
and it will read past the end of the source. In most cases, this is
probably benign, but if this crosses into a new page it could cause a
crash.

Fix the labels in the cortex-a9 strcat.

Modify the overread test to vary the dst alignment to expost this bug.
Also, shrink the strcat/strlcat overread cases since the dst alignment
variation increases the runtime too much.

Bug: 24345899
Change-Id: Ib34a559bfcebd89861985b29cae6c1e47b5b5855
2015-09-24 14:17:36 -07:00
Christopher Ferris
54ee0407dc Add cortex-a53.a57 target for 32 bit big/little.
The routines optimized for cortex-a7 and cortex-a53 cause performance
drops on cortex-a57. Instead create a target that is the middle ground
that works relatively well on either core.

Change-Id: Ie2b6cc9a59a01c7b30602ee368b2b90f5e886289
2015-09-24 14:00:00 -07:00
Josh Gao
7fda8d2aa4 Implement setjmp cookies on ARM.
Reuse the top bits of _JB_SIGFLAG field previously used to store a
boolean to store a cookie that's validated by [sig]longjmp to make it
harder to use as a ROP gadget. Additionally, encrypt saved registers
with the cookie so that an attacker can't modify a register's value to
a specific value without knowing the cookie.

Bug: http://b/23942752
Change-Id: Id0eb8d06916e89d5d776bfcaa9458f8826717ba3
2015-09-17 14:07:24 -07:00
Elliott Hughes
6f4594d5dc Add preadv/pwritev.
Bug: http://b/12612572
Change-Id: I38ff2684d69bd0fe3f21b1d371b88fa60d5421cb
2015-08-26 14:48:55 -07:00
Josh Gao
06b3f70cfe Add exported __popcount_tab for libgcc compat under compiler-rt.
Change-Id: I8df09e8f199761edbba290d7f1ea530781054b03
2015-08-24 13:06:10 -07:00
Christopher Ferris
e4d51cf37a Merge "Add optimized cortex-a7/cortex-a53 memset/memcpy." 2015-08-18 17:18:11 +00:00
Christopher Ferris
5930772286 Add optimized cortex-a7/cortex-a53 memset/memcpy.
Add an optimized memset that is ~20% faster for cortex-a7 and
cortex-a53.

Add a 32 bit optimized cortex-a53 memcpy that is about ~20% faster
on cached data.

Fix the cortex-a15 __str{cat,cpy}_chk.S, memcpy_base.S to remove
the phony functions, since they aren't needed any more. Then add
a direct include of these for cortex-a53.

Verified the new functions by stepping through all of the major
paths and verifying the backtrace is still correct.

Bug: 22696180
Change-Id: Iec92a3f82d51243cca76c9aff9f35d920ff865ae
2015-08-17 13:02:03 -07:00
Elliott Hughes
5891abdc66 Invalidate cached pid in vfork.
Bug: http://b/23008979
Change-Id: I1dd900ac988cdbe10aad3abc53240c5d352891d5
2015-08-07 19:44:12 -07:00
Christopher Ferris
8264cbba7e Remove pushes from memsets (krait/cortex-a9).
On the path that only uses r0 in both the krait and cortex-a9
memset, remove the push and use r3 instead.

In addition, for cortex-a9, remove the artificial function since
it's not needed since dwarf unwinding is now supported on arm.

Change-Id: Ia4ed1cc435b03627a7193215e76c8ea3335f949a
2015-07-27 14:07:37 -07:00
Christopher Ferris
795a8e3d69 Make all labels local.
Change the non-local labels to .L labels.

Change-Id: I720e894f2e311af8f4a0970303d8b86575fb69a5
2015-07-23 12:12:55 -07:00
Dan Albert
95fd031c4d Revert "Stop libc from cross-referencing unwind symbols"
This reverts commit cd13b14e98.

Bug: http://b/19958712
Change-Id: I7cc7f69728c42c37e129aee30d761c4cd7e30e94
2015-07-20 16:57:11 -07:00
Christopher Ferris
e1e434af12 Replace bx lr with update of pc from the stack.
When there is arm assembler of this format:

ldmxx sp!, {..., lr} or pop {..., lr}
bx lr

It can be replaced with:

ldmxx sp!, {..., pc} or pop {..., pc}

Change-Id: Ic27048c52f90ac4360ad525daf0361a830dc22a3
2015-07-08 11:20:27 -07:00
Tim Murray
9876aa273d Merge "Add support for cortex-a53 in bionic." 2015-06-16 19:04:14 +00:00
Tim Murray
a73b2c961f Add support for cortex-a53 in bionic.
allows -mcpu=cortex-a53 to be passed as part of a command line.

Change-Id: Id4203a9fd197f4c3b661bad21ac58c32819fd687
2015-06-15 21:43:30 -07:00
Elliott Hughes
b1304935b6 Hide accidentally-exposed __clock_nanosleep.
Bug: http://b/21858067
Change-Id: Iaa83a5e17cfff796aed4f641d0d14427614d9399
2015-06-15 19:39:04 -07:00
Elliott Hughes
be57a40d29 Add process_vm_readv and process_vm_writev.
Bug: http://b/21761353
Change-Id: Ic8ef3f241d62d2a4271fbc783c8af50257bac498
2015-06-10 17:24:20 -07:00
Nick Kralevich
e1d0810cd7 Add O_PATH support for flistxattr()
A continuation of commit 2825f10b7f.

Add O_PATH compatibility support for flistxattr(). This allows
a process to list out all the extended attributes associated with
O_PATH file descriptors.

Change-Id: Ie2285ac7ad2e4eac427ddba6c2d182d41b130f75
2015-06-06 11:25:41 -07:00
Nick Kralevich
2825f10b7f libc: Add O_PATH support for fgetxattr / fsetxattr
Support O_PATH file descriptors when handling fgetxattr and fsetxattr.
This avoids requiring file read access to pull extended attributes.

This is needed to support O_PATH file descriptors when calling
SELinux's fgetfilecon() call. In particular, this allows the querying
and setting of SELinux file context by using something like the following
code:

  int dirfd = open("/path/to/dir", O_DIRECTORY);
  int fd = openat(dirfd, "file", O_PATH | O_NOFOLLOW);
  char *context;
  fgetfilecon(fd, &context);

This change was motivated by a comment in
https://android-review.googlesource.com/#/c/152680/1/toys/posix/ls.c

Change-Id: Ic0cdf9f9dd0e35a63b44a4c4a08400020041eddf
2015-06-01 15:51:56 -07:00
Dan Albert
c05554ec5c Fix error handling for negative size in ftruncate.
Bug: 21309901
Change-Id: I54692ab8105dd09db6af7a2c0894a17bdd118aa0
2015-05-20 14:20:33 -07:00
Yabin Cui
40a8f214a5 Hide rt_sigqueueinfo.
Bug: 19358804
Change-Id: I38a53ad64c81d0eefdd1d24599e769fd8a477a56
2015-05-18 11:29:20 -07:00
Elliott Hughes
8a330cad8d Merge "Simplify three copyright headers." 2015-05-12 17:27:04 +00:00
Elliott Hughes
c69ace87ec Simplify three copyright headers.
There's no reason to have multiple years in our own copyright headers,
and given the stupidity of our NOTICE file generation, it just creates
more junk.

Change-Id: I065a3811c2e2584e3b649a18ad9460286bc72b92
2015-05-12 10:10:01 -07:00
Chih-Hung Hsieh
33f33515b5 Use unified syntax to compile with both llvm and gcc.
All arch-arm and arch-arm64 .S files were compiled
by gcc with and without this patch. The output object files
were identical. When compiled with llvm and this patch,
the output files were also identical to gcc's output.

BUG: 18061004
Change-Id: I458914d512ddf5496e4eb3d288bf032cd526d32b
2015-05-11 17:15:03 -07:00
Kyle Repinski
e0905c94d3 cortex-a9: Fix reference to __memcpy_base_aligned.
With a different memcpy, __memcpy_base_aligned ceased to exist.
Instead, point to the name defined by whatever includes memcpy_base.S

Change-Id: I242cf49cbada35337ba155d7f170e86a905ff55f
2015-04-28 14:29:15 -05:00
Elliott Hughes
3391a9ff13 Simplify close(2) EINTR handling.
This doesn't affect code like Chrome that correctly ignores EINTR on
close, makes code that tries TEMP_FAILURE_RETRY work (where before it might
have closed a different fd and appeared to succeed, or had a bogus EBADF),
and makes "goto fail" code work (instead of mistakenly assuming that EINTR
means that the close failed).

Who loses? Anyone actively trying to detect that they caught a signal while
in close(2). I don't think those people exist, and I think they have better
alternatives available.

Bug: https://code.google.com/p/chromium/issues/detail?id=269623
Bug: http://b/20501816
Change-Id: I11e2f66532fe5d1b0082b2433212e24bdda8219b
2015-04-23 08:41:45 -07:00
Christopher Ferris
41efc92e35 Use assembly memmove for all arm32 processors.
Bug: 15110993
Change-Id: Ia3dcd6b8c4032f8c72b6f2e628b635ce99667c09
2015-04-08 16:53:16 -07:00
Dmitriy Ivanov
cd13b14e98 Stop libc from cross-referencing unwind symbols
This makes unwind symbols 'protected',
  which should prevent them from relocating
  against libc++.so/libcutls.so.

  This is temporary file and it is going
  to be removed once libc.so stops exporting
  them.

Bug: http://b/19958712
Change-Id: I96a765afe47e68d2e2ceb288870e63a25ca52081
2015-04-07 01:48:35 +00:00
Christopher Ferris
24958514b9 Use ALIAS_SYMBOL for assembler aliasing.
Change-Id: I8d04d2da0a1ac440cc9044fc819c9a8eda5ff17d
2015-03-25 09:12:00 -07:00
Christopher Ferris
fa5faa0ce6 Make gensyscalls.py use the ALIAS_SYMBOL macro.
Change-Id: Ib94c0abb6fc85126ecc5ed3f1962b2b8b90b9952
2015-03-24 21:08:26 -07: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
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
Colin Cross
da2c0a708e Merge changes Ib87855e8,I4b46ae20,I66364a5c,Id3fcf680
* changes:
  Use LOCAL_LDFLAGS_64 instead of enumerating 64-bit architectures
  Fix typo in cpu variant makefile depenendency for arm64
  Remove libc_static_common_src_files
  Share LP32 makefile settings between arches
2015-02-05 01:57:28 +00:00
Colin Cross
1742a32aea Share LP32 makefile settings between arches
Add <var>_32 to patch-up-arch-specific-flags, and move the LP32
cruft varaibles from the 32-bit arch specific makefiles into the
top level Android.mk.

Change-Id: Id3fcf6805d4af048c2524c94b1295416ebe7d057
2015-02-04 17:35:49 -08:00
Nick Kralevich
00490ae3f3 Ensure raw fchmod/fchmodat syscalls are hidden.
In https://android-review.googlesource.com/#/c/127908/5/libc/SYSCALLS.TXT@116
Elliott said:

  for LP64 these will be hidden. for LP32 we were cowards and left
  them all public for compatibility (though i don't think we ever
  dremeled to see whether it was needed). we don't have an easy
  way to recognize additions, though, so we can't prevent adding
  new turds.

Add a mechanism to prevent the adding of new turds, and use that
mechanism on the fchmod/fchmodat system calls.

Bug: 19233951
Change-Id: I98f98345970b631a379f348df57858f9fc3d57c0
2015-02-03 12:10:30 -08: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
76f8916b90 Clean up <stdlib.h> slightly.
Interestingly, this mostly involves cleaning up our implementation of
various <string.h> functions.

Change-Id: Ifaef49b5cb997134f7bc0cc31bdac844bdb9e089
2015-01-26 14:28:41 -08:00
Dmitriy Ivanov
a137f53980 Add ARM_IRELATIVE relocation
Bug: 17399706
Change-Id: I1dea46c3a3c4572558e718283489c323794176c7
2015-01-08 22:22:27 -08:00
Elliott Hughes
1ef6ec40e1 Move the generic arm memcmp.S into the generic directory.
Change-Id: I48e4d14a0dcddbb246edbac6d0329619574ab44d
2014-12-15 11:06:34 -08:00
Elliott Hughes
f92cc30571 Remove arm assembler not referenced from any makefile.
I also suspect that libc/arch-arm/bionic/memcmp.S is supposed to like in the
generic directory these days, but this change just removes dead code.

Change-Id: I9072488df6e9b7261d79b6014914a0e937cb387b
2014-12-14 17:52:32 -08:00
Elliott Hughes
51f5d83237 Fix arm64 clone stack handling.
Make sure we adjust the stack pointer so a signal can't overwrite data.

Bug: 15195265
Change-Id: I5ab9469a82cb214c32f40a713268a1ab74a4c6fa
2014-12-10 11:08:47 -08:00
Jiangli Yuan
c3d1728583 Use the stmdb instead of str to save the fn/arg
Directly save data into stack without properly adjustment
   of stack point is dangous. For example, if a signal comes,
   kernel will put sigframe into userspace's stack, which
   will overwrite the saved data if sp is not adjusted properly.

Bug: 15195265
Change-Id: Iea0cadfd3b94d50cf40252ad52fe5950811b9192
Signed-off-by: Jiangli Yuan <a6808c@motorola.com>
2014-12-10 18:47:01 +00:00
Yabin Cui
94926f8cfa Merge "support _POSIX_REALTIME_SIGNALS" 2014-12-09 20:10:19 +00:00
Yabin Cui
634816055f support _POSIX_REALTIME_SIGNALS
Bug: 18489947
Change-Id: I2e834d68bc10ca5fc7ebde047b517a3074179475
2014-12-08 21:52:43 -08:00
Elliott Hughes
56e017306e Simplify our endian.h implementation.
We can rely on the compiler's builtins. Tested on arm, arm64, mips, x86,
and x86-64.

Change-Id: I0f774ed7e85b3c791a3178d8ef17c6500e6a9ace
2014-12-08 20:35:08 -08:00
Elliott Hughes
75096226c8 Switch arm and arm64 over to the x86 style of jmpbuf.
Specifically, use the argument to sigsetjmp as a flag in the buffer
to indicate whether or not the signal mask is valid.

Bug: 16918359
Change-Id: I5bb1f1220f14c105c6bc57e0c28c1dc366d1438f
2014-12-08 16:15:59 -08:00
Elliott Hughes
7b78e8187e Fix signal mask save/restore for arm64.
Bug: 16918359
Change-Id: Ieb15f7f1658f5accee05665b72ba17831a80ea9d
2014-12-06 11:18:00 -08:00
Elliott Hughes
b393299b85 Clean up arm setjmp family.
Bug: 16918359
Change-Id: I9b986bdbdbaefe9d9896a820ee8cfe860adfe5c5
2014-12-05 15:39:51 -08:00
Elliott Hughes
9fb536de97 Clean up the arm64 setjmp.
Note that this doesn't address the fact that we don't save/restore the
real-time signals. But it does let us pass the tests we currently fail.

Bug: 16918359
Change-Id: I063a6926164289a71026a412da7f5dd2ca9a74b3
2014-12-05 15:05:45 -08:00
Elliott Hughes
1309dcc842 Code using neon uses ARCH_ARM_HAVE_NEON.
Bug: 18556103
Change-Id: Ia8674dda223f81d616d15ee47b402ab4a3f98079
2014-12-03 17:41:26 -08:00
Elliott Hughes
cb4c615bb9 Remove __ARM_HAVE_VFP.
Bug: 18556103
Change-Id: I6d4cc6a1b359ad2df1ce6687fd26f392059f6efd
2014-12-03 17:07:01 -08:00
Elliott Hughes
a5602c566e Remove __ARM_HAVE_HALFWORD_MULTIPLY.
Bug: 18556103
Change-Id: I17e498539f77ddf7d1fb980ee93155d3c3ccd85e
2014-12-02 16:58:17 -08:00
Elliott Hughes
6651aa6bc1 Remove __ARM_HAVE_LDREXD.
No one uses this.

Bug: 18556103
Change-Id: Icecc3a7b5cb0a36960f27d030d8f4f8ee471f86c
2014-12-03 00:57:07 +00:00
Elliott Hughes
b514026eb2 Kill <machine/exec.h>.
Bug: 18546535
Change-Id: I479e003deab21e31eb5caa5393067ed1dc558387
2014-12-02 16:16:29 -08:00
Bernhard Rosenkränzer
ce46f5576a Specify .cpu cortex-a15
When building with clang without this change, as errors out saying pldw
is an unsupported instruction (because it isn't part of the ARMv7 core
instruction set).
Let as know using pldw is fine.

Change-Id: Ie1f9c4b873e93ab2b3b374d2d46e476a4e581710
Signed-off-by: Bernhard Rosenkränzer <Bernhard.Rosenkranzer@linaro.org>
2014-11-30 22:17:30 +01:00
Elliott Hughes
ee369fb319 Bring our <machine/endian.h> files back in sync.
They'd drifted slightly which led to a compilation error in toybox,
which was assuming pid_t was defined. arm and arm64 were picking it
up via <endian.h> but x86 wasn't.

Change-Id: I58401e6c0066959dfc3b305b020876aaf7074bbf
2014-11-21 18:34:36 -08:00
Elliott Hughes
b86a4c7f65 Add sethostname(2).
Not very useful, but helps building stuff like toybox out of the box.

Change-Id: I110e39030452bd093a84278e019c5752d293718d
2014-11-07 16:48:27 -08:00
Christopher Ferris
7123d4371a Fix generic __memcpy_chk implementation.
- Clean up the labels (add .L to make them local).
- Change to using cfi directives.
- Fix unwinding of the __memcpy_chk fail path.

Bug: 18033671
Change-Id: I12845f10c7ce5e6699c15c558bda64c83f6a392a
2014-10-17 14:44:36 -07:00
Haruki Hasegawa
1816025684 Add clock_settime and clock_nanosleep.
Add the missing prototypes, fix the existing prototypes to use clockid_t
rather than int, fix clock_nanosleep's failure behavior, and add simple
tests.

Bug: 17644443
Bug: https://code.google.com/p/android/issues/detail?id=77372
Change-Id: I03fba369939403918abcabae9551a7123953d780
Signed-off-by: Haruki Hasegawa <h6a.h4i.0@gmail.com>
2014-10-13 17:04:10 -07:00
Christopher Ferris
7d849ac378 Add stpcpy assembler version.
For generic, continue to use the C version of the code.

Bug: 13746695
Change-Id: I77426a70b06131f2373bb51265bea1240bb3f101
2014-09-30 19:23:26 -07:00
Christopher Ferris
c8bd2abab2 Cleanup arm assembly.
Remove the old arm directives.
Change the non-local labels to .L labels.
Add cfi directives to strcpy.S.

Change-Id: I9bafee1ffe5d85c92d07cfa8a85338cef9759562
2014-09-29 15:53:10 -07:00
Dan Albert
690211fcf8 Make __aeabi_*() symbols weak.
This is needed to avoid multiple symbol definitions when linking with
libstdc++ or with compiler-rt.

Change-Id: I2f713bcff113222f0d2538e49691e715d8a8475d
2014-09-26 15:36:14 -07:00
Elliott Hughes
7c02d9428c Clean up the architecture-specific makefiles.
Group things appropriately and name each group.

Change-Id: I0da45eb0ccde19c31d5e984d0e6eb3dad26630dc
2014-09-16 19:06:31 -07:00
Elliott Hughes
b1a6c319c4 No arm source refers to SOFTFLOAT.
So why bother #defining it?

Change-Id: I539e91916cee082cacac594ddf628419b737fa9d
2014-09-16 16:27:35 -07:00
Elliott Hughes
148dff3ec6 Fix 32-bit arm unwinding through signal frames.
gdb was already okay; libgcc and libunwind need a little extra help.

Bug: 17436734
Change-Id: I1f5108f9877373be078554a1ea4938aa4436204e
2014-09-16 14:10:53 -07:00
Elliott Hughes
36f451a6d9 Fix signal trampolines.
* LP32 should use sa_restorer too. gdb expects this, and future (>= 3.15) x86
  kernels will apparently stop supporting the case where SA_RESTORER isn't
  set.

* gdb and libunwind care about the exact instruction sequences, so we need to
  modify the code slightly in a few cases to match what they're looking for.

* gdb also cares about the exact function names (for some architectures),
  so we need to use __restore and __restore_rt rather than __sigreturn and
  __rt_sigreturn.

* It's possible that we don't have a VDSO; dl_iterate_phdr shouldn't assume
  that getauxval(AT_SYSINFO_EHDR) will return a non-null pointer.

This fixes unwinding through a signal handler in gdb for all architectures.
It doesn't fix libunwind for arm and arm64. I'll keep investigating that...

Bug: 17436734
Change-Id: Ic1ea1184db6655c5d96180dc07bcc09628e647cb
2014-09-15 15:04:14 -07:00
Elliott Hughes
b587f339db Add posix_fadvise(3).
(cherry-pick of 00008263782e484020420c606f7d145fe7d0a4d8.)

Bug: 12449798
Change-Id: I07cbf3f670a0d1304b68148325a774f266b5c433
2014-09-11 08:45:46 -07:00
Elliott Hughes
011e111d29 Ensure __set_errno is still visible on LP32.
The use of the .hidden directive to avoid going via the PLT for
__set_errno had the side-effect of actually making __set_errno
hidden (which is odd because assembler directives don't usually
affect symbols defined in a different file --- you can't even
create a weak reference to a symbol that's defined in a different
file).

This change switches the system call stubs over to a new always-hidden
__set_errno_internal and has a visible __set_errno on LP32 just for
binary compatibility with old NDK apps.

(cherry-pick of 7efad83d430f4d824f2aaa75edea5106f6ff8aae.)

Bug: 17423135
Change-Id: I6b6d7a05dda85f923d22e5ffd169a91e23499b7b
2014-09-08 16:46:50 -07:00