Subject: kern/21937: compat/linux: syscall 192 is actually mmap2(), not mmap()
To: None <gnats-bugs@gnats.netbsd.org>
From: None <tv@pobox.com>
List: netbsd-bugs
Date: 06/20/2003 00:31:58
>Number:         21937
>Category:       kern
>Synopsis:       compat/linux: syscall 192 is actually mmap2(), not mmap()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 20 04:34:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Todd Vierling
>Release:        NetBSD 1.6.1_STABLE
>Organization:
	DUH.ORG:  Pointing out the obvious since 1994.
>Environment:
System: NetBSD server.duh.org 1.6.1_STABLE NetBSD 1.6.1_STABLE (HOME) #2: Wed May 21 13:10:29 EDT 2003 tv@server.duh.org:/export/SRC/duh/netbsd-kernels/HOME i386
Architecture: i386
Machine: i386
>Description:

On arm, i386, m68k, and powerpc at syscall 192, and on mips at syscall 220,
there is a syscall named "mmap2", a more-or-less hack that is used by glibc
to implement the 64-bit mmap64() call (aka mmap() with _LARGEFILE_SOURCE
set at compile time).

i386 had been implementing this with linux_sys_mmap(), which seemed to work
so long as the "offset" argument was 0.  This does not work with any other
value of "offset", because the values end up not being page aligned.  Enter
the real meaning of mmap2() arguments:  "offset" is a number of pages, not
a number of raw bytes.

>How-To-Repeat:

Call mmap64(..., getpagesize()) under NetBSD's Linux emulation with args
that otherwise work with the 32-bit mmap() call under Linux emulation.
Watch as it fails, even though the only change is from mmap() to mmap64().

>Fix:

The following diffball implements mmap2() for all the architectures
mentioned above.  The way I composed linux_sys_mmap2_args might be
considered hacky (it's simply a #define to linux_sys_mmap_args), so a
KNF style guru should look at that.

Note:  This does not enable mmap2() for alpha, as that is not needed by
glibc (the regular mmap() call is used instead, as off_t is already 64-bit
on Linux/alpha).

If happy, please also pull up to the 1.6 branch.  This is one of several
changes needed to make CrossOver Office run on NetBSD/i386.

=====

begin 644 sys.diff.gz
M'XL("$2,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