vm_mmap.c (117224) | vm_mmap.c (118771) |
---|---|
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. --- 31 unchanged lines hidden (view full) --- 40 * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94 41 */ 42 43/* 44 * Mapped file (mmap) interface to VM 45 */ 46 47#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. --- 31 unchanged lines hidden (view full) --- 40 * @(#)vm_mmap.c 8.4 (Berkeley) 1/12/94 41 */ 42 43/* 44 * Mapped file (mmap) interface to VM 45 */ 46 47#include <sys/cdefs.h> |
48__FBSDID("$FreeBSD: head/sys/vm/vm_mmap.c 117224 2003-07-04 12:23:43Z phk $"); | 48__FBSDID("$FreeBSD: head/sys/vm/vm_mmap.c 118771 2003-08-11 07:14:08Z bms $"); |
49 50#include "opt_compat.h" 51#include "opt_mac.h" 52 53#include <sys/param.h> 54#include <sys/systm.h> 55#include <sys/kernel.h> 56#include <sys/lock.h> --- 984 unchanged lines hidden (view full) --- 1041 return (ENOMEM); 1042#else 1043 error = suser(td); 1044 if (error) 1045 return (error); 1046#endif 1047 1048 error = vm_map_wire(&td->td_proc->p_vmspace->vm_map, addr, | 49 50#include "opt_compat.h" 51#include "opt_mac.h" 52 53#include <sys/param.h> 54#include <sys/systm.h> 55#include <sys/kernel.h> 56#include <sys/lock.h> --- 984 unchanged lines hidden (view full) --- 1041 return (ENOMEM); 1042#else 1043 error = suser(td); 1044 if (error) 1045 return (error); 1046#endif 1047 1048 error = vm_map_wire(&td->td_proc->p_vmspace->vm_map, addr, |
1049 addr + size, TRUE); | 1049 addr + size, VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES); |
1050 return (error == KERN_SUCCESS ? 0 : ENOMEM); 1051} 1052 1053#ifndef _SYS_SYSPROTO_H_ 1054struct mlockall_args { 1055 int how; 1056}; 1057#endif 1058 1059/* 1060 * MPSAFE 1061 */ 1062int 1063mlockall(td, uap) 1064 struct thread *td; 1065 struct mlockall_args *uap; 1066{ | 1050 return (error == KERN_SUCCESS ? 0 : ENOMEM); 1051} 1052 1053#ifndef _SYS_SYSPROTO_H_ 1054struct mlockall_args { 1055 int how; 1056}; 1057#endif 1058 1059/* 1060 * MPSAFE 1061 */ 1062int 1063mlockall(td, uap) 1064 struct thread *td; 1065 struct mlockall_args *uap; 1066{ |
1067 /* mtx_lock(&Giant); */ 1068 /* mtx_unlock(&Giant); */ 1069 return 0; | 1067 vm_map_t map; 1068 int error; 1069 1070 map = &td->td_proc->p_vmspace->vm_map; 1071 error = 0; 1072 1073 if ((uap->how == 0) || ((uap->how & ~(MCL_CURRENT|MCL_FUTURE)) != 0)) 1074 return (EINVAL); 1075 1076#ifdef pmap_wired_count 1077 /* 1078 * If wiring all pages in the process would cause it to exceed 1079 * a hard resource limit, return ENOMEM. 1080 */ 1081 if (map->size - ptoa(pmap_wired_count(vm_map_pmap(map)) > 1082 td->td_proc->p_rlimit[RLIMIT_MEMLOCK].rlim_cur)) 1083 return (ENOMEM); 1084#else 1085 error = suser(td); 1086 if (error) 1087 return (error); 1088#endif 1089 1090 if (uap->how & MCL_FUTURE) { 1091 vm_map_lock(map); 1092 vm_map_modflags(map, MAP_WIREFUTURE, 0); 1093 vm_map_unlock(map); 1094 error = 0; 1095 } 1096 1097 if (uap->how & MCL_CURRENT) { 1098 /* 1099 * P1003.1-2001 mandates that all currently mapped pages 1100 * will be memory resident and locked (wired) upon return 1101 * from mlockall(). vm_map_wire() will wire pages, by 1102 * calling vm_fault_wire() for each page in the region. 1103 */ 1104 error = vm_map_wire(map, vm_map_min(map), vm_map_max(map), 1105 VM_MAP_WIRE_USER|VM_MAP_WIRE_HOLESOK); 1106 error = (error == KERN_SUCCESS ? 0 : EAGAIN); 1107 } 1108 1109 return (error); |
1070} 1071 1072#ifndef _SYS_SYSPROTO_H_ 1073struct munlockall_args { | 1110} 1111 1112#ifndef _SYS_SYSPROTO_H_ 1113struct munlockall_args { |
1074 int how; | 1114 register_t dummy; |
1075}; 1076#endif 1077 1078/* 1079 * MPSAFE 1080 */ 1081int 1082munlockall(td, uap) 1083 struct thread *td; 1084 struct munlockall_args *uap; 1085{ | 1115}; 1116#endif 1117 1118/* 1119 * MPSAFE 1120 */ 1121int 1122munlockall(td, uap) 1123 struct thread *td; 1124 struct munlockall_args *uap; 1125{ |
1086 /* mtx_lock(&Giant); */ 1087 /* mtx_unlock(&Giant); */ 1088 return 0; | 1126 vm_map_t map; 1127 int error; 1128 1129 map = &td->td_proc->p_vmspace->vm_map; 1130#ifndef pmap_wired_count 1131 error = suser(td); 1132 if (error) 1133 return (error); 1134#endif 1135 1136 /* Clear the MAP_WIREFUTURE flag from this vm_map. */ 1137 vm_map_lock(map); 1138 vm_map_modflags(map, 0, MAP_WIREFUTURE); 1139 vm_map_unlock(map); 1140 1141 /* Forcibly unwire all pages. */ 1142 error = vm_map_unwire(map, vm_map_min(map), vm_map_max(map), 1143 VM_MAP_WIRE_USER|VM_MAP_WIRE_HOLESOK); 1144 1145 return (error); |
1089} 1090 1091#ifndef _SYS_SYSPROTO_H_ 1092struct munlock_args { 1093 const void *addr; 1094 size_t len; 1095}; 1096#endif --- 23 unchanged lines hidden (view full) --- 1120 1121#ifndef pmap_wired_count 1122 error = suser(td); 1123 if (error) 1124 return (error); 1125#endif 1126 1127 error = vm_map_unwire(&td->td_proc->p_vmspace->vm_map, addr, | 1146} 1147 1148#ifndef _SYS_SYSPROTO_H_ 1149struct munlock_args { 1150 const void *addr; 1151 size_t len; 1152}; 1153#endif --- 23 unchanged lines hidden (view full) --- 1177 1178#ifndef pmap_wired_count 1179 error = suser(td); 1180 if (error) 1181 return (error); 1182#endif 1183 1184 error = vm_map_unwire(&td->td_proc->p_vmspace->vm_map, addr, |
1128 addr + size, TRUE); | 1185 addr + size, VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES); |
1129 return (error == KERN_SUCCESS ? 0 : ENOMEM); 1130} 1131 1132/* 1133 * vm_mmap() 1134 * 1135 * MPSAFE 1136 * --- 140 unchanged lines hidden (view full) --- 1277 } else if (flags & MAP_SHARED) { 1278 /* 1279 * Shared memory is also shared with children. 1280 */ 1281 rv = vm_map_inherit(map, *addr, *addr + size, VM_INHERIT_SHARE); 1282 if (rv != KERN_SUCCESS) 1283 (void) vm_map_remove(map, *addr, *addr + size); 1284 } | 1186 return (error == KERN_SUCCESS ? 0 : ENOMEM); 1187} 1188 1189/* 1190 * vm_mmap() 1191 * 1192 * MPSAFE 1193 * --- 140 unchanged lines hidden (view full) --- 1334 } else if (flags & MAP_SHARED) { 1335 /* 1336 * Shared memory is also shared with children. 1337 */ 1338 rv = vm_map_inherit(map, *addr, *addr + size, VM_INHERIT_SHARE); 1339 if (rv != KERN_SUCCESS) 1340 (void) vm_map_remove(map, *addr, *addr + size); 1341 } |
1342 1343 /* 1344 * If the process has requested that all future mappings 1345 * be wired, then heed this. 1346 */ 1347 if ((rv == KERN_SUCCESS) && (map->flags & MAP_WIREFUTURE)) 1348 vm_map_wire(map, *addr, *addr + size, 1349 VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES); 1350 |
|
1285 switch (rv) { 1286 case KERN_SUCCESS: 1287 return (0); 1288 case KERN_INVALID_ADDRESS: 1289 case KERN_NO_SPACE: 1290 return (ENOMEM); 1291 case KERN_PROTECTION_FAILURE: 1292 return (EACCES); 1293 default: 1294 return (EINVAL); 1295 } 1296} | 1351 switch (rv) { 1352 case KERN_SUCCESS: 1353 return (0); 1354 case KERN_INVALID_ADDRESS: 1355 case KERN_NO_SPACE: 1356 return (ENOMEM); 1357 case KERN_PROTECTION_FAILURE: 1358 return (EACCES); 1359 default: 1360 return (EINVAL); 1361 } 1362} |