From owner-freebsd-hackers Sun Apr 21 12:25: 6 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mailhub.yumyumyum.org (dsl092-171-091.wdc1.dsl.speakeasy.net [66.92.171.91]) by hub.freebsd.org (Postfix) with SMTP id 6277C37B419 for ; Sun, 21 Apr 2002 12:24:54 -0700 (PDT) Received: (qmail 16373 invoked from network); 21 Apr 2002 19:24:44 -0000 Received: from ken.yumyumyum.org (192.168.0.2) by router.yumyumyum.org with SMTP; 21 Apr 2002 19:24:44 -0000 Content-Type: text/plain; charset="us-ascii" From: Kenneth Culver To: freebsd-hackers@freebsd.org, freebsd-emulation@freebsd.org Subject: implementing linux mmap2 syscall Date: Sun, 21 Apr 2002 15:25:08 -0400 X-Mailer: KMail [version 1.4] MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200204211525.08827.culverk@yumyumyum.org> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, =09I have recently been trying to implement the linux mmap2 syscall into = our=20 linuxulator, and I have run into a little problem.=20 I looked at the code that was used to implement the regular linux_mmap=20 syscall, and I've also looked in the linux kernel at the code that they u= se=20 for mmap and mmap2. Basically this is in the linux kernel: This is what mmap does in linux... static inline unsigned long do_mmap(struct file *file, unsigned long addr= , =09unsigned long len, unsigned long prot, =09unsigned long flag, unsigned long offset) { =09unsigned long ret =3D -EINVAL; =09if ((offset + PAGE_ALIGN(len)) < offset) =09=09goto out; =09if (!(offset & ~PAGE_MASK)) =09=09ret =3D do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_S= HIFT); out: =09return ret; } This is what mmap2 does: andstatic inline long do_mmap2( =09unsigned long addr, unsigned long len, =09unsigned long prot, unsigned long flags, =09unsigned long fd, unsigned long pgoff) { =09int error =3D -EBADF; =09struct file * file =3D NULL; =09flags &=3D ~(MAP_EXECUTABLE | MAP_DENYWRITE); =09if (!(flags & MAP_ANONYMOUS)) { =09=09file =3D fget(fd); =09=09if (!file) =09=09=09goto out; =09} =09down_write(¤t->mm->mmap_sem); =09error =3D do_mmap_pgoff(file, addr, len, prot, flags, pgoff); =09up_write(¤t->mm->mmap_sem); =09if (file) =09=09fput(file); out: =09return error; } So what it looks like to me is that mmap2 expects an offset that's alread= y=20 page-aligned (I'm not sure if this is the right way to say it), where mma= p=20 doesn't. the FreeBSD code in the linuxulator basically just takes the off= set=20 that is passed in with the linux mmap, and uses that to call FreeBSD's mm= ap=20 (the kernel version, not the one called from userland). So basically I'm=20 kinda stuck as to what to do to implement linux's mmap2. The only thing I= can=20 think of is to implement a FreeBSD "mmap2" that basically assumes that th= e=20 offset passed in is already page aligned or whatever, and just uses it, a= nd=20 then have linux_mmap2() just call the FreeBSD mmap2(). Any ideas? Ken To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message