2013-02-27 19:22:40 +08:00
|
|
|
//===-- sanitizer_linux.h ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Linux-specific syscall wrappers and classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SANITIZER_LINUX_H
|
|
|
|
#define SANITIZER_LINUX_H
|
|
|
|
|
2013-09-10 22:36:16 +08:00
|
|
|
#include "sanitizer_platform.h"
|
2018-03-17 06:29:29 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
|
|
|
|
SANITIZER_OPENBSD || SANITIZER_SOLARIS
|
2013-04-05 15:41:21 +08:00
|
|
|
#include "sanitizer_common.h"
|
2013-02-27 19:22:40 +08:00
|
|
|
#include "sanitizer_internal_defs.h"
|
2017-08-29 05:03:23 +08:00
|
|
|
#include "sanitizer_platform_limits_netbsd.h"
|
2018-03-17 06:29:29 +08:00
|
|
|
#include "sanitizer_platform_limits_openbsd.h"
|
2013-10-15 20:57:59 +08:00
|
|
|
#include "sanitizer_platform_limits_posix.h"
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
#include "sanitizer_platform_limits_solaris.h"
|
2017-08-29 05:03:23 +08:00
|
|
|
#include "sanitizer_posix.h"
|
2013-02-27 19:22:40 +08:00
|
|
|
|
2013-07-30 03:09:49 +08:00
|
|
|
struct link_map; // Opaque type returned by dlopen().
|
2013-02-27 19:22:40 +08:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
// Dirent structure for getdents(). Note that this structure is different from
|
|
|
|
// the one in <dirent.h>, which is used by readdir().
|
|
|
|
struct linux_dirent;
|
|
|
|
|
Removed platform-specific ifdefs from sanitizer_procmaps.h
Summary: Removed platform-specific ifdefs for linux, mac, freebsd and netbsd from sanitizer_procmaps.h
Patch by Yicheng Wang <yichengfb@fb.com>
Reviewers: kcc, kubamracek, alekseyshl, fjricci, vitalybuka
Reviewed By: fjricci, vitalybuka
Subscribers: vitalybuka, emaste, krytarowski, llvm-commits
Differential Revision: https://reviews.llvm.org/D38098
llvm-svn: 313999
2017-09-23 01:48:24 +08:00
|
|
|
struct ProcSelfMapsBuff {
|
|
|
|
char *data;
|
|
|
|
uptr mmaped_size;
|
|
|
|
uptr len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MemoryMappingLayoutData {
|
|
|
|
ProcSelfMapsBuff proc_self_maps;
|
|
|
|
const char *current;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ReadProcMaps(ProcSelfMapsBuff *proc_maps);
|
|
|
|
|
2013-02-27 19:22:40 +08:00
|
|
|
// Syscall wrappers.
|
2013-05-08 22:43:49 +08:00
|
|
|
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
|
2017-07-14 05:59:01 +08:00
|
|
|
uptr internal_sigaltstack(const void* ss, void* oss);
|
2014-01-31 19:29:51 +08:00
|
|
|
uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
|
|
|
|
__sanitizer_sigset_t *oldset);
|
2017-12-14 00:23:54 +08:00
|
|
|
uptr internal_clock_gettime(__sanitizer_clockid_t clk_id, void *tp);
|
2014-03-07 18:03:54 +08:00
|
|
|
|
|
|
|
// Linux-only syscalls.
|
|
|
|
#if SANITIZER_LINUX
|
|
|
|
uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5);
|
2014-01-31 19:29:51 +08:00
|
|
|
// Used only by sanitizer_stoptheworld. Signal handlers that are actually used
|
|
|
|
// (like the process-wide error reporting SEGV handler) must use
|
|
|
|
// internal_sigaction instead.
|
|
|
|
int internal_sigaction_norestorer(int signum, const void *act, void *oldact);
|
2016-10-06 17:58:11 +08:00
|
|
|
#if (defined(__x86_64__) || SANITIZER_MIPS64) && !SANITIZER_GO
|
[sanitizer][esan] Add internal_sigaction_syscall
Summary:
Adds a version of sigaction that uses a raw system call, to avoid circular
dependencies and support calling sigaction prior to setting up
interceptors. The new sigaction relies on an assembly sigreturn routine
for its restorer, which is Linux x86_64-only for now.
Uses the new sigaction to initialize the working set tool's shadow fault
handler prior to libc interceptor being set up. This is required to
support instrumentation invoked during interceptor setup, which happens
with an instrumented tcmalloc or other allocator compiled with esan.
Adds a test that emulates an instrumented allocator.
Reviewers: aizatsky
Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka
Differential Revision: http://reviews.llvm.org/D21083
llvm-svn: 272676
2016-06-14 23:15:38 +08:00
|
|
|
// Uses a raw system call to avoid interceptors.
|
|
|
|
int internal_sigaction_syscall(int signum, const void *act, void *oldact);
|
|
|
|
#endif
|
2014-03-07 18:03:54 +08:00
|
|
|
void internal_sigdelset(__sanitizer_sigset_t *set, int signum);
|
2015-12-09 05:54:39 +08:00
|
|
|
#if defined(__x86_64__) || defined(__mips__) || defined(__aarch64__) \
|
2017-04-11 22:58:26 +08:00
|
|
|
|| defined(__powerpc64__) || defined(__s390__) || defined(__i386__) \
|
|
|
|
|| defined(__arm__)
|
2013-09-02 19:36:19 +08:00
|
|
|
uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
|
|
|
|
int *parent_tidptr, void *newtls, int *child_tidptr);
|
|
|
|
#endif
|
2014-03-07 18:03:54 +08:00
|
|
|
#endif // SANITIZER_LINUX
|
2013-02-27 19:22:40 +08:00
|
|
|
|
|
|
|
// This class reads thread IDs from /proc/<pid>/task using only syscalls.
|
|
|
|
class ThreadLister {
|
|
|
|
public:
|
2018-05-10 05:21:26 +08:00
|
|
|
explicit ThreadLister(pid_t pid);
|
2013-02-27 19:22:40 +08:00
|
|
|
~ThreadLister();
|
2018-05-10 05:21:26 +08:00
|
|
|
bool ListThreads(InternalMmapVector<tid_t> *threads);
|
2013-02-27 19:22:40 +08:00
|
|
|
|
|
|
|
private:
|
2018-05-10 05:21:26 +08:00
|
|
|
pid_t pid_;
|
2018-05-08 07:29:48 +08:00
|
|
|
int descriptor_ = -1;
|
2018-05-07 13:56:36 +08:00
|
|
|
InternalMmapVector<char> buffer_;
|
2013-02-27 19:22:40 +08:00
|
|
|
};
|
2013-03-19 17:30:52 +08:00
|
|
|
|
2013-05-07 22:41:43 +08:00
|
|
|
// Exposed for testing.
|
|
|
|
uptr ThreadDescriptorSize();
|
2013-05-29 21:07:42 +08:00
|
|
|
uptr ThreadSelf();
|
|
|
|
uptr ThreadSelfOffset();
|
2013-05-07 22:41:43 +08:00
|
|
|
|
2013-05-14 21:24:46 +08:00
|
|
|
// Matches a library's file name against a base name (stripping path and version
|
|
|
|
// information).
|
|
|
|
bool LibraryNameIs(const char *full_name, const char *base_name);
|
|
|
|
|
2013-07-30 03:09:49 +08:00
|
|
|
// Call cb for each region mapped by map.
|
|
|
|
void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr));
|
2017-05-02 23:13:36 +08:00
|
|
|
|
|
|
|
#if SANITIZER_ANDROID
|
|
|
|
|
|
|
|
#if defined(__aarch64__)
|
|
|
|
# define __get_tls() \
|
|
|
|
({ void** __v; __asm__("mrs %0, tpidr_el0" : "=r"(__v)); __v; })
|
|
|
|
#elif defined(__arm__)
|
|
|
|
# define __get_tls() \
|
|
|
|
({ void** __v; __asm__("mrc p15, 0, %0, c13, c0, 3" : "=r"(__v)); __v; })
|
|
|
|
#elif defined(__mips__)
|
|
|
|
// On mips32r1, this goes via a kernel illegal instruction trap that's
|
|
|
|
// optimized for v1.
|
|
|
|
# define __get_tls() \
|
|
|
|
({ register void** __v asm("v1"); \
|
|
|
|
__asm__(".set push\n" \
|
|
|
|
".set mips32r2\n" \
|
|
|
|
"rdhwr %0,$29\n" \
|
|
|
|
".set pop\n" : "=r"(__v)); \
|
|
|
|
__v; })
|
|
|
|
#elif defined(__i386__)
|
|
|
|
# define __get_tls() \
|
|
|
|
({ void** __v; __asm__("movl %%gs:0, %0" : "=r"(__v)); __v; })
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
# define __get_tls() \
|
|
|
|
({ void** __v; __asm__("mov %%fs:0, %0" : "=r"(__v)); __v; })
|
|
|
|
#else
|
|
|
|
#error "Unsupported architecture."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// The Android Bionic team has allocated a TLS slot for TSan starting with N,
|
|
|
|
// given that Android currently doesn't support ELF TLS. It is used to store
|
|
|
|
// Sanitizers thread specific data.
|
|
|
|
static const int TLS_SLOT_TSAN = 8;
|
|
|
|
|
|
|
|
ALWAYS_INLINE uptr *get_android_tls_ptr() {
|
|
|
|
return reinterpret_cast<uptr *>(&__get_tls()[TLS_SLOT_TSAN]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SANITIZER_ANDROID
|
|
|
|
|
2013-02-27 19:22:40 +08:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
2018-03-17 06:29:29 +08:00
|
|
|
#endif
|
2013-02-27 19:22:40 +08:00
|
|
|
#endif // SANITIZER_LINUX_H
|