sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
This commit is contained in:
kamil 2019-08-18 04:10:22 +00:00
parent 8b8cf24cd0
commit 997c4cdc97
5 changed files with 40 additions and 14 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.21 2012/11/29 02:05:38 christos Exp $
# $NetBSD: Makefile,v 1.22 2019/08/18 04:10:22 kamil Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
.include <bsd.own.mk>
@ -13,4 +13,8 @@ SRCS= sysctl.c
CPPFLAGS+= -DRUMP_ACTION
RUMPSRCS+= sysctlbyname.c sysctlgetmibinfo.c
SANITIZER_RENAME_CLASSES+= rump
SANITIZER_RENAME_FILES.rump+= ${PROG}_rumpops.c ${RUMPSRCS}
SANITIZER_RENAME_SYMBOL.rump+= sysctlbyname sysctlgetmibinfo
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: prog_ops.h,v 1.2 2010/12/13 21:48:01 pooka Exp $ */
/* $NetBSD: prog_ops.h,v 1.3 2019/08/18 04:10:22 kamil Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -32,19 +32,33 @@
#include <sys/types.h>
#ifndef CRUNCHOPS
struct sysctlnode;
struct prog_ops {
int (*op_init)(void);
int (*op_sysctl)(const int *, u_int, void *, size_t *,
const void *, size_t);
/* Indirection needed for sanitizers. */
int (*op_sysctlbyname)(const char *, void *, size_t *,
const void *, size_t);
int (*op_sysctlgetmibinfo)(const char *, int *, u_int *, char *,
size_t *, struct sysctlnode **, int);
};
extern const struct prog_ops prog_ops;
#define prog_init prog_ops.op_init
#define prog_sysctl prog_ops.op_sysctl
#define prog_sysctlbyname prog_ops.op_sysctlbyname
#define prog_sysctlgetmibinfo prog_ops.op_sysctlgetmibinfo
#else
#define prog_init ((int (*)(void))NULL)
#define prog_sysctl sysctl
#define prog_sysctlbyname sysctlbyname
#define prog_sysctlgetmibinfo sysctlgetmibinfo
#endif
#endif /* _PROG_OPS_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysctl.c,v 1.161 2018/10/30 19:41:21 kre Exp $ */
/* $NetBSD: sysctl.c,v 1.162 2019/08/18 04:10:22 kamil Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@ -68,7 +68,7 @@ __COPYRIGHT("@(#) Copyright (c) 1993\
#if 0
static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: sysctl.c,v 1.161 2018/10/30 19:41:21 kre Exp $");
__RCSID("$NetBSD: sysctl.c,v 1.162 2019/08/18 04:10:22 kamil Exp $");
#endif
#endif /* not lint */
@ -896,7 +896,7 @@ parse(char *l, regex_t *re, size_t *lastcompiled)
namelen = CTL_MAXNAME;
sz = sizeof(gsname);
if (sysctlgetmibinfo(key, &name[0], &namelen, gsname, &sz, &node,
if (prog_sysctlgetmibinfo(key, &name[0], &namelen, gsname, &sz, &node,
SYSCTL_VERSION) == -1) {
if (optional)
return;
@ -1441,7 +1441,7 @@ parse_create(char *l)
namelen = sizeof(name) / sizeof(name[0]);
sz = sizeof(gsname);
*t = '\0';
rc = sysctlgetmibinfo(nname, &name[0], &namelen,
rc = prog_sysctlgetmibinfo(nname, &name[0], &namelen,
gsname, &sz, NULL, SYSCTL_VERSION);
*t = sep[0];
if (rc == -1) {
@ -1489,7 +1489,7 @@ parse_destroy(char *l)
memset(name, 0, sizeof(name));
namelen = sizeof(name) / sizeof(name[0]);
sz = sizeof(gsname);
rc = sysctlgetmibinfo(l, &name[0], &namelen, gsname, &sz, NULL,
rc = prog_sysctlgetmibinfo(l, &name[0], &namelen, gsname, &sz, NULL,
SYSCTL_VERSION);
if (rc == -1) {
sysctlparseerror(namelen, l);
@ -1538,7 +1538,7 @@ parse_describe(char *l)
memset(name, 0, sizeof(name));
namelen = sizeof(name) / sizeof(name[0]);
sz = sizeof(gsname);
rc = sysctlgetmibinfo(l, &name[0], &namelen, gsname, &sz, NULL,
rc = prog_sysctlgetmibinfo(l, &name[0], &namelen, gsname, &sz, NULL,
SYSCTL_VERSION);
if (rc == -1) {
sysctlparseerror(namelen, l);
@ -2266,7 +2266,7 @@ kern_cp_time(HANDLER_ARGS)
if (namelen == 2 && Aflag) {
sz = sizeof(n);
rc = sysctlbyname("hw.ncpu", &n, &sz, NULL, 0);
rc = prog_sysctlbyname("hw.ncpu", &n, &sz, NULL, 0);
if (rc != 0)
return; /* XXX print an error, eh? */
n++; /* Add on space for the sum. */
@ -2414,7 +2414,7 @@ kern_cp_id(HANDLER_ARGS)
if (namelen == 2) {
sz = sizeof(n);
rc = sysctlbyname("hw.ncpu", &n, &sz, NULL, 0);
rc = prog_sysctlbyname("hw.ncpu", &n, &sz, NULL, 0);
if (rc != 0)
return; /* XXX print an error, eh? */
sz = n * sizeof(u_int64_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysctl_hostops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $ */
/* $NetBSD: sysctl_hostops.c,v 1.2 2019/08/18 04:10:22 kamil Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: sysctl_hostops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $");
__RCSID("$NetBSD: sysctl_hostops.c,v 1.2 2019/08/18 04:10:22 kamil Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -38,4 +38,8 @@ __RCSID("$NetBSD: sysctl_hostops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $");
const struct prog_ops prog_ops = {
.op_sysctl = sysctl,
.op_sysctlbyname = sysctlbyname,
.op_sysctlgetmibinfo = sysctlgetmibinfo,
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysctl_rumpops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $ */
/* $NetBSD: sysctl_rumpops.c,v 1.2 2019/08/18 04:10:22 kamil Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: sysctl_rumpops.c,v 1.1 2010/12/13 17:47:40 pooka Exp $");
__RCSID("$NetBSD: sysctl_rumpops.c,v 1.2 2019/08/18 04:10:22 kamil Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -44,4 +44,8 @@ const struct prog_ops prog_ops = {
.op_init = rumpclient_init,
.op_sysctl = rump_sys___sysctl,
.op_sysctlbyname = sysctlbyname,
.op_sysctlgetmibinfo = sysctlgetmibinfo,
};