Rename SYNC_* constants to conform to style guide

PiperOrigin-RevId: 322137271
Change-Id: I03d7f2e4841f42e439359727a686d55f1b4ab081
This commit is contained in:
Christian Blichmann 2020-07-20 07:05:24 -07:00 committed by Copybara-Service
parent c7a27dd4b1
commit aaa3eded8f
5 changed files with 22 additions and 23 deletions

View File

@ -239,7 +239,7 @@ absl::Status Sandbox::SynchronizePtrBefore(v::Callable* ptr) {
} }
// Cast is safe, since type is v::Type::kPointer // Cast is safe, since type is v::Type::kPointer
auto* p = static_cast<v::Ptr*>(ptr); auto* p = static_cast<v::Ptr*>(ptr);
if (p->GetSyncType() == v::Pointable::SYNC_NONE) { if (p->GetSyncType() == v::Pointable::kSyncNone) {
return absl::OkStatus(); return absl::OkStatus();
} }
@ -250,9 +250,9 @@ absl::Status Sandbox::SynchronizePtrBefore(v::Callable* ptr) {
} }
// Allocation occurs during both before/after synchronization modes. But the // 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. // was requested.
if ((p->GetSyncType() & v::Pointable::SYNC_BEFORE) == 0) { if ((p->GetSyncType() & v::Pointable::kSyncBefore) == 0) {
return absl::OkStatus(); return absl::OkStatus();
} }
@ -270,7 +270,7 @@ absl::Status Sandbox::SynchronizePtrAfter(v::Callable* ptr) const {
return absl::OkStatus(); return absl::OkStatus();
} }
v::Ptr* p = reinterpret_cast<v::Ptr*>(ptr); v::Ptr* p = reinterpret_cast<v::Ptr*>(ptr);
if ((p->GetSyncType() & v::Pointable::SYNC_AFTER) == 0) { if ((p->GetSyncType() & v::Pointable::kSyncAfter) == 0) {
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@ -32,7 +32,7 @@ class IntBase : public Reg<T>, public Pointable {
IntBase() : IntBase(static_cast<T>(0)) {} IntBase() : IntBase(static_cast<T>(0)) {}
explicit IntBase(T value) { this->SetValue(value); } 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); return new Ptr(this, type);
} }
}; };

View File

@ -33,17 +33,17 @@ class Pointable {
public: public:
enum SyncType { enum SyncType {
// Do not synchronize the underlying object after/before calls. // Do not synchronize the underlying object after/before calls.
SYNC_NONE = 0x0, kSyncNone = 0x0,
// Synchronize the underlying object (send the data to the sandboxee) // Synchronize the underlying object (send the data to the sandboxee)
// before the call takes place. // before the call takes place.
SYNC_BEFORE = 0x1, kSyncBefore = 0x1,
// Synchronize the underlying object (retrieve data from the sandboxee) // Synchronize the underlying object (retrieve data from the sandboxee)
// after the call has finished. // after the call has finished.
SYNC_AFTER = 0x2, kSyncAfter = 0x2,
// Synchronize the underlying object with the remote object, by sending the // Synchronize the underlying object with the remote object, by sending the
// data to the sandboxee before the call, and retrieving it from the // data to the sandboxee before the call, and retrieving it from the
// sandboxee after the call has finished. // 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 // 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. // Functions to get pointers with certain type of synchronization scheme.
Ptr* PtrNone() { Ptr* PtrNone() {
if (ptr_none_ == nullptr) { if (ptr_none_ == nullptr) {
ptr_none_.reset(CreatePtr(SYNC_NONE)); ptr_none_.reset(CreatePtr(kSyncNone));
} }
return ptr_none_.get(); return ptr_none_.get();
@ -61,25 +61,22 @@ class Pointable {
Ptr* PtrBoth() { Ptr* PtrBoth() {
if (ptr_both_ == nullptr) { if (ptr_both_ == nullptr) {
ptr_both_.reset(CreatePtr(SYNC_BOTH)); ptr_both_.reset(CreatePtr(kSyncBoth));
} }
return ptr_both_.get(); return ptr_both_.get();
} }
Ptr* PtrBefore() { Ptr* PtrBefore() {
if (ptr_before_ == nullptr) { if (ptr_before_ == nullptr) {
ptr_before_.reset(CreatePtr(SYNC_BEFORE)); ptr_before_.reset(CreatePtr(kSyncBefore));
} }
return ptr_before_.get(); return ptr_before_.get();
} }
Ptr* PtrAfter() { Ptr* PtrAfter() {
if (ptr_after_ == nullptr) { if (ptr_after_ == nullptr) {
ptr_after_.reset(CreatePtr(SYNC_AFTER)); ptr_after_.reset(CreatePtr(kSyncAfter));
} }
return ptr_after_.get(); return ptr_after_.get();
} }

View File

@ -38,6 +38,7 @@ class Ptr : public Reg<Var*>, public Pointable {
Var* GetPointedVar() const { return Reg<Var*>::GetValue(); } Var* GetPointedVar() const { return Reg<Var*>::GetValue(); }
void SetValue(Var* ptr) final { val_->SetRemote(ptr); } void SetValue(Var* ptr) final { val_->SetRemote(ptr); }
Var* GetValue() const final { Var* GetValue() const final {
return reinterpret_cast<Var*>(val_->GetRemote()); return reinterpret_cast<Var*>(val_->GetRemote());
} }
@ -46,6 +47,7 @@ class Ptr : public Reg<Var*>, public Pointable {
remote_ptr_cache_ = GetValue(); remote_ptr_cache_ = GetValue();
return &remote_ptr_cache_; return &remote_ptr_cache_;
} }
void SetDataFromPtr(const void* ptr, size_t max_sz) final { void SetDataFromPtr(const void* ptr, size_t max_sz) final {
void* tmp; void* tmp;
memcpy(&tmp, ptr, std::min(sizeof(tmp), max_sz)); memcpy(&tmp, ptr, std::min(sizeof(tmp), max_sz));
@ -57,14 +59,14 @@ class Ptr : public Reg<Var*>, public Pointable {
void SetSyncType(SyncType sync_type) { sync_type_ = sync_type; } void SetSyncType(SyncType sync_type) { sync_type_ = sync_type; }
std::string ToString() const final { std::string ToString() const final {
Var* var = GetPointedVar();
return absl::StrFormat( return absl::StrFormat(
"Ptr to obj:%p (type:'%s' val:'%s'), local:%p, remote:%p, size:%tx", "Ptr to obj:%p (type:'%s' val:'%s'), local:%p, remote:%p, size:%tx",
GetPointedVar(), GetPointedVar()->GetTypeString(), var, var->GetTypeString(), var->ToString(), var->GetLocal(),
GetPointedVar()->ToString(), GetPointedVar()->GetLocal(), var->GetRemote(), var->GetSize());
GetPointedVar()->GetRemote(), GetPointedVar()->GetSize());
} }
Ptr* CreatePtr(Pointable::SyncType type = Pointable::SYNC_NONE) override { Ptr* CreatePtr(Pointable::SyncType type = Pointable::kSyncNone) override {
return new Ptr(this, type); return new Ptr(this, type);
} }
@ -81,7 +83,7 @@ class Ptr : public Reg<Var*>, public Pointable {
// Good, old nullptr // Good, old nullptr
class NullPtr : public Ptr { class NullPtr : public Ptr {
public: public:
NullPtr() : Ptr(&void_obj_, SyncType::SYNC_NONE) {} NullPtr() : Ptr(&void_obj_, SyncType::kSyncNone) {}
private: private:
Reg<void*> void_obj_; Reg<void*> void_obj_;
@ -91,7 +93,7 @@ class NullPtr : public Ptr {
class RemotePtr : public Ptr { class RemotePtr : public Ptr {
public: public:
explicit RemotePtr(void* remote_addr) explicit RemotePtr(void* remote_addr)
: Ptr(&pointed_obj_, SyncType::SYNC_NONE) { : Ptr(&pointed_obj_, SyncType::kSyncNone) {
pointed_obj_.SetRemote(remote_addr); pointed_obj_.SetRemote(remote_addr);
} }

View File

@ -38,7 +38,7 @@ class Void : public Callable, public Pointable {
const void* GetDataPtr() override { return nullptr; } const void* GetDataPtr() override { return nullptr; }
void SetDataFromPtr(const void* ptr, size_t max_sz) override {} 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); return new Ptr(this, type);
} }
}; };