Commit graph

12112 commits

Author SHA1 Message Date
Steven Moreland
8401230be6 bionic: max_android_page_size to 16384
The maximum page size Android supports
now is 16384, and Art only supports 16kB,
so we can save a bit of space.

Bug: 332556665
Test: N/A
Change-Id: I23df607bcc5cf9e96d7b6a66169413cd1a883f7e
2024-05-22 18:29:04 +00:00
Elliott Hughes
7c22b4c372 Merge "Don't leak a thread when timer_create() fails." into main 2024-05-22 11:40:39 +00:00
Christopher Ferris
65e349d6c8 Read maps data before using and do safe reads.
Rather than only updating the maps when a pc can't be found, always update
the maps before using them. This avoids issues where the maps change
and it could cause a crash reading from a map that has been modified.

This assumes that executed code never gets unloaded, or that the
code is unloaded so infrequently that it doesn't matter. This happens
because the pcs for the backtraces are gathered as the program runs
and those pcs are symbolized and made into relative pcs at a later time.

Also, add safe reading of the elf data when necessary to avoid any
crashes if maps are changing while this is running.

Since the MapEntry objects can be deleted, copy the values for
the current map in the backtrace code to detect when in our own code
instead of keeping a pointer.

Bug: 340988785

Test: malloc_debug unit/system tests pass.
Test: libmemunreachable tests pass.
Change-Id: Ica2ba50a5bcf9e19c7e4033e29a5a67a1847d1a6
2024-05-21 17:41:22 -07:00
Elliott Hughes
c793bc00f5 Don't leak a thread when timer_create() fails.
We do the same thing in pthread_create().

This has the nice side-effect of letting us move part of the child setup that we were doing in the parent into the child where it belongs.

Bug: https://issuetracker.google.com/340125671
Change-Id: Ibe646d5ca9066f487d08fd40f004550349e8a02e
2024-05-21 21:35:49 +00:00
Elliott Hughes
ccc4dbf135 execinfo.cpp: Add a __riscv case.
This makes this TraceFunction() more like trace_function() in malloc_debug. I'll leave whether we can collapse these into one implementation as an open question for now...

Change-Id: I3981e4114244d49f8dbae1d3b776a7e9c32be688
2024-05-21 15:11:15 +00:00
Elliott Hughes
a13b3b32e0 Merge "Tidy and document the inline/__inline/__inline__ situation." into main 2024-05-21 11:49:20 +00:00
Elliott Hughes
09c660bf75 Add riscv64 implementation of __get_bionic_tcb_for_thread().
Bug: http://b/339287219
Change-Id: I2b6f2603cd34e1575d575565c369663bfcdf9be1
2024-05-17 17:18:57 +00:00
Elliott Hughes
88908db595 Merge "Minor <android/dlext.h> documentation improvements." into main 2024-05-16 21:21:24 +00:00
Treehugger Robot
bdba54d9c5 Merge "Update <android/api-level.h>." into main 2024-05-16 20:35:55 +00:00
Treehugger Robot
923b48c1c5 Merge "Update <system_properties.h> documentation." into main 2024-05-16 19:57:13 +00:00
Elliott Hughes
c2622a5d4c Minor <android/dlext.h> documentation improvements.
Change-Id: I7ba1228c938e2fce858beb126e1e81620bba0459
2024-05-16 19:02:36 +00:00
Elliott Hughes
3772ae4f96 Update <system_properties.h> documentation.
Change-Id: I70de8dee963d00c480e0cb2faa9988d1d6c76d05
2024-05-16 18:45:03 +00:00
Elliott Hughes
d6c3a078bc Update <android/api-level.h>.
Change-Id: Id1522fdaf3041dcd3f296a716e8a2a1936c389e8
2024-05-16 18:31:47 +00:00
Elliott Hughes
72b10fc254 Document <link.h>.
I was only here to stop saying "Android R", which doesn't mean much to most app developers, but while I'm here...

Change-Id: I0ffd5d679747491d338064e36efc80b2b82e9e06
2024-05-16 18:10:23 +00:00
Treehugger Robot
03a4448dcf Merge "[MTE] cleanup: factor out BIONIC_MEMTAG_UPGRADE_SECS handling" into main 2024-05-15 19:40:01 +00:00
Florian Mayer
f3326581c0 [MTE] cleanup: factor out BIONIC_MEMTAG_UPGRADE_SECS handling
This makes __libc_init_mte easier to read.

Change-Id: I2826f62e53895093d1631d4e6c7e3ff844cf9def
2024-05-15 16:39:36 +00:00
Elliott Hughes
3469e7df9b Tidy and document the inline/__inline/__inline__ situation.
We can (and should) use `inline` in C++ but not in C headers that
need to support ANSI/C89/C90. `__inline__` works everywhere, but
traditionally we've used the BSD `__inline` in public headers.

Change-Id: I920e0a1f5fcd01cf8ddd89240ef66b25c50378d7
2024-05-15 16:06:07 +00:00
Dan Albert
2237fcf1fa Revert "Use inline keyword without underscores consistently"
This reverts commit 58f06e1112.

Bare `inline` is not ANSI C compatible, and NDK users may be using
that.

Test: treehugger
Change-Id: I82c5424522142001cd59da63ef3fd440014451ad
2024-05-14 17:55:54 +00:00
Treehugger Robot
d06e2e7b29 Merge "Rename GWP-ASan android_mallopt() arguments" into main 2024-05-09 17:29:34 +00:00
Jiyong Park
3aa32e2c81 Merge "Export capability.h as a filegroup" into main 2024-05-07 02:17:26 +00:00
Florian Mayer
d29fcf6e37 Merge "[MTE] update ring buffer when enabling stack trace collection" into main 2024-05-07 00:41:10 +00:00
Florian Mayer
c6d1e23b3f [MTE] update ring buffer when enabling stack trace collection
A change in scudo changed to lazy allocation of the ring buffer,
so we need to update the globals once we enable stack trace collection

Bug: 339020123
Test: sanitizer test app
Change-Id: Ideda7b761e75052d09df27de1f6b04aeb9a03dc2
2024-05-06 14:46:32 -07:00
Christopher Ferris
5fa285da96 Merge "Change malloc_not_svelte to malloc_low_memory." into main 2024-05-06 19:45:06 +00:00
Mitch Phillips
ebc2ac934f Rename GWP-ASan android_mallopt() arguments
The previous names were difficult to decipher. Now, let's change this
all to be more clear as it's actually one android_mallopt() call
depending on where it's called from, rather than the intended behaviour.

Also updated the comments so it's clear what happened across different
versions of Android.

Test: atest bionic-unit-tests CtsGwpAsanTestCases
Bug: N/a
Change-Id: I0582cab0b74aa09f4af54f9fbe5ba22697f82082
2024-05-03 13:20:45 +02:00
Jiyong Park
35a280d818 Export capability.h as a filegroup
... so that it can be used by fs_config_[dirs|files] genrules.
Previously, the fs_config_* were created by Android.mk and capability.h
was referenced directly from there. Since Soong doesn't allow that,
let's export the file explicitly.

Bug: 337993745
Test: m
Change-Id: I2777a4dbe6b977bc64c5f6defe748fa7993e578e
2024-05-03 16:53:39 +09:00
Treehugger Robot
a97a4754a3 Merge "Add deprecation message for __sF." into main 2024-05-02 22:19:13 +00:00
Treehugger Robot
000745aa37 Merge "Allow deprecation messages." into main 2024-05-02 21:53:15 +00:00
Dan Albert
cc86c74362 Add deprecation message for __sF.
Bug: None
Test: treehugger
Change-Id: I9dd9e77ad024c2ea292f021bb2709378f755c1d8
2024-05-02 20:05:29 +00:00
Dan Albert
398e1aa030 Allow deprecation messages.
I'll land another patch that makes this required once I've fixed up
all the callers.

Bug: https://github.com/android/ndk/issues/2014
Test: treehugger
Change-Id: I62b9fdd3174f37d33f01c27f7f4e9134f6d9df6e
2024-05-02 20:05:28 +00:00
Elliott Hughes
622b6aeeef __system_property_add: log specifics about failures.
Failure to add a property should be rare, so log the specific
failure to aid in debugging.

Bug: http://b/322714325
Change-Id: I9461428f16d7d04d5aceb910a5cf1c928cfe9da2
2024-05-01 23:46:45 +00:00
Christopher Ferris
b54250572d Change malloc_not_svelte to malloc_low_memory.
The malloc_not_svelte product variable has been removed and is
replaced by malloc_low_memory. This switches the sense of the

Test: Verified scudo config is used by default.
Test: Verified Android GO config uses the jemalloc low memory config.
Test: Verified that the default config on oriole produces the exact same
Test: libc.so with and without this change.
Change-Id: I48085fa6c2dcf5c61f847ef1f15c38653d1f7214
2024-05-01 15:33:45 -07:00
Florian Mayer
05c16e7f54 Make "remapping stacks as PROT_MTE" debug log
This was spamming logcat

Change-Id: I3255b583d594a91faae8680aaef94d793c3c26a9
2024-04-30 18:13:14 +00:00
Elliott Hughes
81c54c72b3 Upstream sync.
Also clean up some obsolete cruft from openbsd-compat.h...

Test: treehugger
Change-Id: I9eae0f8304e701d032045617427289002d234cd8
2024-04-29 23:41:39 +00:00
Treehugger Robot
cdbc7c75f5 Merge "[scudo] -1 is also valid for M_DECAY_TIME" into main 2024-04-29 20:07:46 +00:00
Chia-hung Duan
6abb406e0a [scudo] -1 is also valid for M_DECAY_TIME
Test: Run tests
Change-Id: I044ef84bf0ec97c0f8cb8d3a2340b82218d85efc
2024-04-26 15:24:24 -07:00
Treehugger Robot
9c7892202f Merge "Only try to initialize appcompat properties if the folder is present" into main 2024-04-24 22:35:37 +00:00
Elliott Hughes
5063d26249 Merge "Always use __foo__ for attribute names." into main 2024-04-23 00:12:32 +00:00
Treehugger Robot
ae038dcdea Merge "Replace commented-out deprecated attribute with doc comment." into main 2024-04-22 22:34:41 +00:00
Elliott Hughes
a933582f3e __system_property_set: add string names for init's error codes.
https://issuetracker.google.com/336223505 is not the first
hard-to-read bug here.

Change-Id: I520aeb2cb87423f8db394bf4709d659e3eb3a309
2024-04-22 22:18:06 +00:00
Elliott Hughes
9b9371bd0e Replace commented-out deprecated attribute with doc comment.
This attribute had been commented out since it was first
committed a decade ago. No-one's going to chase down arm32-only
trivia like that before arm32 and x86 are removed as obsolete...

Change-Id: I8e29d16657b3f4ce379e65732d747f969ea31dae
2024-04-22 20:17:22 +00:00
Elliott Hughes
a1b5ca2fe0 Always use __foo__ for attribute names.
To avoid collisions with other macros.

Change-Id: I015639043deaceccaf5f11365f8bdc45ca703da5
2024-04-22 20:10:53 +00:00
Nate Myren
9437444cf5 Only try to initialize appcompat properties if the folder is present
If the Init process doesn't write the appcompat system properties
folder, do not attempt to initialize it

Bug: 331307495
Test: manual
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d071e949a6153e76eb7c67e5947d4d387a8afe2d)
Merged-In: I21716ea87e55a63a1b79127887c451d0fcf006f3
Change-Id: I21716ea87e55a63a1b79127887c451d0fcf006f3
2024-04-19 19:07:34 +00:00
Elliott Hughes
7d3c6cd25c Document pthread_key_create(3), pthread_key_delete(3), and PTHREAD_KEYS_MAX.
In particular "how to work around the PTHREAD_KEYS_MAX limit".

Change-Id: I330936d598ddddfa0903f0505fd00f8fcbf02543
2024-04-18 22:02:38 +00:00
Christopher Ferris
785e161dd8 Merge "Update to v6.8 kernel headers." into main 2024-04-18 16:35:43 +00:00
Nick Desaulniers
ceed466d60 libc: remove __size_mul_overflow
We should just be able to use __builtin_umull_overflow now, which expects
unsigned long parameters. We don't need __builtin_umul_overflow (which expects
unsigned ints) because Bionic is LP64 or ILP32, so for ILP32
sizeof(size_t) == sizeof(unsigned long),
so __builtin_umull_overflow will work for either ILP32 or LP64.

Test: mm
Change-Id: I872491731bca05e561767f8bfeda4c6704e10ccb
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
2024-04-17 14:54:57 -07:00
Nick Desaulniers
0be8f184c2 Merge "Use inline keyword without underscores consistently" into main 2024-04-17 21:19:27 +00:00
Treehugger Robot
0b1161d9b5 Merge "Clean up __always_inline" into main 2024-04-17 20:19:14 +00:00
Nick Desaulniers
58f06e1112 Use inline keyword without underscores consistently
s/__inline__/inline
s/__inline/inline

Change-Id: I5d8d930a7a41d678a0795e7a608dacbb9eb8cb37
2024-04-17 10:51:09 -07:00
Nick Desaulniers
c574f79afa Clean up __always_inline
While studying the implementation of POSIX pthread_rwlock* functions, I noticed
that two functions were marked __always_inline twice. "They must really mean it
this time."

Also add back `inline` keyword to one other usage of __always_inline to be
consistent with other uses of __always_inline throughout the codebase.

Change-Id: Ibf9eaed5fc9fd03afcdd969cff82dec71a8ce30f
2024-04-17 10:50:41 -07:00
Florian Mayer
7d098bbee7 Fix incorrect links
Change-Id: Iee24c6b2e1a63d01359dadd5af7499fa3b4abaa5
2024-04-16 21:12:40 +00:00
Christopher Ferris
b830ddf90e Update to v6.8 kernel headers.
Kernel headers coming from:

Git: https://android.googlesource.com/kernel/common/
Branch: android-mainline
Tag: android-mainline-6.8

Test: Builds and bionic unit tests pass on raven.
Test: Able to log in to an Android GO 32 bit device.
Change-Id: I0022cdb20c19726f526acaab2866f1e25794b77e
2024-04-16 09:49:56 -07:00
Elliott Hughes
12773b6eca Merge "Simplify Oryon ifunc resolvers." into main 2024-04-16 15:06:14 +00:00
Elliott Hughes
f978a85cc3 Simplify Oryon ifunc resolvers.
Mainly just factoring out the code, but there are two functional
changes here too:

1. The inline assembler was missing `volatile`, making the hwcap
check ineffective (because the compiler would sometimes move the
MIDR_EL1 read above the hwcap check).

2. The previous code accepted variants 0x0 to 0x5 while the comment
said 0x1 to 0x5. The comment was correct.

I resisted the temptation to actually have a table to search on the assumption that it'll be a while before we need such a thing.

Bug: https://issuetracker.google.com/330105715
Change-Id: I9fdc1e70e49b26ef32794b55ca5e5fd37f1163f9
2024-04-16 15:05:55 +00:00
Treehugger Robot
e7f4506bcb Merge "Add LINE_MAX." into main 2024-04-15 23:20:22 +00:00
Steven Moreland
117478dd4e Merge "Prefer __BIONIC_DEPRECATED_PAGE_SIZE_MACRO" into main 2024-04-10 20:57:45 +00:00
Mitch Phillips
4435aff516 Merge "[GWP-ASan] Use recoverable everywhere" into main 2024-04-10 09:30:58 +00:00
Treehugger Robot
3db97c73a2 Merge "Add NGROUPS." into main 2024-04-09 19:33:36 +00:00
Elliott Hughes
e5bd239ba1 Add NGROUPS.
Historical code still uses this, and people work around its absence
locally. All of iOS/macOS and musl/glibc have this.

Change-Id: I119834f535b346275be5fa1df3c323eee9e242cc
2024-04-09 16:48:18 +00:00
Elliott Hughes
f666d822bd <sys/shm.h>: fix a hard-coded 4096 page size.
Change-Id: I932b1ea44ab6a54a2e4d2bcd1577c6f5859f583a
2024-04-09 16:40:27 +00:00
Steven Moreland
a69e5af7ee Prefer __BIONIC_DEPRECATED_PAGE_SIZE_MACRO
Platform and future NDK releases will have no PAGE_SIZE by default,
unless __BIONIC_DEPRECATED_PAGE_SIZE_MACRO is specified.

This ensures that when people use these headers with non-standard build
systems, they will still become aware of the changes.

Bug: 312546062
Test: build/boot
Change-Id: I29f5de2cd5d59d3cefdd45a6da1ccdd7c12f1f19
2024-04-09 16:35:15 +00:00
Elliott Hughes
b266f6522f Add LINE_MAX.
LINE_MAX is a bad idea from the 1970s that we've ignored until now,
but there's already one hack in the AOSP tree (external/ltp) to work
around its absence, and kselftests would need another. Both uses are
bad code, but bad code exists, and iOS/macOS and musl/glibc all have
the same 2048 value, and it is in POSIX, so at least it's consistent
idiocy. Hopefully we're not encouraging more of it!

Bug: https://github.com/llvm/llvm-project/issues/88119
Change-Id: Ief219c3fe20b3d95da7040c4b9411f997b1c0470
2024-04-09 15:41:10 +00:00
Mitch Phillips
aa8c229e7d [GWP-ASan] Use recoverable everywhere
Use recoverable mode for system processes and system apps as well.
Given we're a sampled bug detector anyway, why not let these processes
continue. This might save some user experience if something ends up
crashing that requires a SysUI reboot (like system_server). And, hey,
starting up processes is expensive.

Bug: N/A
Test: atest CtsGwpAsanTestCases
Change-Id: Ia6be4fcf3b3ed55a3089587d060aba7ab318cf97
2024-04-09 12:35:31 +02:00
Elliott Hughes
252ed5704a Merge "riscv64: use L() in the handful of places we didn't already." into main 2024-04-08 21:30:36 +00:00
Elliott Hughes
6937761c52 arm64: use L() in the handful of places we didn't already.
Change-Id: Ieb3cc5c9623291421c1d2fdc204e27812fee8ffd
2024-04-08 16:38:41 +00:00
Elliott Hughes
9e892499d9 riscv64: use L() in the handful of places we didn't already.
Change-Id: If34ae7a0eb3f7d0bd84018de4b987fd437decf58
2024-04-08 16:32:25 +00:00
Treehugger Robot
b97459693e Merge "Hide overaligned global address from the compiler." into main 2024-04-05 01:42:14 +00:00
Peter Collingbourne
8bd83d8c98 Hide overaligned global address from the compiler.
The address of contents is only guaranteed to be aligned to 4KB on
4KB page size systems, but the compiler was generating code that
assumed it to be aligned to 64KB, which broke on a 4KB page size
system. This probably ought to be fixed, either in the compiler so
it can't generate code assuming such large alignments (it's hard to
see what useful optimizations are possible by assuming such large
alignments anyway) or by making bionic respect the p_align field in
PT_LOAD, but for now let's hide the address behind an asm statement
that the compiler can't see through.

As a result of this change, the code generation for the function
__bionic_setjmp_cookie_get on x86 changed so that it clobbers ecx,
as allowed by the calling convention. However, the x86 assembly
implementation for setjmp was assuming that it wouldn't be
clobbered. Fix it.

Bug: 332534664
Change-Id: I07fa737d8cf892d27ce08c305dafb0a53fef36cb
2024-04-04 16:33:01 -07:00
Florian Mayer
e564066696 Merge "Disable USE_SCUDO branches for HWASan" into main 2024-04-04 20:07:45 +00:00
Florian Mayer
d8ad152208 Disable USE_SCUDO branches for HWASan
It would be nicer to do this in the build system properly, and skip
linking scudo altogether when using HWASan, but this workaround is
almost as good, so we should submit this for now.

Test: CtsWrapHwasanTestCases
Change-Id: If38df37daadae93b8979279dce7f2c9cc5bc03f8
2024-04-04 20:07:04 +00:00
Vaisakh K V
54a612187d Custom memset implementation for Qualcomm Oryon CPU
Submitted on behalf of a third-party: Linaro Limited

License rights, if any, to the submission are granted solely by the
copyright owner of such submission under its applicable intellectual
property.

Copyright (c) 2012, Linaro Limited
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.
* Neither the name of the Linaro nor the
 names of its contributors may be used to endorse or promote products
 derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Origin Project URL: https://android.googlesource.com/platform/bionic/
Commit ID: 7e4fa56099

Third Party code includes additions/modifications from Qualcomm Innovation Center, Inc.

Test: All
Change-Id: I479a572a325e27262d27aa37c516618e4322e9bb
2024-03-29 13:35:04 +05:30
Vaisakh K V
83e55841ea Custom memcpy implementation for Qualcomm Oryon CPU
Submitted on behalf of a third-party: Arm Limited

License rights, if any, to the submission are granted solely by the
copyright owner of such submission under its applicable intellectual
property.

Copyright (c) 2012-2022, Arm Limited.
SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception

Origin Project URL: https://github.com/ARM-software/optimized-routines
Tag: v24.01

Third Party code includes additions/modifications from Qualcomm Innovation Center, Inc.

Test: All
Change-Id: I0c97398a435e3f8ddf8ad38bc6bd71cc0d78aea5
2024-03-29 13:25:10 +05:30
Treehugger Robot
29f233a59e Merge "sysconf()/getpagesize() documentation." into main 2024-03-27 23:25:40 +00:00
Elliott Hughes
3bfb6eeb14 sysconf()/getpagesize() documentation.
Plus a little bit of cleanup of the sysconf() implementation...

Change-Id: I017d50e537e4721c9a4c4a62e9dea771ee920fb8
2024-03-27 21:23:42 +00:00
Elliott Hughes
5a42460cc6 Merge "elf.h: add EF_RISCV_FLOAT_ABI." into main 2024-03-26 23:08:53 +00:00
Treehugger Robot
fb95ed5df7 Merge "Improve our dlsym()/dlvsym() docs a bit more." into main 2024-03-26 22:33:48 +00:00
Elliott Hughes
b90d6b35a6 elf.h: add EF_RISCV_FLOAT_ABI.
See code comments for details. I think everything we could reasonably
upstream from this file is now an upstream pull request. If they get in,
I'll try my luck with the arm32 TLS constant (which is a bit more
interesting because there's a probably obsolete conflict upstream, but
someone who knows about FreeBSD/arm32 would want to look at that).

Test: treehugger
Change-Id: I5bf197045940d25efb2a520716499d924c362b57
2024-03-26 19:15:42 +00:00
Elliott Hughes
cb47a4f671 Use ifuncs for memset and memrchr.
Not useful right now, but Qualcomm has an Oryon memset they'd like to
use, and there's no reason to treat memrchr as a weird special case.

Bug: https://issuetracker.google.com/330105715
Test: treehugger
Change-Id: Id879479bf4f45433debcb3fe08cfa96bb1eb3b93
2024-03-26 18:58:50 +00:00
Elliott Hughes
edc73c5492 Improve our dlsym()/dlvsym() docs a bit more.
RTLD_DEFAULT/RTLD_NEXT already linked to the functions, but the functions should link to the constants too.

Change-Id: I854b632092f077d71918e99b3caec874e1df1ef3
2024-03-26 16:46:29 +00:00
Elliott Hughes
6bf133dc5f Remove duplicate ELF_ST_TYPE() macro.
The Linux uapi header fixed their definition in 5.19 to not have the cast that we were working around here. (See https://lkml.kernel.org/r/Ymv7G1BeX4kt3obz@localhost.localdomain for the upstream patch.)

Change-Id: Ied3368551ebb82f44f411684fe3666d06efbd22e
2024-03-22 20:46:52 +00:00
Elliott Hughes
2a70ee680c Merge "Update FreeBSD elf_common.h." into main 2024-03-22 20:40:42 +00:00
Treehugger Robot
ef9504be7d Merge "Change doc about crash_detail name" into main 2024-03-21 22:09:00 +00:00
Ryan Prichard
a35df79cd8 Merge "Fix StaticTlsLayout for atypical alignment values" into main 2024-03-21 21:38:59 +00:00
Florian Mayer
a5d6778356 Change doc about crash_detail name
Test: none, doc change
Bug: 326097280
Change-Id: I5a79b8ac7448e564a9d72ad1c9323cea35d82227
2024-03-21 13:50:44 -07:00
Elliott Hughes
6cd03eff43 Update FreeBSD elf_common.h.
Looks like I'd been bad here, and added new stuff to this file rather
than <elf.h> directly. I've also done nothing to upstream any of this.
This patch at least addresses the former problem, moving our stuff out
into <elf.h>.

Rather than *delete* anything that conflicts with Linux in elf_common.h,
I've disable it with // or #if, and marked those as Android changes to
make it less likely that the next update accidentally drops them (which
isn't super likely, since most of them should actually cause build
failures when they conflict with uapi).

Test: treehugger
Change-Id: Id0deccc7305c60b0f708b55e2eed0dedc0bca41d
2024-03-21 20:13:36 +00:00
Ryan Prichard
439639268d Fix StaticTlsLayout for atypical alignment values
arm32/arm64: Previously, the loader miscalculated a negative value for
offset_bionic_tcb_ when the executable's alignment was greater than
(8 * sizeof(void*)). The process then tended to crash.

riscv: Previously, the loader didn't propagate the p_align field of the
PT_TLS segment into StaticTlsLayout::alignment_, so high alignment
values were ignored.

__bionic_check_tls_alignment: Stop capping alignment at page_size().
There is no need to cap it, and the uncapped value is necessary for
correctly positioning the TLS segment relative to the thread pointer
(TP) for ARM and x86. The uncapped value is now used for computing
static TLS layout, but only a page of alignment is actually provided:
 * static TLS: __allocate_thread_mapping uses mmap, which provides only
   a page's worth of alignment
 * dynamic TLS: BionicAllocator::memalign caps align to page_size()
 * There were no callers to StaticTlsLayout::alignment(), so remove it.

Allow PT_TLS.p_align to be 0: quietly convert it to 1.

For static TLS, ensure that the address of a TLS block is congruent to
p_vaddr, modulo p_align. That is, ensure this formula holds:

    (&tls_block % p_align) == (p_vaddr % p_align)

For dynamic TLS, a TLS block is still allocated congruent to 0 modulo
p_align. Fixing dynamic TLS congruence is mostly a separate problem
from fixing static TLS congruence, and requires changing the dynamic
TLS allocator and/or DTV structure, so it should be fixed in a
later follow-up commit.

Typically (p_vaddr % p_align) is zero, but it's currently possible to
get a non-zero value with LLD: when .tbss has greater than page
alignment, but .tdata does not, LLD can produce a TLS segment where
(p_vaddr % p_align) is non-zero. LLD calculates TP offsets assuming
the loader will align the segment using (p_vaddr % p_align).
Previously, Bionic and LLD disagreed on the offsets from the TP to
the executable's TLS variables.

Add unit tests for StaticTlsLayout in bionic-unit-tests-static.

See also:
 * https://github.com/llvm/llvm-project/issues/40872
 * https://sourceware.org/bugzilla/show_bug.cgi?id=24606
 * https://reviews.llvm.org/D61824
 * https://reviews.freebsd.org/D31538

Bug: http://b/133354825
Bug: http://b/328844725
Bug: http://b/328844839
Test: bionic-unit-tests bionic-unit-tests-static
Change-Id: I8850c32ff742a45d3450d8fc39075c10a1e11000
2024-03-20 17:01:35 -07:00
Elliott Hughes
526bd985c8 Include the SPDX identifiers in NOTICE files.
We're starting to see projects _only_ use the SPDX identifiers (and
they're more readable "at a glance" anyway), so it's probably time to
include these...

Test: N/A
Change-Id: I5c76d77dcd392a8db1166108e410389d349a42c3
2024-03-19 15:56:30 +00:00
Elliott Hughes
63df96b7fb Merge "crt*.o cleanup." into main 2024-03-14 18:37:18 +00:00
Treehugger Robot
f3a8ae87fd Merge "Ignore bionic versioning in vendor modules" into main 2024-03-14 03:35:13 +00:00
Elliott Hughes
6a30b71b07 crt*.o cleanup.
Say .S instead of .c in a comment, and don't add an include directory we don't need.

Change-Id: I4cfc39904a4ad67a2aadb6691c527f7e38d9c4c7
2024-03-13 23:41:32 +00:00
Florian Mayer
60573deb72 Merge "Move memtag_stack out of libc_globals" into main 2024-03-13 17:54:37 +00:00
Justin Yun
ced630225a Ignore bionic versioning in vendor modules
Vendor modules do not follow bionic versioning but define their own
versioning for LLNDK. Ignore the __INTRODUCED_IN annotation for
vendor modules.

Bug: 302113279
Test: build trunk-staging and next configurations
Change-Id: I04646b524d17f7ae47f0f96cb98f221f3e821629
2024-03-13 21:02:58 +09:00
Elliott Hughes
eb4cf41766 Add missing documentation to <dlfcn.h>.
All the dude wanted was to mention that dlclose() can cause problems with thread locals...

Change-Id: Iea23c49b6b2d6d93b85b2aa0ab1183e68cf39695
2024-03-12 23:45:00 +00:00
Florian Mayer
73750dc38e Move memtag_stack out of libc_globals
We cannot use a WriteProtected because we are accessing it in a
multithreaded context.

Test: atest memtag_stack_dlopen_test w/ MTE
Test: atest bionic-unit-tests w/ MTE
Test: atest bionic-unit-tests on _fullmte
Bug: 328256432
Change-Id: I39faa75f97fd5b3fb755a46e88346c17c0e9a8e2
2024-03-12 12:42:23 -07:00
Florian Mayer
5cc10a9a0d Merge "Make memtag_handle_longjmp precise" into main 2024-03-12 18:12:46 +00:00
Florian Mayer
0e1412e08e Make memtag_handle_longjmp precise
We would get the SP inside of memtag_handle_longjmp, which could prevent
us from detecting the case where a longjmp is going into a function that
had already returned. This changes makes the behaviour more predictable.

Change-Id: I75bf931c8f4129a2f38001156b7bbe0b54a726ee
2024-03-06 16:46:45 -08:00
Elliott Hughes
7c37e12827 Merge "Clarify the timespec argument to clock_nanosleep()." into main am: 70ecb746f3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2987070

Change-Id: Ie84b92a2839ad09f5f73f1cce173df5a14e3e237
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-05 15:44:19 +00:00
Elliott Hughes
c2ce647e2a Merge "Consistently use 'op' in argument names." into main am: 47f8ab80cc
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2987969

Change-Id: Id162bd1a19777501ea982996f3689a22142e18e2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-05 15:44:07 +00:00
Elliott Hughes
786484d808 Merge "_Fork(): clarify what not running pthread_atfork() handlers means in practice." into main am: 69bc81615b
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2987030

Change-Id: Ic3bcc3ec2addc60edf75d612eb4c5bd35f902040
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-05 15:43:53 +00:00
Elliott Hughes
70ecb746f3 Merge "Clarify the timespec argument to clock_nanosleep()." into main 2024-03-05 15:25:46 +00:00
Elliott Hughes
47f8ab80cc Merge "Consistently use 'op' in argument names." into main 2024-03-05 15:25:18 +00:00