diff --git a/sandboxed_api/BUILD.bazel b/sandboxed_api/BUILD.bazel index fbe40b3..59ed83a 100644 --- a/sandboxed_api/BUILD.bazel +++ b/sandboxed_api/BUILD.bazel @@ -147,10 +147,10 @@ cc_library( ":var_type", "//sandboxed_api/sandbox2:comms", "//sandboxed_api/util:status", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/synchronization", diff --git a/sandboxed_api/examples/zlib/BUILD.bazel b/sandboxed_api/examples/zlib/BUILD.bazel index 3dc1c75..3716280 100644 --- a/sandboxed_api/examples/zlib/BUILD.bazel +++ b/sandboxed_api/examples/zlib/BUILD.bazel @@ -42,7 +42,7 @@ cc_binary( ":zlib-sapi_embed", "//sandboxed_api:vars", "//sandboxed_api/util:flags", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/status:statusor", ], ) diff --git a/sandboxed_api/examples/zlib/main_zlib.cc b/sandboxed_api/examples/zlib/main_zlib.cc index 7d94c10..e6e2b2a 100644 --- a/sandboxed_api/examples/zlib/main_zlib.cc +++ b/sandboxed_api/examples/zlib/main_zlib.cc @@ -20,7 +20,7 @@ #include #include "absl/base/macros.h" #include "sandboxed_api/util/flag.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "sandboxed_api/examples/zlib/zlib-sapi.sapi.h" #include "sandboxed_api/examples/zlib/zlib-sapi_embed.h" #include "sandboxed_api/vars.h" @@ -48,7 +48,7 @@ int main(int argc, char** argv) { << status.message(); } - sapi::StatusOr ret; + absl::StatusOr ret; int flush; unsigned have; sapi::v::Struct strm; diff --git a/sandboxed_api/proto_helper.h b/sandboxed_api/proto_helper.h index b00a73e..63c4294 100644 --- a/sandboxed_api/proto_helper.h +++ b/sandboxed_api/proto_helper.h @@ -22,13 +22,13 @@ #include #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "sandboxed_api/proto_arg.pb.h" namespace sapi { template -sapi::StatusOr> SerializeProto(const T& proto) { +absl::StatusOr> SerializeProto(const T& proto) { static_assert(std::is_base_of::value, "Template argument must be a proto message"); // Wrap protobuf in a envelope so that we know the name of the protobuf @@ -46,7 +46,7 @@ sapi::StatusOr> SerializeProto(const T& proto) { } template -sapi::StatusOr DeserializeProto(const char* data, size_t len) { +absl::StatusOr DeserializeProto(const char* data, size_t len) { static_assert(std::is_base_of::value, "Template argument must be a proto message"); ProtoArg envelope; diff --git a/sandboxed_api/rpcchannel.cc b/sandboxed_api/rpcchannel.cc index 1aad74d..66e1b2b 100644 --- a/sandboxed_api/rpcchannel.cc +++ b/sandboxed_api/rpcchannel.cc @@ -15,7 +15,7 @@ #include "sandboxed_api/rpcchannel.h" #include -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/synchronization/mutex.h" #include "sandboxed_api/call.h" @@ -36,7 +36,7 @@ absl::Status RPCChannel::Call(const FuncCall& call, uint32_t tag, FuncRet* ret, return absl::OkStatus(); } -sapi::StatusOr RPCChannel::Return(v::Type exp_type) { +absl::StatusOr RPCChannel::Return(v::Type exp_type) { uint32_t tag; uint64_t len; FuncRet ret; @@ -203,7 +203,7 @@ absl::Status RPCChannel::Close(int remote_fd) { return absl::OkStatus(); } -sapi::StatusOr RPCChannel::Strlen(void* str) { +absl::StatusOr RPCChannel::Strlen(void* str) { absl::MutexLock lock(&mutex_); if (!comms_->SendTLV(comms::kMsgStrlen, sizeof(str), reinterpret_cast(&str))) { diff --git a/sandboxed_api/rpcchannel.h b/sandboxed_api/rpcchannel.h index c54ef8e..4fec23b 100644 --- a/sandboxed_api/rpcchannel.h +++ b/sandboxed_api/rpcchannel.h @@ -18,7 +18,7 @@ #include #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/synchronization/mutex.h" #include "sandboxed_api/call.h" #include "sandboxed_api/sandbox2/comms.h" @@ -61,13 +61,13 @@ class RPCChannel { absl::Status Close(int remote_fd); // Returns length of a null-terminated c-style string (invokes strlen). - sapi::StatusOr Strlen(void* str); + absl::StatusOr Strlen(void* str); sandbox2::Comms* comms() const { return comms_; } private: // Receives the result after a call. - sapi::StatusOr Return(v::Type exp_type); + absl::StatusOr Return(v::Type exp_type); sandbox2::Comms* comms_; // Owned by sandbox2; absl::Mutex mutex_; diff --git a/sandboxed_api/sandbox.cc b/sandboxed_api/sandbox.cc index 18239a4..b18a1b0 100644 --- a/sandboxed_api/sandbox.cc +++ b/sandboxed_api/sandbox.cc @@ -391,7 +391,7 @@ absl::Status Sandbox::TransferFromSandboxee(v::Var* var) { return var->TransferFromSandboxee(GetRpcChannel(), pid()); } -sapi::StatusOr Sandbox::GetCString(const v::RemotePtr& str, +absl::StatusOr Sandbox::GetCString(const v::RemotePtr& str, uint64_t max_length) { if (!is_active()) { return absl::UnavailableError("Sandbox not active"); diff --git a/sandboxed_api/sandbox.h b/sandboxed_api/sandbox.h index 8b4ee6a..5d69eb0 100644 --- a/sandboxed_api/sandbox.h +++ b/sandboxed_api/sandbox.h @@ -102,7 +102,7 @@ class Sandbox { absl::Status TransferToSandboxee(v::Var* var); absl::Status TransferFromSandboxee(v::Var* var); - sapi::StatusOr GetCString(const v::RemotePtr& str, + absl::StatusOr GetCString(const v::RemotePtr& str, uint64_t max_length = 10ULL << 20 /* 10 MiB*/ ); diff --git a/sandboxed_api/sandbox2/BUILD.bazel b/sandboxed_api/sandbox2/BUILD.bazel index ad415c2..2bf7542 100644 --- a/sandboxed_api/sandbox2/BUILD.bazel +++ b/sandboxed_api/sandbox2/BUILD.bazel @@ -88,9 +88,9 @@ cc_library( ":regs", ":syscall", ":util", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", ], ) @@ -300,12 +300,12 @@ cc_library( "//sandboxed_api/util:flags", "//sandboxed_api/util:raw_logging", "//sandboxed_api/util:status", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/synchronization", @@ -374,9 +374,9 @@ cc_library( "//sandboxed_api/sandbox2/util:fileops", "//sandboxed_api/sandbox2/util:strerror", "//sandboxed_api/util:raw_logging", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@org_kernel_libcap//:libcap", @@ -411,10 +411,10 @@ cc_library( "//sandboxed_api/sandbox2/util:strerror", "//sandboxed_api/util:raw_logging", "//sandboxed_api/util:status", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", ], @@ -509,8 +509,8 @@ cc_library( "//sandboxed_api/sandbox2/util:fileops", "//sandboxed_api/sandbox2/util:strerror", "//sandboxed_api/util:raw_logging", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", ], @@ -526,9 +526,9 @@ cc_library( ":util", "//sandboxed_api/sandbox2/util:strerror", "//sandboxed_api/util:status", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/memory", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", ], ) @@ -573,10 +573,10 @@ cc_library( "//sandboxed_api/util:raw_logging", "//sandboxed_api/util:status", "//sandboxed_api/util:status_proto", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/synchronization", @@ -803,9 +803,9 @@ cc_test( ":testing", "//sandboxed_api/sandbox2/util:bpf_helper", "//sandboxed_api/util:status_matchers", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_glog//:glog", "@com_google_googletest//:gtest_main", diff --git a/sandboxed_api/sandbox2/buffer.cc b/sandboxed_api/sandbox2/buffer.cc index 9c39339..074618d 100644 --- a/sandboxed_api/sandbox2/buffer.cc +++ b/sandboxed_api/sandbox2/buffer.cc @@ -21,7 +21,7 @@ #include #include "absl/memory/memory.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "sandboxed_api/sandbox2/util.h" #include "sandboxed_api/sandbox2/util/strerror.h" @@ -29,7 +29,7 @@ namespace sandbox2 { // Creates a new Buffer that is backed by the specified file descriptor. -sapi::StatusOr> Buffer::CreateFromFd(int fd) { +absl::StatusOr> Buffer::CreateFromFd(int fd) { auto buffer = absl::WrapUnique(new Buffer{}); struct stat stat_buf; @@ -54,7 +54,7 @@ sapi::StatusOr> Buffer::CreateFromFd(int fd) { // Creates a new Buffer of the specified size, backed by a temporary file that // will be immediately deleted. -sapi::StatusOr> Buffer::CreateWithSize(int64_t size) { +absl::StatusOr> Buffer::CreateWithSize(int64_t size) { int fd; if (!util::CreateMemFd(&fd)) { return absl::InternalError("Could not create buffer temp file"); diff --git a/sandboxed_api/sandbox2/buffer.h b/sandboxed_api/sandbox2/buffer.h index 72f042d..d613bcd 100644 --- a/sandboxed_api/sandbox2/buffer.h +++ b/sandboxed_api/sandbox2/buffer.h @@ -19,7 +19,7 @@ #include #include -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" namespace sandbox2 { @@ -37,11 +37,11 @@ class Buffer final { // Creates a new Buffer that is backed by the specified file descriptor. // The Buffer takes ownership of the descriptor and will close it when // destroyed. - static sapi::StatusOr> CreateFromFd(int fd); + static absl::StatusOr> CreateFromFd(int fd); // Creates a new Buffer of the specified size, backed by a temporary file that // will be immediately deleted. - static sapi::StatusOr> CreateWithSize(int64_t size); + static absl::StatusOr> CreateWithSize(int64_t size); // Returns a pointer to the buffer, which is read/write. uint8_t* data() const { return buf_; } diff --git a/sandboxed_api/sandbox2/comms.cc b/sandboxed_api/sandbox2/comms.cc index 3e61013..8a357b6 100644 --- a/sandboxed_api/sandbox2/comms.cc +++ b/sandboxed_api/sandbox2/comms.cc @@ -36,7 +36,7 @@ #include "google/protobuf/message.h" #include "absl/memory/memory.h" #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/synchronization/mutex.h" diff --git a/sandboxed_api/sandbox2/examples/network_proxy/BUILD.bazel b/sandboxed_api/sandbox2/examples/network_proxy/BUILD.bazel index 480c078..fb07dd5 100644 --- a/sandboxed_api/sandbox2/examples/network_proxy/BUILD.bazel +++ b/sandboxed_api/sandbox2/examples/network_proxy/BUILD.bazel @@ -48,8 +48,8 @@ cc_binary( "//sandboxed_api/sandbox2/util:strerror", "//sandboxed_api/util:flags", "//sandboxed_api/util:status", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings:str_format", ], ) diff --git a/sandboxed_api/sandbox2/examples/network_proxy/networkproxy_bin.cc b/sandboxed_api/sandbox2/examples/network_proxy/networkproxy_bin.cc index b355522..84eb715 100644 --- a/sandboxed_api/sandbox2/examples/network_proxy/networkproxy_bin.cc +++ b/sandboxed_api/sandbox2/examples/network_proxy/networkproxy_bin.cc @@ -13,7 +13,7 @@ #include "sandboxed_api/util/flag.h" #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/str_format.h" #include "sandboxed_api/sandbox2/client.h" #include "sandboxed_api/sandbox2/comms.h" @@ -58,7 +58,7 @@ absl::Status CommunicationTest(int sock) { return absl::OkStatus(); } -sapi::StatusOr CreateAddres(int port) { +absl::StatusOr CreateAddres(int port) { static struct sockaddr_in6 saddr {}; saddr.sin6_family = AF_INET6; saddr.sin6_port = htons(port); @@ -86,7 +86,7 @@ absl::Status ConnectWithHandler(int s, const struct sockaddr_in6& saddr) { return absl::OkStatus(); } -sapi::StatusOr ConnectToServer(int port) { +absl::StatusOr ConnectToServer(int port) { SAPI_ASSIGN_OR_RETURN(struct sockaddr_in6 saddr, CreateAddres(port)); sandbox2::file_util::fileops::FDCloser s(socket(AF_INET6, SOCK_STREAM, 0)); @@ -134,7 +134,7 @@ int main(int argc, char** argv) { return 2; } - sapi::StatusOr sock_s = ConnectToServer(port); + absl::StatusOr sock_s = ConnectToServer(port); if (!sock_s.ok()) { LOG(ERROR) << sock_s.status().message(); return 3; diff --git a/sandboxed_api/sandbox2/forkserver.cc b/sandboxed_api/sandbox2/forkserver.cc index d0b637c..dc6a283 100644 --- a/sandboxed_api/sandbox2/forkserver.cc +++ b/sandboxed_api/sandbox2/forkserver.cc @@ -36,7 +36,7 @@ #include "absl/memory/memory.h" #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -142,7 +142,7 @@ absl::Status SendPid(int signaling_fd) { return absl::OkStatus(); } -sapi::StatusOr ReceivePid(int signaling_fd) { +absl::StatusOr ReceivePid(int signaling_fd) { union { struct cmsghdr cmh; char ctrl[CMSG_SPACE(sizeof(struct ucred))]; diff --git a/sandboxed_api/sandbox2/mounts.cc b/sandboxed_api/sandbox2/mounts.cc index e1c0198..7e800ea 100644 --- a/sandboxed_api/sandbox2/mounts.cc +++ b/sandboxed_api/sandbox2/mounts.cc @@ -27,7 +27,7 @@ #include "google/protobuf/util/message_differencer.h" #include "absl/container/flat_hash_set.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/ascii.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -97,7 +97,7 @@ absl::string_view GetOutsidePath(const MountTree::Node& node) { } } -sapi::StatusOr ExistingPathInsideDir( +absl::StatusOr ExistingPathInsideDir( absl::string_view dir_path, absl::string_view relative_path) { auto path = file::CleanPath(file::JoinPath(dir_path, relative_path)); if (file_util::fileops::StripBasename(path) != dir_path) { diff --git a/sandboxed_api/sandbox2/network_proxy/BUILD.bazel b/sandboxed_api/sandbox2/network_proxy/BUILD.bazel index d489a53..f099939 100644 --- a/sandboxed_api/sandbox2/network_proxy/BUILD.bazel +++ b/sandboxed_api/sandbox2/network_proxy/BUILD.bazel @@ -29,8 +29,8 @@ cc_library( ":filtering", "//sandboxed_api/sandbox2:comms", "//sandboxed_api/sandbox2/util:fileops", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/memory", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_glog//:glog", ], @@ -63,8 +63,8 @@ cc_library( "//sandboxed_api/sandbox2:comms", "//sandboxed_api/sandbox2/util:strerror", "//sandboxed_api/util:status", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_glog//:glog", ], diff --git a/sandboxed_api/sandbox2/network_proxy/filtering.cc b/sandboxed_api/sandbox2/network_proxy/filtering.cc index fc93e6c..aac47df 100644 --- a/sandboxed_api/sandbox2/network_proxy/filtering.cc +++ b/sandboxed_api/sandbox2/network_proxy/filtering.cc @@ -18,7 +18,7 @@ #include #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" @@ -27,7 +27,7 @@ namespace sandbox2 { -static sapi::StatusOr Addr6ToString( +static absl::StatusOr Addr6ToString( const struct sockaddr_in6* saddr) { char addr[INET6_ADDRSTRLEN]; int port = htons(saddr->sin6_port); @@ -39,7 +39,7 @@ static sapi::StatusOr Addr6ToString( } // Converts sockaddr_in structure into a string IPv4 representation. -static sapi::StatusOr Addr4ToString( +static absl::StatusOr Addr4ToString( const struct sockaddr_in* saddr) { char addr[INET_ADDRSTRLEN]; int port = htons(saddr->sin_port); @@ -51,7 +51,7 @@ static sapi::StatusOr Addr4ToString( } // Converts sockaddr_in6 structure into a string IPv6 representation. -sapi::StatusOr AddrToString(const struct sockaddr* saddr) { +absl::StatusOr AddrToString(const struct sockaddr* saddr) { switch (saddr->sa_family) { case AF_INET: return Addr4ToString(reinterpret_cast(saddr)); diff --git a/sandboxed_api/sandbox2/network_proxy/filtering.h b/sandboxed_api/sandbox2/network_proxy/filtering.h index c0a235b..b830d8e 100644 --- a/sandboxed_api/sandbox2/network_proxy/filtering.h +++ b/sandboxed_api/sandbox2/network_proxy/filtering.h @@ -19,14 +19,14 @@ #include -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "sandboxed_api/sandbox2/comms.h" namespace sandbox2 { // Converts sockaddr_in or sockaddr_in6 structure into a string // representation. -sapi::StatusOr AddrToString(const struct sockaddr* saddr); +absl::StatusOr AddrToString(const struct sockaddr* saddr); struct IPv4 { in_addr_t ip; diff --git a/sandboxed_api/sandbox2/network_proxy/server.cc b/sandboxed_api/sandbox2/network_proxy/server.cc index 41f6f7e..6ba1ba7 100644 --- a/sandboxed_api/sandbox2/network_proxy/server.cc +++ b/sandboxed_api/sandbox2/network_proxy/server.cc @@ -26,7 +26,7 @@ #include #include "absl/memory/memory.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "sandboxed_api/sandbox2/util/fileops.h" namespace sandbox2 { @@ -105,7 +105,7 @@ void NetworkProxyServer::NotifySuccess() { } void NetworkProxyServer::NotifyViolation(const struct sockaddr* saddr) { - if (sapi::StatusOr result = AddrToString(saddr); result.ok()) { + if (absl::StatusOr result = AddrToString(saddr); result.ok()) { violation_msg_ = std::move(result).value(); } else { violation_msg_ = std::string(result.status().message()); diff --git a/sandboxed_api/sandbox2/policybuilder.cc b/sandboxed_api/sandbox2/policybuilder.cc index d185631..dbae2d9 100644 --- a/sandboxed_api/sandbox2/policybuilder.cc +++ b/sandboxed_api/sandbox2/policybuilder.cc @@ -35,7 +35,7 @@ #include #include "absl/memory/memory.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/escaping.h" #include "absl/strings/match.h" #include "sandboxed_api/sandbox2/namespace.h" @@ -658,7 +658,7 @@ PolicyBuilder& PolicyBuilder::DangerDefaultAllowAll() { return *this; } -sapi::StatusOr PolicyBuilder::ValidateAbsolutePath( +absl::StatusOr PolicyBuilder::ValidateAbsolutePath( absl::string_view path) { if (!file::IsAbsolutePath(path)) { return absl::InvalidArgumentError( @@ -667,7 +667,7 @@ sapi::StatusOr PolicyBuilder::ValidateAbsolutePath( return ValidatePath(path); } -sapi::StatusOr PolicyBuilder::ValidatePath( +absl::StatusOr PolicyBuilder::ValidatePath( absl::string_view path) { std::string fixed_path = file::CleanPath(path); if (fixed_path != path) { @@ -688,7 +688,7 @@ std::vector PolicyBuilder::ResolveBpfFunc(BpfFunc f) { return policy; } -sapi::StatusOr> PolicyBuilder::TryBuild() { +absl::StatusOr> PolicyBuilder::TryBuild() { auto output = absl::WrapUnique(new Policy()); if (!last_status_.ok()) { diff --git a/sandboxed_api/sandbox2/policybuilder.h b/sandboxed_api/sandbox2/policybuilder.h index 07095ba..17e95ff 100644 --- a/sandboxed_api/sandbox2/policybuilder.h +++ b/sandboxed_api/sandbox2/policybuilder.h @@ -29,7 +29,7 @@ #include #include "absl/base/macros.h" #include "absl/memory/memory.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/string_view.h" #include "sandboxed_api/sandbox2/mounts.h" #include "sandboxed_api/sandbox2/network_proxy/filtering.h" @@ -390,7 +390,7 @@ class PolicyBuilder final { // Builds the policy returning a unique_ptr to it. This should only be called // once. - sapi::StatusOr> TryBuild(); + absl::StatusOr> TryBuild(); // Builds the policy returning a unique_ptr to it. This should only be called // once. @@ -532,9 +532,9 @@ class PolicyBuilder final { std::vector ResolveBpfFunc(BpfFunc f); - static sapi::StatusOr ValidateAbsolutePath( + static absl::StatusOr ValidateAbsolutePath( absl::string_view path); - static sapi::StatusOr ValidatePath(absl::string_view path); + static absl::StatusOr ValidatePath(absl::string_view path); void StoreDescription(PolicyBuilderDescription* pb_description); diff --git a/sandboxed_api/sandbox2/policybuilder_test.cc b/sandboxed_api/sandbox2/policybuilder_test.cc index ca13614..b5387d9 100644 --- a/sandboxed_api/sandbox2/policybuilder_test.cc +++ b/sandboxed_api/sandbox2/policybuilder_test.cc @@ -24,7 +24,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/memory/memory.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" @@ -58,7 +58,7 @@ class PolicyBuilderPeer { int policy_size() const { return builder_->user_policy_.size(); } - static sapi::StatusOr ValidateAbsolutePath( + static absl::StatusOr ValidateAbsolutePath( absl::string_view path) { return PolicyBuilder::ValidateAbsolutePath(path); } diff --git a/sandboxed_api/sandbox2/sandbox2.cc b/sandboxed_api/sandbox2/sandbox2.cc index 86c06dc..d0c1e22 100644 --- a/sandboxed_api/sandbox2/sandbox2.cc +++ b/sandboxed_api/sandbox2/sandbox2.cc @@ -21,7 +21,7 @@ #include #include "absl/memory/memory.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/time/time.h" #include "sandboxed_api/sandbox2/monitor.h" #include "sandboxed_api/sandbox2/result.h" @@ -34,7 +34,7 @@ Sandbox2::~Sandbox2() { } } -sapi::StatusOr Sandbox2::AwaitResultWithTimeout( +absl::StatusOr Sandbox2::AwaitResultWithTimeout( absl::Duration timeout) { CHECK(monitor_ != nullptr) << "Sandbox was not launched yet"; CHECK(monitor_thread_ != nullptr) << "Sandbox was already waited on"; diff --git a/sandboxed_api/sandbox2/sandbox2.h b/sandboxed_api/sandbox2/sandbox2.h index 633297f..62dd4fe 100644 --- a/sandboxed_api/sandbox2/sandbox2.h +++ b/sandboxed_api/sandbox2/sandbox2.h @@ -26,7 +26,7 @@ #include #include "absl/base/macros.h" #include "absl/memory/memory.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/executor.h" #include "sandboxed_api/sandbox2/ipc.h" @@ -76,7 +76,7 @@ class Sandbox2 final { // Waits for sandbox execution to finish within the timeout. // Returns execution result or a DeadlineExceededError if the sandboxee does // not finish in time. - sapi::StatusOr AwaitResultWithTimeout(absl::Duration timeout); + absl::StatusOr AwaitResultWithTimeout(absl::Duration timeout); // Requests termination of the sandboxee. // Sandbox should still waited with AwaitResult(), as it may finish for other diff --git a/sandboxed_api/sandbox2/util.cc b/sandboxed_api/sandbox2/util.cc index b760d26..55f7aa6 100644 --- a/sandboxed_api/sandbox2/util.cc +++ b/sandboxed_api/sandbox2/util.cc @@ -182,7 +182,7 @@ bool CreateMemFd(int* fd, const char* name) { return true; } -sapi::StatusOr Communicate(const std::vector& argv, +absl::StatusOr Communicate(const std::vector& argv, const std::vector& envv, std::string* output) { int cout_pipe[2]; @@ -280,7 +280,7 @@ std::string GetRlimitName(int resource) { } } -sapi::StatusOr ReadCPathFromPid(pid_t pid, uintptr_t ptr) { +absl::StatusOr ReadCPathFromPid(pid_t pid, uintptr_t ptr) { std::string path(PATH_MAX, '\0'); iovec local_iov[] = {{&path[0], path.size()}}; diff --git a/sandboxed_api/sandbox2/util.h b/sandboxed_api/sandbox2/util.h index e42bf72..a925b02 100644 --- a/sandboxed_api/sandbox2/util.h +++ b/sandboxed_api/sandbox2/util.h @@ -25,7 +25,7 @@ #include #include "absl/base/macros.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" namespace sandbox2 { namespace util { @@ -62,7 +62,7 @@ bool CreateMemFd(int* fd, const char* name = "buffer_file"); // Executes a the program given by argv and the specified environment and // captures any output to stdout/stderr. -sapi::StatusOr Communicate(const std::vector& argv, +absl::StatusOr Communicate(const std::vector& argv, const std::vector& envv, std::string* output); @@ -74,7 +74,7 @@ std::string GetRlimitName(int resource); // Reads a path string (NUL-terminated, shorter than PATH_MAX) from another // process memory -sapi::StatusOr ReadCPathFromPid(pid_t pid, uintptr_t ptr); +absl::StatusOr ReadCPathFromPid(pid_t pid, uintptr_t ptr); } // namespace util } // namespace sandbox2 diff --git a/sandboxed_api/sandbox2/util/BUILD.bazel b/sandboxed_api/sandbox2/util/BUILD.bazel index d48d9a4..924e22e 100644 --- a/sandboxed_api/sandbox2/util/BUILD.bazel +++ b/sandboxed_api/sandbox2/util/BUILD.bazel @@ -139,9 +139,9 @@ cc_library( "//sandboxed_api/sandbox2:util", "//sandboxed_api/util:raw_logging", "//sandboxed_api/util:status", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/base:endian", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", ], ) @@ -173,8 +173,8 @@ cc_library( deps = [ ":fileops", ":strerror", - "//sandboxed_api/util:statusor", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", ], ) @@ -199,8 +199,8 @@ cc_library( hdrs = ["maps_parser.h"], copts = sapi_platform_copts(), deps = [ - "//sandboxed_api/util:statusor", "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", ], ) diff --git a/sandboxed_api/sandbox2/util/maps_parser.cc b/sandboxed_api/sandbox2/util/maps_parser.cc index cf0955f..6687989 100644 --- a/sandboxed_api/sandbox2/util/maps_parser.cc +++ b/sandboxed_api/sandbox2/util/maps_parser.cc @@ -15,12 +15,12 @@ #include "sandboxed_api/sandbox2/util/maps_parser.h" #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/str_split.h" namespace sandbox2 { -sapi::StatusOr> ParseProcMaps( +absl::StatusOr> ParseProcMaps( const std::string& contents) { // Note: The format string // https://github.com/torvalds/linux/blob/v4.14/fs/proc/task_mmu.c#L289 diff --git a/sandboxed_api/sandbox2/util/maps_parser.h b/sandboxed_api/sandbox2/util/maps_parser.h index 862d3e7..ea0a419 100644 --- a/sandboxed_api/sandbox2/util/maps_parser.h +++ b/sandboxed_api/sandbox2/util/maps_parser.h @@ -19,7 +19,7 @@ #include #include -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" namespace sandbox2 { @@ -37,7 +37,7 @@ struct MapsEntry { std::string path; }; -sapi::StatusOr> ParseProcMaps( +absl::StatusOr> ParseProcMaps( const std::string& contents); } // namespace sandbox2 diff --git a/sandboxed_api/sandbox2/util/minielf.cc b/sandboxed_api/sandbox2/util/minielf.cc index dce033b..737dc97 100644 --- a/sandboxed_api/sandbox2/util/minielf.cc +++ b/sandboxed_api/sandbox2/util/minielf.cc @@ -95,7 +95,7 @@ class ElfParser { static constexpr size_t kMaxInterpreterSize = 1000; ElfParser() = default; - sapi::StatusOr Parse(FILE* elf, uint32_t features); + absl::StatusOr Parse(FILE* elf, uint32_t features); private: // Endianess support functions @@ -133,16 +133,16 @@ class ElfParser { // Reads elf header. absl::Status ReadFileHeader(); // Reads a single elf program header. - sapi::StatusOr ReadProgramHeader(absl::string_view src); + absl::StatusOr ReadProgramHeader(absl::string_view src); // Reads all elf program headers. absl::Status ReadProgramHeaders(); // Reads a single elf section header. - sapi::StatusOr ReadSectionHeader(absl::string_view src); + absl::StatusOr ReadSectionHeader(absl::string_view src); // Reads all elf section headers. absl::Status ReadSectionHeaders(); // Reads contents of an elf section. - sapi::StatusOr ReadSectionContents(int idx); - sapi::StatusOr ReadSectionContents( + absl::StatusOr ReadSectionContents(int idx); + absl::StatusOr ReadSectionContents( const Elf64_Shdr& section_header); // Reads all symbols from symtab section. absl::Status ReadSymbolsFromSymtab(const Elf64_Shdr& symtab); @@ -219,7 +219,7 @@ absl::Status ElfParser::ReadFileHeader() { return absl::OkStatus(); } -sapi::StatusOr ElfParser::ReadSectionHeader(absl::string_view src) { +absl::StatusOr ElfParser::ReadSectionHeader(absl::string_view src) { if (src.size() < sizeof(Elf64_Shdr)) { return absl::FailedPreconditionError( absl::StrCat("invalid section header data: got ", src.size(), @@ -266,7 +266,7 @@ absl::Status ElfParser::ReadSectionHeaders() { return absl::OkStatus(); } -sapi::StatusOr ElfParser::ReadSectionContents(int idx) { +absl::StatusOr ElfParser::ReadSectionContents(int idx) { if (idx < 0 || idx >= section_headers_.size()) { return absl::FailedPreconditionError( absl::StrCat("invalid section header index: ", idx)); @@ -274,7 +274,7 @@ sapi::StatusOr ElfParser::ReadSectionContents(int idx) { return ReadSectionContents(section_headers_.at(idx)); } -sapi::StatusOr ElfParser::ReadSectionContents( +absl::StatusOr ElfParser::ReadSectionContents( const Elf64_Shdr& section_header) { auto offset = section_header.sh_offset; if (offset > file_size_) { @@ -292,7 +292,7 @@ sapi::StatusOr ElfParser::ReadSectionContents( return rv; } -sapi::StatusOr ElfParser::ReadProgramHeader(absl::string_view src) { +absl::StatusOr ElfParser::ReadProgramHeader(absl::string_view src) { if (src.size() < sizeof(Elf64_Phdr)) { return absl::FailedPreconditionError( absl::StrCat("invalid program header data: got ", src.size(), @@ -454,7 +454,7 @@ absl::Status ElfParser::ReadImportedLibrariesFromDynamic( return absl::OkStatus(); } -sapi::StatusOr ElfParser::Parse(FILE* elf, uint32_t features) { +absl::StatusOr ElfParser::Parse(FILE* elf, uint32_t features) { elf_ = elf; // Basic sanity check. if (features & ~(ElfFile::kAll)) { @@ -511,7 +511,7 @@ sapi::StatusOr ElfParser::Parse(FILE* elf, uint32_t features) { return std::move(result_); } -sapi::StatusOr ElfFile::ParseFromFile(const std::string& filename, +absl::StatusOr ElfFile::ParseFromFile(const std::string& filename, uint32_t features) { std::unique_ptr elf{fopen(filename.c_str(), "r"), [](FILE* f) { fclose(f); }}; diff --git a/sandboxed_api/sandbox2/util/minielf.h b/sandboxed_api/sandbox2/util/minielf.h index c33a604..027e21c 100644 --- a/sandboxed_api/sandbox2/util/minielf.h +++ b/sandboxed_api/sandbox2/util/minielf.h @@ -20,7 +20,7 @@ #include #include -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" namespace sandbox2 { @@ -33,7 +33,7 @@ class ElfFile { std::string name; }; - static sapi::StatusOr ParseFromFile(const std::string& filename, + static absl::StatusOr ParseFromFile(const std::string& filename, uint32_t features); int64_t file_size() const { return file_size_; } diff --git a/sandboxed_api/sandbox2/util/temp_file.cc b/sandboxed_api/sandbox2/util/temp_file.cc index 602a18c..09a5a1b 100644 --- a/sandboxed_api/sandbox2/util/temp_file.cc +++ b/sandboxed_api/sandbox2/util/temp_file.cc @@ -22,7 +22,7 @@ #include #include -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "sandboxed_api/sandbox2/util/fileops.h" #include "sandboxed_api/sandbox2/util/strerror.h" @@ -33,7 +33,7 @@ namespace { constexpr absl::string_view kMktempSuffix = "XXXXXX"; } // namespace -sapi::StatusOr> CreateNamedTempFile( +absl::StatusOr> CreateNamedTempFile( absl::string_view prefix) { std::string name_template = absl::StrCat(prefix, kMktempSuffix); int fd = mkstemp(&name_template[0]); @@ -43,7 +43,7 @@ sapi::StatusOr> CreateNamedTempFile( return std::pair{std::move(name_template), fd}; } -sapi::StatusOr CreateNamedTempFileAndClose( +absl::StatusOr CreateNamedTempFileAndClose( absl::string_view prefix) { auto result_or = CreateNamedTempFile(prefix); if (result_or.ok()) { @@ -56,7 +56,7 @@ sapi::StatusOr CreateNamedTempFileAndClose( return result_or.status(); } -sapi::StatusOr CreateTempDir(absl::string_view prefix) { +absl::StatusOr CreateTempDir(absl::string_view prefix) { std::string name_template = absl::StrCat(prefix, kMktempSuffix); if (mkdtemp(&name_template[0]) == nullptr) { return absl::UnknownError(absl::StrCat("mkdtemp():", StrError(errno))); diff --git a/sandboxed_api/sandbox2/util/temp_file.h b/sandboxed_api/sandbox2/util/temp_file.h index ae8f986..8324a61 100644 --- a/sandboxed_api/sandbox2/util/temp_file.h +++ b/sandboxed_api/sandbox2/util/temp_file.h @@ -17,24 +17,24 @@ #include -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" namespace sandbox2 { // Creates a temporary file under a path starting with prefix. File is not // unlinked and its path is returned together with an open fd. -sapi::StatusOr> CreateNamedTempFile( +absl::StatusOr> CreateNamedTempFile( absl::string_view prefix); // Creates a temporary file under a path starting with prefix. File is not // unlinked and its path is returned. FD of the created file is closed just // after creation. -sapi::StatusOr CreateNamedTempFileAndClose( +absl::StatusOr CreateNamedTempFileAndClose( absl::string_view prefix); // Creates a temporary directory under a path starting with prefix. // Returns the path of the created directory. -sapi::StatusOr CreateTempDir(absl::string_view prefix); +absl::StatusOr CreateTempDir(absl::string_view prefix); } // namespace sandbox2 diff --git a/sandboxed_api/tools/clang_generator/emitter.cc b/sandboxed_api/tools/clang_generator/emitter.cc index 5f30953..03bb5e3 100644 --- a/sandboxed_api/tools/clang_generator/emitter.cc +++ b/sandboxed_api/tools/clang_generator/emitter.cc @@ -15,7 +15,7 @@ #include "sandboxed_api/tools/clang_generator/emitter.h" #include "absl/random/random.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/match.h" @@ -47,7 +47,7 @@ constexpr absl::string_view kHeaderProlog = #include "absl/base/macros.h" #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "sandboxed_api/sandbox.h" #include "sandboxed_api/vars.h" #include "sandboxed_api/util/status_macros.h" @@ -197,7 +197,7 @@ std::string PrintFunctionPrototype(const clang::FunctionDecl* decl) { return out; } -sapi::StatusOr EmitFunction(const clang::FunctionDecl* decl) { +absl::StatusOr EmitFunction(const clang::FunctionDecl* decl) { std::string out; absl::StrAppend(&out, "\n// ", PrintFunctionPrototype(decl), "\n"); const std::string function_name = decl->getNameAsString(); @@ -249,7 +249,7 @@ sapi::StatusOr EmitFunction(const clang::FunctionDecl* decl) { return out; } -sapi::StatusOr EmitHeader( +absl::StatusOr EmitHeader( std::vector functions, const QualTypeSet& types, const GeneratorOptions& options) { std::string out; diff --git a/sandboxed_api/tools/clang_generator/emitter.h b/sandboxed_api/tools/clang_generator/emitter.h index ad9f5f8..78e1f12 100644 --- a/sandboxed_api/tools/clang_generator/emitter.h +++ b/sandboxed_api/tools/clang_generator/emitter.h @@ -18,7 +18,7 @@ #include #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "absl/strings/string_view.h" #include "clang/AST/Decl.h" #include "clang/AST/Type.h" @@ -36,7 +36,7 @@ namespace sapi { std::string GetIncludeGuard(absl::string_view filename); // Outputs a formatted header for a list of functions and their related types. -sapi::StatusOr EmitHeader( +absl::StatusOr EmitHeader( std::vector functions, const QualTypeSet& types, const GeneratorOptions& options); diff --git a/sandboxed_api/tools/clang_generator/generator.cc b/sandboxed_api/tools/clang_generator/generator.cc index ffe2106..90504eb 100644 --- a/sandboxed_api/tools/clang_generator/generator.cc +++ b/sandboxed_api/tools/clang_generator/generator.cc @@ -18,7 +18,7 @@ #include #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "clang/Format/Format.h" #include "sandboxed_api/sandbox2/util/fileops.h" #include "sandboxed_api/tools/clang_generator/diagnostics.h" @@ -67,7 +67,7 @@ bool GeneratorASTVisitor::VisitFunctionDecl(clang::FunctionDecl* decl) { namespace internal { -sapi::StatusOr ReformatGoogleStyle(const std::string& filename, +absl::StatusOr ReformatGoogleStyle(const std::string& filename, const std::string& code) { // Configure code style based on Google style, but enforce pointer alignment clang::format::FormatStyle style = diff --git a/sandboxed_api/tools/clang_generator/generator.h b/sandboxed_api/tools/clang_generator/generator.h index 3b9680b..8732a26 100644 --- a/sandboxed_api/tools/clang_generator/generator.h +++ b/sandboxed_api/tools/clang_generator/generator.h @@ -20,7 +20,7 @@ #include "absl/container/flat_hash_set.h" #include "absl/memory/memory.h" #include "absl/status/status.h" -#include "sandboxed_api/util/statusor.h" +#include "absl/status/statusor.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Frontend/CompilerInstance.h" @@ -66,7 +66,7 @@ class GeneratorASTVisitor namespace internal { -sapi::StatusOr ReformatGoogleStyle(const std::string& filename, +absl::StatusOr ReformatGoogleStyle(const std::string& filename, const std::string& code); } // namespace internal diff --git a/sandboxed_api/tools/clang_generator/types.cc b/sandboxed_api/tools/clang_generator/types.cc index 321d1e2..8efb4ef 100644 --- a/sandboxed_api/tools/clang_generator/types.cc +++ b/sandboxed_api/tools/clang_generator/types.cc @@ -208,7 +208,7 @@ std::string MapQualTypeReturn(const clang::ASTContext& context, return "absl::Status"; } // Remove const qualifier like in MapQualType(). - return absl::StrCat("sapi::StatusOr<", + return absl::StrCat("absl::StatusOr<", MaybeRemoveConst(context, qual).getAsString(), ">"); } diff --git a/sandboxed_api/tools/clang_generator/types.h b/sandboxed_api/tools/clang_generator/types.h index 82a4478..b4d5946 100644 --- a/sandboxed_api/tools/clang_generator/types.h +++ b/sandboxed_api/tools/clang_generator/types.h @@ -68,7 +68,7 @@ std::string MapQualTypeParameter(const clang::ASTContext& context, // Maps a qualified type used as a function return type to a type name // compatible with the generated Sandboxed API. Uses MapQualTypeParameter() and -// wraps the type in a sapi::StatusOr<> if qual is non-void. Otherwise returns +// wraps the type in a absl::StatusOr<> if qual is non-void. Otherwise returns // absl::Status. std::string MapQualTypeReturn(const clang::ASTContext& context, clang::QualType qual); diff --git a/sandboxed_api/tools/generator2/code.py b/sandboxed_api/tools/generator2/code.py index fb31101..84cff80 100644 --- a/sandboxed_api/tools/generator2/code.py +++ b/sandboxed_api/tools/generator2/code.py @@ -461,7 +461,7 @@ class ReturnType(ArgumentType): """Class representing function return type. Attributes: - return_type: sapi::StatusOr where T is original return type, or + return_type: absl::StatusOr where T is original return type, or absl::Status for functions returning void """ @@ -474,7 +474,7 @@ class ReturnType(ArgumentType): """Returns function return type prepared from the type.""" # TODO(szwl): const ptrs do not play well with SAPI C++ API... spelling = self._clang_type.spelling.replace('const', '') - return_type = 'sapi::StatusOr<{}>'.format(spelling) + return_type = 'absl::StatusOr<{}>'.format(spelling) return_type = 'absl::Status' if self.is_void() else return_type return return_type diff --git a/sandboxed_api/tools/generator2/code_test_util.py b/sandboxed_api/tools/generator2/code_test_util.py index 1fd5f9d..82ee3a6 100644 --- a/sandboxed_api/tools/generator2/code_test_util.py +++ b/sandboxed_api/tools/generator2/code_test_util.py @@ -32,7 +32,7 @@ class TestApi { ::sapi::Sandbox* sandbox() const { return sandbox_; } // int function_a(int, int) - sapi::StatusOr function_a(int x, int y) { + absl::StatusOr function_a(int x, int y) { ::sapi::v::Int ret; ::sapi::v::Int x_((x)); ::sapi::v::Int y_((y)); @@ -42,7 +42,7 @@ class TestApi { } // int types_1(bool, unsigned char, char, unsigned short, short) - sapi::StatusOr types_1(bool a0, unsigned char a1, char a2, unsigned short a3, short a4) { + absl::StatusOr types_1(bool a0, unsigned char a1, char a2, unsigned short a3, short a4) { ::sapi::v::Int ret; ::sapi::v::Bool a0_((a0)); ::sapi::v::UChar a1_((a1)); @@ -55,7 +55,7 @@ class TestApi { } // int types_2(int, unsigned int, long, unsigned long) - sapi::StatusOr types_2(int a0, unsigned int a1, long a2, unsigned long a3) { + absl::StatusOr types_2(int a0, unsigned int a1, long a2, unsigned long a3) { ::sapi::v::Int ret; ::sapi::v::Int a0_((a0)); ::sapi::v::UInt a1_((a1)); @@ -67,7 +67,7 @@ class TestApi { } // int types_3(long long, unsigned long long, float, double) - sapi::StatusOr types_3(long long a0, unsigned long long a1, float a2, double a3) { + absl::StatusOr types_3(long long a0, unsigned long long a1, float a2, double a3) { ::sapi::v::Int ret; ::sapi::v::LLong a0_((a0)); ::sapi::v::ULLong a1_((a1)); @@ -79,7 +79,7 @@ class TestApi { } // int types_4(signed char, short, int, long) - sapi::StatusOr types_4(signed char a0, short a1, int a2, long a3) { + absl::StatusOr types_4(signed char a0, short a1, int a2, long a3) { ::sapi::v::Int ret; ::sapi::v::SChar a0_((a0)); ::sapi::v::Short a1_((a1)); @@ -91,7 +91,7 @@ class TestApi { } // int types_5(long long, long double) - sapi::StatusOr types_5(long long a0, long double a1) { + absl::StatusOr types_5(long long a0, long double a1) { ::sapi::v::Int ret; ::sapi::v::LLong a0_((a0)); ::sapi::v::Reg a1_((a1)); @@ -136,7 +136,7 @@ class TestApi { ::sapi::Sandbox* sandbox() const { return sandbox_; } // uint function(uintp) - sapi::StatusOr function(::sapi::v::Ptr* a) { + absl::StatusOr function(::sapi::v::Ptr* a) { ::sapi::v::UInt ret; SAPI_RETURN_IF_ERROR(sandbox_->Call("function", &ret, a)); @@ -173,7 +173,7 @@ class TestApi { ::sapi::Sandbox* sandbox() const { return sandbox_; } // ProcessStatus ProcessDatapoint(ProcessStatus) - sapi::StatusOr ProcessDatapoint(ProcessStatus status) { + absl::StatusOr ProcessDatapoint(ProcessStatus status) { ::sapi::v::IntBase ret; ::sapi::v::IntBase status_((status)); diff --git a/sandboxed_api/util/statusor_test.cc b/sandboxed_api/util/statusor_test.cc deleted file mode 100644 index ba80ce1..0000000 --- a/sandboxed_api/util/statusor_test.cc +++ /dev/null @@ -1,407 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// This file is a custom fork of the version in Asylo. This will become obsolete -// and will be replaced once Abseil releases absl::Status. - -#include "sandboxed_api/util/statusor.h" - -#include -#include -#include - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "sandboxed_api/util/status_matchers.h" - -using ::testing::Eq; -using ::testing::IsFalse; -using ::testing::Not; -using ::testing::Pointee; - -namespace sapi { -namespace { - -constexpr auto kErrorCode = absl::StatusCode::kInvalidArgument; -constexpr char kErrorMessage[] = "Invalid argument"; - -const int kIntElement = 47; -constexpr char kStringElement[] = "47 is 42, corrected for inflation"; - -// A data type without a default constructor. -struct Foo { - int bar; - std::string baz; - - explicit Foo(int value) : bar(value), baz(kStringElement) {} -}; - -// A data type with dynamically-allocated data. -struct HeapAllocatedObject { - int* value; - - HeapAllocatedObject() { - value = new int; - *value = kIntElement; - } - - HeapAllocatedObject(const HeapAllocatedObject& other) { *this = other; } - - HeapAllocatedObject& operator=(const HeapAllocatedObject& other) { - value = new int; - *value = *other.value; - return *this; - } - - HeapAllocatedObject(HeapAllocatedObject&& other) { *this = std::move(other); } - - HeapAllocatedObject& operator=(HeapAllocatedObject&& other) { - value = other.value; - other.value = nullptr; - return *this; - } - - ~HeapAllocatedObject() { delete value; } -}; - -// Constructs a Foo. -struct FooCtor { - using value_type = Foo; - - Foo operator()() { return Foo(kIntElement); } -}; - -// Constructs a HeapAllocatedObject. -struct HeapAllocatedObjectCtor { - using value_type = HeapAllocatedObject; - - HeapAllocatedObject operator()() { return HeapAllocatedObject(); } -}; - -// Constructs an integer. -struct IntCtor { - using value_type = int; - - int operator()() { return kIntElement; } -}; - -// Constructs a string. -struct StringCtor { - using value_type = std::string; - - std::string operator()() { return std::string(kStringElement); } -}; - -// Constructs a vector of strings. -struct StringVectorCtor { - using value_type = std::vector; - - std::vector operator()() { - return {kStringElement, kErrorMessage}; - } -}; - -bool operator==(const Foo& lhs, const Foo& rhs) { - return (lhs.bar == rhs.bar) && (lhs.baz == rhs.baz); -} - -bool operator==(const HeapAllocatedObject& lhs, - const HeapAllocatedObject& rhs) { - return *lhs.value == *rhs.value; -} - -// Returns an rvalue reference to the StatusOr object pointed to by -// |statusor|. -template -StatusOr&& MoveStatusOr(StatusOr* statusor) { - return std::move(*statusor); -} - -// A test fixture is required for typed tests. -template -class StatusOrTest : public ::testing::Test {}; - -using TestTypes = ::testing::Types; -TYPED_TEST_SUITE(StatusOrTest, TestTypes); - -// Verify that the default constructor for StatusOr constructs an object with a -// non-ok status. -TYPED_TEST(StatusOrTest, ConstructorDefault) { - StatusOr statusor; - EXPECT_THAT(statusor.ok(), IsFalse()); - EXPECT_THAT(statusor.status().code(), Eq(absl::StatusCode::kUnknown)); -} - -// Verify that StatusOr can be constructed from a Status object. -TYPED_TEST(StatusOrTest, ConstructorStatus) { - StatusOr statusor( - absl::Status(kErrorCode, kErrorMessage)); - - EXPECT_THAT(statusor.ok(), IsFalse()); - EXPECT_THAT(statusor.status().ok(), IsFalse()); - EXPECT_THAT(statusor.status(), Eq(absl::Status(kErrorCode, kErrorMessage))); -} - -// Verify that StatusOr can be constructed from an object of its element type. -TYPED_TEST(StatusOrTest, ConstructorElementConstReference) { - auto value = TypeParam()(); - StatusOr statusor{value}; - - ASSERT_THAT(statusor, IsOk()); - ASSERT_THAT(statusor.status(), IsOk()); - EXPECT_THAT(statusor.ValueOrDie(), Eq(value)); -} - -// Verify that StatusOr can be constructed from an rvalue reference of an object -// of its element type. -TYPED_TEST(StatusOrTest, ConstructorElementRValue) { - auto value = TypeParam()(); - auto value_copy(value); - StatusOr statusor(std::move(value)); - - ASSERT_THAT(statusor, IsOk()); - ASSERT_THAT(statusor.status(), IsOk()); - - // Compare to a copy of the original value, since the original was moved. - EXPECT_THAT(statusor.ValueOrDie(), Eq(value_copy)); -} - -// Verify that StatusOr can be copy-constructed from a StatusOr with a non-ok -// status. -TYPED_TEST(StatusOrTest, CopyConstructorNonOkStatus) { - StatusOr statusor1 = - absl::Status(kErrorCode, kErrorMessage); - StatusOr statusor2(statusor1); - - EXPECT_THAT(statusor1.ok(), Eq(statusor2.ok())); - EXPECT_THAT(statusor1.status(), Eq(statusor2.status())); -} - -// Verify that StatusOr can be copy-constructed from a StatusOr with an ok -// status. -TYPED_TEST(StatusOrTest, CopyConstructorOkStatus) { - StatusOr statusor1{TypeParam()()}; - StatusOr statusor2{statusor1}; - - EXPECT_THAT(statusor1.ok(), Eq(statusor2.ok())); - ASSERT_THAT(statusor2, IsOk()); - EXPECT_THAT(statusor1.ValueOrDie(), Eq(statusor2.ValueOrDie())); -} - -// Verify that copy-assignment of a StatusOr with a non-ok is working as -// expected. -TYPED_TEST(StatusOrTest, CopyAssignmentNonOkStatus) { - StatusOr statusor1{ - absl::Status(kErrorCode, kErrorMessage)}; - StatusOr statusor2{TypeParam()()}; - - // Invoke the copy-assignment operator. - statusor2 = statusor1; - EXPECT_THAT(statusor1.ok(), Eq(statusor2.ok())); - EXPECT_THAT(statusor1.status(), Eq(statusor2.status())); -} - -// Verify that copy-assignment of a StatusOr with an ok status is working as -// expected. -TYPED_TEST(StatusOrTest, CopyAssignmentOkStatus) { - StatusOr statusor1{TypeParam()()}; - StatusOr statusor2{ - absl::Status(kErrorCode, kErrorMessage)}; - - // Invoke the copy-assignment operator. - statusor2 = statusor1; - EXPECT_THAT(statusor1.ok(), Eq(statusor2.ok())); - ASSERT_THAT(statusor2, IsOk()); - EXPECT_THAT(statusor1.ValueOrDie(), Eq(statusor2.ValueOrDie())); -} - -// Verify that StatusOr can be move-constructed from a StatusOr with a non-ok -// status. -TYPED_TEST(StatusOrTest, MoveConstructorNonOkStatus) { - absl::Status status(kErrorCode, kErrorMessage); - StatusOr statusor1(status); - StatusOr statusor2(std::move(statusor1)); - - // Verify that the status of the donor object was updated. - EXPECT_THAT(statusor1.ok(), IsFalse()); // NOLINT - EXPECT_THAT(statusor1.status(), StatusIs(absl::StatusCode::kInternal)); - - // Verify that the destination object contains the status previously held by - // the donor. - EXPECT_THAT(statusor2.ok(), IsFalse()); - EXPECT_THAT(statusor2.status(), Eq(status)); -} - -// Verify that StatusOr can be move-constructed from a StatusOr with an ok -// status. -TYPED_TEST(StatusOrTest, MoveConstructorOkStatus) { - auto value = TypeParam()(); - StatusOr statusor1(value); - StatusOr statusor2(std::move(statusor1)); - - // The destination object should possess the value previously held by the - // donor. - ASSERT_THAT(statusor2, IsOk()); - EXPECT_THAT(statusor2.ValueOrDie(), Eq(value)); -} - -// Verify that move-assignment from a StatusOr with a non-ok status is working -// as expected. -TYPED_TEST(StatusOrTest, MoveAssignmentOperatorNonOkStatus) { - absl::Status status(kErrorCode, kErrorMessage); - StatusOr statusor1(status); - StatusOr statusor2{TypeParam()()}; - - // Invoke the move-assignment operator. - statusor2 = std::move(statusor1); - - // Verify that the status of the donor object was updated. - EXPECT_THAT(statusor1.ok(), IsFalse()); // NOLINT - EXPECT_THAT(statusor1.status(), StatusIs(absl::StatusCode::kInternal)); - - // Verify that the destination object contains the status previously held by - // the donor. - EXPECT_THAT(statusor2.ok(), IsFalse()); - EXPECT_THAT(statusor2.status(), Eq(status)); -} - -// Verify that move-assignment from a StatusOr with an ok status is working as -// expected. -TYPED_TEST(StatusOrTest, MoveAssignmentOperatorOkStatus) { - auto value = TypeParam()(); - StatusOr statusor1(value); - StatusOr statusor2( - absl::Status(kErrorCode, kErrorMessage)); - - // Invoke the move-assignment operator. - statusor2 = std::move(statusor1); - - // The destination object should possess the value previously held by the - // donor. - ASSERT_THAT(statusor2, IsOk()); - EXPECT_THAT(statusor2.ValueOrDie(), Eq(value)); -} - -// Verify that the sapi::IsOk() gMock matcher works with StatusOr. -TYPED_TEST(StatusOrTest, IsOkMatcher) { - auto value = TypeParam()(); - StatusOr statusor(value); - - EXPECT_THAT(statusor, IsOk()); - - statusor = StatusOr( - absl::Status(kErrorCode, kErrorMessage)); - EXPECT_THAT(statusor, Not(IsOk())); -} - -// Tests for move-only types. These tests use std::unique_ptr<> as the -// test type, since it is valuable to support this type in the Asylo infra. -// These tests are not part of the typed test suite for the following reasons: -// * std::unique_ptr<> cannot be used as a type in tests that expect -// the test type to support copy operations. -// * std::unique_ptr<> provides an equality operator that checks equality of -// the underlying ptr. Consequently, it is difficult to generalize existing -// tests that verify ValueOrDie() functionality using equality comparisons. - -// Verify that a StatusOr object can be constructed from a move-only type. -TEST(StatusOrTest, InitializationMoveOnlyType) { - auto* str = new std::string(kStringElement); - std::unique_ptr value(str); - StatusOr> statusor(std::move(value)); - - ASSERT_THAT(statusor, IsOk()); - EXPECT_THAT(statusor.ValueOrDie().get(), Eq(str)); -} - -// Verify that a StatusOr object can be move-constructed from a move-only type. -TEST(StatusOrTest, MoveConstructorMoveOnlyType) { - auto* str = new std::string(kStringElement); - std::unique_ptr value(str); - StatusOr> statusor1(std::move(value)); - StatusOr> statusor2(std::move(statusor1)); - - // The destination object should possess the value previously held by the - // donor. - ASSERT_THAT(statusor2, IsOk()); - EXPECT_THAT(statusor2.ValueOrDie().get(), Eq(str)); -} - -// Verify that a StatusOr object can be move-assigned to from a StatusOr object -// containing a move-only type. -TEST(StatusOrTest, MoveAssignmentMoveOnlyType) { - auto* str = new std::string(kStringElement); - std::unique_ptr value(str); - StatusOr> statusor1(std::move(value)); - StatusOr> statusor2( - absl::Status(kErrorCode, kErrorMessage)); - - // Invoke the move-assignment operator. - statusor2 = std::move(statusor1); - - // The destination object should possess the value previously held by the - // donor. - ASSERT_THAT(statusor2, IsOk()); - EXPECT_THAT(statusor2.ValueOrDie().get(), Eq(str)); -} - -// Verify that a value can be moved out of a StatusOr object via ValueOrDie(). -TEST(StatusOrTest, ValueOrDieMovedValue) { - auto* str = new std::string(kStringElement); - std::unique_ptr value(str); - StatusOr> statusor(std::move(value)); - - std::unique_ptr moved_value = std::move(statusor).ValueOrDie(); - EXPECT_THAT(moved_value.get(), Eq(str)); - EXPECT_THAT(*moved_value, Eq(kStringElement)); -} - -TEST(StatusOrTest, MapToStatusOrUniquePtr) { - // A reduced version of a problematic type found in the wild. All of the - // operations below should compile. - using MapType = std::map>>; - - MapType a; - - // Move-construction - MapType b(std::move(a)); - - // Move-assignment - a = std::move(b); -} - -TEST(StatusOrTest, ValueOrOk) { - const StatusOr status_or = 0; - EXPECT_EQ(status_or.value_or(-1), 0); -} - -TEST(StatusOrTest, ValueOrDefault) { - const StatusOr status_or = absl::CancelledError(); - EXPECT_EQ(status_or.value_or(-1), -1); -} - -TEST(StatusOrTest, MoveOnlyValueOrOk) { - EXPECT_THAT(StatusOr>(absl::make_unique(0)) - .value_or(absl::make_unique(-1)), - Pointee(0)); -} - -TEST(StatusOr, MoveOnlyValueOrDefault) { - EXPECT_THAT(StatusOr>(absl::CancelledError()) - .value_or(absl::make_unique(-1)), - Pointee(-1)); -} - -} // namespace -} // namespace sapi diff --git a/sandboxed_api/var_proto.h b/sandboxed_api/var_proto.h index 4d1dac2..ffa8128 100644 --- a/sandboxed_api/var_proto.h +++ b/sandboxed_api/var_proto.h @@ -41,7 +41,7 @@ class Proto : public Pointable, public Var { explicit Proto(const T& proto) : wrapped_var_(SerializeProto(proto).value()) {} - static sapi::StatusOr> FromMessage(const T& proto) { + static absl::StatusOr> FromMessage(const T& proto) { SAPI_ASSIGN_OR_RETURN(std::vector len_val, SerializeProto(proto)); return Proto(len_val); } @@ -59,7 +59,7 @@ class Proto : public Pointable, public Var { void* GetLocal() const override { return wrapped_var_.GetLocal(); } // Returns a copy of the stored protobuf object. - sapi::StatusOr GetMessage() const { + absl::StatusOr GetMessage() const { return DeserializeProto( reinterpret_cast(wrapped_var_.GetData()), wrapped_var_.GetDataSize());