lib/cobalt: Avoid making mmap offset argument unconditionally 64-bit
PATCH v3 1/1 lib/cobalt: Avoid making mmap offset argument unconditionally 64-bit
From: Jan Kiszka <[email protected]>
When _FILE_OFFSET_BITS is 64, mmap is handled by the mmap64 symbol of glibc. The original mmap continues to expect native off_t size, i.e. 32 bits on 32-bit archs.
While we require applications to be rebuilt with the same settings Xenomai was built with as well (either both _TIME_BITS and _FILE_OFFSET_BITS set to 64 or both left unset) which practically shadows this issue, it remains wrong to change the wrapped mmap function in a was that is incompatible with glibc.
To avoid running into conflicts between enabling and disabling _TIME_BITS=64 and, thus, also _FILE_OFFSET_BITS=64, factor out the affected mmap wrappers as well as their __real stubs into a separate code module.
There is one catch: The cobalt-call to mmap in umm.c needs to be forced to mmap64 to become agnostic to _FILE_OFFSET_BITS used by the cobalt core internally.
---
Change in v3:
- pin internal call to __cobalt_mmap64
lib/cobalt/Makefile.am | 15 ++++++++ lib/cobalt/mmap.c | 79 ++++++++++++++++++++++++++++++++++++++++++ lib/cobalt/rtdm.c | 38 -------------------- lib/cobalt/umm.c | 2 +- lib/cobalt/wrappers.c | 17 --------- 5 files changed, 95 insertions(+), 56 deletions(-) create mode 100644 lib/cobalt/mmap.c
lib/cobalt/Makefile.am +15 -0
@@ -7,9 +7,12 @@ noinst_HEADERS = \ lib_LTLIBRARIES = libcobalt.la libmodechk.la +noinst_LTLIBRARIES = libcobaltext.la + libcobalt_la_LDFLAGS = @XENO_LIB_LDFLAGS@ -version-info 2:0:0 -lpthread -lrt libcobalt_la_LIBADD = \ + libcobaltext.la \ arch/@XENO_TARGET_ARCH@/libarch.la \ ../boilerplate/libboilerplate.la
@@ -43,6 +46,18 @@ libcobalt_la_CPPFLAGS = \ -I$(top_srcdir)/include/cobalt \ -I$(top_srcdir)/include +# source files that require native off_t size +libcobaltext_la_SOURCES = \ + mmap.c + +libcobaltext_la_LDFLAGS = @XENO_LIB_LDFLAGS@ + +libcobaltext_la_CPPFLAGS = \ + @XENO_COBALT_CFLAGS@ \ + -I$(top_srcdir)/include/cobalt \ + -I$(top_srcdir)/include \ + -U_TIME_BITS -U_FILE_OFFSET_BITS + libmodechk_la_LIBADD = libcobalt.la libmodechk_la_SOURCES = \
lib/cobalt/mmap.c new file +79 -0
79 lines not on this page · raw message
lib/cobalt/rtdm.c +0 -38
@@ -541,41 +541,3 @@ COBALT_IMPL(int, shutdown, (int fd, int how))return __STD (shutdown (fd, how)); } - -COBALT_IMPL(void *, mmap64, (void *addr, size_t length, int prot, int flags, - int fd, off64_t offset)) -{ -struct _rtdm_mmap_request rma; -int ret; - -if (fd <0 )/* We don't do anonymous mappings. */ - goto regular; - -/* RTDM ignores the address hint, and rejects MAP_FIXED. */ - rma.length = length; - rma.offset = offset; - rma.prot = prot; - rma.flags = flags; - - ret =XENOMAI_SYSCALL3 (sc_cobalt_mmap, fd, &rma, &addr); -if (ret != -EADV && ret != -ENOSYS ) { - ret =set_errno (ret); -if (ret) -return MAP_FAILED ; - -return addr; - } - -regular: -#if mmap64 == mmap -return __STD (mmap (addr, length, prot, flags, fd, offset)); -#else -return __STD (mmap64 (addr, length, prot, flags, fd, offset)); -#endif -} - -COBALT_IMPL(void *, mmap, (void *addr, size_t length, int prot, int flags, - int fd, off_t offset)) -{ -return __COBALT (mmap64 (addr, length, prot, flags, fd, offset)); -}
lib/cobalt/umm.c +1 -1
@@ -58,7 +58,7 @@ static void *__map_umm(const char *name, uint32_t *size_r)return MAP_FAILED ; } - addr =__RT (mmap (NULL , statbuf.size,PROT_READ |PROT_WRITE , + addr =__RT (mmap64 (NULL , statbuf.size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ));__RT (close (fd));
lib/cobalt/wrappers.c +0 -17
@@ -28,7 +28,6 @@#include <sys/select.h> #include <sys/socket.h> #include <sys/time.h> -#include <sys/mman.h> #include <stdio.h> #include <stdarg.h> #include <stdlib.h>
@@ -384,22 +383,6 @@ int __real_select (int __nfds, fd_set *__restrict __readfds,return select (__nfds, __readfds, __writefds, __exceptfds, __timeout); } -__weak -void *__real_mmap (void *addr,size_t length,int prot,int flags, -int fd,off_t offset) -{ -return mmap (addr, length, prot, flags, fd, offset); -} - -#if mmap64 != mmap -__weak -void *__real_mmap64 (void *addr,size_t length,int prot,int flags, -int fd,off64_t offset) -{ -return mmap64 (addr, length, prot, flags, fd, offset); -} -#endif -__weak int __real_vfprintf (FILE *stream,const char *fmt,va_list args) {
Signature · 1 line
2.51.0