Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Apr 2002 15:25:08 -0400
From:      Kenneth Culver <culverk@yumyumyum.org>
To:        freebsd-hackers@freebsd.org, freebsd-emulation@freebsd.org
Subject:   implementing linux mmap2 syscall
Message-ID:  <200204211525.08827.culverk@yumyumyum.org>

next in thread | raw e-mail | index | archive | help

Hi,
	I have recently been trying to implement the linux mmap2 syscall into our 
linuxulator, and I have run into a little problem. 

I looked at the code that was used to implement the regular linux_mmap 
syscall, and I've also looked in the linux kernel at the code that they use 
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,
	unsigned long len, unsigned long prot,
	unsigned long flag, unsigned long offset)
{
	unsigned long ret = -EINVAL;
	if ((offset + PAGE_ALIGN(len)) < offset)
		goto out;
	if (!(offset & ~PAGE_MASK))
		ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
out:
	return ret;
}

This is what mmap2 does:

andstatic inline long do_mmap2(
	unsigned long addr, unsigned long len,
	unsigned long prot, unsigned long flags,
	unsigned long fd, unsigned long pgoff)
{
	int error = -EBADF;
	struct file * file = NULL;

	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
	if (!(flags & MAP_ANONYMOUS)) {
		file = fget(fd);
		if (!file)
			goto out;
	}

	down_write(&current->mm->mmap_sem);
	error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
	up_write(&current->mm->mmap_sem);

	if (file)
		fput(file);
out:
	return error;
}

So what it looks like to me is that mmap2 expects an offset that's already 
page-aligned (I'm not sure if this is the right way to say it), where mmap 
doesn't. the FreeBSD code in the linuxulator basically just takes the offset 
that is passed in with the linux mmap, and uses that to call FreeBSD's mmap 
(the kernel version, not the one called from userland). So basically I'm 
kinda stuck as to what to do to implement linux's mmap2. The only thing I can 
think of is to implement a FreeBSD "mmap2" that basically assumes that the 
offset passed in is already page aligned or whatever, and just uses it, and 
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204211525.08827.culverk>