Skip to content

Commit

Permalink
Fix file cache test for 32-bit architectures
Browse files Browse the repository at this point in the history
If 64-bit file offsets are selected with _FILE_OFFSET_BITS on a 32-bit
architecture, the default mmap() call takes a 64-bit off_t, but dlsym()
returns a pointer to a function that takes a 32-bit off_t.

To fix it:

- always call original mmap64() if it is available,
- use XSTRINGIFY(mmap) instead of "mmap".

The latter is needed, because some systems define mmap as a macro which
expands to another identifier.

Fixes: ptesarik#80
Signed-off-by: Petr Tesarik <[email protected]>
  • Loading branch information
ptesarik committed May 23, 2024
1 parent d529a57 commit 16c73b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
next
----
* Minor cache improvements and a NULL-pointer dereference fix.
* Fix test suite for 32-bit architectures.

0.5.4
-----
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(off_t)
AC_SUBST(SIZEOF_OFF_T, $ac_cv_sizeof_off_t)

AC_CHECK_FUNCS(mmap64)

dnl This makes sure pkg.m4 is available.
m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config])

Expand Down
13 changes: 12 additions & 1 deletion src/kdumpfile/test-fcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,20 @@ static char *mmapbuf;

static int failmmap;

#ifdef HAVE_MMAP64

#define STR_MMAP XSTRINGIFY(mmap64)
static void* (*orig_mmap)(void *addr, size_t length, int prot, int flags,
int fd, off64_t offset);

#else

#define STR_MMAP XSTRINGIFY(mmap)
static void* (*orig_mmap)(void *addr, size_t length, int prot, int flags,
int fd, off_t offset);

#endif

void *
mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
{
Expand Down Expand Up @@ -445,7 +456,7 @@ main(int argc, char **argv)
return TEST_ERR;
}

orig_mmap = dlsym(RTLD_NEXT, "mmap");
orig_mmap = dlsym(RTLD_NEXT, STR_MMAP);
if (!orig_mmap) {
fprintf(stderr, "Cannot get original mmap() address: %s\n",
dlerror());
Expand Down

0 comments on commit 16c73b8

Please sign in to comment.