OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
//===-- sanitizer_openbsd.cc ----------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is shared between various sanitizers' runtime libraries and
|
|
|
|
// implements Solaris-specific functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_platform.h"
|
|
|
|
#if SANITIZER_OPENBSD
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "sanitizer_common.h"
|
|
|
|
#include "sanitizer_flags.h"
|
|
|
|
#include "sanitizer_internal_defs.h"
|
|
|
|
#include "sanitizer_libc.h"
|
|
|
|
#include "sanitizer_placement_new.h"
|
|
|
|
#include "sanitizer_platform_limits_posix.h"
|
|
|
|
#include "sanitizer_procmaps.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
extern char **environ;
|
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
uptr internal_mmap(void *addr, size_t length, int prot, int flags, int fd,
|
|
|
|
u64 offset) {
|
|
|
|
return (uptr)mmap(addr, length, prot, flags, fd, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
uptr internal_munmap(void *addr, uptr length) { return munmap(addr, length); }
|
|
|
|
|
|
|
|
int internal_mprotect(void *addr, uptr length, int prot) {
|
|
|
|
return mprotect(addr, length, prot);
|
|
|
|
}
|
|
|
|
|
2018-10-22 05:17:03 +08:00
|
|
|
int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp,
|
|
|
|
const void *newp, uptr newlen) {
|
|
|
|
Printf("internal_sysctlbyname not implemented for OpenBSD");
|
|
|
|
Die();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
|
|
|
|
// On OpenBSD we cannot get the full path
|
|
|
|
struct kinfo_proc kp;
|
2018-08-31 16:10:06 +08:00
|
|
|
uptr kl;
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
const int Mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()};
|
2018-08-31 16:10:06 +08:00
|
|
|
if (internal_sysctl(Mib, ARRAY_SIZE(Mib), &kp, &kl, NULL, 0) != -1)
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
return internal_snprintf(buf,
|
|
|
|
(KI_MAXCOMLEN < buf_len ? KI_MAXCOMLEN : buf_len),
|
|
|
|
"%s", kp.p_comm);
|
|
|
|
return (uptr)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GetArgsAndEnv(char ***argv, char ***envp) {
|
2018-08-31 16:10:06 +08:00
|
|
|
uptr nargv;
|
|
|
|
uptr nenv;
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
int argvmib[4] = {CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV};
|
|
|
|
int envmib[4] = {CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ENV};
|
2018-08-31 16:10:06 +08:00
|
|
|
if (internal_sysctl(argvmib, 4, NULL, &nargv, NULL, 0) == -1) {
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
Printf("sysctl KERN_PROC_NARGV failed\n");
|
|
|
|
Die();
|
|
|
|
}
|
2018-08-31 16:10:06 +08:00
|
|
|
if (internal_sysctl(envmib, 4, NULL, &nenv, NULL, 0) == -1) {
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
Printf("sysctl KERN_PROC_NENV failed\n");
|
|
|
|
Die();
|
|
|
|
}
|
2018-08-31 16:10:06 +08:00
|
|
|
if (internal_sysctl(argvmib, 4, &argv, &nargv, NULL, 0) == -1) {
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
Printf("sysctl KERN_PROC_ARGV failed\n");
|
|
|
|
Die();
|
|
|
|
}
|
2018-08-31 16:10:06 +08:00
|
|
|
if (internal_sysctl(envmib, 4, &envp, &nenv, NULL, 0) == -1) {
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
Printf("sysctl KERN_PROC_ENV failed\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char **GetArgv() {
|
|
|
|
char **argv, **envp;
|
|
|
|
GetArgsAndEnv(&argv, &envp);
|
|
|
|
return argv;
|
|
|
|
}
|
|
|
|
|
2018-11-07 03:23:12 +08:00
|
|
|
char **GetEnviron() {
|
|
|
|
char **argv, **envp;
|
|
|
|
GetArgsAndEnv(&argv, &envp);
|
|
|
|
return envp;
|
|
|
|
}
|
|
|
|
|
OpenBSD UBsan support / common
Summary:
Sanitizer common, enable OpenBSD platform.
- Enable common interceptors as possible and create few distinct ones.
- Create necessary sanitizer_struct types.
Patch by: David CARLIER
Reviewers: krytarowski, vitalybuka, visa, kettenis
Reviewed By: vitalybuka
Subscribers: emaste, srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43909
llvm-svn: 326650
2018-03-03 20:04:40 +08:00
|
|
|
void ReExec() {
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __sanitizer
|
|
|
|
|
|
|
|
#endif // SANITIZER_OPENBSD
|