kern_sysctl.c (1829d5da5355930d5cfa8ec8add8ff47dc0bebab) kern_sysctl.c (f6dfe47a145263dc5eb67fa4789925ab708709bc)
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

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

929
930 if (!arg1)
931 error = EPERM;
932 else
933 error = SYSCTL_IN(req, arg1, sizeof(int));
934 return (error);
935}
936
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

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

929
930 if (!arg1)
931 error = EPERM;
932 else
933 error = SYSCTL_IN(req, arg1, sizeof(int));
934 return (error);
935}
936
937#ifdef VIMAGE
938int
939sysctl_handle_v_int(SYSCTL_HANDLER_ARGS)
940{
941 int tmpout, error = 0;
942
943 SYSCTL_RESOLVE_V_ARG1();
944
945 /*
946 * Attempt to get a coherent snapshot by making a copy of the data.
947 */
948 tmpout = *(int *)arg1;
949 error = SYSCTL_OUT(req, &tmpout, sizeof(int));
937
950
951 if (error || !req->newptr)
952 return (error);
953
954 if (!arg1)
955 error = EPERM;
956 else
957 error = SYSCTL_IN(req, arg1, sizeof(int));
958 return (error);
959}
960#endif
961
938/*
939 * Based on on sysctl_handle_int() convert milliseconds into ticks.
940 */
941
942int
943sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS)
944{
945 int error, s, tt;
946
962/*
963 * Based on on sysctl_handle_int() convert milliseconds into ticks.
964 */
965
966int
967sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS)
968{
969 int error, s, tt;
970
947 tt = *(int *)oidp->oid_arg1;
971 SYSCTL_RESOLVE_V_ARG1();
972
973 tt = *(int *)arg1;
948 s = (int)((int64_t)tt * 1000 / hz);
949
950 error = sysctl_handle_int(oidp, &s, 0, req);
951 if (error || !req->newptr)
952 return (error);
953
954 tt = (int)((int64_t)s * hz / 1000);
955 if (tt < 1)
956 return (EINVAL);
957
974 s = (int)((int64_t)tt * 1000 / hz);
975
976 error = sysctl_handle_int(oidp, &s, 0, req);
977 if (error || !req->newptr)
978 return (error);
979
980 tt = (int)((int64_t)s * hz / 1000);
981 if (tt < 1)
982 return (EINVAL);
983
958 *(int *)oidp->oid_arg1 = tt;
984 *(int *)arg1 = tt;
959 return (0);
960}
961
962
963/*
964 * Handle a long, signed or unsigned. arg1 points to it.
965 */
966

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

1064 arg2 = (req->newlen - req->newidx);
1065 error = SYSCTL_IN(req, arg1, arg2);
1066 ((char *)arg1)[arg2] = '\0';
1067 }
1068
1069 return (error);
1070}
1071
985 return (0);
986}
987
988
989/*
990 * Handle a long, signed or unsigned. arg1 points to it.
991 */
992

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

1090 arg2 = (req->newlen - req->newidx);
1091 error = SYSCTL_IN(req, arg1, arg2);
1092 ((char *)arg1)[arg2] = '\0';
1093 }
1094
1095 return (error);
1096}
1097
1098#ifdef VIMAGE
1099int
1100sysctl_handle_v_string(SYSCTL_HANDLER_ARGS)
1101{
1102 int error=0;
1103 char *tmparg;
1104 size_t outlen;
1105
1106 SYSCTL_RESOLVE_V_ARG1();
1107
1108 /*
1109 * Attempt to get a coherent snapshot by copying to a
1110 * temporary kernel buffer.
1111 */
1112retry:
1113 outlen = strlen((char *)arg1)+1;
1114 tmparg = malloc(outlen, M_SYSCTLTMP, M_WAITOK);
1115
1116 if (strlcpy(tmparg, (char *)arg1, outlen) >= outlen) {
1117 free(tmparg, M_SYSCTLTMP);
1118 goto retry;
1119 }
1120
1121 error = SYSCTL_OUT(req, tmparg, outlen);
1122 free(tmparg, M_SYSCTLTMP);
1123
1124 if (error || !req->newptr)
1125 return (error);
1126
1127 if ((req->newlen - req->newidx) >= arg2) {
1128 error = EINVAL;
1129 } else {
1130 arg2 = (req->newlen - req->newidx);
1131 error = SYSCTL_IN(req, arg1, arg2);
1132 ((char *)arg1)[arg2] = '\0';
1133 }
1134
1135 return (error);
1136}
1137#endif
1138
1072/*
1073 * Handle any kind of opaque data.
1074 * arg1 points to it, arg2 is the size.
1075 */
1076
1077int
1078sysctl_handle_opaque(SYSCTL_HANDLER_ARGS)
1079{

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

1101 goto retry;
1102 }
1103
1104 error = SYSCTL_IN(req, arg1, arg2);
1105
1106 return (error);
1107}
1108
1139/*
1140 * Handle any kind of opaque data.
1141 * arg1 points to it, arg2 is the size.
1142 */
1143
1144int
1145sysctl_handle_opaque(SYSCTL_HANDLER_ARGS)
1146{

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

1168 goto retry;
1169 }
1170
1171 error = SYSCTL_IN(req, arg1, arg2);
1172
1173 return (error);
1174}
1175
1176#ifdef VIMAGE
1177int
1178sysctl_handle_v_opaque(SYSCTL_HANDLER_ARGS)
1179{
1180 int error, tries;
1181 u_int generation;
1182 struct sysctl_req req2;
1183
1184 SYSCTL_RESOLVE_V_ARG1();
1185
1186 tries = 0;
1187 req2 = *req;
1188retry:
1189 generation = curthread->td_generation;
1190 error = SYSCTL_OUT(req, arg1, arg2);
1191 if (error)
1192 return (error);
1193 tries++;
1194 if (generation != curthread->td_generation && tries < 3) {
1195 *req = req2;
1196 goto retry;
1197 }
1198
1199 error = SYSCTL_IN(req, arg1, arg2);
1200
1201 return (error);
1202}
1203#endif
1204
1109/*
1110 * Transfer functions to/from kernel space.
1111 * XXX: rather untested at this point
1112 */
1113static int
1114sysctl_old_kernel(struct sysctl_req *req, const void *p, size_t l)
1115{
1116 size_t i = 0;

--- 423 unchanged lines hidden ---
1205/*
1206 * Transfer functions to/from kernel space.
1207 * XXX: rather untested at this point
1208 */
1209static int
1210sysctl_old_kernel(struct sysctl_req *req, const void *p, size_t l)
1211{
1212 size_t i = 0;

--- 423 unchanged lines hidden ---