vm_mmap.c (042bb29940c41b0dd24b308c3415da3e53be60d1) vm_mmap.c (c04c996b25fc4b1a69c758c0614ea9436e6ae3f3)
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.

--- 1123 unchanged lines hidden (view full) ---

1132 * disallow this in all cases.
1133 */
1134 if (foff & PAGE_MASK)
1135 return (EINVAL);
1136
1137 if ((flags & MAP_FIXED) == 0) {
1138 fitit = TRUE;
1139 *addr = round_page(*addr);
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.

--- 1123 unchanged lines hidden (view full) ---

1132 * disallow this in all cases.
1133 */
1134 if (foff & PAGE_MASK)
1135 return (EINVAL);
1136
1137 if ((flags & MAP_FIXED) == 0) {
1138 fitit = TRUE;
1139 *addr = round_page(*addr);
1140 mtx_lock(&Giant);
1141 } else {
1142 if (*addr != trunc_page(*addr))
1143 return (EINVAL);
1144 fitit = FALSE;
1140 } else {
1141 if (*addr != trunc_page(*addr))
1142 return (EINVAL);
1143 fitit = FALSE;
1145 mtx_lock(&Giant);
1146 (void) vm_map_remove(map, *addr, *addr + size);
1147 }
1148
1149 /*
1150 * Lookup/allocate object.
1151 */
1152 if (flags & MAP_ANON) {
1153 type = OBJT_DEFAULT;
1154 /*
1155 * Unnamed anonymous regions always start at 0.
1156 */
1157 if (handle == 0)
1158 foff = 0;
1159 } else {
1160 vp = (struct vnode *) handle;
1144 (void) vm_map_remove(map, *addr, *addr + size);
1145 }
1146
1147 /*
1148 * Lookup/allocate object.
1149 */
1150 if (flags & MAP_ANON) {
1151 type = OBJT_DEFAULT;
1152 /*
1153 * Unnamed anonymous regions always start at 0.
1154 */
1155 if (handle == 0)
1156 foff = 0;
1157 } else {
1158 vp = (struct vnode *) handle;
1159 mtx_lock(&Giant);
1161 if (vp->v_type == VCHR) {
1162 type = OBJT_DEVICE;
1163 handle = (void *)(intptr_t)vp->v_rdev;
1164 } else {
1165 struct vattr vat;
1166 int error;
1167
1168 error = VOP_GETATTR(vp, &vat, td->td_ucred, td);

--- 6 unchanged lines hidden (view full) ---

1175 /*
1176 * if it is a regular file without any references
1177 * we do not need to sync it.
1178 */
1179 if (vp->v_type == VREG && vat.va_nlink == 0) {
1180 flags |= MAP_NOSYNC;
1181 }
1182 }
1160 if (vp->v_type == VCHR) {
1161 type = OBJT_DEVICE;
1162 handle = (void *)(intptr_t)vp->v_rdev;
1163 } else {
1164 struct vattr vat;
1165 int error;
1166
1167 error = VOP_GETATTR(vp, &vat, td->td_ucred, td);

--- 6 unchanged lines hidden (view full) ---

1174 /*
1175 * if it is a regular file without any references
1176 * we do not need to sync it.
1177 */
1178 if (vp->v_type == VREG && vat.va_nlink == 0) {
1179 flags |= MAP_NOSYNC;
1180 }
1181 }
1182 mtx_unlock(&Giant);
1183 }
1184
1185 if (handle == NULL) {
1186 object = NULL;
1187 docow = 0;
1188 } else {
1189 object = vm_pager_allocate(type,
1190 handle, objsize, prot, foff);
1191 if (object == NULL) {
1183 }
1184
1185 if (handle == NULL) {
1186 object = NULL;
1187 docow = 0;
1188 } else {
1189 object = vm_pager_allocate(type,
1190 handle, objsize, prot, foff);
1191 if (object == NULL) {
1192 mtx_unlock(&Giant);
1193 return (type == OBJT_DEVICE ? EINVAL : ENOMEM);
1194 }
1195 docow = MAP_PREFAULT_PARTIAL;
1196 }
1197
1198 /*
1199 * Force device mappings to be shared.
1200 */

--- 37 unchanged lines hidden (view full) ---

1238 } else if (flags & MAP_SHARED) {
1239 /*
1240 * Shared memory is also shared with children.
1241 */
1242 rv = vm_map_inherit(map, *addr, *addr + size, VM_INHERIT_SHARE);
1243 if (rv != KERN_SUCCESS)
1244 (void) vm_map_remove(map, *addr, *addr + size);
1245 }
1192 return (type == OBJT_DEVICE ? EINVAL : ENOMEM);
1193 }
1194 docow = MAP_PREFAULT_PARTIAL;
1195 }
1196
1197 /*
1198 * Force device mappings to be shared.
1199 */

--- 37 unchanged lines hidden (view full) ---

1237 } else if (flags & MAP_SHARED) {
1238 /*
1239 * Shared memory is also shared with children.
1240 */
1241 rv = vm_map_inherit(map, *addr, *addr + size, VM_INHERIT_SHARE);
1242 if (rv != KERN_SUCCESS)
1243 (void) vm_map_remove(map, *addr, *addr + size);
1244 }
1246 mtx_unlock(&Giant);
1247 switch (rv) {
1248 case KERN_SUCCESS:
1249 return (0);
1250 case KERN_INVALID_ADDRESS:
1251 case KERN_NO_SPACE:
1252 return (ENOMEM);
1253 case KERN_PROTECTION_FAILURE:
1254 return (EACCES);
1255 default:
1256 return (EINVAL);
1257 }
1258}
1245 switch (rv) {
1246 case KERN_SUCCESS:
1247 return (0);
1248 case KERN_INVALID_ADDRESS:
1249 case KERN_NO_SPACE:
1250 return (ENOMEM);
1251 case KERN_PROTECTION_FAILURE:
1252 return (EACCES);
1253 default:
1254 return (EINVAL);
1255 }
1256}