mirror of
https://github.com/intel/linux-sgx
synced 2026-06-08 14:49:32 +00:00
Updates for SGX 2.17 reproducible build.
Signed-off-by: Zhang Lili <lili.z.zhang@intel.com>
This commit is contained in:
@@ -29,68 +29,72 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Test Pointer Auttributes */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "sgx_trts.h"
|
||||
#include "../Enclave.h"
|
||||
#include "Enclave_t.h"
|
||||
#include "sgx_lfence.h"
|
||||
#include "sgx_trts.h"
|
||||
|
||||
/* checksum_internal:
|
||||
* get simple checksum of input buffer and length
|
||||
*/
|
||||
int32_t checksum_internal(char *buf, size_t count)
|
||||
int32_t checksum_internal(char* buf, size_t count)
|
||||
{
|
||||
register int32_t sum = 0;
|
||||
int16_t *ptr = (int16_t *)buf;
|
||||
int16_t* ptr = (int16_t*)buf;
|
||||
|
||||
/* Main summing loop */
|
||||
while(count > 1) {
|
||||
while (count > 1) {
|
||||
sum = sum + *ptr++;
|
||||
count = count - 2;
|
||||
}
|
||||
|
||||
/* Add left-over byte, if any */
|
||||
if (count > 0)
|
||||
sum = sum + *((char *)ptr);
|
||||
if (count > 0) {
|
||||
sum = sum + *((char*)ptr);
|
||||
}
|
||||
|
||||
return ~sum;
|
||||
return ~sum;
|
||||
}
|
||||
|
||||
/* ecall_pointer_user_check, ecall_pointer_in, ecall_pointer_out, ecall_pointer_in_out:
|
||||
* The root ECALLs to test [in], [out], [user_check] attributes.
|
||||
*/
|
||||
size_t ecall_pointer_user_check(void *val, size_t sz)
|
||||
size_t ecall_pointer_user_check(void* val, size_t sz)
|
||||
{
|
||||
/* check if the buffer is allocated outside */
|
||||
if (sgx_is_outside_enclave(val, sz) != 1)
|
||||
abort();
|
||||
|
||||
char tmp[100] = {0};
|
||||
size_t len = sz>100?100:sz;
|
||||
|
||||
/*fence after sgx_is_outside_enclave check*/
|
||||
sgx_lfence();
|
||||
|
||||
char tmp[100] = { 0 };
|
||||
size_t len = sz > 100 ? 100 : sz;
|
||||
|
||||
/* copy the memory into the enclave to make sure 'val'
|
||||
* is not being changed in checksum_internal() */
|
||||
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);
|
||||
|
||||
/* modify outside memory directly */
|
||||
memcpy(val, "SGX_SUCCESS", len>12?12:len);
|
||||
|
||||
return len;
|
||||
int32_t sum = checksum_internal((char*)tmp, len);
|
||||
printf("Checksum(0x%p, %zu) = 0x%x\n",
|
||||
val, len, (unsigned int)sum);
|
||||
|
||||
/* modify outside memory directly */
|
||||
memcpy_verw(val, "SGX_SUCCESS", len > 12 ? 12 : len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/* ecall_pointer_in:
|
||||
* the buffer of val is copied to the enclave.
|
||||
*/
|
||||
|
||||
void ecall_pointer_in(int *val)
|
||||
void ecall_pointer_in(int* val)
|
||||
{
|
||||
if (sgx_is_within_enclave(val, sizeof(int)) != 1)
|
||||
abort();
|
||||
@@ -100,7 +104,7 @@ void ecall_pointer_in(int *val)
|
||||
/* ecall_pointer_out:
|
||||
* the buffer of val is copied to the untrusted side.
|
||||
*/
|
||||
void ecall_pointer_out(int *val)
|
||||
void ecall_pointer_out(int* val)
|
||||
{
|
||||
if (sgx_is_within_enclave(val, sizeof(int)) != 1)
|
||||
abort();
|
||||
@@ -111,7 +115,7 @@ void ecall_pointer_out(int *val)
|
||||
/* ecall_pointer_in_out:
|
||||
* the buffer of val is double-copied.
|
||||
*/
|
||||
void ecall_pointer_in_out(int *val)
|
||||
void ecall_pointer_in_out(int* val)
|
||||
{
|
||||
if (sgx_is_within_enclave(val, sizeof(int)) != 1)
|
||||
abort();
|
||||
@@ -154,7 +158,7 @@ void ocall_pointer_attr(void)
|
||||
/* ecall_pointer_string:
|
||||
* [string] defines a string.
|
||||
*/
|
||||
void ecall_pointer_string(char *str)
|
||||
void ecall_pointer_string(char* str)
|
||||
{
|
||||
strncpy(str, "0987654321", strlen(str));
|
||||
}
|
||||
@@ -162,17 +166,17 @@ void ecall_pointer_string(char *str)
|
||||
/* ecall_pointer_string_const:
|
||||
* const [string] defines a string that cannot be modified.
|
||||
*/
|
||||
void ecall_pointer_string_const(const char *str)
|
||||
void ecall_pointer_string_const(const char* str)
|
||||
{
|
||||
char* temp = new char[strlen(str)];
|
||||
strncpy(temp, str, strlen(str));
|
||||
delete []temp;
|
||||
delete[] temp;
|
||||
}
|
||||
|
||||
/* ecall_pointer_size:
|
||||
* 'len' needs to be specified to tell Edger8r the length of 'str'.
|
||||
*/
|
||||
void ecall_pointer_size(void *ptr, size_t len)
|
||||
void ecall_pointer_size(void* ptr, size_t len)
|
||||
{
|
||||
strncpy((char*)ptr, "0987654321", len);
|
||||
}
|
||||
@@ -180,9 +184,9 @@ void ecall_pointer_size(void *ptr, size_t len)
|
||||
/* ecall_pointer_count:
|
||||
* 'cnt' needs to be specified to tell Edger8r the number of elements in 'arr'.
|
||||
*/
|
||||
void ecall_pointer_count(int *arr, size_t count)
|
||||
void ecall_pointer_count(int* arr, size_t count)
|
||||
{
|
||||
int cnt = (int) count;
|
||||
int cnt = (int)count;
|
||||
for (int i = (cnt - 1); i >= 0; i--)
|
||||
arr[i] = (cnt - 1 - i);
|
||||
}
|
||||
@@ -195,4 +199,3 @@ void ecall_pointer_isptr_readonly(buffer_t buf, size_t len)
|
||||
{
|
||||
strncpy((char*)buf, "0987654321", len);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user