Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/riastradh-drm2]: src/sys/external/bsd/drm2/include/linux First stab at v...
details: https://anonhg.NetBSD.org/src/rev/a3575c75603b
branches: riastradh-drm2
changeset: 788066:a3575c75603b
user: riastradh <riastradh%NetBSD.org@localhost>
date: Wed Jul 24 02:04:31 2013 +0000
description:
First stab at vm_mmap in <linux/mm.h>. Also PAGE_SIZE & round_page.
diffstat:
sys/external/bsd/drm2/include/linux/mm.h | 77 +++++++++++++++++++++++++++++++-
1 files changed, 76 insertions(+), 1 deletions(-)
diffs (89 lines):
diff -r 6d45739239e1 -r a3575c75603b sys/external/bsd/drm2/include/linux/mm.h
--- a/sys/external/bsd/drm2/include/linux/mm.h Wed Jul 24 02:04:16 2013 +0000
+++ b/sys/external/bsd/drm2/include/linux/mm.h Wed Jul 24 02:04:31 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mm.h,v 1.1.2.1 2013/07/24 00:33:12 riastradh Exp $ */
+/* $NetBSD: mm.h,v 1.1.2.2 2013/07/24 02:04:31 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -32,4 +32,79 @@
#ifndef _LINUX_MM_H_
#define _LINUX_MM_H_
+#include <sys/kauth.h>
+#include <sys/file.h>
+#include <sys/mman.h>
+#include <sys/proc.h>
+#include <sys/vnode.h>
+
+#include <uvm/uvm_extern.h>
+
+#define PAGE_ALIGN(x) round_page(x)
+
+/*
+ * ###################################################################
+ * ############### XXX THIS NEEDS SERIOUS SCRUTINY XXX ###############
+ * ###################################################################
+ */
+
+/*
+ * XXX unsigned long is a loser but will probably work accidentally.
+ * XXX struct file might not map quite right between Linux and NetBSD.
+ * XXX This is large enough it should take its own file.
+ */
+
+static inline unsigned long
+vm_mmap(struct file *file, unsigned long base, unsigned long size,
+ unsigned long prot, unsigned long flags, unsigned long token)
+{
+ struct vnode *vnode;
+ vaddr_t addr = 0;
+ int error;
+
+ /*
+ * Cargo-culted from sys_mmap. Various conditions kasserted
+ * rather than checked for expedience and safey.
+ */
+
+ KASSERT(base == 0);
+ KASSERT(prot == (PROT_READ | PROT_WRITE));
+ KASSERT(flags == MAP_SHARED);
+
+ KASSERT(file->f_type == DTYPE_VNODE);
+ vnode = file->f_data;
+
+ KASSERT(vnode->v_type == VCHR);
+ KASSERT((file->f_flag & (FREAD | FWRITE)) == (FREAD | FWRITE));
+
+ {
+ struct vattr va;
+
+ vn_lock(vnode, (LK_SHARED | LK_RETRY));
+ error = VOP_GETATTR(vnode, &va, kauth_cred_get());
+ VOP_UNLOCK(vnode);
+ if (error)
+ goto out;
+ /* XXX kassert? */
+ if ((va.va_flags & (SF_SNAPSHOT | IMMUTABLE | APPEND)) != 0) {
+ error = EACCES;
+ goto out;
+ }
+ }
+
+ /* XXX pax_mprotect? pax_aslr? */
+
+ error = uvm_mmap(&curproc->p_vmspace->vm_map, &addr, size,
+ (VM_PROT_READ | VM_PROT_WRITE), (VM_PROT_READ | VM_PROT_WRITE),
+ MAP_SHARED, vnode, base,
+ curproc->p_rlimit[RLIMIT_MEMLOCK].rlim_cur);
+ if (error)
+ goto out;
+
+ KASSERT(addr <= -1024UL); /* XXX Kludgerosity! */
+
+out: /* XXX errno NetBSD->Linux (kludgerific) */
+ return (error? (-error) : (unsigned long)addr);
+}
+
#endif /* _LINUX_MM_H_ */
Home |
Main Index |
Thread Index |
Old Index