Initial release of Intel SGX for Linux.

This release is used in conjunction with the linux-sgx-driver Intial release:
https://github.com/01org/linux-sgx-driver
commit-id: 0e865ce5e6b297a787bcdc12d98bada8174be6d7

Intel-id: 33399

Signed-off-by: Angie Chinchilla <angie.v.chinchilla@intel.com>
This commit is contained in:
Angie Chinchilla
2016-06-23 18:51:53 -04:00
parent ba82cfcbb0
commit 9441de4c38
2767 changed files with 820699 additions and 0 deletions

View File

@ -0,0 +1,102 @@
/*
* Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Test Array Attributes */
#include "sgx_trts.h"
#include "../Enclave.h"
#include "Enclave_t.h"
/* ecall_array_user_check:
* [user_check] parameter does not perfrom copy operations.
*/
void ecall_array_user_check(int arr[4])
{
if (sgx_is_outside_enclave(arr, 4 * sizeof(int)) != 1)
abort();
for (int i = 0; i < 4; i++) {
assert(arr[i] == i);
arr[i] = 3 - i;
}
}
/* ecall_array_in:
* arr[] is copied to trusted domain, but modified
* results will not be reflected to the untrusted side.
*/
void ecall_array_in(int arr[4])
{
for (int i = 0; i < 4; i++) {
assert(arr[i] == i);
arr[i] = (3 - i);
}
}
/* ecall_array_out:
* arr[] is allocated inside the enclave, and it will be copied
* to the untrusted side
*/
void ecall_array_out(int arr[4])
{
for (int i = 0; i < 4; i++) {
/* arr is not copied from App */
assert(arr[i] == 0);
arr[i] = (3 - i);
}
}
/* ecall_array_in_out:
* arr[] will be allocated inside the enclave, content of arr[] will be copied either.
* After ECALL returns, the results will be copied to the outside.
*/
void ecall_array_in_out(int arr[4])
{
for (int i = 0; i < 4; i++) {
assert(arr[i] == i);
arr[i] = (3 - i);
}
}
/* ecall_array_isary:
* [isary] tells Edger8r that user defined 'array_t' is an array type.
*/
void ecall_array_isary(array_t arr)
{
if (sgx_is_outside_enclave(arr, sizeof(array_t)) != 1)
abort();
int n = sizeof(array_t)/sizeof(arr[0]);
for (int i = 0; i < n; i++) {
assert(arr[i] == i);
arr[i] = (n - 1 - i);
}
}

View File

@ -0,0 +1,98 @@
/*
* Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Arrays.edl - Samples for array attributes. */
enclave {
/*
* Only for fixed-size array (size is explicitly specified).
*/
trusted {
/*
* []: can be used to declare an array.
* [user_check]:
* pointer of the array won't be valified, and the buffer pointed by 'arr'
* is not copied into the enclave either. But enclave can modify the memory outside.
*/
public void ecall_array_user_check([user_check] int arr[4]);
/*
* [in]:
* buffer for the array will be allocated inside the enclave,
* content of the array will be copied into the new allocated memory inside.
* Any changes performed inside the enclave will not affect the array outside.
*/
public void ecall_array_in([in] int arr[4]);
/*
* [out]:
* buffer for the array will be allocated inside the enclave,
* but the content of the array won't be copied. After ECALL returns,
* the buffer inside the enclave will copied into outside array.
*/
public void ecall_array_out([out] int arr[4]);
/*
* [in, out]:
* buffer for the array will be allocated inside the enclave,
* the content of the array will be copied either. After ECALL returns,
* the buffer inside the enclave will by copied into outside array again.
*/
public void ecall_array_in_out([in, out] int arr[4]);
/*
* [isary]:
* tells Edger8r the user defined 'array_t' is an array type, 'arr' will be
* treated as a pointer, no memory copied either due to [user_check].
* For OCALLs, 'arr' shall point to the memory outside the enclave.
*/
public void ecall_array_isary([user_check, isary] array_t arr);
};
untrusted {
/*
* [user_check|in|out|in,out|isary] can also be used in OCALLs, refer to the "User Guide" for details.
*/
};
};

View File

@ -0,0 +1,84 @@
/*
* Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Test Calling Conventions */
#include <string.h>
#include <stdio.h>
#include "../Enclave.h"
#include "Enclave_t.h"
/* ecall_function_calling_convs:
* memccpy is defined in system C library.
*/
void ecall_function_calling_convs(void)
{
sgx_status_t ret = SGX_ERROR_UNEXPECTED;
char s1[] = "1234567890";
char s2[] = "0987654321";
char buf[BUFSIZ] = {'\0'};
memcpy(buf, s1, strlen(s1));
ret = memccpy(NULL, s1, s2, '\0', strlen(s1));
if (ret != SGX_SUCCESS)
abort();
assert(memcmp(s1, s2, strlen(s1)) == 0);
return;
}
/* ecall_function_public:
* The public ECALL that invokes the OCALL 'ocall_function_allow'.
*/
void ecall_function_public(void)
{
sgx_status_t ret = SGX_ERROR_UNEXPECTED;
ret = ocall_function_allow();
if (ret != SGX_SUCCESS)
abort();
return;
}
/* ecall_function_private:
* The private ECALL that only can be invoked in the OCALL 'ocall_function_allow'.
*/
int ecall_function_private(void)
{
return 1;
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Functions.edl - Samples for function attributes. */
enclave {
/*
* Following keywords/attributes are supported for untrusted functions:
* cdecl, stdcall, fastcall, dllimport (only for Windows).
* [public] is only supported for the trusted functions.
* Trusted function will be treated as [private] w/o the [public].
*/
trusted {
public void ecall_function_calling_convs(void);
/*
* [public]:
* public ECALL can be called directly in App.
*/
public void ecall_function_public(void);
/*
* [private]:
* private ECALL cannot be called directly in App.
*/
int ecall_function_private(void);
};
untrusted {
/*
* [cdecl]:
* tells edger8r the calling convention of the OCALLs is 'cdecl'.
* [dllimport]:
* indicats the OCALL is provided in DLLs.
*
* Note: memccpy() is provided by MS system DLL, we don't need to implement it in App side.
*/
[cdecl, dllimport] void *memccpy([in, out, size=len] void *dest, [in, size=len] const void *src, int val, size_t len);
/*
* [allow]:
* OCALL 'ocall_function_allow' can invoke ECALL 'ecall_function_private' in App side.
*
* Note: No ECALL can be called in OCALL w/o [allow].
*/
void ocall_function_allow(void) allow(ecall_function_private);
};
};

View File

@ -0,0 +1,217 @@
/*
* Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Test Pointer Auttributes */
#include <sys/types.h>
#include <string.h>
#include "sgx_trts.h"
#include "../Enclave.h"
#include "Enclave_t.h"
/* checksum_internal:
* get simple checksum of input buffer and length
*/
int32_t checksum_internal(char *buf, size_t count)
{
register int32_t sum = 0;
int16_t *ptr = (int16_t *)buf;
/* Main summing loop */
while(count > 1) {
sum = sum + *ptr++;
count = count - 2;
}
/* Add left-over byte, if any */
if (count > 0)
sum = sum + *((char *)ptr);
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)
{
/* 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;
/* 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, sum);
/* modify outside memory directly */
memcpy(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)
{
if (sgx_is_within_enclave(val, sizeof(int)) != 1)
abort();
*val = 1234;
}
/* ecall_pointer_out:
* the buffer of val is copied to the untrusted side.
*/
void ecall_pointer_out(int *val)
{
if (sgx_is_within_enclave(val, sizeof(int)) != 1)
abort();
assert(*val == 0);
*val = 1234;
}
/* ecall_pointer_in_out:
* the buffer of val is double-copied.
*/
void ecall_pointer_in_out(int *val)
{
if (sgx_is_within_enclave(val, sizeof(int)) != 1)
abort();
*val = 1234;
}
/* ocall_pointer_attr:
* The root ECALL that test OCALL [in], [out], [user_check].
*/
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;
}
/* ecall_pointer_string:
* [string] defines a string.
*/
void ecall_pointer_string(char *str)
{
strncpy(str, "0987654321", strlen(str));
}
/* ecall_pointer_string_const:
* const [string] defines a string that cannot be modified.
*/
void ecall_pointer_string_const(const char *str)
{
char* temp = new char[strlen(str)];
strncpy(temp, str, strlen(str));
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)
{
strncpy((char*)ptr, "0987654321", len);
}
/* ecall_pointer_count:
* 'cnt' needs to be specified to tell Edger8r the number of elements in 'arr'.
*/
void ecall_pointer_count(int *arr, int cnt)
{
for (int i = (cnt - 1); i >= 0; i--)
arr[i] = (cnt - 1 - i);
}
/* ecall_pointer_isptr_readonly:
* 'buf' is user defined type, shall be tagged with [isptr].
* if it's not writable, [readonly] shall be specified.
*/
void ecall_pointer_isptr_readonly(buffer_t buf, size_t len)
{
strncpy((char*)buf, "0987654321", len);
}
/* get_buffer_len:
* get the length of input buffer 'buf'.
*/
size_t get_buffer_len(const char* buf)
{
(void)buf;
return 10*sizeof(int);
}
/* ecall_pointer_sizefunc:
* call get_buffer_len to determin the length of 'buf'.
*/
void ecall_pointer_sizefunc(char *buf)
{
int *tmp = (int*)buf;
for (int i = 0; i < 10; i++) {
assert(tmp[i] == 0);
tmp[i] = i;
}
}

View File

@ -0,0 +1,190 @@
/*
* Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Pointers.edl - Samples for pointer attributes. */
enclave {
/*
* Following keywords/attributes are supported for pointers in Edger8r:
* in, out, user_check,
* string, wstring,
* const, size, count, sizefunc, isptr, readonly
*/
trusted {
/*
* [user_check]:
* the pointer won't be validated, and the buffer pointed by
* 'val' is not copied into the enclave either. But Enclave
* can modify the memory pointed by 'val'.
*/
public size_t ecall_pointer_user_check([user_check] void *val, size_t sz);
/*
* [in]:
* buffer with the same size will be allocated inside the enclave,
* content pointed by 'val' will be copied into the new allocated
* memory inside. Any changes performed inside the enclave will not
* affect the buffer outside.
*/
public void ecall_pointer_in([in] int *val);
/*
* [out]:
* buffer with the same size will be allocated inside the enclave,
* but the content pointed by 'val' won't be copied. But after return,
* the buffer inside the enclave will copied into outside 'val'.
*/
public void ecall_pointer_out([out] int *val);
/*
* [in, out]:
* buffer with the same size will be allocated inside the enclave,
* the content pointed by 'val' will be copied either. After return,
* the buffer inside the enclave will by copied into outside 'val' again.
*/
public void ecall_pointer_in_out([in, out] int *val);
/*
* [string]:
* the attribute tells Edger8r 'str' is NULL terminated string, so strlen
* will be used to count the length of buffer pointed by 'str'.
*/
public void ecall_pointer_string([in, out, string] char *str);
/*
* [const]:
* the attribute tells Edger8r the buffer pointed by 'str' cannot be modified,
* so users cannot decorate 'str' with [out] attribute anymore.
*/
public void ecall_pointer_string_const([in, string] const char *str);
/*
* [size]:
* the attribute tells Edger8r the length of buffer in byte pointed by 'ptr'
* (shall be copied or not).
* Note: Users shall not specify [size] on [string] parameters.
*/
public void ecall_pointer_size([in, out, size=len] void *ptr, size_t len);
/*
* [count]:
* the attribute tells Edger8r the number of integers to be copied from 'arr'.
*/
public void ecall_pointer_count([in, out, count=cnt] int *arr, int cnt);
/*
* [isptr]:
* tells Edger8r the user defined type is a pointer;
* [readonly]:
* forbids the buffer allocated inside the enclave to be copied back to App
* (cannot use with [out]).
*/
public void ecall_pointer_isptr_readonly([in, isptr, readonly, size=len] buffer_t buf, size_t len);
/*
* [sizefunc]:
* call a function to decide the size/length of the parameter;
* Note:
* User need to define and implement `get_buf_len' as:
* size_t get_buf_len(const char* buf);
*/
public void ecall_pointer_sizefunc([sizefunc = get_buffer_len, in, out] char *buf);
};
/*
* Users can define multiple trusted/untrusted blocks,
* edger8r will merged them into one trusted/untrusted block.
*/
trusted {
/*
* Test pointer attributes in OCALLs
*/
public void ocall_pointer_attr(void);
};
untrusted {
/*
* [user_check]:
* the pointer won't be valified, and the buffer pointed by 'val' is not
* copied to outside buffer either. Besides 'App' cannot modify the memory
* pointer by 'val'.
*/
void ocall_pointer_user_check([user_check] int *val);
/*
* [in]:
* buffer with the same size will be allocated in 'App' side, the content
* pointed by 'val' will be copied into the new allocated memory outside.
* Any changes performed by 'App' will not affect the buffer pointed by 'val'.
*/
void ocall_pointer_in([in] int *val);
/*
* [out]:
* buffer with the same size will be allocated in 'App' side, the content
* pointed by 'val' won't be copied. But after return, the buffer outside
* will be copied into the enclave.
*/
void ocall_pointer_out([out] int *val);
/*
* [in, out]:
* buffer with the same size will be allocated in 'App' side, the content
* pointed by 'val' will be copied either. After return, the buffer outside
* will copied into the enclave.
*/
void ocall_pointer_in_out([in, out] int *val);
};
};

View File

@ -0,0 +1,155 @@
/*
* Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Test Basic Types */
#include "sgx_trts.h"
#include "../Enclave.h"
#include "Enclave_t.h"
#include <limits>
#include <cmath>
/* used to eliminate `unused variable' warning */
#define UNUSED(val) (void)(val)
#define ULP 2
/* used to compare double variables in order to avoid compile warnings */
bool almost_equal(double x, double y)
{
/* the machine epsilon has to be scaled to the magnitude of the larger value
and multiplied by the desired precision in ULPs (units in the last place) */
return std::abs(x-y) <= std::numeric_limits<double>::epsilon() * std::abs(x+y) * ULP;
}
/* used to compare double variables in order to avoid compile warnings */
bool almost_equal(float x, float y)
{
/* the machine epsilon has to be scaled to the magnitude of the larger value
and multiplied by the desired precision in ULPs (units in the last place) */
return std::abs(x-y) <= std::numeric_limits<float>::epsilon() * std::abs(x+y) * ULP;
}
/* ecall_type_char:
* [char] value passed by App.
*/
void ecall_type_char(char val)
{
assert(val == 0x12);
#ifndef DEBUG
UNUSED(val);
#endif
}
/* ecall_type_int:
* [int] value passed by App.
*/
void ecall_type_int(int val)
{
assert(val == 1234);
#ifndef DEBUG
UNUSED(val);
#endif
}
/* ecall_type_float:
* [float] value passed by App.
*/
void ecall_type_float(float val)
{
assert(almost_equal(val, (float)1234.0));
#ifndef DEBUG
UNUSED(val);
#endif
}
/* ecall_type_double:
* [double] value passed by App.
*/
void ecall_type_double(double val)
{
assert(almost_equal(val, (double)1234.5678));
#ifndef DEBUG
UNUSED(val);
#endif
}
/* ecall_type_size_t:
* [size_t] value passed by App.
*/
void ecall_type_size_t(size_t val)
{
assert(val == (size_t)12345678);
#ifndef DEBUG
UNUSED(val);
#endif
}
/* ecall_type_wchar_t:
* [wchar_t] value passed by App.
*/
void ecall_type_wchar_t(wchar_t val)
{
assert(val == (wchar_t)0x1234);
#ifndef DEBUG
UNUSED(val);
#endif
}
/* ecall_type_struct:
* struct_foo_t is defined in EDL and can be used in ECALL.
*/
void ecall_type_struct(struct struct_foo_t val)
{
assert(val.struct_foo_0 == 1234);
assert(val.struct_foo_1 == 5678);
#ifndef DEBUG
UNUSED(val);
#endif
}
/*
* ecall_type_enum_union:
* enum_foo_t/union_foo_t is defined in EDL
* and can be used in ECALL.
*/
void ecall_type_enum_union(enum enum_foo_t val1, union union_foo_t *val2)
{
if (sgx_is_outside_enclave(val2, sizeof(union union_foo_t)) != 1)
abort();
val2->union_foo_0 = 1;
val2->union_foo_1 = 2; /* overwrite union_foo_0 */
assert(val1 == ENUM_FOO_0);
#ifndef DEBUG
UNUSED(val1);
#endif
}

View File

@ -0,0 +1,87 @@
/*
* Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Types.edl - Samples for basic types. */
enclave {
/*
* Following types can be supported in Edger8r:
* char, short, int, float, double, void,
* int8_t, int16_t, int32_t, int64_t,
* size_t, wchar_t,
* uint8_t, uint16_t, uint32_t, uint64_t,
* unsigned, struct, enum, union.
*/
/*
* We will demo few types in ECALL functions, data
* types in OCALL functions can be handled either.
*/
/* structure definition */
struct struct_foo_t {
/* Basic types can be used in structure. */
uint32_t struct_foo_0;
uint64_t struct_foo_1;
};
/* enum definition */
enum enum_foo_t {
ENUM_FOO_0 = 0,
ENUM_FOO_1 = 1
};
/* union definition */
union union_foo_t {
uint32_t union_foo_0;
uint32_t union_foo_1;
uint64_t union_foo_3;
};
trusted {
public void ecall_type_char(char val);
public void ecall_type_int(int val);
public void ecall_type_float(float val);
public void ecall_type_double(double val);
public void ecall_type_size_t(size_t val);
public void ecall_type_wchar_t(wchar_t val);
public void ecall_type_struct(struct struct_foo_t val);
public void ecall_type_enum_union(enum enum_foo_t val1, [user_check] union union_foo_t *val2);
/* for using user defined types, please refer to Pointers.edl, Arrays.edl. */
};
};