Re: mmap to access ARM registers

  • From: Mike Pall <mikelj-1705@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 9 May 2017 21:53:07 +0200

John Swenson wrote:

The standard C program that Altera provides works great, it opens /dev/mem
then passes that to mmap, specifies the range (2MB) and offset, using the
returned pointer works correctly.

Please try to run ltrace and strace on the C program and check
which library call and which system call is actually invoked.

Various combinations of C libraries and kernels on various
architectures do strange things to fix up 32/64 bit issues. Like
transparently redirecting to mmap64() or passing extra flags.

[E.g. stat is really __xstat and pread is really pread64 etc.]

The first problem was that off_t is not defined, so looking around it looks
like it should be signed 64 bit integer.

On most toolchains the actual type depends on defines like:
  -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
These in turn define various macros and redirections to fix up
I/O calls. And these affect their prototypes, too.

The FFI is a low-level API and cannot see these contortions. It's
all done in C headers and in the C library behind the scenes.

If you cannot find the right underlying function in the C library,
you could also use the C syscall() API directly and pick the
64 bit-clean Linux mmap syscall for your architecture. Passing
64 bit arguments to syscalls on a 32 bit system is another
challenge, though (you have to split them in host byte order).

--Mike

Other related posts: