1 //===-- sanitizer_openbsd.cc ----------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is shared between various sanitizers' runtime libraries and
9 // implements Solaris-specific functions.
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_platform.h"
17 #include "sanitizer_common.h"
18 #include "sanitizer_flags.h"
19 #include "sanitizer_internal_defs.h"
20 #include "sanitizer_libc.h"
21 #include "sanitizer_placement_new.h"
22 #include "sanitizer_platform_limits_posix.h"
23 #include "sanitizer_procmaps.h"
35 #include <sys/sysctl.h>
36 #include <sys/types.h>
39 extern char **environ;
41 namespace __sanitizer {
43 uptr internal_mmap(void *addr, size_t length, int prot, int flags, int fd,
45 return (uptr)mmap(addr, length, prot, flags, fd, offset);
48 uptr internal_munmap(void *addr, uptr length) { return munmap(addr, length); }
50 int internal_mprotect(void *addr, uptr length, int prot) {
51 return mprotect(addr, length, prot);
54 int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp,
55 const void *newp, uptr newlen) {
56 Printf("internal_sysctlbyname not implemented for OpenBSD");
61 uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
62 // On OpenBSD we cannot get the full path
65 const int Mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()};
66 if (internal_sysctl(Mib, ARRAY_SIZE(Mib), &kp, &kl, NULL, 0) != -1)
67 return internal_snprintf(buf,
68 (KI_MAXCOMLEN < buf_len ? KI_MAXCOMLEN : buf_len),
73 static void GetArgsAndEnv(char ***argv, char ***envp) {
76 int argvmib[4] = {CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV};
77 int envmib[4] = {CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ENV};
78 if (internal_sysctl(argvmib, 4, NULL, &nargv, NULL, 0) == -1) {
79 Printf("sysctl KERN_PROC_NARGV failed\n");
82 if (internal_sysctl(envmib, 4, NULL, &nenv, NULL, 0) == -1) {
83 Printf("sysctl KERN_PROC_NENV failed\n");
86 if (internal_sysctl(argvmib, 4, &argv, &nargv, NULL, 0) == -1) {
87 Printf("sysctl KERN_PROC_ARGV failed\n");
90 if (internal_sysctl(envmib, 4, &envp, &nenv, NULL, 0) == -1) {
91 Printf("sysctl KERN_PROC_ENV failed\n");
98 GetArgsAndEnv(&argv, &envp);
102 char **GetEnviron() {
104 GetArgsAndEnv(&argv, &envp);
112 } // namespace __sanitizer
114 #endif // SANITIZER_OPENBSD