Implement P0315R4, Lambdas in unevaluated contexts.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_openbsd.cc
blob6ff8b0d10a9ce2a603f597ca20f7770c4aefa9b9
1 //===-- sanitizer_openbsd.cc ----------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is shared between various sanitizers' runtime libraries and
9 // implements Solaris-specific functions.
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_platform.h"
13 #if SANITIZER_OPENBSD
15 #include <stdio.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"
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <limits.h>
28 #include <pthread.h>
29 #include <sched.h>
30 #include <signal.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <sys/mman.h>
34 #include <sys/shm.h>
35 #include <sys/sysctl.h>
36 #include <sys/types.h>
37 #include <unistd.h>
39 extern char **environ;
41 namespace __sanitizer {
43 uptr internal_mmap(void *addr, size_t length, int prot, int flags, int fd,
44 u64 offset) {
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");
57 Die();
58 return 0;
61 uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
62 // On OpenBSD we cannot get the full path
63 struct kinfo_proc kp;
64 uptr kl;
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),
69 "%s", kp.p_comm);
70 return (uptr)0;
73 static void GetArgsAndEnv(char ***argv, char ***envp) {
74 uptr nargv;
75 uptr nenv;
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");
80 Die();
82 if (internal_sysctl(envmib, 4, NULL, &nenv, NULL, 0) == -1) {
83 Printf("sysctl KERN_PROC_NENV failed\n");
84 Die();
86 if (internal_sysctl(argvmib, 4, &argv, &nargv, NULL, 0) == -1) {
87 Printf("sysctl KERN_PROC_ARGV failed\n");
88 Die();
90 if (internal_sysctl(envmib, 4, &envp, &nenv, NULL, 0) == -1) {
91 Printf("sysctl KERN_PROC_ENV failed\n");
92 Die();
96 char **GetArgv() {
97 char **argv, **envp;
98 GetArgsAndEnv(&argv, &envp);
99 return argv;
102 void ReExec() {
103 UNIMPLEMENTED();
106 } // namespace __sanitizer
108 #endif // SANITIZER_OPENBSD