mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Rename SYNC_*
constants to conform to style guide
PiperOrigin-RevId: 322137271 Change-Id: I03d7f2e4841f42e439359727a686d55f1b4ab081
This commit is contained in:
parent
c7a27dd4b1
commit
aaa3eded8f
|
@ -239,7 +239,7 @@ absl::Status Sandbox::SynchronizePtrBefore(v::Callable* ptr) {
|
|||
}
|
||||
// Cast is safe, since type is v::Type::kPointer
|
||||
auto* p = static_cast<v::Ptr*>(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<v::Ptr*>(ptr);
|
||||
if ((p->GetSyncType() & v::Pointable::SYNC_AFTER) == 0) {
|
||||
if ((p->GetSyncType() & v::Pointable::kSyncAfter) == 0) {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class IntBase : public Reg<T>, public Pointable {
|
|||
IntBase() : IntBase(static_cast<T>(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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ class Ptr : public Reg<Var*>, public Pointable {
|
|||
Var* GetPointedVar() const { return Reg<Var*>::GetValue(); }
|
||||
|
||||
void SetValue(Var* ptr) final { val_->SetRemote(ptr); }
|
||||
|
||||
Var* GetValue() const final {
|
||||
return reinterpret_cast<Var*>(val_->GetRemote());
|
||||
}
|
||||
|
@ -46,6 +47,7 @@ class Ptr : public Reg<Var*>, 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<Var*>, 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<Var*>, 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*> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user