123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #include <sys/types.h>
- #include <string.h>
- #include "sgx_trts.h"
- #include "sgx_lfence.h"
- #include "../Enclave.h"
- #include "Enclave_t.h"
- int32_t checksum_internal(char *buf, size_t count)
- {
- register int32_t sum = 0;
- int16_t *ptr = (int16_t *)buf;
-
- while(count > 1) {
- sum = sum + *ptr++;
- count = count - 2;
- }
-
- if (count > 0)
- sum = sum + *((char *)ptr);
- return ~sum;
- }
- size_t ecall_pointer_user_check(void *val, size_t sz)
- {
-
- if (sgx_is_outside_enclave(val, sz) != 1)
- abort();
-
- sgx_lfence();
- char tmp[100] = {0};
- size_t len = sz>100?100:sz;
-
-
- memcpy(tmp, val, len);
-
- int32_t sum = checksum_internal((char *)tmp, len);
- printf("Checksum(0x%p, %zu) = 0x%x\n",
- val, len, (unsigned int)sum);
-
-
- memcpy(val, "SGX_SUCCESS", len>12?12:len);
- return len;
- }
- void ecall_pointer_in(int *val)
- {
- if (sgx_is_within_enclave(val, sizeof(int)) != 1)
- abort();
- *val = 1234;
- }
- void ecall_pointer_out(int *val)
- {
- if (sgx_is_within_enclave(val, sizeof(int)) != 1)
- abort();
- assert(*val == 0);
- *val = 1234;
- }
- void ecall_pointer_in_out(int *val)
- {
- if (sgx_is_within_enclave(val, sizeof(int)) != 1)
- abort();
- *val = 1234;
- }
- void ocall_pointer_attr(void)
- {
- sgx_status_t ret = SGX_ERROR_UNEXPECTED;
- int val = 0;
- ret = ocall_pointer_user_check(&val);
- if (ret != SGX_SUCCESS)
- abort();
- val = 0;
- ret = ocall_pointer_in(&val);
- if (ret != SGX_SUCCESS)
- abort();
- assert(val == 0);
- val = 0;
- ret = ocall_pointer_out(&val);
- if (ret != SGX_SUCCESS)
- abort();
- assert(val == 1234);
- val = 0;
- ret = ocall_pointer_in_out(&val);
- if (ret != SGX_SUCCESS)
- abort();
- assert(val == 1234);
- return;
- }
- void ecall_pointer_string(char *str)
- {
- strncpy(str, "0987654321", strlen(str));
- }
- void ecall_pointer_string_const(const char *str)
- {
- char* temp = new char[strlen(str)];
- strncpy(temp, str, strlen(str));
- delete []temp;
- }
- void ecall_pointer_size(void *ptr, size_t len)
- {
- strncpy((char*)ptr, "0987654321", len);
- }
- void ecall_pointer_count(int *arr, int cnt)
- {
- for (int i = (cnt - 1); i >= 0; i--)
- arr[i] = (cnt - 1 - i);
- }
- void ecall_pointer_isptr_readonly(buffer_t buf, size_t len)
- {
- strncpy((char*)buf, "0987654321", len);
- }
|