[PATCH] Force the argument buffer for mmap syscall to be initialized

Richard Sandiford richard at codesourcery.com
Mon Jun 5 08:49:54 UTC 2006


"Jie Zhang" <jzhang918 at gmail.com> writes:
> Some archs still use old mmap syscall, like this:
>
> static inline _syscall1(__ptr_t, _mmap, unsigned long *, buffer);
> __ptr_t mmap(__ptr_t addr, size_t len, int prot,
>              int flags, int fd, __off_t offset)
> {
>     unsigned long buffer[6];
>
>     buffer[0] = (unsigned long) addr;
>     buffer[1] = (unsigned long) len;
>     buffer[2] = (unsigned long) prot;
>     buffer[3] = (unsigned long) flags;
>     buffer[4] = (unsigned long) fd;
>     buffer[5] = (unsigned long) offset;
>     return (__ptr_t) _mmap(buffer);
> }
>
> GCC 4.1 will optimize away all the statements which initialize the
> arguments buffer. this patch should fix it. It also fixes the same
> issue in ldso code.
>
> Is it OK? If yes, please help install it. Thanks.

FWIW, I think this is really a bug in the bits/syscalls.h syscall asms.
Syscalls can in general read and clobber memory, so the syscall should
include a "memory" clobber to indicate this.  See:

    http://www.uclibc.org/lists/uclibc/2006-March/014931.html

which fixed the same problem for m68k.

Richard



More information about the uClibc mailing list