summaryrefslogtreecommitdiffstats
path: root/sys/i386/linux
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2009-10-28 20:17:54 +0000
committerjhb <jhb@FreeBSD.org>2009-10-28 20:17:54 +0000
commitb13876f9565066cb7498fa55144d0b3847503f66 (patch)
tree5cbc45ad0c152523955a7ed0f56342a1ed4a08c2 /sys/i386/linux
parentd8407ac333fd2cee2652a5c4e30bc978d7e39730 (diff)
downloadFreeBSD-src-b13876f9565066cb7498fa55144d0b3847503f66.zip
FreeBSD-src-b13876f9565066cb7498fa55144d0b3847503f66.tar.gz
Fix some problems with effective mmap() offsets > 32 bits. This was
partially fixed on amd64 earlier. Rather than forcing linux_mmap_common() to use a 32-bit offset, have it accept a 64-bit file offset. This offset is then passed to the real mmap() call. Rather than inventing a structure to hold the normal linux_mmap args that has a 64-bit offset, just pass each of the arguments individually to linux_mmap_common() since that more closes matches the existing style of various kern_foo() functions. Submitted by: Christian Zander @ Nvidia MFC after: 1 week
Diffstat (limited to 'sys/i386/linux')
-rw-r--r--sys/i386/linux/linux_machdep.c65
1 files changed, 31 insertions, 34 deletions
diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c
index cd3cf79..4e119d8 100644
--- a/sys/i386/linux/linux_machdep.c
+++ b/sys/i386/linux/linux_machdep.c
@@ -93,6 +93,10 @@ struct l_old_select_argv {
struct l_timeval *timeout;
};
+static int linux_mmap_common(struct thread *td, l_uintptr_t addr,
+ l_size_t len, l_int prot, l_int flags, l_int fd,
+ l_loff_t pos);
+
int
linux_to_bsd_sigaltstack(int lsa)
{
@@ -591,12 +595,9 @@ linux_clone(struct thread *td, struct linux_clone_args *args)
#define STACK_SIZE (2 * 1024 * 1024)
#define GUARD_SIZE (4 * PAGE_SIZE)
-static int linux_mmap_common(struct thread *, struct l_mmap_argv *);
-
int
linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
{
- struct l_mmap_argv linux_args;
#ifdef DEBUG
if (ldebug(mmap2))
@@ -605,14 +606,9 @@ linux_mmap2(struct thread *td, struct linux_mmap2_args *args)
args->flags, args->fd, args->pgoff);
#endif
- linux_args.addr = args->addr;
- linux_args.len = args->len;
- linux_args.prot = args->prot;
- linux_args.flags = args->flags;
- linux_args.fd = args->fd;
- linux_args.pgoff = args->pgoff * PAGE_SIZE;
-
- return (linux_mmap_common(td, &linux_args));
+ return (linux_mmap_common(td, args->addr, args->len, args->prot,
+ args->flags, args->fd, (uint64_t)(uint32_t)args->pgoff *
+ PAGE_SIZE));
}
int
@@ -632,11 +628,14 @@ linux_mmap(struct thread *td, struct linux_mmap_args *args)
linux_args.flags, linux_args.fd, linux_args.pgoff);
#endif
- return (linux_mmap_common(td, &linux_args));
+ return (linux_mmap_common(td, linux_args.addr, linux_args.len,
+ linux_args.prot, linux_args.flags, linux_args.fd,
+ (uint32_t)linux_args.pgoff));
}
static int
-linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args)
+linux_mmap_common(struct thread *td, l_uintptr_t addr, l_size_t len, l_int prot,
+ l_int flags, l_int fd, l_loff_t pos)
{
struct proc *p = td->td_proc;
struct mmap_args /* {
@@ -659,21 +658,20 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args)
* Linux mmap(2):
* You must specify exactly one of MAP_SHARED and MAP_PRIVATE
*/
- if (! ((linux_args->flags & LINUX_MAP_SHARED) ^
- (linux_args->flags & LINUX_MAP_PRIVATE)))
+ if (!((flags & LINUX_MAP_SHARED) ^ (flags & LINUX_MAP_PRIVATE)))
return (EINVAL);
- if (linux_args->flags & LINUX_MAP_SHARED)
+ if (flags & LINUX_MAP_SHARED)
bsd_args.flags |= MAP_SHARED;
- if (linux_args->flags & LINUX_MAP_PRIVATE)
+ if (flags & LINUX_MAP_PRIVATE)
bsd_args.flags |= MAP_PRIVATE;
- if (linux_args->flags & LINUX_MAP_FIXED)
+ if (flags & LINUX_MAP_FIXED)
bsd_args.flags |= MAP_FIXED;
- if (linux_args->flags & LINUX_MAP_ANON)
+ if (flags & LINUX_MAP_ANON)
bsd_args.flags |= MAP_ANON;
else
bsd_args.flags |= MAP_NOSYNC;
- if (linux_args->flags & LINUX_MAP_GROWSDOWN)
+ if (flags & LINUX_MAP_GROWSDOWN)
bsd_args.flags |= MAP_STACK;
/*
@@ -681,12 +679,12 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args)
* on Linux/i386. We do this to ensure maximum compatibility.
* Linux/ia64 does the same in i386 emulation mode.
*/
- bsd_args.prot = linux_args->prot;
+ bsd_args.prot = prot;
if (bsd_args.prot & (PROT_READ | PROT_WRITE | PROT_EXEC))
bsd_args.prot |= PROT_READ | PROT_EXEC;
/* Linux does not check file descriptor when MAP_ANONYMOUS is set. */
- bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : linux_args->fd;
+ bsd_args.fd = (bsd_args.flags & MAP_ANON) ? -1 : fd;
if (bsd_args.fd != -1) {
/*
* Linux follows Solaris mmap(2) description:
@@ -711,9 +709,9 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args)
fdrop(fp, td);
}
- if (linux_args->flags & LINUX_MAP_GROWSDOWN) {
+ if (flags & LINUX_MAP_GROWSDOWN) {
/*
- * The linux MAP_GROWSDOWN option does not limit auto
+ * The Linux MAP_GROWSDOWN option does not limit auto
* growth of the region. Linux mmap with this option
* takes as addr the inital BOS, and as len, the initial
* region size. It can then grow down from addr without
@@ -734,8 +732,7 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args)
* fixed size of (STACK_SIZE - GUARD_SIZE).
*/
- if ((caddr_t)PTRIN(linux_args->addr) + linux_args->len >
- p->p_vmspace->vm_maxsaddr) {
+ if ((caddr_t)PTRIN(addr) + len > p->p_vmspace->vm_maxsaddr) {
/*
* Some linux apps will attempt to mmap
* thread stacks near the top of their
@@ -766,19 +763,19 @@ linux_mmap_common(struct thread *td, struct l_mmap_argv *linux_args)
* we map the full stack, since we don't have a way
* to autogrow it.
*/
- if (linux_args->len > STACK_SIZE - GUARD_SIZE) {
- bsd_args.addr = (caddr_t)PTRIN(linux_args->addr);
- bsd_args.len = linux_args->len;
+ if (len > STACK_SIZE - GUARD_SIZE) {
+ bsd_args.addr = (caddr_t)PTRIN(addr);
+ bsd_args.len = len;
} else {
- bsd_args.addr = (caddr_t)PTRIN(linux_args->addr) -
- (STACK_SIZE - GUARD_SIZE - linux_args->len);
+ bsd_args.addr = (caddr_t)PTRIN(addr) -
+ (STACK_SIZE - GUARD_SIZE - len);
bsd_args.len = STACK_SIZE - GUARD_SIZE;
}
} else {
- bsd_args.addr = (caddr_t)PTRIN(linux_args->addr);
- bsd_args.len = linux_args->len;
+ bsd_args.addr = (caddr_t)PTRIN(addr);
+ bsd_args.len = len;
}
- bsd_args.pos = linux_args->pgoff;
+ bsd_args.pos = pos;
#ifdef DEBUG
if (ldebug(mmap))
OpenPOWER on IntegriCloud