-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interceptors for the sysctl(3) API family from NetBSD
Summary: Add new interceptors for: - sysctl - sysctlbyname - sysctlgetmibinfo - sysctlnametomib - asysctl - asysctlbyname Cover the API with a new test file TestCases/NetBSD/sysctl.cc. Reviewers: joerg, vitalybuka Reviewed By: vitalybuka Subscribers: devnexen, kubamracek, llvm-commits, mgorny, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D54076 llvm-svn: 348228
- Loading branch information
1 parent
175d2b8
commit 5b8d585
Showing
3 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
compiler-rt/test/sanitizer_common/TestCases/NetBSD/sysctl.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s | ||
|
||
#include <sys/param.h> | ||
#include <sys/types.h> | ||
|
||
#include <sys/sysctl.h> | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void test_sysctl() { | ||
char buf[100]; | ||
size_t len = sizeof(buf); | ||
int mib[] = {CTL_KERN, KERN_OSTYPE}; | ||
int rv = sysctl(mib, __arraycount(mib), buf, &len, NULL, 0); | ||
assert(!rv); | ||
|
||
printf("sysctl: '%s' size: '%zu'\n", buf, len); | ||
} | ||
|
||
void test_sysctlbyname() { | ||
char buf[100]; | ||
size_t len = sizeof(buf); | ||
int mib[] = {CTL_KERN, KERN_OSTYPE}; | ||
int rv = sysctlbyname("kern.ostype", buf, &len, NULL, 0); | ||
assert(!rv); | ||
|
||
printf("sysctlbyname: '%s' size: '%zu'\n", buf, len); | ||
} | ||
|
||
void test_sysctlgetmibinfo() { | ||
int mib[CTL_MAXNAME]; | ||
unsigned int mib_len = __arraycount(mib); | ||
int rv = sysctlgetmibinfo("kern.ostype", &mib[0], &mib_len, NULL, NULL, NULL, | ||
SYSCTL_VERSION); | ||
assert(!rv); | ||
|
||
char buf[100]; | ||
size_t len = sizeof(buf); | ||
rv = sysctl(mib, mib_len, buf, &len, NULL, 0); | ||
assert(!rv); | ||
|
||
printf("sysctlgetmibinfo: '%s' size: '%zu'\n", buf, len); | ||
} | ||
|
||
void test_sysctlnametomib() { | ||
int mib[CTL_MAXNAME]; | ||
size_t mib_len = __arraycount(mib); | ||
int rv = sysctlnametomib("kern.ostype", &mib[0], &mib_len); | ||
assert(!rv); | ||
|
||
char buf[100]; | ||
size_t len = sizeof(buf); | ||
rv = sysctl(mib, mib_len, buf, &len, NULL, 0); | ||
assert(!rv); | ||
|
||
printf("sysctlnametomib: '%s' size: '%zu'\n", buf, len); | ||
} | ||
|
||
void test_asysctl() { | ||
int mib[] = {CTL_KERN, KERN_OSTYPE}; | ||
size_t len; | ||
char *buf = (char *)asysctl(mib, __arraycount(mib), &len); | ||
assert(buf); | ||
|
||
printf("asysctl: '%s' size: '%zu'\n", buf, len); | ||
|
||
free(buf); | ||
} | ||
|
||
void test_asysctlbyname() { | ||
size_t len; | ||
char *buf = (char *)asysctlbyname("kern.ostype", &len); | ||
assert(buf); | ||
|
||
printf("asysctlbyname: '%s' size: '%zu'\n", buf, len); | ||
|
||
free(buf); | ||
} | ||
|
||
int main(void) { | ||
printf("sysctl\n"); | ||
|
||
test_sysctl(); | ||
test_sysctlbyname(); | ||
test_sysctlgetmibinfo(); | ||
test_sysctlnametomib(); | ||
test_asysctl(); | ||
test_asysctlbyname(); | ||
|
||
// CHECK: sysctl | ||
// CHECK: sysctl: '{{.*}}' size: '{{.*}}' | ||
// CHECK: sysctlbyname: '{{.*}}' size: '{{.*}}' | ||
// CHECK: sysctlgetmibinfo: '{{.*}}' size: '{{.*}}' | ||
// CHECK: sysctlnametomib: '{{.*}}' size: '{{.*}}' | ||
// CHECK: asysctl: '{{.*}}' size: '{{.*}}' | ||
// CHECK: asysctlbyname: '{{.*}}' size: '{{.*}}' | ||
|
||
return 0; | ||
} |