vm_mmap.c (181239) | vm_mmap.c (182371) |
---|---|
1/*- 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1991, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * the Systems Programming Group of the University of Utah Computer 8 * Science Department. --- 27 unchanged lines hidden (view full) --- 36 * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94 37 */ 38 39/* 40 * Mapped file (mmap) interface to VM 41 */ 42 43#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1991, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * the Systems Programming Group of the University of Utah Computer 8 * Science Department. --- 27 unchanged lines hidden (view full) --- 36 * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94 37 */ 38 39/* 40 * Mapped file (mmap) interface to VM 41 */ 42 43#include <sys/cdefs.h> |
44__FBSDID("$FreeBSD: head/sys/vm/vm_mmap.c 181239 2008-08-03 14:26:15Z trhodes $"); | 44__FBSDID("$FreeBSD: head/sys/vm/vm_mmap.c 182371 2008-08-28 15:23:18Z attilio $"); |
45 46#include "opt_compat.h" 47#include "opt_hwpmc_hooks.h" 48#include "opt_mac.h" 49 50#include <sys/param.h> 51#include <sys/systm.h> 52#include <sys/kernel.h> --- 1097 unchanged lines hidden (view full) --- 1150 vm_prot_t prot, vm_prot_t *maxprotp, int *flagsp, 1151 struct vnode *vp, vm_ooffset_t foff, vm_object_t *objp) 1152{ 1153 struct vattr va; 1154 void *handle; 1155 vm_object_t obj; 1156 struct mount *mp; 1157 struct cdevsw *dsw; | 45 46#include "opt_compat.h" 47#include "opt_hwpmc_hooks.h" 48#include "opt_mac.h" 49 50#include <sys/param.h> 51#include <sys/systm.h> 52#include <sys/kernel.h> --- 1097 unchanged lines hidden (view full) --- 1150 vm_prot_t prot, vm_prot_t *maxprotp, int *flagsp, 1151 struct vnode *vp, vm_ooffset_t foff, vm_object_t *objp) 1152{ 1153 struct vattr va; 1154 void *handle; 1155 vm_object_t obj; 1156 struct mount *mp; 1157 struct cdevsw *dsw; |
1158 struct ucred *cred; |
|
1158 int error, flags, type; 1159 int vfslocked; 1160 1161 mp = vp->v_mount; | 1159 int error, flags, type; 1160 int vfslocked; 1161 1162 mp = vp->v_mount; |
1163 cred = td->td_ucred; |
|
1162 vfslocked = VFS_LOCK_GIANT(mp); 1163 if ((error = vget(vp, LK_EXCLUSIVE, td)) != 0) { 1164 VFS_UNLOCK_GIANT(vfslocked); 1165 return (error); 1166 } 1167 flags = *flagsp; 1168 obj = vp->v_object; 1169 if (vp->v_type == VREG) { --- 43 unchanged lines hidden (view full) --- 1213 /* 1214 * Force device mappings to be shared. 1215 */ 1216 flags |= MAP_SHARED; 1217 } else { 1218 error = EINVAL; 1219 goto done; 1220 } | 1164 vfslocked = VFS_LOCK_GIANT(mp); 1165 if ((error = vget(vp, LK_EXCLUSIVE, td)) != 0) { 1166 VFS_UNLOCK_GIANT(vfslocked); 1167 return (error); 1168 } 1169 flags = *flagsp; 1170 obj = vp->v_object; 1171 if (vp->v_type == VREG) { --- 43 unchanged lines hidden (view full) --- 1215 /* 1216 * Force device mappings to be shared. 1217 */ 1218 flags |= MAP_SHARED; 1219 } else { 1220 error = EINVAL; 1221 goto done; 1222 } |
1221 if ((error = VOP_GETATTR(vp, &va, td->td_ucred, td))) { | 1223 if ((error = VOP_GETATTR(vp, &va, cred))) |
1222 goto done; | 1224 goto done; |
1223 } | |
1224#ifdef MAC | 1225#ifdef MAC |
1225 error = mac_vnode_check_mmap(td->td_ucred, vp, prot, flags); | 1226 error = mac_vnode_check_mmap(cred, vp, prot, flags); |
1226 if (error != 0) 1227 goto done; 1228#endif 1229 if ((flags & MAP_SHARED) != 0) { 1230 if ((va.va_flags & (SF_SNAPSHOT|IMMUTABLE|APPEND)) != 0) { 1231 if (prot & PROT_WRITE) { 1232 error = EPERM; 1233 goto done; --- 13 unchanged lines hidden (view full) --- 1247 } 1248 obj = vm_pager_allocate(type, handle, objsize, prot, foff); 1249 if (obj == NULL) { 1250 error = (type == OBJT_DEVICE ? EINVAL : ENOMEM); 1251 goto done; 1252 } 1253 *objp = obj; 1254 *flagsp = flags; | 1227 if (error != 0) 1228 goto done; 1229#endif 1230 if ((flags & MAP_SHARED) != 0) { 1231 if ((va.va_flags & (SF_SNAPSHOT|IMMUTABLE|APPEND)) != 0) { 1232 if (prot & PROT_WRITE) { 1233 error = EPERM; 1234 goto done; --- 13 unchanged lines hidden (view full) --- 1248 } 1249 obj = vm_pager_allocate(type, handle, objsize, prot, foff); 1250 if (obj == NULL) { 1251 error = (type == OBJT_DEVICE ? EINVAL : ENOMEM); 1252 goto done; 1253 } 1254 *objp = obj; 1255 *flagsp = flags; |
1255 vfs_mark_atime(vp, td); | 1256 vfs_mark_atime(vp, cred); |
1256 1257done: 1258 vput(vp); 1259 VFS_UNLOCK_GIANT(vfslocked); 1260 return (error); 1261} 1262 1263/* --- 236 unchanged lines hidden --- | 1257 1258done: 1259 vput(vp); 1260 VFS_UNLOCK_GIANT(vfslocked); 1261 return (error); 1262} 1263 1264/* --- 236 unchanged lines hidden --- |