mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-27 05:21:08 +01:00
Introduce signed and unsigned version of CTLTYPE_QUAD, renaming
existing uses. Rename sysctl_handle_quad() to sysctl_handle_64().
This commit is contained in:
parent
2634879bbb
commit
cbc134ad03
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=217616
@ -381,10 +381,14 @@ jailparam_import(struct jailparam *jp, const char *value)
|
||||
((unsigned long *)jp->jp_value)[i] =
|
||||
strtoul(avalue, &ep, 10);
|
||||
goto integer_test;
|
||||
case CTLTYPE_QUAD:
|
||||
case CTLTYPE_S64:
|
||||
((int64_t *)jp->jp_value)[i] =
|
||||
strtoimax(avalue, &ep, 10);
|
||||
goto integer_test;
|
||||
case CTLTYPE_U64:
|
||||
((uint64_t *)jp->jp_value)[i] =
|
||||
strtoumax(avalue, &ep, 10);
|
||||
goto integer_test;
|
||||
case CTLTYPE_STRUCT:
|
||||
tvalue = alloca(fw + 1);
|
||||
strlcpy(tvalue, avalue, fw + 1);
|
||||
@ -768,10 +772,14 @@ jailparam_export(struct jailparam *jp)
|
||||
snprintf(valbuf, sizeof(valbuf), "%lu",
|
||||
((unsigned long *)jp->jp_value)[i]);
|
||||
break;
|
||||
case CTLTYPE_QUAD:
|
||||
case CTLTYPE_S64:
|
||||
snprintf(valbuf, sizeof(valbuf), "%jd",
|
||||
(intmax_t)((int64_t *)jp->jp_value)[i]);
|
||||
break;
|
||||
case CTLTYPE_U64:
|
||||
snprintf(valbuf, sizeof(valbuf), "%ju",
|
||||
(uintmax_t)((uint64_t *)jp->jp_value)[i]);
|
||||
break;
|
||||
case CTLTYPE_STRUCT:
|
||||
switch (jp->jp_structtype) {
|
||||
case JPS_IN_ADDR:
|
||||
@ -941,7 +949,8 @@ jailparam_type(struct jailparam *jp)
|
||||
case CTLTYPE_ULONG:
|
||||
jp->jp_valuelen = sizeof(long);
|
||||
break;
|
||||
case CTLTYPE_QUAD:
|
||||
case CTLTYPE_S64:
|
||||
case CTLTYPE_U64:
|
||||
jp->jp_valuelen = sizeof(int64_t);
|
||||
break;
|
||||
case CTLTYPE_STRING:
|
||||
|
@ -170,7 +170,8 @@ parse(char *string)
|
||||
long longval;
|
||||
unsigned long ulongval;
|
||||
size_t newsize = 0;
|
||||
quad_t quadval;
|
||||
int64_t i64val;
|
||||
uint64_t u64val;
|
||||
int mib[CTL_MAXNAME];
|
||||
char *cp, *bufp, buf[BUFSIZ], *endptr, fmt[BUFSIZ];
|
||||
u_int kind;
|
||||
@ -230,7 +231,8 @@ parse(char *string)
|
||||
(kind & CTLTYPE) == CTLTYPE_UINT ||
|
||||
(kind & CTLTYPE) == CTLTYPE_LONG ||
|
||||
(kind & CTLTYPE) == CTLTYPE_ULONG ||
|
||||
(kind & CTLTYPE) == CTLTYPE_QUAD) {
|
||||
(kind & CTLTYPE) == CTLTYPE_S64 ||
|
||||
(kind & CTLTYPE) == CTLTYPE_U64) {
|
||||
if (strlen(newval) == 0)
|
||||
errx(1, "empty numeric value");
|
||||
}
|
||||
@ -277,13 +279,21 @@ parse(char *string)
|
||||
break;
|
||||
case CTLTYPE_STRING:
|
||||
break;
|
||||
case CTLTYPE_QUAD:
|
||||
quadval = strtoq(newval, &endptr, 0);
|
||||
case CTLTYPE_S64:
|
||||
i64val = strtoimax(newval, &endptr, 0);
|
||||
if (endptr == newval || *endptr != '\0')
|
||||
errx(1, "invalid quad integer"
|
||||
" '%s'", (char *)newval);
|
||||
newval = &quadval;
|
||||
newsize = sizeof(quadval);
|
||||
errx(1, "invalid int64_t '%s'",
|
||||
(char *)newval);
|
||||
newval = &i64val;
|
||||
newsize = sizeof(i64val);
|
||||
break;
|
||||
case CTLTYPE_U64:
|
||||
u64val = strtoumax(newval, &endptr, 0);
|
||||
if (endptr == newval || *endptr != '\0')
|
||||
errx(1, "invalid uint64_t '%s'",
|
||||
(char *)newval);
|
||||
newval = &u64val;
|
||||
newsize = sizeof(u64val);
|
||||
break;
|
||||
case CTLTYPE_OPAQUE:
|
||||
/* FALLTHROUGH */
|
||||
@ -493,6 +503,21 @@ oidfmt(int *oid, int len, char *fmt, u_int *kind)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int ctl_sign[CTLTYPE+1] = {
|
||||
[CTLTYPE_INT] = 1,
|
||||
[CTLTYPE_LONG] = 1,
|
||||
[CTLTYPE_S64] = 1,
|
||||
};
|
||||
|
||||
static int ctl_size[CTLTYPE+1] = {
|
||||
[CTLTYPE_INT] = sizeof(int),
|
||||
[CTLTYPE_UINT] = sizeof(u_int),
|
||||
[CTLTYPE_LONG] = sizeof(long),
|
||||
[CTLTYPE_ULONG] = sizeof(u_long),
|
||||
[CTLTYPE_S64] = sizeof(int64_t),
|
||||
[CTLTYPE_U64] = sizeof(int64_t),
|
||||
};
|
||||
|
||||
/*
|
||||
* This formats and outputs the value of one variable
|
||||
*
|
||||
@ -500,7 +525,6 @@ oidfmt(int *oid, int len, char *fmt, u_int *kind)
|
||||
* Returns one if didn't know what to do with this.
|
||||
* Return minus one if we had errors.
|
||||
*/
|
||||
|
||||
static int
|
||||
show_var(int *oid, int nlen)
|
||||
{
|
||||
@ -576,7 +600,9 @@ show_var(int *oid, int nlen)
|
||||
oidfmt(oid, nlen, fmt, &kind);
|
||||
p = val;
|
||||
ctltype = (kind & CTLTYPE);
|
||||
sign = (ctltype == CTLTYPE_INT || ctltype == CTLTYPE_LONG) ? 1 : 0;
|
||||
sign = ctl_sign[ctltype];
|
||||
intlen = ctl_size[ctltype];
|
||||
|
||||
switch (ctltype) {
|
||||
case CTLTYPE_STRING:
|
||||
if (!nflag)
|
||||
@ -589,19 +615,10 @@ show_var(int *oid, int nlen)
|
||||
case CTLTYPE_UINT:
|
||||
case CTLTYPE_LONG:
|
||||
case CTLTYPE_ULONG:
|
||||
case CTLTYPE_QUAD:
|
||||
case CTLTYPE_S64:
|
||||
case CTLTYPE_U64:
|
||||
if (!nflag)
|
||||
printf("%s%s", name, sep);
|
||||
switch (kind & CTLTYPE) {
|
||||
case CTLTYPE_INT:
|
||||
case CTLTYPE_UINT:
|
||||
intlen = sizeof(int); break;
|
||||
case CTLTYPE_LONG:
|
||||
case CTLTYPE_ULONG:
|
||||
intlen = sizeof(long); break;
|
||||
case CTLTYPE_QUAD:
|
||||
intlen = sizeof(quad_t); break;
|
||||
}
|
||||
hexlen = 2 + (intlen * CHAR_BIT + 3) / 4;
|
||||
sep1 = "";
|
||||
while (len >= intlen) {
|
||||
@ -616,9 +633,10 @@ show_var(int *oid, int nlen)
|
||||
umv = *(u_long *)p;
|
||||
mv = *(long *)p;
|
||||
break;
|
||||
case CTLTYPE_QUAD:
|
||||
umv = *(u_quad_t *)p;
|
||||
mv = *(quad_t *)p;
|
||||
case CTLTYPE_S64:
|
||||
case CTLTYPE_U64:
|
||||
umv = *(uint64_t *)p;
|
||||
mv = *(int64_t *)p;
|
||||
break;
|
||||
}
|
||||
fputs(sep1, stdout);
|
||||
|
@ -101,7 +101,7 @@ This is a node intended to be a parent for other nodes.
|
||||
This is a signed integer.
|
||||
.It Dv CTLTYPE_STRING
|
||||
This is a nul-terminated string stored in a character array.
|
||||
.It Dv CTLTYPE_QUAD
|
||||
.It Dv CTLTYPE_S64
|
||||
This is a 64-bit signed integer.
|
||||
.It Dv CTLTYPE_OPAQUE
|
||||
This is an opaque data structure.
|
||||
@ -114,6 +114,8 @@ This is an unsigned integer.
|
||||
This is a signed long.
|
||||
.It Dv CTLTYPE_ULONG
|
||||
This is an unsigned long.
|
||||
.It Dv CTLTYPE_U64
|
||||
This is a 64-bit unsigned integer.
|
||||
.El
|
||||
.Pp
|
||||
All sysctl types except for new node declarations require one or more flags
|
||||
|
@ -102,7 +102,7 @@ kstat_sysctl(SYSCTL_HANDLER_ARGS)
|
||||
uint64_t val;
|
||||
|
||||
val = ksent->value.ui64;
|
||||
return sysctl_handle_quad(oidp, &val, 0, req);
|
||||
return sysctl_handle_64(oidp, &val, 0, req);
|
||||
}
|
||||
|
||||
void
|
||||
@ -117,7 +117,7 @@ kstat_install(kstat_t *ksp)
|
||||
("data_type=%d", ksent->data_type));
|
||||
SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
|
||||
SYSCTL_CHILDREN(ksp->ks_sysctl_root), OID_AUTO, ksent->name,
|
||||
CTLTYPE_QUAD | CTLFLAG_RD, ksent, sizeof(*ksent),
|
||||
CTLTYPE_U64 | CTLFLAG_RD, ksent, sizeof(*ksent),
|
||||
kstat_sysctl, "QU", "");
|
||||
}
|
||||
}
|
||||
|
@ -3541,7 +3541,7 @@ sysctl_handle_macstat(SYSCTL_HANDLER_ARGS)
|
||||
t3_mac_update_stats(&p->mac);
|
||||
PORT_UNLOCK(p);
|
||||
|
||||
return (sysctl_handle_quad(oidp, parg, 0, req));
|
||||
return (sysctl_handle_64(oidp, parg, 0, req));
|
||||
}
|
||||
|
||||
void
|
||||
@ -3741,7 +3741,7 @@ t3_add_configured_sysctls(adapter_t *sc)
|
||||
* all that here.
|
||||
*/
|
||||
#define CXGB_SYSCTL_ADD_QUAD(a) SYSCTL_ADD_OID(ctx, poidlist, OID_AUTO, #a, \
|
||||
(CTLTYPE_QUAD | CTLFLAG_RD), pi, offsetof(struct mac_stats, a), \
|
||||
(CTLTYPE_U64 | CTLFLAG_RD), pi, offsetof(struct mac_stats, a), \
|
||||
sysctl_handle_macstat, "QU", 0)
|
||||
CXGB_SYSCTL_ADD_QUAD(tx_octets);
|
||||
CXGB_SYSCTL_ADD_QUAD(tx_octets_bad);
|
||||
|
@ -4378,7 +4378,7 @@ msk_sysctl_stat64(SYSCTL_HANDLER_ARGS)
|
||||
result += *stat;
|
||||
MSK_IF_UNLOCK(sc_if);
|
||||
|
||||
return (sysctl_handle_quad(oidp, &result, 0, req));
|
||||
return (sysctl_handle_64(oidp, &result, 0, req));
|
||||
}
|
||||
|
||||
#undef MSK_READ_MIB32
|
||||
@ -4389,9 +4389,9 @@ msk_sysctl_stat64(SYSCTL_HANDLER_ARGS)
|
||||
sc, offsetof(struct msk_hw_stats, n), msk_sysctl_stat32, \
|
||||
"IU", d)
|
||||
#define MSK_SYSCTL_STAT64(sc, c, o, p, n, d) \
|
||||
SYSCTL_ADD_PROC(c, p, OID_AUTO, o, CTLTYPE_QUAD | CTLFLAG_RD, \
|
||||
SYSCTL_ADD_PROC(c, p, OID_AUTO, o, CTLTYPE_U64 | CTLFLAG_RD, \
|
||||
sc, offsetof(struct msk_hw_stats, n), msk_sysctl_stat64, \
|
||||
"Q", d)
|
||||
"QU", d)
|
||||
|
||||
static void
|
||||
msk_sysctl_node(struct msk_if_softc *sc_if)
|
||||
|
@ -615,8 +615,12 @@ sysctl_sysctl_debug_dump_node(struct sysctl_oid_list *l, int i)
|
||||
}
|
||||
break;
|
||||
case CTLTYPE_INT: printf(" Int\n"); break;
|
||||
case CTLTYPE_UINT: printf(" u_int\n"); break;
|
||||
case CTLTYPE_LONG: printf(" Long\n"); break;
|
||||
case CTLTYPE_ULONG: printf(" u_long\n"); break;
|
||||
case CTLTYPE_STRING: printf(" String\n"); break;
|
||||
case CTLTYPE_QUAD: printf(" Quad\n"); break;
|
||||
case CTLTYPE_U64: printf(" uint64_t\n"); break;
|
||||
case CTLTYPE_S64: printf(" int64_t\n"); break;
|
||||
case CTLTYPE_OPAQUE: printf(" Opaque/struct\n"); break;
|
||||
default: printf("\n");
|
||||
}
|
||||
@ -1035,9 +1039,8 @@ sysctl_handle_long(SYSCTL_HANDLER_ARGS)
|
||||
/*
|
||||
* Handle a 64 bit int, signed or unsigned. arg1 points to it.
|
||||
*/
|
||||
|
||||
int
|
||||
sysctl_handle_quad(SYSCTL_HANDLER_ARGS)
|
||||
sysctl_handle_64(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
int error = 0;
|
||||
uint64_t tmpout;
|
||||
|
@ -140,7 +140,7 @@ sysctl_kern_timecounter_freq(SYSCTL_HANDLER_ARGS)
|
||||
struct timecounter *tc = arg1;
|
||||
|
||||
freq = tc->tc_frequency;
|
||||
return sysctl_handle_quad(oidp, &freq, 0, req);
|
||||
return sysctl_handle_64(oidp, &freq, 0, req);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -341,7 +341,7 @@ tc_init(struct timecounter *tc)
|
||||
"counter", CTLTYPE_UINT | CTLFLAG_RD, tc, sizeof(*tc),
|
||||
sysctl_kern_timecounter_get, "IU", "current timecounter value");
|
||||
SYSCTL_ADD_PROC(NULL, SYSCTL_CHILDREN(tc_root), OID_AUTO,
|
||||
"frequency", CTLTYPE_QUAD | CTLFLAG_RD, tc, sizeof(*tc),
|
||||
"frequency", CTLTYPE_U64 | CTLFLAG_RD, tc, sizeof(*tc),
|
||||
sysctl_kern_timecounter_freq, "QU", "timecounter frequency");
|
||||
SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(tc_root), OID_AUTO,
|
||||
"quality", CTLFLAG_RD, &(tc->tc_quality), 0,
|
||||
|
@ -165,7 +165,7 @@ sysctl_machdep_counter_freq(SYSCTL_HANDLER_ARGS)
|
||||
if (softc == NULL)
|
||||
return (EOPNOTSUPP);
|
||||
freq = counter_freq;
|
||||
error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
|
||||
error = sysctl_handle_64(oidp, &freq, sizeof(freq), req);
|
||||
if (error == 0 && req->newptr != NULL) {
|
||||
counter_freq = freq;
|
||||
softc->et.et_frequency = counter_freq;
|
||||
@ -174,8 +174,8 @@ sysctl_machdep_counter_freq(SYSCTL_HANDLER_ARGS)
|
||||
return (error);
|
||||
}
|
||||
|
||||
SYSCTL_PROC(_machdep, OID_AUTO, counter_freq, CTLTYPE_QUAD | CTLFLAG_RW,
|
||||
0, sizeof(u_int), sysctl_machdep_counter_freq, "IU",
|
||||
SYSCTL_PROC(_machdep, OID_AUTO, counter_freq, CTLTYPE_U64 | CTLFLAG_RW,
|
||||
NULL, 0, sysctl_machdep_counter_freq, "QU",
|
||||
"Timecounter frequency in Hz");
|
||||
|
||||
static unsigned
|
||||
|
@ -167,7 +167,7 @@ sysctl_machdep_counter_freq(SYSCTL_HANDLER_ARGS)
|
||||
if (softc == NULL)
|
||||
return (EOPNOTSUPP);
|
||||
freq = counter_freq;
|
||||
error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
|
||||
error = sysctl_handle_64(oidp, &freq, sizeof(freq), req);
|
||||
if (error == 0 && req->newptr != NULL) {
|
||||
counter_freq = freq;
|
||||
softc->et.et_frequency = counter_freq;
|
||||
@ -176,8 +176,8 @@ sysctl_machdep_counter_freq(SYSCTL_HANDLER_ARGS)
|
||||
return (error);
|
||||
}
|
||||
|
||||
SYSCTL_PROC(_machdep, OID_AUTO, counter_freq, CTLTYPE_QUAD | CTLFLAG_RW,
|
||||
0, sizeof(u_int), sysctl_machdep_counter_freq, "IU",
|
||||
SYSCTL_PROC(_machdep, OID_AUTO, counter_freq, CTLTYPE_U64 | CTLFLAG_RW,
|
||||
NULL, 0, sysctl_machdep_counter_freq, "QU",
|
||||
"Timecounter frequency in Hz");
|
||||
|
||||
static unsigned
|
||||
|
@ -66,12 +66,13 @@ struct ctlname {
|
||||
#define CTLTYPE_NODE 1 /* name is a node */
|
||||
#define CTLTYPE_INT 2 /* name describes an integer */
|
||||
#define CTLTYPE_STRING 3 /* name describes a string */
|
||||
#define CTLTYPE_QUAD 4 /* name describes a 64-bit number */
|
||||
#define CTLTYPE_S64 4 /* name describes a signed 64-bit number */
|
||||
#define CTLTYPE_OPAQUE 5 /* name describes a structure */
|
||||
#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
|
||||
#define CTLTYPE_UINT 6 /* name describes an unsigned integer */
|
||||
#define CTLTYPE_LONG 7 /* name describes a long */
|
||||
#define CTLTYPE_ULONG 8 /* name describes an unsigned long */
|
||||
#define CTLTYPE_U64 9 /* name describes an unsigned 64-bit number */
|
||||
|
||||
#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
|
||||
#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
|
||||
@ -176,8 +177,7 @@ struct sysctl_oid {
|
||||
int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_quad(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_intptr(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_64(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
|
||||
int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
|
||||
|
||||
@ -354,26 +354,26 @@ SYSCTL_ALLOWED_TYPES(UINT64, uint64_t *a; unsigned long long *b; );
|
||||
#define SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr) \
|
||||
SYSCTL_ASSERT_TYPE(INT64, ptr, parent, name); \
|
||||
SYSCTL_OID(parent, nbr, name, \
|
||||
CTLTYPE_QUAD | CTLFLAG_MPSAFE | (access), \
|
||||
ptr, val, sysctl_handle_quad, "Q", descr)
|
||||
CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \
|
||||
ptr, val, sysctl_handle_64, "Q", descr)
|
||||
|
||||
#define SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr) \
|
||||
sysctl_add_oid(ctx, parent, nbr, name, \
|
||||
CTLTYPE_QUAD | CTLFLAG_MPSAFE | (access), \
|
||||
CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \
|
||||
SYSCTL_ADD_ASSERT_TYPE(INT64, ptr), 0, \
|
||||
sysctl_handle_quad, "Q", __DESCR(descr))
|
||||
sysctl_handle_64, "Q", __DESCR(descr))
|
||||
|
||||
#define SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr) \
|
||||
SYSCTL_ASSERT_TYPE(UINT64, ptr, parent, name); \
|
||||
SYSCTL_OID(parent, nbr, name, \
|
||||
CTLTYPE_QUAD | CTLFLAG_MPSAFE | (access), \
|
||||
ptr, val, sysctl_handle_quad, "QU", descr)
|
||||
CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \
|
||||
ptr, val, sysctl_handle_64, "QU", descr)
|
||||
|
||||
#define SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr) \
|
||||
sysctl_add_oid(ctx, parent, nbr, name, \
|
||||
CTLTYPE_QUAD | CTLFLAG_MPSAFE | (access), \
|
||||
CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \
|
||||
SYSCTL_ADD_ASSERT_TYPE(UINT64, ptr), 0, \
|
||||
sysctl_handle_quad, "QU", __DESCR(descr))
|
||||
sysctl_handle_64, "QU", __DESCR(descr))
|
||||
|
||||
/* Oid for an opaque object. Specified by a pointer and a length. */
|
||||
#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
|
||||
|
@ -263,7 +263,7 @@ sysctl_machdep_tsc_freq(SYSCTL_HANDLER_ARGS)
|
||||
if (tsc_timecounter.tc_frequency == 0)
|
||||
return (EOPNOTSUPP);
|
||||
freq = tsc_freq;
|
||||
error = sysctl_handle_quad(oidp, &freq, 0, req);
|
||||
error = sysctl_handle_64(oidp, &freq, 0, req);
|
||||
if (error == 0 && req->newptr != NULL) {
|
||||
tsc_freq = freq;
|
||||
tsc_timecounter.tc_frequency = tsc_freq;
|
||||
@ -271,7 +271,7 @@ sysctl_machdep_tsc_freq(SYSCTL_HANDLER_ARGS)
|
||||
return (error);
|
||||
}
|
||||
|
||||
SYSCTL_PROC(_machdep, OID_AUTO, tsc_freq, CTLTYPE_QUAD | CTLFLAG_RW,
|
||||
SYSCTL_PROC(_machdep, OID_AUTO, tsc_freq, CTLTYPE_U64 | CTLFLAG_RW,
|
||||
0, 0, sysctl_machdep_tsc_freq, "QU", "");
|
||||
|
||||
static unsigned
|
||||
|
Loading…
Reference in New Issue
Block a user