From dcfd85d74e4f3518d99e9936c64bbe7935ac6164 Mon Sep 17 00:00:00 2001 From: Sandboxed API Team Date: Wed, 17 Nov 2021 02:40:34 -0800 Subject: [PATCH] Extend existing CPU architecture spellings in config header and define platform spellings. PiperOrigin-RevId: 410474889 Change-Id: I41f870ad49e2203a6bdf833102c0d0a9cafa7af4 --- sandboxed_api/config.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/sandboxed_api/config.h b/sandboxed_api/config.h index a6b0331..71395fc 100644 --- a/sandboxed_api/config.h +++ b/sandboxed_api/config.h @@ -16,6 +16,7 @@ #define SANDBOXED_API_CONFIG_H_ #include +#include #include "absl/base/config.h" @@ -46,7 +47,7 @@ namespace cpu { // CPU architectures known to Sandbox2 enum Architecture : uint16_t { // Linux: Use a magic value, so it can be easily spotted in the seccomp-bpf - // bytecode decompilation stream. Must be < (1<<15), as/ that's the size of + // bytecode decompilation stream. Must be < (1<<15), as that is the size of // data which can be returned by BPF. kUnknown = 0xCAF0, kX8664, @@ -92,6 +93,37 @@ static_assert(host_cpu::Architecture() != cpu::kUnknown, "Host CPU architecture is not supported: One of x86-64, POWER64 " "(little endian), ARM or AArch64 is required."); +namespace os { + +// Operating Systems known to Sandbox2 +enum Platform : uint16_t { + kUnknown, + kAndroid, + kLinux, +}; + +} // namespace os + +namespace host_os { + +// Returns the current host OS platform if supported. If not supported, +// returns platforms::kUnknown. +constexpr os::Platform Platform() { +#if defined(__ANDROID__) + return os::kAndroid; +#elif defined(__linux__) + return os::kLinux; +#else + return os::kUnknown; +#endif +} + +constexpr bool IsAndroid() { return Platform() == os::kAndroid; } + +constexpr bool IsLinux() { return Platform() == os::kLinux; } + +} // namespace host_os + namespace sanitizers { constexpr bool IsMSan() {