Skip to content

Commit 8856345

Browse files
committed
Add primitive enclave init entry point
Add user defined enclave init entry points to primitives API PiperOrigin-RevId: 255032718 Change-Id: I36a73c53c35f1864966d4fe05ddce5a6a3a5cd48
1 parent 15e9a1a commit 8856345

File tree

12 files changed

+55
-6
lines changed

12 files changed

+55
-6
lines changed

asylo/platform/core/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ cc_library(
118118
"//asylo/platform/posix/io:io_manager",
119119
"//asylo/platform/posix/signal:signal_manager",
120120
"//asylo/platform/posix/threading:thread_manager",
121+
"//asylo/platform/primitives",
122+
"//asylo/platform/primitives:trusted_runtime",
121123
"//asylo/util:logging",
122124
"//asylo/util:status",
123125
"@com_google_absl//absl/memory",

asylo/platform/core/trusted_application.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@
4444
#include "asylo/platform/posix/io/random_devices.h"
4545
#include "asylo/platform/posix/signal/signal_manager.h"
4646
#include "asylo/platform/posix/threading/thread_manager.h"
47+
#include "asylo/platform/primitives/primitive_status.h"
48+
#include "asylo/platform/primitives/trusted_runtime.h"
4749
#include "asylo/util/posix_error_space.h"
4850
#include "asylo/util/status.h"
4951
#include "asylo/util/status_macros.h"
5052

53+
using asylo::primitives::PrimitiveStatus;
5154
using EnclaveState = ::asylo::TrustedApplication::State;
5255
using google::protobuf::RepeatedPtrField;
5356

@@ -572,3 +575,5 @@ int __asylo_transfer_secure_snapshot_key(const char *input, size_t input_len,
572575
} // extern "C"
573576

574577
} // namespace asylo
578+
579+
extern "C" PrimitiveStatus enc_init() { return PrimitiveStatus::OkStatus(); }

asylo/platform/host_call/test/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ sim_enclave_test(
8888
],
8989
deps = [
9090
":host_call_test_lib",
91+
"//asylo/platform/primitives",
92+
"//asylo/platform/primitives:trusted_runtime",
9193
"//asylo/platform/primitives/test:sim_test_backend",
9294
],
9395
)

asylo/platform/host_call/test/test_enclave.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
#include "asylo/platform/host_call/test/enclave_test_selectors.h"
2020
#include "asylo/platform/host_call/trusted/host_call_dispatcher.h"
2121
#include "asylo/platform/host_call/trusted/host_calls.h"
22+
#include "asylo/platform/primitives/primitive_status.h"
2223
#include "asylo/platform/primitives/trusted_primitives.h"
24+
#include "asylo/platform/primitives/trusted_runtime.h"
2325
#include "asylo/platform/system_call/system_call.h"
2426
#include "asylo/platform/system_call/type_conversions/types_functions.h"
2527
#include "asylo/util/status_macros.h"
2628

29+
using asylo::primitives::PrimitiveStatus;
30+
2731
namespace asylo {
2832
namespace host_call {
2933
namespace {
@@ -559,3 +563,5 @@ extern "C" primitives::PrimitiveStatus asylo_enclave_fini() {
559563

560564
} // namespace host_call
561565
} // namespace asylo
566+
567+
extern "C" PrimitiveStatus enc_init() { return PrimitiveStatus::OkStatus(); }

asylo/platform/primitives/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ cc_library(
6060
"//asylo/platform/primitives/util:trusted_memory.h",
6161
],
6262
copts = ASYLO_DEFAULT_COPTS,
63-
deps = select({
63+
deps = [":primitives"] + select({
6464
"//asylo/platform/primitives:sgx": [
6565
"//asylo/platform/primitives/sgx:trusted_sgx",
6666
],
@@ -84,6 +84,7 @@ cc_library(
8484
name = "trusted_runtime",
8585
hdrs = ["trusted_runtime.h"],
8686
copts = ASYLO_DEFAULT_COPTS,
87+
deps = [":primitives"],
8788
)
8889

8990
# Test ParameterStack implementation.

asylo/platform/primitives/examples/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ sim_enclave(
4040
copts = ASYLO_DEFAULT_COPTS,
4141
deps = [
4242
"//asylo/platform/primitives",
43+
"//asylo/platform/primitives:trusted_runtime",
4344
"//asylo/util:status_macros",
4445
],
4546
)

asylo/platform/primitives/examples/hello_enclave.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
#include "asylo/platform/primitives/extent.h"
2323
#include "asylo/platform/primitives/primitive_status.h"
2424
#include "asylo/platform/primitives/trusted_primitives.h"
25+
#include "asylo/platform/primitives/trusted_runtime.h"
2526
#include "asylo/util/status_macros.h"
2627

28+
using asylo::primitives::EntryHandler;
29+
using asylo::primitives::PrimitiveStatus;
30+
using asylo::primitives::TrustedPrimitives;
31+
2732
namespace asylo {
2833
namespace primitives {
2934

@@ -60,10 +65,6 @@ PrimitiveStatus Hello(void *context, TrustedParameterStack *params) {
6065
} // namespace
6166

6267
extern "C" PrimitiveStatus asylo_enclave_init() {
63-
ASYLO_RETURN_IF_ERROR(TrustedPrimitives::RegisterEntryHandler(
64-
kAbortEnclaveSelector, EntryHandler{Abort}));
65-
ASYLO_RETURN_IF_ERROR(TrustedPrimitives::RegisterEntryHandler(
66-
kHelloEnclaveSelector, EntryHandler{Hello}));
6768
return PrimitiveStatus::OkStatus();
6869
}
6970

@@ -73,3 +74,13 @@ extern "C" PrimitiveStatus asylo_enclave_fini() {
7374

7475
} // namespace primitives
7576
} // namespace asylo
77+
78+
extern "C" PrimitiveStatus enc_init() {
79+
ASYLO_RETURN_IF_ERROR(TrustedPrimitives::RegisterEntryHandler(
80+
asylo::primitives::kAbortEnclaveSelector,
81+
EntryHandler{asylo::primitives::Abort}));
82+
ASYLO_RETURN_IF_ERROR(TrustedPrimitives::RegisterEntryHandler(
83+
asylo::primitives::kHelloEnclaveSelector,
84+
EntryHandler{asylo::primitives::Hello}));
85+
return PrimitiveStatus::OkStatus();
86+
}

asylo/platform/primitives/test/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ sim_enclave(
5353
copts = ASYLO_DEFAULT_COPTS,
5454
deps = [
5555
":test_selectors",
56+
"//asylo/platform/primitives",
57+
"//asylo/platform/primitives:trusted_runtime",
5658
],
5759
)
5860

asylo/platform/primitives/test/test_enclave.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
#include "asylo/platform/primitives/primitive_status.h"
2424
#include "asylo/platform/primitives/test/test_selectors.h"
2525
#include "asylo/platform/primitives/trusted_primitives.h"
26+
#include "asylo/platform/primitives/trusted_runtime.h"
2627
#include "asylo/util/status_macros.h"
2728

29+
using asylo::primitives::PrimitiveStatus;
30+
2831
namespace asylo {
2932
namespace primitives {
3033

@@ -254,3 +257,5 @@ extern "C" PrimitiveStatus asylo_enclave_fini() {
254257

255258
} // namespace primitives
256259
} // namespace asylo
260+
261+
extern "C" PrimitiveStatus enc_init() { return PrimitiveStatus::OkStatus(); }

asylo/platform/primitives/trusted_runtime.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
#include <cstdlib>
2424
#include <cstring>
2525

26+
#include "asylo/platform/primitives/primitive_status.h"
27+
2628
extern "C" {
2729

30+
// Prototype of the user-defined enclave initialization function.
31+
asylo::primitives::PrimitiveStatus enc_init();
32+
2833
// Emulates the Unix `sbrk` system call. See sbrk(2). This functions must be
2934
// exported by each backend to support linking against libc.
3035
void *enclave_sbrk(intptr_t increment);

0 commit comments

Comments
 (0)