Skip to content

Commit 3408b49

Browse files
committed
Revert "[asan] Support running without /proc.", +1
Revert r350104 "[asan] Fix build on windows." Revert r350101 "[asan] Support running without /proc." These changes break Mac build, too. llvm-svn: 350112
1 parent 5ede950 commit 3408b49

15 files changed

+15
-84
lines changed

compiler-rt/lib/asan/asan_linux.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ void AsanCheckIncompatibleRT() {
210210
}
211211
} else {
212212
if (__asan_rt_version == ASAN_RT_VERSION_UNDEFINED) {
213-
if (!MemoryMappingLayout::IsAvailable())
214-
return;
215213
// Ensure that dynamic runtime is not present. We should detect it
216214
// as early as possible, otherwise ASan interceptors could bind to
217215
// the functions in dynamic ASan runtime instead of the functions in

compiler-rt/lib/asan/asan_thread.cc

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "asan_thread.h"
1919
#include "asan_mapping.h"
2020
#include "sanitizer_common/sanitizer_common.h"
21-
#include "sanitizer_common/sanitizer_file.h"
2221
#include "sanitizer_common/sanitizer_placement_new.h"
2322
#include "sanitizer_common/sanitizer_stackdepot.h"
2423
#include "sanitizer_common/sanitizer_tls_get_addr.h"
@@ -224,11 +223,9 @@ void AsanThread::Init(const InitOptions *options) {
224223
atomic_store(&stack_switching_, false, memory_order_release);
225224
CHECK_EQ(this->stack_size(), 0U);
226225
SetThreadStackAndTls(options);
227-
if (stack_top_ != stack_bottom_) {
228-
CHECK_GT(this->stack_size(), 0U);
229-
CHECK(AddrIsInMem(stack_bottom_));
230-
CHECK(AddrIsInMem(stack_top_ - 1));
231-
}
226+
CHECK_GT(this->stack_size(), 0U);
227+
CHECK(AddrIsInMem(stack_bottom_));
228+
CHECK(AddrIsInMem(stack_top_ - 1));
232229
ClearShadowForThreadStackAndTLS();
233230
fake_stack_ = nullptr;
234231
if (__asan_option_detect_stack_use_after_return)
@@ -285,42 +282,27 @@ AsanThread *CreateMainThread() {
285282
return main_thread;
286283
}
287284

288-
static bool StackLimitsAreAvailable() {
289-
#if SANITIZER_WINDOWS
290-
return true;
291-
#else
292-
return MemoryMappingLayout::IsAvailable();
293-
#endif
294-
}
295-
296285
// This implementation doesn't use the argument, which is just passed down
297286
// from the caller of Init (which see, above). It's only there to support
298287
// OS-specific implementations that need more information passed through.
299288
void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
300289
DCHECK_EQ(options, nullptr);
301-
// If this process is "init" (pid 1), /proc may not be mounted yet.
302-
if (!start_routine_ && !StackLimitsAreAvailable()) {
303-
stack_top_ = stack_bottom_ = 0;
304-
tls_begin_ = tls_end_ = 0;
305-
} else {
306-
uptr tls_size = 0;
307-
uptr stack_size = 0;
308-
GetThreadStackAndTls(tid() == 0, &stack_bottom_, &stack_size, &tls_begin_,
309-
&tls_size);
310-
stack_top_ = stack_bottom_ + stack_size;
311-
tls_end_ = tls_begin_ + tls_size;
312-
dtls_ = DTLS_Get();
313-
314-
int local;
315-
CHECK(AddrIsInStack((uptr)&local));
316-
}
290+
uptr tls_size = 0;
291+
uptr stack_size = 0;
292+
GetThreadStackAndTls(tid() == 0, &stack_bottom_, &stack_size, &tls_begin_,
293+
&tls_size);
294+
stack_top_ = stack_bottom_ + stack_size;
295+
tls_end_ = tls_begin_ + tls_size;
296+
dtls_ = DTLS_Get();
297+
298+
int local;
299+
CHECK(AddrIsInStack((uptr)&local));
317300
}
318301

319302
#endif // !SANITIZER_FUCHSIA && !SANITIZER_RTEMS
320303

321304
void AsanThread::ClearShadowForThreadStackAndTLS() {
322-
if (stack_top_ != stack_bottom_)
323-
PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0);
305+
PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0);
324306
if (tls_begin_ != tls_end_) {
325307
uptr tls_begin_aligned = RoundDownTo(tls_begin_, SHADOW_GRANULARITY);
326308
uptr tls_end_aligned = RoundUpTo(tls_end_, SHADOW_GRANULARITY);
@@ -332,9 +314,6 @@ void AsanThread::ClearShadowForThreadStackAndTLS() {
332314

333315
bool AsanThread::GetStackFrameAccessByAddr(uptr addr,
334316
StackFrameAccess *access) {
335-
if (stack_top_ == stack_bottom_)
336-
return false;
337-
338317
uptr bottom = 0;
339318
if (AddrIsInStack(addr)) {
340319
bottom = stack_bottom();

compiler-rt/lib/hwasan/hwasan_thread.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size) {
4444
ScopedTaggingDisabler disabler;
4545

4646
// If this process is "init" (pid 1), /proc may not be mounted yet.
47-
if (IsMainThread() && !MemoryMappingLayout::IsAvailable()) {
47+
if (IsMainThread() && !FileExists("/proc/self/maps")) {
4848
stack_top_ = stack_bottom_ = 0;
4949
tls_begin_ = tls_end_ = 0;
5050
} else {

compiler-rt/lib/sanitizer_common/sanitizer_flags.inc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,3 @@ COMMON_FLAG(bool, dump_registers, true,
243243
COMMON_FLAG(bool, detect_write_exec, false,
244244
"If true, triggers warning when writable-executable pages requests "
245245
"are being made")
246-
COMMON_FLAG(bool, test_only_emulate_no_procfs, false,
247-
"TEST ONLY fail to open any files under /proc to emulate sanitized "
248-
"\"init\"")

compiler-rt/lib/sanitizer_common/sanitizer_linux.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,6 @@ uptr internal_execve(const char *filename, char *const argv[],
453453

454454
// ----------------- sanitizer_common.h
455455
bool FileExists(const char *filename) {
456-
if (ShouldMockFailureToOpen(filename))
457-
return false;
458456
struct stat st;
459457
#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
460458
if (internal_syscall(SYSCALL(newfstatat), AT_FDCWD, filename, &st, 0))
@@ -1005,8 +1003,6 @@ ThreadLister::~ThreadLister() {
10051003
// Take care of unusable kernel area in top gigabyte.
10061004
static uptr GetKernelAreaSize() {
10071005
#if SANITIZER_LINUX && !SANITIZER_X32
1008-
if (!MemoryMappingLayout::IsAvailable())
1009-
return 0;
10101006
const uptr gbyte = 1UL << 30;
10111007

10121008
// Firstly check if there are writable segments

compiler-rt/lib/sanitizer_common/sanitizer_linux.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ struct MemoryMappingLayoutData {
4444
};
4545

4646
void ReadProcMaps(ProcSelfMapsBuff *proc_maps);
47-
bool IsProcMapsAvailable();
4847

4948
// Syscall wrappers.
5049
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);

compiler-rt/lib/sanitizer_common/sanitizer_mac.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ uptr internal_waitpid(int pid, int *status, int options) {
282282

283283
// ----------------- sanitizer_common.h
284284
bool FileExists(const char *filename) {
285-
if (ShouldMockFailureToOpen(filename))
286-
return false;
287285
struct stat st;
288286
if (stat(filename, &st))
289287
return false;

compiler-rt/lib/sanitizer_common/sanitizer_posix.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include "sanitizer_common.h"
2020
#include "sanitizer_file.h"
21-
#include "sanitizer_flags.h"
2221
#include "sanitizer_libc.h"
2322
#include "sanitizer_posix.h"
2423
#include "sanitizer_procmaps.h"
@@ -158,8 +157,6 @@ void MprotectMallocZones(void *addr, int prot) {}
158157
#endif
159158

160159
fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *errno_p) {
161-
if (ShouldMockFailureToOpen(filename))
162-
return kInvalidFd;
163160
int flags;
164161
switch (mode) {
165162
case RdOnly: flags = O_RDONLY; break;
@@ -232,8 +229,6 @@ static inline bool IntervalsAreSeparate(uptr start1, uptr end1,
232229
// several worker threads on Mac, which aren't expected to map big chunks of
233230
// memory).
234231
bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) {
235-
if (!MemoryMappingLayout::IsAvailable())
236-
return true; // hope for the best
237232
MemoryMappingLayout proc_maps(/*cache_enabled*/true);
238233
MemoryMappedSegment segment;
239234
while (proc_maps.Next(&segment)) {
@@ -339,11 +334,6 @@ fd_t ReserveStandardFds(fd_t fd) {
339334
return fd;
340335
}
341336

342-
bool ShouldMockFailureToOpen(const char *path) {
343-
return common_flags()->test_only_emulate_no_procfs &&
344-
internal_strncmp(path, "/proc/", 6) == 0;
345-
}
346-
347337
} // namespace __sanitizer
348338

349339
#endif // SANITIZER_POSIX

compiler-rt/lib/sanitizer_common/sanitizer_posix.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ bool IsStateDetached(int state);
103103
// Move the fd out of {0, 1, 2} range.
104104
fd_t ReserveStandardFds(fd_t fd);
105105

106-
bool ShouldMockFailureToOpen(const char *path);
107-
108106
} // namespace __sanitizer
109107

110108
#endif // SANITIZER_POSIX_H

compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class MemoryMappingLayout {
7575
// to obtain the memory mappings. It should fall back to pre-cached data
7676
// instead of aborting.
7777
static void CacheMemoryMappings();
78-
static bool IsAvailable();
7978

8079
// Adds all mapped objects into a vector.
8180
void DumpListOfModules(InternalMmapVectorNoCtor<LoadedModule> *modules);

0 commit comments

Comments
 (0)