Commit a6198d25 authored by Peter Griess's avatar Peter Griess Committed by Owen Yamauchi

Move folly::symbolizer::systemError() into Exception.h

Summary:
- This is pretty similar to some stuff that we already have in
Exception.h. Move (and rename) it.

Test Plan: - Unit tests

Reviewed By: simpkins@fb.com

FB internal diff: D748313
parent 5d43d2ab
......@@ -22,6 +22,7 @@
#include <stdexcept>
#include <system_error>
#include "folly/Conv.h"
#include "folly/Likely.h"
namespace folly {
......@@ -38,6 +39,14 @@ inline void throwSystemError(const char* msg) {
throwSystemError(errno, msg);
}
// Helper to throw std::system_error from errno and components of a string
template <class... Args>
void throwSystemError(Args... args) __attribute__((noreturn));
template <class... Args>
inline void throwSystemError(Args... args) {
throwSystemError(errno, folly::to<std::string>(args...));
}
// Check a Posix return code (0 on success, error number on error), throw
// on error.
inline void checkPosixError(int err, const char* msg) {
......
......@@ -28,6 +28,7 @@
#include <glog/logging.h>
#include "folly/Conv.h"
#include "folly/Exception.h"
namespace folly {
namespace symbolizer {
......@@ -45,20 +46,20 @@ ElfFile::ElfFile(const char* name)
length_(0),
baseAddress_(0) {
if (fd_ == -1) {
systemError("open ", name);
folly::throwSystemError("open ", name);
}
struct stat st;
int r = fstat(fd_, &st);
if (r == -1) {
systemError("fstat");
folly::throwSystemError("fstat");
}
length_ = st.st_size;
file_ = static_cast<char*>(
mmap(nullptr, length_, PROT_READ, MAP_SHARED, fd_, 0));
if (file_ == MAP_FAILED) {
systemError("mmap");
folly::throwSystemError("mmap");
}
init();
}
......
......@@ -134,15 +134,6 @@ class ElfFile {
uintptr_t baseAddress_;
};
template <class... Args>
void systemError(Args... args) __attribute__((noreturn));
template <class... Args>
void systemError(Args... args) {
throw std::system_error(errno, std::system_category(),
folly::to<std::string>(args...));
}
template <class... Args>
inline void enforce(bool v, Args... args) {
if (UNLIKELY(!v)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment