Commit graph

27 commits

Author SHA1 Message Date
Elliott Hughes
25af17c587 Clarify the fcntl() "that's not how F_SETFD works" error.
The first app developer (we know of) that hit this didn't understand
what it was trying to tell them.

Before:
    FORTIFY: fcntl(F_SETFD) passed non-FD_CLOEXEC flag: 0x801

After:
    FORTIFY: fcntl(F_SETFD) only supports FD_CLOEXEC but was passed 0x801

Bug: https://issuetracker.google.com/304348746
Test: treehugger
Change-Id: I8522e851d8f74c91152ebae68b083b5272d49255
2023-10-12 16:04:14 +00:00
Elliott Hughes
e7943f8b95 Consistently use #if defined(__BIONIC__).
Test: treehugger
Change-Id: I844b909404532eb9165cba1ed6f237bdd4a46990
2023-09-28 10:47:51 -07:00
Elliott Hughes
95646e6666 Add ASSERT_ERRNO and EXPECT_ERRNO (and use them).
We've talked about this many times in the past, but partners struggle to
understand "expected 38, got 22" in these contexts, and I always have to
go and check the header files just to be sure I'm sure.

I actually think the glibc geterrorname_np() function (which would
return "ENOSYS" rather than "Function not implemented") would be more
helpful, but I'll have to go and implement that first, and then come
back.

Being forced to go through all our errno assertions did also make me
want to use a more consistent style for our ENOSYS assertions in
particular --- there's a particularly readable idiom, and I'll also come
back and move more of those checks to the most readable idiom.

I've added a few missing `errno = 0`s before tests, and removed a few
stray `errno = 0`s from tests that don't actually make assertions about
errno, since I had to look at every single reference to errno anyway.

Test: treehugger
Change-Id: Iba7c56f2adc30288c3e00ade106635e515e88179
2023-09-21 14:15:59 -07:00
Christopher Ferris
c833fabed7 Mark death tests properly.
A few death tests are not set to silence tombstones, so fix
all of those occurrences.

Test: Ran all death tests and no tombstones generated.
Change-Id: If2b54b1a3432edbd54076439d40527d966607f70
2023-07-24 14:31:15 -07:00
Elliott Hughes
dfe67d266c Tell people when they've messed up with fcntl(FD_SETFD).
This is a subtle bug that even experts struggle with.

Test: treehugger
Change-Id: If9cf16a1c32c836f5688bb3374cfd21d55125b17
2022-11-30 20:19:22 +00:00
Colin Cross
7da20341e9 Build bionic unit tests for musl
Modify bionic unit tests that are built for glibc so that they also
build against musl.  They don't all pass though:

With glibc:
 2 SLOW TESTS
 4 TIMEOUT TESTS
313 FAILED TESTS
  YOU HAVE 2 DISABLED TESTS

With musl:
11 SLOW TESTS
11 TIMEOUT TESTS
363 FAILED TESTS
  YOU HAVE 2 DISABLED TESTS

Bug: 190084016
Test: m bionic-unit-tests-glibc with musl
Test: atest bionic-unit-tests-static
Test: atest --host bionic-unit-tests-glibc with glibc
Change-Id: I79b6eab04fed3cc4392450df5eef2579412edfe1
2021-08-12 11:13:11 -07:00
Elliott Hughes
09e77f35ab _FILE_OFFSET_BITS=64 support for fcntl.
On Android, fcntl is always implemented by fcntl64(2). This means that
an LP32 binary can `fcntl(F_SETLK, struct flock)` (because fcntl64(2)
passes through to the 32-bit fcntl(2) to handle F_SETLK), and it can
also `fcntl(F_SETLK64, struct flock64)`. What it can't do before this
patch is set _FILE_OFFSET_BITS=64 and then `fcntl(F_SETLK, struct
flock)` where that `struct flock` is actually implicitly `struct
flock64`.

Move the kernel uapi structs out of the way, define them ourselves based
on __LP64__ and _FILE_OFFSET_BITS, and fix up the relevant F_ constants.

(Also add a .clang-format to turn off clang-format in libc/include/.)

Bug: N/A
Test: treehugger (and strace!)
Change-Id: Iccd6c83d9133e1efcf93a7b49a6ae0f1bbd3d58b
2020-01-29 19:36:14 -08:00
Mark Salyzyn
68a3bcc249 bionic tests: switch to using android-base/file.h for TemporaryFile
A matching definition of TemporaryFile exists in libbase now.

Test: compile
Bug: 119313545
Change-Id: I6f84dbf3af9a9c4b270a2532a36c9cb4c0f6bb8f
2018-11-13 10:57:28 -08:00
Yi Kong
32bc0fcf69 Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
2018-08-02 18:09:44 -07:00
Elliott Hughes
fc30bfe2a4 Don't try to link(2) in a test if we're not root.
Bug: http://b/68055982
Test: ran tests
Change-Id: Icdbe3dd58fb84f3661e5d9ed3ff6884cc0ea2ff8
2017-10-24 22:54:34 -07:00
Kazuhiro Inaba
f7a8e95fe8 Fix fcntrl#tee test to use the same expected/actual buffer size.
Previously the test compared /proc/version read into expected[256]
with actual[BUFSIZ]. This CL aligns the both of the buffer sizes to
the same BUFSIZ, so that /proc/version longer than 256 bytes won't
result in a test failure.

Bug: 66872345
Test: fcntl#tee on a device with long /proc/version (Chromebook Plus)
Change-Id: I004dd2189565b0bdde1aa22a2f25fafe74560180
(cherry picked from commit 85a08ae9fead3f24daf108108257e4793a192e5f)
2017-09-25 23:34:19 +00:00
Elliott Hughes
212ea2b74e Merge "With O_TMPFILE, open(2) takes a mode argument."
am: 2fdefadcee

Change-Id: I5cd1f9103b4b5f20f18fd3f7f5be2511e2b1990f
2017-08-04 20:20:38 +00:00
Elliott Hughes
b115aefbb3 With O_TMPFILE, open(2) takes a mode argument.
Strictly, the mode isn't really meaningful unless you supply O_EXCL,
but the kernel will take it and fstat will return it even if you
never give the file a name.

Also warn for O_TMPFILE without a mode at compile time where possible.

Bug: N/A
Test: ran tests
Change-Id: I729b6d6e6190676fd017a1190b6200bf9abdbfd8
2017-08-04 10:20:18 -07:00
Josh Gao
e567fed451 Merge "Explain why we have a test that FALLOC_FL_PUNCH_HOLE is missing." am: 4f61181428
am: b466d39c40

Change-Id: Ia5c40bf1231e3a525532832e6509277b7d833401
2017-06-09 06:06:56 +00:00
Josh Gao
24ed8b5fbf Explain why we have a test that FALLOC_FL_PUNCH_HOLE is missing.
Change-Id: I7388f2e0bc419f195247a1d3e73195cb4d199d5c
Test: none
2017-06-02 14:58:44 -07:00
Matthias Hausner
47a52109a4 bionic: tests: only test falloc_punch on ext4
Test fcntl#falloc_punch is wrong. It checks that fallocate() with mode
FALLOC_FL_PUNCH_HOLE fails on ext4 file system on older kernels. The
test fails to ensure that the file it creates is indeed on an ext4
partition. On an Angelfish device for example, the file is created on an
f2fs partition, which supports FALLOC_FL_PUNCH_HOLE, and thus the test
fails (wrongly).

Change-Id: I23c1ba4d0fcee81551531779e93ac3d5e19ba1d7
Fixes: 62220977
Test: run bionic-unit-tests as per bionic/README.md###Device tests
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
2017-06-02 14:25:06 -07:00
Nick Desaulniers
09d900d50f bionic: tests: add test for fallocate FALLOC_FL_PUNCH_HOLE
Bug: 28760453
Change-Id: I1a58d19bf45eac5f930b0f649cf9b8c9046302f3
2016-09-21 09:24:50 -07:00
Nick Desaulniers
094f316151 bionic: tests: add test for fallocate FALLOC_FL_PUNCH_HOLE
Bug: 28760453
Change-Id: I1a58d19bf45eac5f930b0f649cf9b8c9046302f3
2016-09-12 13:28:47 -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
55147ada3c Add missing prototype for readahead in <fcntl.h>.
Change-Id: Icfe85e9cf95c657b495c4e9cd10dec50b0b8f6db
2016-04-05 11:06:02 -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
3f525d41c2 Add splice, tee, and vmsplice.
Change-Id: I5f43380b88d776a8bb607b47dbbc5db5a2fe6163
2014-06-24 19:03:31 -07:00
Elliott Hughes
063525c61d Consistently use #if defined(__BIONIC__) in tests.
I've also switched some tests to be positive rather than negative,
because !defined is slightly harder to reason about and there are
only two cases: bionic and glibc.

Change-Id: I8d3ac40420ca5aead3e88c69cf293f267273c8ef
2014-05-13 11:19:57 -07:00
Serban Constantinescu
48501af98f AArch64: Fix flock64 for LP64.
On LP64 systems F_GETLK64, F_SETLK64 and F_SETLKW64 definitions should
map onto the F_GETLK, F_SETLK and F_SETLKW definitions, respectively.
LP64 also doesn't have a struct flock64.

Change-Id: Ibdfed9645d9e946999acd6efa8b96ea6238ed5bf
Signed-off-by: Marcus Oakland <marcus.oakland@arm.com>
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
2014-04-08 12:19:23 -07:00
Elliott Hughes
db1ea34748 Implement some of the missing LFS64 support.
This gives us:

* <dirent.h>
  struct dirent64
  readdir64, readdir64_r, alphasort64, scandir64

* <fcntl.h>
  creat64, openat64, open64.

* <sys/stat.h>
  struct stat64
  fstat64, fstatat64, lstat64, stat64.

* <sys/statvfs.h>
  struct statvfs64
  statvfs64, fstatvfs64.

* <sys/vfs.h>
  struct statfs64
  statfs64, fstatfs64.

This also removes some of the incorrect #define hacks we've had in the
past (for stat64, for example, which we promised to clean up way back
in bug 8472078).

Bug: 11865851
Bug: 8472078
Change-Id: Ia46443521918519f2dfa64d4621027dfd13ac566
2014-02-18 15:39:24 -08:00
Elliott Hughes
f64b8ea09d Add fallocate/fallocate64/posix_fallocate/posix_fallocate64.
Bug: 5287571
Bug: 12612860
Change-Id: I4501b9c6cdf9a830336ce0b3afc4ea716b6a0f6f
2014-02-03 16:20:46 -08:00
Elliott Hughes
062092543f Clean up the 32-bit kernel support, fix LP64 fcntl declaration.
In practice, thanks to all the registers the stubs don't actually change,
but it's confusing to have an incorrect declaration.

I suspect that fcntl remains broken for aarch64; it happens to work for
x86_64 because the first vararg argument gets placed in the right register
anyway, but I have no reason to believe that's true for aarch64.

This patch adds a unit test, though, so we'll be able to tell when we get
as far as running the unit tests.

Change-Id: I58dd0054fe99d7d51d04c22781d8965dff1afbf3
2013-11-06 16:33:39 -08:00