int sgx_init_tp(void) { assert(sizeof(struct sgx_stub_info) < PAGE_SIZE); sgx_stub_info *stub = mmap((void *)STUB_ADDR, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (stub == MAP_FAILED) return 0; sgx_stub_info_tp *stub_tp = mmap((void *)STUB_ADDR_TP, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (stub_tp == MAP_FAILED) return 0; //stub area init memset((void *)stub, 0x00, PAGE_SIZE); stub->abi = OPENSGX_ABI_VERSION; stub->trampoline = (void *)(uintptr_t)sgx_trampoline; //stub tp init memset((void *)stub_tp, 0x00, PAGE_SIZE); stub_tp->abi = OPENSGX_ABI_VERSION; stub_tp->trampoline = (void *)(uintptr_t)sgx_trampoline_tp; return sys_sgx_init(); }
int main(int argc, char **argv) { int fd, ret; egate_t e; echan_t *channels; echan_t *pchan[2]; int done = 0; char *quoteenc, *quoteconf, *intelkey; unsigned char intel_pubkey[KEY_LENGTH], intel_seckey[KEY_LENGTH]; int optend; tcs_t *quotetcs; sigstruct_t *quotess; /* Parse options */ parse_options(argc, argv, "eenc, "econf, &intelkey, &optend); if (optend > argc - 1) { usage(argv[0]); exit(-1); } /* After options are done, get teh test enclave and configuration file */ fd = open(argv[1], O_RDWR); if (fd < 0) { perror("open"); exit(-1); } load_rsa_keys(intelkey, intel_pubkey, intel_seckey, KEY_LENGTH_BITS); sys_sgx_init(intel_pubkey); channels = mmap(NULL, 2*sizeof(echan_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (!channels) { perror("mmap"); exit(-1); } close(fd); pchan[0] = channels; pchan[1] = channels + 1; quotetcs = create_elf_enclave_conf(quoteenc, quoteconf, "ess, GDB_DEBUG); if (!quotetcs) { fprintf(stdout, "Unable to create quoting enclave.\n"); fflush(stdout); exit(-1); } egate_proxy_init(&e, quotetcs, quotess, pchan); /* Now do the while loop that serves the buffer. */ while (!done) { ecmd_t c; char buffer[2048]; ret = egate_user_poll(&e, &c, buffer, 2048); if (ret) break; if (c.t <= ECMD_LAST_SYSTEM) { // Handle predefined cmd egate_user_cmd(&e, &c, buffer, 2048, &done); } else { fprintf(stderr, "Unhandled user-specific communication " "from enclave: CMD %d LEN %lu.\n", c.t, c.len); } } munmap(channels, sizeof(2*sizeof(echan_t))); unlink(argv[1]); }