enclave_ecalls.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include "pal_linux.h"
  4. #include "pal_security.h"
  5. #include <api.h>
  6. #include "ecall_types.h"
  7. #define SGX_CAST(type, item) ((type) (item))
  8. extern void * enclave_base, * enclave_top;
  9. void pal_linux_main (int argc, const char ** argv, const char ** envp,
  10. struct pal_sec * sec_info);
  11. int enclave_ecall_pal_main (void * pms)
  12. {
  13. ms_ecall_pal_main_t * ms = SGX_CAST(ms_ecall_pal_main_t *, pms);
  14. if (!pms) return -PAL_ERROR_INVAL;
  15. enclave_base = ms->ms_enclave_base;
  16. enclave_top = ms->ms_enclave_base + ms->ms_enclave_size;
  17. pal_linux_main(ms->ms_argc, ms->ms_argv,
  18. ms->ms_envp,
  19. ms->ms_sec_info);
  20. ocall_exit();
  21. return 0;
  22. }
  23. int enclave_ecall_thread_start (void * pms)
  24. {
  25. ms_ecall_thread_start_t * ms = SGX_CAST(ms_ecall_thread_start_t *, pms);
  26. if (!pms) return -PAL_ERROR_INVAL;
  27. if (ms->ms_child_tid)
  28. *ms->ms_child_tid = ms->ms_tid;
  29. ms->ms_func(ms->ms_arg);
  30. ocall_exit();
  31. return 0;
  32. }
  33. void * ecall_table[ECALL_NR] = {
  34. [ECALL_PAL_MAIN] = (void *) enclave_ecall_pal_main,
  35. [ECALL_THREAD_START] = (void *) enclave_ecall_thread_start,
  36. };