kern_sysctl.c (126121) | kern_sysctl.c (126253) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Mike Karels at Berkeley Software Design, Inc. 7 * 8 * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD --- 26 unchanged lines hidden (view full) --- 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94 40 */ 41 42#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Mike Karels at Berkeley Software Design, Inc. 7 * 8 * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD --- 26 unchanged lines hidden (view full) --- 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94 40 */ 41 42#include <sys/cdefs.h> |
43__FBSDID("$FreeBSD: head/sys/kern/kern_sysctl.c 126121 2004-02-22 12:31:44Z pjd $"); | 43__FBSDID("$FreeBSD: head/sys/kern/kern_sysctl.c 126253 2004-02-26 00:27:04Z truckman $"); |
44 45#include "opt_compat.h" 46#include "opt_mac.h" 47 48#include <sys/param.h> 49#include <sys/systm.h> 50#include <sys/kernel.h> 51#include <sys/sysctl.h> --- 923 unchanged lines hidden (view full) --- 975 req.newfunc = sysctl_new_kernel; 976 req.lock = REQ_LOCKED; 977 978 SYSCTL_LOCK(); 979 980 error = sysctl_root(0, name, namelen, &req); 981 982 if (req.lock == REQ_WIRED) | 44 45#include "opt_compat.h" 46#include "opt_mac.h" 47 48#include <sys/param.h> 49#include <sys/systm.h> 50#include <sys/kernel.h> 51#include <sys/sysctl.h> --- 923 unchanged lines hidden (view full) --- 975 req.newfunc = sysctl_new_kernel; 976 req.lock = REQ_LOCKED; 977 978 SYSCTL_LOCK(); 979 980 error = sysctl_root(0, name, namelen, &req); 981 982 if (req.lock == REQ_WIRED) |
983 vsunlock(req.oldptr, req.oldlen); | 983 kern_munlock(req.td, (vm_offset_t)req.oldptr, 984 (vm_size_t)req.wiredlen); |
984 985 SYSCTL_UNLOCK(); 986 987 if (error && error != ENOMEM) 988 return (error); 989 990 if (retval) { 991 if (req.oldptr && req.oldidx > req.oldlen) --- 28 unchanged lines hidden (view full) --- 1020 1021/* 1022 * Transfer function to/from user space. 1023 */ 1024static int 1025sysctl_old_user(struct sysctl_req *req, const void *p, size_t l) 1026{ 1027 int error = 0; | 985 986 SYSCTL_UNLOCK(); 987 988 if (error && error != ENOMEM) 989 return (error); 990 991 if (retval) { 992 if (req.oldptr && req.oldidx > req.oldlen) --- 28 unchanged lines hidden (view full) --- 1021 1022/* 1023 * Transfer function to/from user space. 1024 */ 1025static int 1026sysctl_old_user(struct sysctl_req *req, const void *p, size_t l) 1027{ 1028 int error = 0; |
1028 size_t i = 0; | 1029 size_t i, len, origidx; |
1029 | 1030 |
1030 if (req->lock == REQ_LOCKED && req->oldptr) | 1031 origidx = req->oldidx; 1032 req->oldidx += l; 1033 if (req->oldptr == NULL) 1034 return (0); 1035 if (req->lock == REQ_LOCKED) |
1031 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 1032 "sysctl_old_user()"); | 1036 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 1037 "sysctl_old_user()"); |
1033 if (req->oldptr) { 1034 i = l; 1035 if (req->oldlen <= req->oldidx) 1036 i = 0; 1037 else 1038 if (i > req->oldlen - req->oldidx) 1039 i = req->oldlen - req->oldidx; 1040 if (i > 0) 1041 error = copyout(p, (char *)req->oldptr + req->oldidx, 1042 i); | 1038 i = l; 1039 len = (req->lock == REQ_WIRED) ? req->wiredlen : req->oldlen; 1040 if (len <= origidx) 1041 i = 0; 1042 else { 1043 if (i > len - origidx) 1044 i = len - origidx; 1045 error = copyout(p, (char *)req->oldptr + origidx, i); |
1043 } | 1046 } |
1044 req->oldidx += l; | |
1045 if (error) 1046 return (error); | 1047 if (error) 1048 return (error); |
1047 if (req->oldptr && i < l) | 1049 if (i < l) |
1048 return (ENOMEM); 1049 return (0); 1050} 1051 1052static int 1053sysctl_new_user(struct sysctl_req *req, void *p, size_t l) 1054{ 1055 int error; --- 10 unchanged lines hidden (view full) --- 1066/* 1067 * Wire the user space destination buffer. If set to a value greater than 1068 * zero, the len parameter limits the maximum amount of wired memory. 1069 * 1070 * XXX - The len parameter is currently ignored due to the lack of 1071 * a place to save it in the sysctl_req structure so that the matching 1072 * amount of memory can be unwired in the sysctl exit code. 1073 */ | 1050 return (ENOMEM); 1051 return (0); 1052} 1053 1054static int 1055sysctl_new_user(struct sysctl_req *req, void *p, size_t l) 1056{ 1057 int error; --- 10 unchanged lines hidden (view full) --- 1068/* 1069 * Wire the user space destination buffer. If set to a value greater than 1070 * zero, the len parameter limits the maximum amount of wired memory. 1071 * 1072 * XXX - The len parameter is currently ignored due to the lack of 1073 * a place to save it in the sysctl_req structure so that the matching 1074 * amount of memory can be unwired in the sysctl exit code. 1075 */ |
1074void | 1076int |
1075sysctl_wire_old_buffer(struct sysctl_req *req, size_t len) 1076{ | 1077sysctl_wire_old_buffer(struct sysctl_req *req, size_t len) 1078{ |
1079 int ret; 1080 size_t wiredlen; 1081 1082 wiredlen = (len > 0 && len < req->oldlen) ? len : req->oldlen; 1083 ret = 0; |
|
1077 if (req->lock == REQ_LOCKED && req->oldptr && 1078 req->oldfunc == sysctl_old_user) { | 1084 if (req->lock == REQ_LOCKED && req->oldptr && 1085 req->oldfunc == sysctl_old_user) { |
1079 vslock(req->oldptr, req->oldlen); 1080 req->lock = REQ_WIRED; | 1086 ret = kern_mlock(req->td, (vm_offset_t)req->oldptr, 1087 (vm_size_t)wiredlen); 1088 if (ret == 0) { 1089 req->lock = REQ_WIRED; 1090 req->wiredlen = wiredlen; 1091 } |
1081 } | 1092 } |
1093 return (ret); |
|
1082} 1083 1084int 1085sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid, 1086 int *nindx, struct sysctl_req *req) 1087{ 1088 struct sysctl_oid *oid; 1089 int indx; --- 193 unchanged lines hidden (view full) --- 1283 1284 do { 1285 req2 = req; 1286 error = sysctl_root(0, name, namelen, &req2); 1287 } while (error == EAGAIN); 1288 1289 req = req2; 1290 if (req.lock == REQ_WIRED) | 1094} 1095 1096int 1097sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid, 1098 int *nindx, struct sysctl_req *req) 1099{ 1100 struct sysctl_oid *oid; 1101 int indx; --- 193 unchanged lines hidden (view full) --- 1295 1296 do { 1297 req2 = req; 1298 error = sysctl_root(0, name, namelen, &req2); 1299 } while (error == EAGAIN); 1300 1301 req = req2; 1302 if (req.lock == REQ_WIRED) |
1291 vsunlock(req.oldptr, req.oldlen); | 1303 kern_munlock(req.td, (vm_offset_t)req.oldptr, 1304 (vm_size_t)req.wiredlen); |
1292 1293 SYSCTL_UNLOCK(); 1294 1295 if (error && error != ENOMEM) 1296 return (error); 1297 1298 if (retval) { 1299 if (req.oldptr && req.oldidx > req.oldlen) --- 223 unchanged lines hidden --- | 1305 1306 SYSCTL_UNLOCK(); 1307 1308 if (error && error != ENOMEM) 1309 return (error); 1310 1311 if (retval) { 1312 if (req.oldptr && req.oldidx > req.oldlen) --- 223 unchanged lines hidden --- |