diff options
Diffstat (limited to 'lib/xray/xray_utils.h')
| -rw-r--r-- | lib/xray/xray_utils.h | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/lib/xray/xray_utils.h b/lib/xray/xray_utils.h index eafa16e1a9d5..60438973fbd0 100644 --- a/lib/xray/xray_utils.h +++ b/lib/xray/xray_utils.h @@ -20,23 +20,40 @@ #include <sys/types.h> #include <utility> +#include "sanitizer_common/sanitizer_common.h" +#if SANITIZER_FUCHSIA +#include <zircon/types.h> +#endif + namespace __xray { -// Default implementation of the reporting interface for sanitizer errors. -void printToStdErr(const char *Buffer); +class LogWriter { +public: +#if SANITIZER_FUCHSIA + LogWriter(zx_handle_t Vmo) : Vmo(Vmo) {} +#else + explicit LogWriter(int Fd) : Fd(Fd) {} +#endif + ~LogWriter(); -// EINTR-safe write routine, provided a file descriptor and a character range. -void retryingWriteAll(int Fd, const char *Begin, const char *End); + // Write a character range into a log. + void WriteAll(const char *Begin, const char *End); -// Reads a long long value from a provided file. -bool readValueFromFile(const char *Filename, long long *Value); + void Flush(); -// EINTR-safe read routine, providing a file descriptor and a character range. -std::pair<ssize_t, bool> retryingReadSome(int Fd, char *Begin, char *End); + // Returns a new log instance initialized using the flag-provided values. + static LogWriter *Open(); + // Closes and deallocates the log instance. + static void Close(LogWriter *LogWriter); -// EINTR-safe open routine, uses flag-provided values for initialising a log -// file. -int getLogFD(); +private: +#if SANITIZER_FUCHSIA + zx_handle_t Vmo = ZX_HANDLE_INVALID; + uint64_t Offset = 0; +#else + int Fd = -1; +#endif +}; constexpr size_t gcd(size_t a, size_t b) { return (b == 0) ? a : gcd(b, a % b); |
