mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
NullPtr: Change SAPI to accept regular nullptr
for sandboxed API calls.
This change allows to use a `nullptr` instead to having to instantiate a `sapi:✌️:NullPtr` object. ``` sapi:✌️:NullPtr null; SAPI_RETURN_IF_ERROR(api.testNullPtr(&null); ``` Becomes: ``` SAPI_RETURN_IF_ERROR(api.testNullPtr(nullptr); ``` PiperOrigin-RevId: 602333882 Change-Id: Ie2517dbedab8c514d7a102c4ef4bad90b34a219d
This commit is contained in:
parent
fa5360351b
commit
f2840b37a3
|
@ -324,6 +324,14 @@ absl::Status Sandbox::Call(const std::string& func, v::Callable* ret,
|
|||
// Copy all arguments into rfcall.
|
||||
int i = 0;
|
||||
for (auto* arg : args) {
|
||||
if (arg == nullptr) {
|
||||
rfcall.arg_type[i] = v::Type::kPointer;
|
||||
rfcall.arg_size[i] = sizeof(void*);
|
||||
rfcall.args[i].arg_int = 0;
|
||||
VLOG(1) << "CALL ARG: (" << i << "): nullptr";
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
rfcall.arg_size[i] = arg->GetSize();
|
||||
rfcall.arg_type[i] = arg->GetType();
|
||||
|
||||
|
@ -357,7 +365,6 @@ absl::Status Sandbox::Call(const std::string& func, v::Callable* ret,
|
|||
}
|
||||
rfcall.args[i].arg_int = fd->GetRemoteFd();
|
||||
}
|
||||
|
||||
VLOG(1) << "CALL ARG: (" << i << "), Type: " << arg->GetTypeString()
|
||||
<< ", Size: " << arg->GetSize() << ", Val: " << arg->ToString();
|
||||
++i;
|
||||
|
@ -382,7 +389,9 @@ absl::Status Sandbox::Call(const std::string& func, v::Callable* ret,
|
|||
|
||||
// Synchronize all pointers after the call if it's needed.
|
||||
for (auto* arg : args) {
|
||||
SAPI_RETURN_IF_ERROR(SynchronizePtrAfter(arg));
|
||||
if (arg != nullptr) {
|
||||
SAPI_RETURN_IF_ERROR(SynchronizePtrAfter(arg));
|
||||
}
|
||||
}
|
||||
|
||||
VLOG(1) << "CALL EXIT: Type: " << ret->GetTypeString()
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/macros.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "sandboxed_api/var_abstract.h"
|
||||
|
@ -79,7 +80,9 @@ class Ptr : public Reg<Var*> {
|
|||
};
|
||||
|
||||
// Good, old nullptr
|
||||
class NullPtr : public Ptr {
|
||||
class ABSL_DEPRECATED(
|
||||
"Use regular `nullptr` or `NULL` instead. This class will eventually get "
|
||||
"removed") NullPtr : public Ptr {
|
||||
public:
|
||||
NullPtr() : Ptr(&void_obj_, SyncType::kSyncNone) {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user