/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2014-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <folly/fibers/Fiber.h>
#include <folly/fibers/LoopController.h>
+#include <folly/ConstexprMath.h>
#include <folly/SingletonThreadLocal.h>
#include <folly/portability/SysSyscall.h>
#include <folly/portability/Unistd.h>
}
}
+void FiberManager::freeFakeStack(void* fakeStack) {
+ static AsanStartSwitchStackFuncPtr fnStart = getStartSwitchStackFunc();
+ static AsanFinishSwitchStackFuncPtr fnFinish = getFinishSwitchStackFunc();
+ if (fnStart == nullptr || fnFinish == nullptr) {
+ LOG(FATAL) << "The version of ASAN in use doesn't support fibers";
+ }
+
+ void* saveFakeStack;
+ const void* stackBottom;
+ size_t stackSize;
+ fnStart(&saveFakeStack, nullptr, 0);
+ fnFinish(fakeStack, &stackBottom, &stackSize);
+ fnStart(nullptr, stackBottom, stackSize);
+ fnFinish(saveFakeStack, nullptr, nullptr);
+}
+
void FiberManager::unpoisonFiberStack(const Fiber* fiber) {
auto stack = fiber->getStack();
}
// Check whether we can find a dynamically linked enter function
- if (nullptr != (fn = (AsanStartSwitchStackFuncPtr)dlsym(
- RTLD_DEFAULT, "__sanitizer_start_switch_fiber"))) {
+ if (nullptr !=
+ (fn = (AsanStartSwitchStackFuncPtr)dlsym(
+ RTLD_DEFAULT, "__sanitizer_start_switch_fiber"))) {
return fn;
}
}
// Check whether we can find a dynamically linked exit function
- if (nullptr != (fn = (AsanFinishSwitchStackFuncPtr)dlsym(
- RTLD_DEFAULT, "__sanitizer_finish_switch_fiber"))) {
+ if (nullptr !=
+ (fn = (AsanFinishSwitchStackFuncPtr)dlsym(
+ RTLD_DEFAULT, "__sanitizer_finish_switch_fiber"))) {
return fn;
}
}
// Check whether we can find a dynamically linked unpoison function
- if (nullptr != (fn = (AsanUnpoisonMemoryRegionFuncPtr)dlsym(
- RTLD_DEFAULT, "__asan_unpoison_memory_region"))) {
+ if (nullptr !=
+ (fn = (AsanUnpoisonMemoryRegionFuncPtr)dlsym(
+ RTLD_DEFAULT, "__asan_unpoison_memory_region"))) {
return fn;
}
return;
}
- stack_ = folly::make_unique<AltStackBuffer>();
+ stack_ = std::make_unique<AltStackBuffer>();
setAlternateStack(stack_->data(), stack_->size());
}
using AltStackBuffer = std::array<char, kAltStackSize>;
std::unique_ptr<AltStackBuffer> stack_;
};
-}
+} // namespace
void FiberManager::registerAlternateSignalStack() {
static folly::SingletonThreadLocal<ScopedAlternateSignalStack> singleton;
alternateSignalStackRegistered_ = true;
}
#endif
-}
-}
+} // namespace fibers
+} // namespace folly