Changeset View
Changeset View
Standalone View
Standalone View
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
#if SANITIZER_LINUX | #if SANITIZER_LINUX | ||||
#include <sys/utsname.h> | #include <sys/utsname.h> | ||||
#endif | #endif | ||||
#if SANITIZER_LINUX && !SANITIZER_ANDROID | #if SANITIZER_LINUX && !SANITIZER_ANDROID | ||||
#include <sys/personality.h> | #include <sys/personality.h> | ||||
#endif | #endif | ||||
#if SANITIZER_LINUX && defined(__loongarch__) | |||||
# include <sys/sysmacros.h> | |||||
#endif | |||||
#if SANITIZER_FREEBSD | #if SANITIZER_FREEBSD | ||||
#include <sys/exec.h> | #include <sys/exec.h> | ||||
#include <sys/procctl.h> | #include <sys/procctl.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <machine/atomic.h> | #include <machine/atomic.h> | ||||
extern "C" { | extern "C" { | ||||
// <sys/umtx.h> must be included after <errno.h> and <sys/types.h> on | // <sys/umtx.h> must be included after <errno.h> and <sys/types.h> on | ||||
// FreeBSD 9.2 and 10.0. | // FreeBSD 9.2 and 10.0. | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | |||||
# elif SANITIZER_LINUX && SANITIZER_RISCV64 | # elif SANITIZER_LINUX && SANITIZER_RISCV64 | ||||
# include "sanitizer_syscall_linux_riscv64.inc" | # include "sanitizer_syscall_linux_riscv64.inc" | ||||
# elif SANITIZER_LINUX && defined(__aarch64__) | # elif SANITIZER_LINUX && defined(__aarch64__) | ||||
# include "sanitizer_syscall_linux_aarch64.inc" | # include "sanitizer_syscall_linux_aarch64.inc" | ||||
# elif SANITIZER_LINUX && defined(__arm__) | # elif SANITIZER_LINUX && defined(__arm__) | ||||
# include "sanitizer_syscall_linux_arm.inc" | # include "sanitizer_syscall_linux_arm.inc" | ||||
# elif SANITIZER_LINUX && defined(__hexagon__) | # elif SANITIZER_LINUX && defined(__hexagon__) | ||||
# include "sanitizer_syscall_linux_hexagon.inc" | # include "sanitizer_syscall_linux_hexagon.inc" | ||||
# elif SANITIZER_LINUX && SANITIZER_LOONGARCH64 | |||||
# include "sanitizer_syscall_linux_loongarch64.inc" | |||||
# else | # else | ||||
# include "sanitizer_syscall_generic.inc" | # include "sanitizer_syscall_generic.inc" | ||||
# endif | # endif | ||||
// --------------- sanitizer_libc.h | // --------------- sanitizer_libc.h | ||||
#if !SANITIZER_SOLARIS && !SANITIZER_NETBSD | #if !SANITIZER_SOLARIS && !SANITIZER_NETBSD | ||||
#if !SANITIZER_S390 | #if !SANITIZER_S390 | ||||
uptr internal_mmap(void *addr, uptr length, int prot, int flags, int fd, | uptr internal_mmap(void *addr, uptr length, int prot, int flags, int fd, | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | static void stat64_to_stat(struct stat64 *in, struct stat *out) { | ||||
out->st_blksize = in->st_blksize; | out->st_blksize = in->st_blksize; | ||||
out->st_blocks = in->st_blocks; | out->st_blocks = in->st_blocks; | ||||
out->st_atime = in->st_atime; | out->st_atime = in->st_atime; | ||||
out->st_mtime = in->st_mtime; | out->st_mtime = in->st_mtime; | ||||
out->st_ctime = in->st_ctime; | out->st_ctime = in->st_ctime; | ||||
} | } | ||||
#endif | #endif | ||||
#if SANITIZER_LINUX && defined(__loongarch__) | |||||
static void statx_to_stat(struct statx *in, struct stat *out) { | |||||
internal_memset(out, 0, sizeof(*out)); | |||||
out->st_dev = makedev(in->stx_dev_major, in->stx_dev_minor); | |||||
out->st_ino = in->stx_ino; | |||||
out->st_mode = in->stx_mode; | |||||
out->st_nlink = in->stx_nlink; | |||||
out->st_uid = in->stx_uid; | |||||
out->st_gid = in->stx_gid; | |||||
out->st_rdev = makedev(in->stx_rdev_major, in->stx_rdev_minor); | |||||
out->st_size = in->stx_size; | |||||
out->st_blksize = in->stx_blksize; | |||||
out->st_blocks = in->stx_blocks; | |||||
out->st_atime = in->stx_atime.tv_sec; | |||||
out->st_atim.tv_nsec = in->stx_atime.tv_nsec; | |||||
out->st_mtime = in->stx_mtime.tv_sec; | |||||
out->st_mtim.tv_nsec = in->stx_mtime.tv_nsec; | |||||
out->st_ctime = in->stx_ctime.tv_sec; | |||||
out->st_ctim.tv_nsec = in->stx_ctime.tv_nsec; | |||||
} | |||||
#endif | |||||
#if SANITIZER_MIPS64 | #if SANITIZER_MIPS64 | ||||
// Undefine compatibility macros from <sys/stat.h> | // Undefine compatibility macros from <sys/stat.h> | ||||
// so that they would not clash with the kernel_stat | // so that they would not clash with the kernel_stat | ||||
// st_[a|m|c]time fields | // st_[a|m|c]time fields | ||||
#if !SANITIZER_GO | #if !SANITIZER_GO | ||||
#undef st_atime | #undef st_atime | ||||
#undef st_mtime | #undef st_mtime | ||||
#undef st_ctime | #undef st_ctime | ||||
Show All 35 Lines | #else | ||||
out->st_mtimensec = in->st_mtime_nsec; | out->st_mtimensec = in->st_mtime_nsec; | ||||
out->st_ctime = in->st_ctime; | out->st_ctime = in->st_ctime; | ||||
out->st_atimensec = in->st_ctime_nsec; | out->st_atimensec = in->st_ctime_nsec; | ||||
#endif | #endif | ||||
} | } | ||||
#endif | #endif | ||||
uptr internal_stat(const char *path, void *buf) { | uptr internal_stat(const char *path, void *buf) { | ||||
#if SANITIZER_FREEBSD | # if SANITIZER_FREEBSD | ||||
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0); | return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0); | ||||
# elif SANITIZER_LINUX | # elif SANITIZER_LINUX | ||||
# if (SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \ | # if defined(__loongarch__) | ||||
struct statx bufx; | |||||
int res = internal_syscall(SYSCALL(statx), AT_FDCWD, (uptr)path, | |||||
AT_NO_AUTOMOUNT, STATX_BASIC_STATS, (uptr)&bufx); | |||||
statx_to_stat(&bufx, (struct stat *)buf); | |||||
return res; | |||||
# elif (SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \ | |||||
(defined(__mips__) && _MIPS_SIM == _ABIN32)) && \ | (defined(__mips__) && _MIPS_SIM == _ABIN32)) && \ | ||||
!SANITIZER_SPARC | !SANITIZER_SPARC | ||||
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf, | return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf, | ||||
0); | 0); | ||||
# else | # else | ||||
struct stat64 buf64; | struct stat64 buf64; | ||||
int res = internal_syscall(SYSCALL(fstatat64), AT_FDCWD, (uptr)path, | int res = internal_syscall(SYSCALL(fstatat64), AT_FDCWD, (uptr)path, | ||||
(uptr)&buf64, 0); | (uptr)&buf64, 0); | ||||
stat64_to_stat(&buf64, (struct stat *)buf); | stat64_to_stat(&buf64, (struct stat *)buf); | ||||
SixWeining: Nit: tab -> spaces | |||||
They are spaces, but with a different indent than our standard I guess. xry111: They are spaces, but with a different indent than our standard I guess. | |||||
return res; | return res; | ||||
# endif | # endif | ||||
# else | # else | ||||
struct stat64 buf64; | struct stat64 buf64; | ||||
int res = internal_syscall(SYSCALL(stat64), path, &buf64); | int res = internal_syscall(SYSCALL(stat64), path, &buf64); | ||||
stat64_to_stat(&buf64, (struct stat *)buf); | stat64_to_stat(&buf64, (struct stat *)buf); | ||||
return res; | return res; | ||||
# endif | # endif | ||||
} | } | ||||
uptr internal_lstat(const char *path, void *buf) { | uptr internal_lstat(const char *path, void *buf) { | ||||
#if SANITIZER_FREEBSD | # if SANITIZER_FREEBSD | ||||
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, | return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, | ||||
AT_SYMLINK_NOFOLLOW); | AT_SYMLINK_NOFOLLOW); | ||||
# elif SANITIZER_LINUX | # elif SANITIZER_LINUX | ||||
# if (defined(_LP64) || SANITIZER_X32 || \ | # if defined(__loongarch__) | ||||
struct statx bufx; | |||||
int res = internal_syscall(SYSCALL(statx), AT_FDCWD, (uptr)path, | |||||
AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, | |||||
STATX_BASIC_STATS, (uptr)&bufx); | |||||
statx_to_stat(&bufx, (struct stat *)buf); | |||||
return res; | |||||
# elif (defined(_LP64) || SANITIZER_X32 || \ | |||||
(defined(__mips__) && _MIPS_SIM == _ABIN32)) && \ | (defined(__mips__) && _MIPS_SIM == _ABIN32)) && \ | ||||
!SANITIZER_SPARC | !SANITIZER_SPARC | ||||
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf, | return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf, | ||||
AT_SYMLINK_NOFOLLOW); | AT_SYMLINK_NOFOLLOW); | ||||
# else | # else | ||||
struct stat64 buf64; | struct stat64 buf64; | ||||
int res = internal_syscall(SYSCALL(fstatat64), AT_FDCWD, (uptr)path, | int res = internal_syscall(SYSCALL(fstatat64), AT_FDCWD, (uptr)path, | ||||
(uptr)&buf64, AT_SYMLINK_NOFOLLOW); | (uptr)&buf64, AT_SYMLINK_NOFOLLOW); | ||||
stat64_to_stat(&buf64, (struct stat *)buf); | stat64_to_stat(&buf64, (struct stat *)buf); | ||||
return res; | return res; | ||||
Not Done ReplyInline ActionsDitto. SixWeining: Ditto. | |||||
Not Done ReplyInline Actionsfor spaces, just keep whatever clang-format does: vitalybuka: for spaces, just keep whatever clang-format does:
git clang-format -f --extensions=inc,cc,h,c… | |||||
When I run this command, it changes the indent of some #if lines but the corresponding #else/#endif lines are not changed. Should I keep it as-is or manually fix those #else/#endif lines? xry111: When I run this command, it changes the indent of some `#if` lines but the corresponding… | |||||
# endif | # endif | ||||
# else | # else | ||||
struct stat64 buf64; | struct stat64 buf64; | ||||
int res = internal_syscall(SYSCALL(lstat64), path, &buf64); | int res = internal_syscall(SYSCALL(lstat64), path, &buf64); | ||||
stat64_to_stat(&buf64, (struct stat *)buf); | stat64_to_stat(&buf64, (struct stat *)buf); | ||||
return res; | return res; | ||||
# endif | # endif | ||||
} | } | ||||
uptr internal_fstat(fd_t fd, void *buf) { | uptr internal_fstat(fd_t fd, void *buf) { | ||||
#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS | #if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS | ||||
#if SANITIZER_MIPS64 | #if SANITIZER_MIPS64 | ||||
// For mips64, fstat syscall fills buffer in the format of kernel_stat | // For mips64, fstat syscall fills buffer in the format of kernel_stat | ||||
struct kernel_stat kbuf; | struct kernel_stat kbuf; | ||||
int res = internal_syscall(SYSCALL(fstat), fd, &kbuf); | int res = internal_syscall(SYSCALL(fstat), fd, &kbuf); | ||||
kernel_stat_to_stat(&kbuf, (struct stat *)buf); | kernel_stat_to_stat(&kbuf, (struct stat *)buf); | ||||
return res; | return res; | ||||
# elif SANITIZER_LINUX && defined(__loongarch__) | |||||
struct statx bufx; | |||||
int res = internal_syscall(SYSCALL(statx), fd, 0, AT_EMPTY_PATH, | |||||
STATX_BASIC_STATS, (uptr)&bufx); | |||||
statx_to_stat(&bufx, (struct stat *)buf); | |||||
return res; | |||||
# else | # else | ||||
return internal_syscall(SYSCALL(fstat), fd, (uptr)buf); | return internal_syscall(SYSCALL(fstat), fd, (uptr)buf); | ||||
# endif | # endif | ||||
#else | #else | ||||
struct stat64 buf64; | struct stat64 buf64; | ||||
int res = internal_syscall(SYSCALL(fstat64), fd, &buf64); | int res = internal_syscall(SYSCALL(fstat64), fd, &buf64); | ||||
stat64_to_stat(&buf64, (struct stat *)buf); | stat64_to_stat(&buf64, (struct stat *)buf); | ||||
return res; | return res; | ||||
#endif | #endif | ||||
} | } | ||||
Show All 29 Lines | |||||
# if SANITIZER_LINUX | # if SANITIZER_LINUX | ||||
return internal_syscall(SYSCALL(unlinkat), AT_FDCWD, (uptr)path, 0); | return internal_syscall(SYSCALL(unlinkat), AT_FDCWD, (uptr)path, 0); | ||||
#else | #else | ||||
return internal_syscall(SYSCALL(unlink), (uptr)path); | return internal_syscall(SYSCALL(unlink), (uptr)path); | ||||
#endif | #endif | ||||
} | } | ||||
uptr internal_rename(const char *oldpath, const char *newpath) { | uptr internal_rename(const char *oldpath, const char *newpath) { | ||||
#if defined(__riscv) && defined(__linux__) | # if (defined(__riscv) || defined(__loongarch__)) && defined(__linux__) | ||||
return internal_syscall(SYSCALL(renameat2), AT_FDCWD, (uptr)oldpath, AT_FDCWD, | return internal_syscall(SYSCALL(renameat2), AT_FDCWD, (uptr)oldpath, AT_FDCWD, | ||||
(uptr)newpath, 0); | (uptr)newpath, 0); | ||||
# elif SANITIZER_LINUX | # elif SANITIZER_LINUX | ||||
return internal_syscall(SYSCALL(renameat), AT_FDCWD, (uptr)oldpath, AT_FDCWD, | return internal_syscall(SYSCALL(renameat), AT_FDCWD, (uptr)oldpath, AT_FDCWD, | ||||
(uptr)newpath); | (uptr)newpath); | ||||
# else | # else | ||||
return internal_syscall(SYSCALL(rename), (uptr)oldpath, (uptr)newpath); | return internal_syscall(SYSCALL(rename), (uptr)oldpath, (uptr)newpath); | ||||
# endif | # endif | ||||
} | } | ||||
uptr internal_sched_yield() { | uptr internal_sched_yield() { | ||||
return internal_syscall(SYSCALL(sched_yield)); | return internal_syscall(SYSCALL(sched_yield)); | ||||
} | } | ||||
void internal_usleep(u64 useconds) { | void internal_usleep(u64 useconds) { | ||||
struct timespec ts; | struct timespec ts; | ||||
▲ Show 20 Lines • Show All 1,706 Lines • ▼ Show 20 Lines | # else | ||||
*bp = ucontext->uc_mcontext.__gregs[REG_S0]; | *bp = ucontext->uc_mcontext.__gregs[REG_S0]; | ||||
*sp = ucontext->uc_mcontext.__gregs[REG_SP]; | *sp = ucontext->uc_mcontext.__gregs[REG_SP]; | ||||
# endif | # endif | ||||
# elif defined(__hexagon__) | # elif defined(__hexagon__) | ||||
ucontext_t *ucontext = (ucontext_t *)context; | ucontext_t *ucontext = (ucontext_t *)context; | ||||
*pc = ucontext->uc_mcontext.pc; | *pc = ucontext->uc_mcontext.pc; | ||||
*bp = ucontext->uc_mcontext.r30; | *bp = ucontext->uc_mcontext.r30; | ||||
*sp = ucontext->uc_mcontext.r29; | *sp = ucontext->uc_mcontext.r29; | ||||
# elif defined(__loongarch__) | |||||
ucontext_t *ucontext = (ucontext_t *)context; | |||||
*pc = ucontext->uc_mcontext.__pc; | |||||
*bp = ucontext->uc_mcontext.__gregs[22]; | |||||
*sp = ucontext->uc_mcontext.__gregs[3]; | |||||
# else | # else | ||||
# error "Unsupported arch" | # error "Unsupported arch" | ||||
# endif | # endif | ||||
} | } | ||||
void SignalContext::InitPcSpBp() { GetPcSpBp(context, &pc, &sp, &bp); } | void SignalContext::InitPcSpBp() { GetPcSpBp(context, &pc, &sp, &bp); } | ||||
void InitializePlatformEarly() { | void InitializePlatformEarly() { | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |
Nit: tab -> spaces