mmap on arm

Paul Kaletta paul at ewido.net
Thu Nov 23 17:54:12 UTC 2006


Hi,

I'm really new to uClibc and I have a problem that I just cannot
solve.  I hope you guys can help me out.

I'm trying to use the mmap system-call on an arm-box that uses uClibc
0.9.28.  However mmap always fails with errno containing EINVAL.

Here's a program that demonstrates what I'm trying to do:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

int main(void)
{
    int fd;
    int size = 100;
    char *data;
    int i;

    char filename[] = "testfile";

    fd = open(filename, O_RDWR);
    if(fd == -1 && errno == ENOENT) {
	fd = open(filename, O_CREAT|O_RDWR|O_TRUNC, S_IWUSR|S_IRUSR);
    }
    if(fd == -1) {
	printf("open failed: %s\n", strerror(errno));
    }

    for(i = 0; i < size; i++)
	write(fd, "\0", 1);

    data = mmap((caddr_t)0,
		size,
		PROT_READ | PROT_WRITE,
		MAP_SHARED,
		fd,
		0);

    if (data == (caddr_t)(-1)) {
    	printf("Memmap failed: %s\n", strerror(errno));
	return -1;
    };

    printf("Memmapped...\n");

    strcpy(data, "Hello World in mmap!\n");

    printf("Stuff written...\n");

    return 0;
}

On a x86-glibc box this prints "Memmapped...\nStuff written...\n", and
testfile contains "Hello World in mmap!\n" followed by a bunch of 0s.
That's what I expected.

On arm-uclibc it only prints "Memmap failed: Invalid argument".  This
is not really helpful, as my arguments don't seem very unreasonable to
me.  But again, I'm inexperienced.

arm-linux-gcc -v
Reading specs from /usr/local/arm/3.4/lib/gcc/arm-linux-uclibc/3.4.3/specs
Configured with:
/opt/buildroot/toolchain_build_arm_nofpu/gcc-3.4.3/configure
--prefix=/usr/local/arm/3.4 --build=i386-pc-linux-gnu
--host=i386-pc-linux-gnu --target=arm-linux-uclibc
--enable-languages=c,c++ --enable-shared --disable-__cxa_atexit
--enable-target-optspace --with-gnu-ld --disable-nls --enable-multilib
--with-float=soft : (reconfigured)
/opt/buildroot/toolchain_build_arm_nofpu/gcc-3.4.3/configure
--prefix=/usr/local/arm/3.4 --build=i386-pc-linux-gnu
--host=i386-pc-linux-gnu --target=arm-linux-uclibc
--enable-languages=c,c++ --enable-shared --disable-__cxa_atexit
--enable-target-optspace --with-gnu-ld --disable-nls --enable-multilib
--with-float=soft
Thread model: posix
gcc version 3.4.3

I searched for an anwser on the web and on the uclibc mailinglist, but
I didn't find anything useful, except  this:

http://bugs.uclibc.org/bug_view_advanced_page.php?bug_id=1071

I looked at the patch, but it doesn't seem to be against 0.9.28,
because that version doesn't have a the libc/sysdeps/linux/arm/mmap.c
file.

I'm really lost.  Any help would be much appreciated.

Ciao,
Paul



More information about the uClibc mailing list