Browse Source

[Pal/Linux-SGX] Document handle_ecall

Simon Gaiser 6 years ago
parent
commit
6585c790aa
2 changed files with 33 additions and 0 deletions
  1. 28 0
      Pal/src/host/Linux-SGX/enclave_ecalls.c
  2. 5 0
      Pal/src/host/Linux-SGX/enclave_entry.S

+ 28 - 0
Pal/src/host/Linux-SGX/enclave_ecalls.c

@@ -19,6 +19,34 @@ extern void * enclave_base, * enclave_top;
 
 static struct atomic_int enclave_start_called = ATOMIC_INIT(0);
 
+
+/*
+ * Called from enclave_entry.S to execute ecalls.
+ *
+ * During normal operation handle_ecall will not return. The exception is that
+ * it will return if invalid parameters are passed. In this case
+ * enclave_entry.S will go into an endless loop since a clean return to urts is
+ * not easy in all cases.
+ *
+ * Parameters:
+ *
+ *  ecall_index:
+ *      Number of requested ecall. Untrusted.
+ *
+ *  ecall_args:
+ *      Pointer to arguments for requested ecall. Untrusted.
+ *
+ *  exit_target:
+ *      Address to return to after EEXIT. Untrusted.
+ *
+ *  untrusted_stack:
+ *      Address to urts stack. Restored before EEXIT and used for ocall
+ *      arguments. Untrusted.
+ *
+ *  enclave_base_addr:
+ *      Base address of enclave. Calculated dynamically in enclave_entry.S.
+ *      Trusted.
+ */
 void handle_ecall (long ecall_index, void * ecall_args, void * exit_target,
                    void * untrusted_stack, void * enclave_base_addr)
 {

+ 5 - 0
Pal/src/host/Linux-SGX/enclave_entry.S

@@ -277,6 +277,11 @@ sgx_ocall:
 	xorq %rbp, %rbp
 
 	movq %rsp, %gs:SGX_STACK
+
+	# It's ok to use the untrusted stack and exit target below without
+	# checks since the processor will ensure that after exiting enclave
+	# mode in-enclave memory can't be accessed.
+
 	movq %gs:SGX_USTACK, %rsp
 	andq $STACK_ALIGN, %rsp