19 #ifndef ASYLO_PLATFORM_PRIMITIVES_UNTRUSTED_PRIMITIVES_H_ 20 #define ASYLO_PLATFORM_PRIMITIVES_UNTRUSTED_PRIMITIVES_H_ 28 #include "absl/base/thread_annotations.h" 29 #include "asylo/platform/primitives/extent.h" 30 #include "asylo/platform/primitives/primitive_status.h" 31 #include "asylo/platform/primitives/primitives.h" 32 #include "asylo/platform/primitives/util/message.h" 33 #include "asylo/util/asylo_macros.h" 34 #include "asylo/util/mutex_guarded.h" 35 #include "asylo/util/status.h" 36 #include "asylo/util/statusor.h" 47 return Backend::Load(std::forward<Args>(args)...);
77 bool IsNull()
const {
return callback ==
nullptr; }
105 class Client :
public std::enable_shared_from_this<Client> {
150 : saved_client_(Client::current_client_), pid_(getpid()) {
151 current_client_ = client;
159 Client *
const saved_client_;
242 memory_to_free_.Lock()->emplace_back(mem);
247 auto to_free = memory_to_free_.Lock();
248 for (
auto ptr : *to_free) {
261 std::unique_ptr<ExitCallProvider> exit_call_provider)
280 ASYLO_MUST_USE_RESULT = 0;
284 const std::unique_ptr<ExitCallProvider> exit_call_provider_;
288 static thread_local Client *current_client_;
291 absl::string_view name_;
294 MutexGuarded<std::vector<
void *>> memory_to_free_;
virtual ~ExitCallProvider()=default
Status EnclaveCall(uint64_t selector, MessageWriter *input, MessageReader *output) ASYLO_MUST_USE_RESULT
Enters the enclave synchronously at an entry point to trusted code designated by selector.
virtual Status RegisterExitHandler(uint64_t untrusted_selector, const ExitHandler &handler) ASYLO_MUST_USE_RESULT=0
Registers a callback as the handler routine for an enclave exit point untrusted_selector.
StatusOr< std::shared_ptr< class Client > > LoadEnclave(Args &&... args)
Loads an enclave.
Definition: untrusted_primitives.h:46
static PrimitiveStatus ExitCallback(uint64_t untrusted_selector, MessageReader *in, MessageWriter *out)
Enclave exit callback function shared with the enclave.
virtual Status EnclaveCallInternal(uint64_t selector, MessageWriter *input, MessageReader *output) ASYLO_MUST_USE_RESULT=0
Provides implementation of EnclaveCall.
ExitHandler(Callback callback, void *context)
Initializes an exit handler with a callback and a context pointer.
Definition: untrusted_primitives.h:71
virtual Status Destroy()=0
virtual Status RegisterExitHandlers() ASYLO_MUST_USE_RESULT
An overridable handler registration method.
An interface to a provider of enclave exit calls.
Definition: untrusted_primitives.h:108
ScopedCurrentClient & operator=(const ScopedCurrentClient &other)=delete
ABSL_CONST_INIT const char kStatusMoveAssignmentMsg[]
void * context
Uninterpreted data passed by the runtime to invocations of the handler.
Definition: untrusted_primitives.h:86
virtual void RegisterMemory(void *mem)
Register memory to be freed upon enclave destruction.
Definition: untrusted_primitives.h:241
Callback structure for dispatching messages from the enclave.
Definition: untrusted_primitives.h:52
virtual Status InvokeExitHandler(uint64_t untrusted_selector, MessageReader *input, MessageWriter *output, Client *client) ASYLO_MUST_USE_RESULT=0
Finds and invokes an exit handler.
static Client * GetCurrentClient()
A static getter for the current client.
virtual ~Client()
Definition: untrusted_primitives.h:163
virtual bool IsClosed() const =0
A predicate for whether the enclave may be entered or will accept messages.
virtual void ReleaseMemory()
Frees enclave resources registered to the client.
Definition: untrusted_primitives.h:246
operator bool() const
Implicit bool conversion for null checks.
Definition: untrusted_primitives.h:80
ScopedCurrentClient(Client *client)
Constructs a "scope object" to set the current client pointer for the lifetime of the object...
Definition: untrusted_primitives.h:149
ExitCallProvider * exit_call_provider()
Accessor to the client's exit call provider.
Definition: untrusted_primitives.h:236
ExitHandler()
Definition: untrusted_primitives.h:57
virtual absl::string_view Name() const
A getter for the enclave name.
Definition: untrusted_primitives.h:191
Client(const absl::string_view name, std::unique_ptr< ExitCallProvider > exit_call_provider)
Constructs a client, reserved for only backend implementations.
Definition: untrusted_primitives.h:260
ExitHandler(Callback callback)
Initializes an exit handler with a callback.
Definition: untrusted_primitives.h:62
bool IsNull() const
A predicate for whether the callback is initialized.
Definition: untrusted_primitives.h:77
Callback callback
Callback function to invoke for this exit.
Definition: untrusted_primitives.h:83
An RAII wrapper that sets thread-local enclave "current client" reference on construction and resets ...
Definition: untrusted_primitives.h:143
void SetCurrentClient()
Stores this as the active thread's "current client".
ScopedCurrentClient(const ScopedCurrentClient &other)=delete