lib/cobalt: Fix detection of mmap64() and open64() aliases
PATCH 1/1 lib/cobalt: Fix detection of mmap64() and open64() aliases
From: Jan Kiszka <[email protected]>
The "#if mmap64 == mmap" and "#if open64 != open" tests were meant to detect libcs which map mmap64() and open64() to their standard names via macros. With glibc, none of these is a macro, and the preprocessor evaluates such identifiers as 0, so the tests always took the alias path. This has two effects:
- __cobalt_mmap64() always falls back to __STD(mmap()). On 32-bit archs, this passes only the lower 32 bits of the offset to the regular mmap(): mmap.c is built with native off_t since commit 0bb6608b6fa7 ("lib/cobalt: Avoid making mmap offset argument unconditionally 64-bit"), before only --disable-y2038 builds were affected. Mapping a regular file or device which is not handled by RTDM at an offset of 4 GiB or more thus maps the wrong page, e.g. when an application built with _FILE_OFFSET_BITS=64 calls mmap(), or when using mmap64().
- The weak __real_mmap64() and __real_open64() fallbacks are never built. Applications linked without the POSIX wrappers (xeno-config --cobalt) fail to link when calling __STD(mmap64()) or __STD(open64()).
Check whether mmap64 and open64 are defined as macros instead, fall back to __STD(mmap64()) otherwise, and build __real_mmap64() and __real_open64() under the same conditions.
--- lib/cobalt/mmap.c | 5 +++-- lib/cobalt/wrappers.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
lib/cobalt/mmap.c +3 -2
@@ -49,7 +49,8 @@ COBALT_IMPL(void *, mmap64, (void *addr, size_t length, int prot, int flags, } regular: -#if mmap64 == mmap +#ifdef mmap64 +/* The libc maps mmap64() to mmap(), its off_t is 64-bit. */ return __STD (mmap (addr, length, prot, flags, fd, offset));#else return __STD (mmap64 (addr, length, prot, flags, fd, offset));
@@ -69,7 +70,7 @@ void *__real_mmap(void *addr, size_t length, int prot, int flags,return mmap (addr, length, prot, flags, fd, offset); } -#if mmap64 != mmap +#ifndef mmap64__weak void *__real_mmap64 (void *addr,size_t length,int prot,int flags,int fd,off64_t offset)
lib/cobalt/wrappers.c +1 -1
@@ -187,7 +187,7 @@ int __real_open(const char *path, int oflag, ...)return open (path, oflag, mode); } -#if open64 != open +#ifndef open64__weak int __real_open64 (const char *path,int oflag, ...) {
Signature · 1 line
2.47.3