From aaa3eded8f4a0e2a22188c73892eddd28b07c91a Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Mon, 20 Jul 2020 07:05:24 -0700 Subject: [PATCH] Rename `SYNC_*` constants to conform to style guide PiperOrigin-RevId: 322137271 Change-Id: I03d7f2e4841f42e439359727a686d55f1b4ab081 --- sandboxed_api/sandbox.cc | 8 ++++---- sandboxed_api/var_int.h | 2 +- sandboxed_api/var_pointable.h | 19 ++++++++----------- sandboxed_api/var_ptr.h | 14 ++++++++------ sandboxed_api/var_void.h | 2 +- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/sandboxed_api/sandbox.cc b/sandboxed_api/sandbox.cc index d746e93..79d93b1 100644 --- a/sandboxed_api/sandbox.cc +++ b/sandboxed_api/sandbox.cc @@ -239,7 +239,7 @@ absl::Status Sandbox::SynchronizePtrBefore(v::Callable* ptr) { } // Cast is safe, since type is v::Type::kPointer auto* p = static_cast(ptr); - if (p->GetSyncType() == v::Pointable::SYNC_NONE) { + if (p->GetSyncType() == v::Pointable::kSyncNone) { return absl::OkStatus(); } @@ -250,9 +250,9 @@ absl::Status Sandbox::SynchronizePtrBefore(v::Callable* ptr) { } // Allocation occurs during both before/after synchronization modes. But the - // memory is transferred to the sandboxee only if v::Pointable::SYNC_BEFORE + // memory is transferred to the sandboxee only if v::Pointable::kSyncBefore // was requested. - if ((p->GetSyncType() & v::Pointable::SYNC_BEFORE) == 0) { + if ((p->GetSyncType() & v::Pointable::kSyncBefore) == 0) { return absl::OkStatus(); } @@ -270,7 +270,7 @@ absl::Status Sandbox::SynchronizePtrAfter(v::Callable* ptr) const { return absl::OkStatus(); } v::Ptr* p = reinterpret_cast(ptr); - if ((p->GetSyncType() & v::Pointable::SYNC_AFTER) == 0) { + if ((p->GetSyncType() & v::Pointable::kSyncAfter) == 0) { return absl::OkStatus(); } diff --git a/sandboxed_api/var_int.h b/sandboxed_api/var_int.h index 7f5b24b..81443ca 100644 --- a/sandboxed_api/var_int.h +++ b/sandboxed_api/var_int.h @@ -32,7 +32,7 @@ class IntBase : public Reg, public Pointable { IntBase() : IntBase(static_cast(0)) {} explicit IntBase(T value) { this->SetValue(value); } - Ptr* CreatePtr(Pointable::SyncType type = Pointable::SYNC_NONE) override { + Ptr* CreatePtr(Pointable::SyncType type = Pointable::kSyncNone) override { return new Ptr(this, type); } }; diff --git a/sandboxed_api/var_pointable.h b/sandboxed_api/var_pointable.h index 9421d73..33cccf1 100644 --- a/sandboxed_api/var_pointable.h +++ b/sandboxed_api/var_pointable.h @@ -33,17 +33,17 @@ class Pointable { public: enum SyncType { // Do not synchronize the underlying object after/before calls. - SYNC_NONE = 0x0, + kSyncNone = 0x0, // Synchronize the underlying object (send the data to the sandboxee) // before the call takes place. - SYNC_BEFORE = 0x1, + kSyncBefore = 0x1, // Synchronize the underlying object (retrieve data from the sandboxee) // after the call has finished. - SYNC_AFTER = 0x2, + kSyncAfter = 0x2, // Synchronize the underlying object with the remote object, by sending the // data to the sandboxee before the call, and retrieving it from the // sandboxee after the call has finished. - SYNC_BOTH = SYNC_BEFORE | SYNC_AFTER, + kSyncBoth = kSyncBefore | kSyncAfter, }; // Necessary to implement creation of Ptr in inheriting class as it is @@ -53,7 +53,7 @@ class Pointable { // Functions to get pointers with certain type of synchronization scheme. Ptr* PtrNone() { if (ptr_none_ == nullptr) { - ptr_none_.reset(CreatePtr(SYNC_NONE)); + ptr_none_.reset(CreatePtr(kSyncNone)); } return ptr_none_.get(); @@ -61,25 +61,22 @@ class Pointable { Ptr* PtrBoth() { if (ptr_both_ == nullptr) { - ptr_both_.reset(CreatePtr(SYNC_BOTH)); + ptr_both_.reset(CreatePtr(kSyncBoth)); } - return ptr_both_.get(); } Ptr* PtrBefore() { if (ptr_before_ == nullptr) { - ptr_before_.reset(CreatePtr(SYNC_BEFORE)); + ptr_before_.reset(CreatePtr(kSyncBefore)); } - return ptr_before_.get(); } Ptr* PtrAfter() { if (ptr_after_ == nullptr) { - ptr_after_.reset(CreatePtr(SYNC_AFTER)); + ptr_after_.reset(CreatePtr(kSyncAfter)); } - return ptr_after_.get(); } diff --git a/sandboxed_api/var_ptr.h b/sandboxed_api/var_ptr.h index 65c206b..0e2f020 100644 --- a/sandboxed_api/var_ptr.h +++ b/sandboxed_api/var_ptr.h @@ -38,6 +38,7 @@ class Ptr : public Reg, public Pointable { Var* GetPointedVar() const { return Reg::GetValue(); } void SetValue(Var* ptr) final { val_->SetRemote(ptr); } + Var* GetValue() const final { return reinterpret_cast(val_->GetRemote()); } @@ -46,6 +47,7 @@ class Ptr : public Reg, public Pointable { remote_ptr_cache_ = GetValue(); return &remote_ptr_cache_; } + void SetDataFromPtr(const void* ptr, size_t max_sz) final { void* tmp; memcpy(&tmp, ptr, std::min(sizeof(tmp), max_sz)); @@ -57,14 +59,14 @@ class Ptr : public Reg, public Pointable { void SetSyncType(SyncType sync_type) { sync_type_ = sync_type; } std::string ToString() const final { + Var* var = GetPointedVar(); return absl::StrFormat( "Ptr to obj:%p (type:'%s' val:'%s'), local:%p, remote:%p, size:%tx", - GetPointedVar(), GetPointedVar()->GetTypeString(), - GetPointedVar()->ToString(), GetPointedVar()->GetLocal(), - GetPointedVar()->GetRemote(), GetPointedVar()->GetSize()); + var, var->GetTypeString(), var->ToString(), var->GetLocal(), + var->GetRemote(), var->GetSize()); } - Ptr* CreatePtr(Pointable::SyncType type = Pointable::SYNC_NONE) override { + Ptr* CreatePtr(Pointable::SyncType type = Pointable::kSyncNone) override { return new Ptr(this, type); } @@ -81,7 +83,7 @@ class Ptr : public Reg, public Pointable { // Good, old nullptr class NullPtr : public Ptr { public: - NullPtr() : Ptr(&void_obj_, SyncType::SYNC_NONE) {} + NullPtr() : Ptr(&void_obj_, SyncType::kSyncNone) {} private: Reg void_obj_; @@ -91,7 +93,7 @@ class NullPtr : public Ptr { class RemotePtr : public Ptr { public: explicit RemotePtr(void* remote_addr) - : Ptr(&pointed_obj_, SyncType::SYNC_NONE) { + : Ptr(&pointed_obj_, SyncType::kSyncNone) { pointed_obj_.SetRemote(remote_addr); } diff --git a/sandboxed_api/var_void.h b/sandboxed_api/var_void.h index c627757..9c07965 100644 --- a/sandboxed_api/var_void.h +++ b/sandboxed_api/var_void.h @@ -38,7 +38,7 @@ class Void : public Callable, public Pointable { const void* GetDataPtr() override { return nullptr; } void SetDataFromPtr(const void* ptr, size_t max_sz) override {} - Ptr* CreatePtr(Pointable::SyncType type = Pointable::SYNC_NONE) override { + Ptr* CreatePtr(Pointable::SyncType type = Pointable::kSyncNone) override { return new Ptr(this, type); } };