mirror of
https://github.com/corda/corda.git
synced 2025-06-23 17:53:31 +00:00
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:
39
common/inc/internal/ae_ipp.h
Normal file
39
common/inc/internal/ae_ipp.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _AE_IPP_H
|
||||
#define _AE_IPP_H
|
||||
|
||||
#include "ippcore.h"
|
||||
#include "ippcp.h"
|
||||
|
||||
#endif
|
297
common/inc/internal/arch.h
Normal file
297
common/inc/internal/arch.h
Normal file
@ -0,0 +1,297 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_ARCH_H_
|
||||
#define _SE_ARCH_H_
|
||||
|
||||
#include "inst.h"
|
||||
#include "se_types.h"
|
||||
#include "sgx_attributes.h"
|
||||
#include "sgx_key.h"
|
||||
#include "sgx_report.h"
|
||||
#include "sgx_tcrypto.h"
|
||||
|
||||
#define SE_PAGE_SIZE 0x1000
|
||||
#define TCS_SIZE SE_PAGE_SIZE
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
#if !defined(__cplusplus) || defined(__INTEL_COMPILER) || (defined(SE_GNU) && !defined(__GXX_EXPERIMENTAL_CXX0X__))
|
||||
#define _ASSERT_CONCAT(a, b) a##b
|
||||
#define ASSERT_CONCAT(a, b) _ASSERT_CONCAT(a, b)
|
||||
#define se_static_assert(e) typedef char ASSERT_CONCAT(assert_line, __LINE__)[(e)?1:-1]
|
||||
#else
|
||||
#define se_static_assert(e) static_assert(e,#e)
|
||||
#endif
|
||||
|
||||
se_static_assert(sizeof(sgx_key_request_t) == 512);
|
||||
se_static_assert(sizeof(sgx_target_info_t) == 512);
|
||||
|
||||
/*SECS data structure*/
|
||||
typedef struct _secs_t
|
||||
{
|
||||
uint64_t size; /* ( 0) Size of the enclave in bytes */
|
||||
PADDED_POINTER(void, base); /* ( 8) Base address of enclave */
|
||||
uint32_t ssa_frame_size; /* ( 16) size of 1 SSA frame in pages */
|
||||
sgx_misc_select_t misc_select; /* ( 20) Which fields defined in SSA.MISC */
|
||||
#define SECS_RESERVED1_LENGTH 24
|
||||
uint8_t reserved1[SECS_RESERVED1_LENGTH]; /* ( 24) reserved */
|
||||
sgx_attributes_t attributes; /* ( 48) ATTRIBUTES Flags Field */
|
||||
sgx_measurement_t mr_enclave; /* ( 64) Integrity Reg 0 - Enclave measurement */
|
||||
#define SECS_RESERVED2_LENGTH 32
|
||||
uint8_t reserved2[SECS_RESERVED2_LENGTH]; /* ( 96) reserved */
|
||||
sgx_measurement_t mr_signer; /* (128) Integrity Reg 1 - Enclave signing key */
|
||||
#define SECS_RESERVED3_LENGTH 96
|
||||
uint8_t reserved3[SECS_RESERVED3_LENGTH]; /* (160) reserved */
|
||||
sgx_prod_id_t isv_prod_id; /* (256) product ID of enclave */
|
||||
sgx_isv_svn_t isv_svn; /* (258) Security Version of the Enclave */
|
||||
#define SECS_RESERVED4_LENGTH 3836
|
||||
uint8_t reserved4[SECS_RESERVED4_LENGTH];/* (260) reserved */
|
||||
} secs_t;
|
||||
|
||||
/*
|
||||
TCS
|
||||
flags definitions
|
||||
*/
|
||||
#define DBGOPTIN 1 /* used by debugger */
|
||||
|
||||
typedef struct _tcs_t
|
||||
{
|
||||
uint64_t reserved0; /* (0) */
|
||||
uint64_t flags; /* (8)bit 0: DBGOPTION */
|
||||
uint64_t ossa; /* (16)State Save Area */
|
||||
uint32_t cssa; /* (24)Current SSA slot */
|
||||
uint32_t nssa; /* (28)Number of SSA slots */
|
||||
uint64_t oentry; /* (32)Offset in enclave to which control is transferred on EENTER if enclave INACTIVE state */
|
||||
uint64_t reserved1; /* (40) */
|
||||
uint64_t ofs_base; /* (48)When added to the base address of the enclave, produces the base address FS segment inside the enclave */
|
||||
uint64_t ogs_base; /* (56)When added to the base address of the enclave, produces the base address GS segment inside the enclave */
|
||||
uint32_t ofs_limit; /* (64)Size to become the new FS limit in 32-bit mode */
|
||||
uint32_t ogs_limit; /* (68)Size to become the new GS limit in 32-bit mode */
|
||||
#define TCS_RESERVED_LENGTH 4024
|
||||
uint8_t reserved[TCS_RESERVED_LENGTH]; /* (72) */
|
||||
}tcs_t;
|
||||
|
||||
se_static_assert(sizeof(tcs_t) == SE_PAGE_SIZE);
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions for SSA
|
||||
****************************************************************************/
|
||||
typedef struct _exit_info_t
|
||||
{
|
||||
uint32_t vector:8; /* Exception number of exceptions reported inside enclave */
|
||||
uint32_t exit_type:3; /* 3: Hardware exceptions, 6: Software exceptions */
|
||||
uint32_t reserved:20;
|
||||
uint32_t valid:1; /* 0: unsupported exceptions, 1: Supported exceptions */
|
||||
} exit_info_t;
|
||||
|
||||
#define SE_VECTOR_DE 0
|
||||
#define SE_VECTOR_DB 1
|
||||
#define SE_VECTOR_BP 3
|
||||
#define SE_VECTOR_BR 5
|
||||
#define SE_VECTOR_UD 6
|
||||
#define SE_VECTOR_MF 16
|
||||
#define SE_VECTOR_AC 17
|
||||
#define SE_VECTOR_XM 19
|
||||
|
||||
typedef struct _ssa_gpr_t
|
||||
{
|
||||
REGISTER( ax); /* (0) */
|
||||
REGISTER( cx); /* (8) */
|
||||
REGISTER( dx); /* (16) */
|
||||
REGISTER( bx); /* (24) */
|
||||
REGISTER( sp); /* (32) */
|
||||
REGISTER( bp); /* (40) */
|
||||
REGISTER( si); /* (48) */
|
||||
REGISTER( di); /* (56) */
|
||||
uint64_t r8; /* (64) */
|
||||
uint64_t r9; /* (72) */
|
||||
uint64_t r10; /* (80) */
|
||||
uint64_t r11; /* (88) */
|
||||
uint64_t r12; /* (96) */
|
||||
uint64_t r13; /* (104) */
|
||||
uint64_t r14; /* (112) */
|
||||
uint64_t r15; /* (120) */
|
||||
REGISTER(flags); /* (128) */
|
||||
REGISTER( ip); /* (136) */
|
||||
REGISTER( sp_u); /* (144) untrusted stack pointer. saved by EENTER */
|
||||
REGISTER( bp_u); /* (152) untrusted frame pointer. saved by EENTER */
|
||||
exit_info_t exit_info; /* (160) contain information for exits */
|
||||
uint32_t reserved; /* (164) padding to multiple of 8 bytes */
|
||||
uint64_t fs; /* (168) FS register */
|
||||
uint64_t gs; /* (176) GS register */
|
||||
} ssa_gpr_t;
|
||||
|
||||
typedef uint64_t si_flags_t;
|
||||
|
||||
#define SI_FLAG_NONE 0x0
|
||||
#define SI_FLAG_R 0x1 /* Read Access */
|
||||
#define SI_FLAG_W 0x2 /* Write Access */
|
||||
#define SI_FLAG_X 0x4 /* Execute Access */
|
||||
#define SI_FLAG_PT_LOW_BIT 0x8 /* PT low bit */
|
||||
#define SI_FLAG_PT_MASK (0xFF<<SI_FLAG_PT_LOW_BIT) /* Page Type Mask [15:8] */
|
||||
#define SI_FLAG_SECS (0x00<<SI_FLAG_PT_LOW_BIT) /* SECS */
|
||||
#define SI_FLAG_TCS (0x01<<SI_FLAG_PT_LOW_BIT) /* TCS */
|
||||
#define SI_FLAG_REG (0x02<<SI_FLAG_PT_LOW_BIT) /* Regular Page */
|
||||
|
||||
#define SI_FLAGS_EXTERNAL (SI_FLAG_PT_MASK | SI_FLAG_R | SI_FLAG_W | SI_FLAG_X) /* Flags visible/usable by instructions */
|
||||
#define SI_FLAGS_R (SI_FLAG_R|SI_FLAG_REG)
|
||||
#define SI_FLAGS_RW (SI_FLAG_R|SI_FLAG_W|SI_FLAG_REG)
|
||||
#define SI_FLAGS_RX (SI_FLAG_R|SI_FLAG_X|SI_FLAG_REG)
|
||||
#define SI_FLAGS_TCS (SI_FLAG_TCS)
|
||||
#define SI_FLAGS_SECS (SI_FLAG_SECS)
|
||||
#define SI_MASK_TCS (SI_FLAG_PT_MASK)
|
||||
#define SI_MASK_MEM_ATTRIBUTE (0x7)
|
||||
|
||||
|
||||
typedef struct _sec_info_t
|
||||
{
|
||||
si_flags_t flags;
|
||||
uint64_t reserved[7];
|
||||
} sec_info_t;
|
||||
|
||||
typedef struct _page_info_t
|
||||
{
|
||||
PADDED_POINTER(void, lin_addr); /* Enclave linear address */
|
||||
PADDED_POINTER(void, src_page); /* Linear address of the page where contents are located */
|
||||
PADDED_POINTER(sec_info_t, sec_info); /* Linear address of the SEC_INFO structure for the page */
|
||||
PADDED_POINTER(void, secs); /* Linear address of EPC slot that contains SECS for this enclave */
|
||||
} page_info_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions for enclave signature
|
||||
****************************************************************************/
|
||||
#define SE_KEY_SIZE 384 /* in bytes */
|
||||
#define SE_EXPONENT_SIZE 4 /* RSA public key exponent size in bytes */
|
||||
|
||||
typedef struct _css_header_t { /* 128 bytes */
|
||||
uint8_t header[12]; /* (0) must be (06000000E100000000000100H) */
|
||||
uint32_t type; /* (12) bit 31: 0 = prod, 1 = debug; Bit 30-0: Must be zero */
|
||||
uint32_t module_vendor; /* (16) Intel=0x8086, ISV=0x0000 */
|
||||
uint32_t date; /* (20) build date as yyyymmdd */
|
||||
uint8_t header2[16]; /* (24) must be (01010000600000006000000001000000H) */
|
||||
uint32_t hw_version; /* (40) For Launch Enclaves: HWVERSION != 0. Others, HWVERSION = 0 */
|
||||
uint8_t reserved[84]; /* (44) Must be 0 */
|
||||
} css_header_t;
|
||||
se_static_assert(sizeof(css_header_t) == 128);
|
||||
|
||||
typedef struct _css_key_t { /* 772 bytes */
|
||||
uint8_t modulus[SE_KEY_SIZE]; /* (128) Module Public Key (keylength=3072 bits) */
|
||||
uint8_t exponent[SE_EXPONENT_SIZE]; /* (512) RSA Exponent = 3 */
|
||||
uint8_t signature[SE_KEY_SIZE]; /* (516) Signature over Header and Body */
|
||||
} css_key_t;
|
||||
se_static_assert(sizeof(css_key_t) == 772);
|
||||
|
||||
typedef struct _css_body_t { /* 128 bytes */
|
||||
sgx_misc_select_t misc_select; /* (900) The MISCSELECT that must be set */
|
||||
sgx_misc_select_t misc_mask; /* (904) Mask of MISCSELECT to enforce */
|
||||
uint8_t reserved[20]; /* (908) Reserved. Must be 0. */
|
||||
sgx_attributes_t attributes; /* (928) Enclave Attributes that must be set */
|
||||
sgx_attributes_t attribute_mask; /* (944) Mask of Attributes to Enforce */
|
||||
sgx_measurement_t enclave_hash; /* (960) MRENCLAVE - (32 bytes) */
|
||||
uint8_t reserved2[32]; /* (992) Must be 0 */
|
||||
uint16_t isv_prod_id; /* (1024) ISV assigned Product ID */
|
||||
uint16_t isv_svn; /* (1026) ISV assigned SVN */
|
||||
} css_body_t;
|
||||
se_static_assert(sizeof(css_body_t) == 128);
|
||||
|
||||
typedef struct _css_buffer_t { /* 780 bytes */
|
||||
uint8_t reserved[12]; /* (1028) Must be 0 */
|
||||
uint8_t q1[SE_KEY_SIZE]; /* (1040) Q1 value for RSA Signature Verification */
|
||||
uint8_t q2[SE_KEY_SIZE]; /* (1424) Q2 value for RSA Signature Verification */
|
||||
} css_buffer_t;
|
||||
se_static_assert(sizeof(css_buffer_t) == 780);
|
||||
|
||||
typedef struct _enclave_css_t { /* 1808 bytes */
|
||||
css_header_t header; /* (0) */
|
||||
css_key_t key; /* (128) */
|
||||
css_body_t body; /* (900) */
|
||||
css_buffer_t buffer; /* (1028) */
|
||||
} enclave_css_t;
|
||||
|
||||
se_static_assert(sizeof(enclave_css_t) == 1808);
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions for launch token
|
||||
****************************************************************************/
|
||||
typedef struct _launch_body_t
|
||||
{
|
||||
uint32_t valid; /* ( 0) 0 = Invalid, 1 = Valid */
|
||||
uint32_t reserved1[11]; /* ( 4) must be zero */
|
||||
sgx_attributes_t attributes; /* ( 48) ATTRIBUTES of Enclave */
|
||||
sgx_measurement_t mr_enclave; /* ( 64) MRENCLAVE of Enclave */
|
||||
uint8_t reserved2[32]; /* ( 96) */
|
||||
sgx_measurement_t mr_signer; /* (128) MRSIGNER of Enclave */
|
||||
uint8_t reserved3[32]; /* (160) */
|
||||
} launch_body_t;
|
||||
se_static_assert(sizeof(launch_body_t) == 192);
|
||||
|
||||
typedef struct _launch_t {
|
||||
launch_body_t body;
|
||||
sgx_cpu_svn_t cpu_svn_le; /* (192) Launch Enclave's CPUSVN */
|
||||
uint16_t isv_prod_id_le; /* (208) Launch Enclave's ISVPRODID */
|
||||
uint16_t isv_svn_le; /* (210) Launch Enclave's ISVSVN */
|
||||
uint8_t reserved2[24]; /* (212) Must be 0 */
|
||||
sgx_misc_select_t masked_misc_select_le; /* (236) */
|
||||
sgx_attributes_t attributes_le; /* (240) ATTRIBUTES of Launch Enclave */
|
||||
sgx_key_id_t key_id; /* (256) Value for key wear-out protection */
|
||||
sgx_mac_t mac; /* (288) CMAC using Launch Token Key */
|
||||
} token_t;
|
||||
se_static_assert(sizeof(token_t) == 304);
|
||||
|
||||
typedef struct _wl_cert_t /* All fields except the mr_signer_list fields, are big-endian integer format */
|
||||
{
|
||||
uint16_t version; /* ( 0) White List Cert format version. For 2015, only valid version is 1 */
|
||||
uint16_t cert_type; /* ( 2) White List Cert Type. For Enclave Signing Key White List Cert, must be 1 */
|
||||
uint16_t provider_id; /* ( 4) Enclave Signing Key White List Provider ID to identify the key used to sign this Enclave signing Key White List Certificate. For 2015, only one White List Provider is approved: WLProviderID-ISecG = 0 */
|
||||
uint16_t le_prod_id; /* ( 6) Launch Enclave ProdID the White List Cert applies to. Linux LE-ProdID = 0x20 */
|
||||
uint32_t wl_version; /* ( 8) Version of the Enclave Signing Key White List. For a specific LE-ProdID, should increase on every WL Cert signing request */
|
||||
uint32_t entry_number; /* (12) Number of MRSIGNER entries in the Cert. If the White List Certificate allows enclave signed by any key to launch, the White List Cert must only contain one all-0 MRSIGNER entry. */
|
||||
sgx_measurement_t mr_signer_list[]; /* (16) White Listed Enclave Signing Key entry 0 - SHA256 Hash of the little-endian format RSA-3072 Enclave Signing Key modulus. If the White List Cert allows enclave signed by any key to launch, this field must be all 0s */
|
||||
}wl_cert_t;
|
||||
typedef struct _wl_provider_cert_t /* All fields are big endian */
|
||||
{
|
||||
uint16_t version; /* ( 0) White List Cert format version. For 2015, only valid version is 1 */
|
||||
uint16_t cert_type; /* ( 2) White List Cert Type, For Enclave Signing Key White List Signer Cert, must be 0 */
|
||||
uint16_t provider_id; /* ( 4) Enclave Signing Key White List Signer ID assigned by the White List Root CA. For 2015, only one White List Provider is approved: WLProviderID-ISecG = 0 */
|
||||
uint16_t root_id; /* ( 6) Identify the White List Root CA key used to sign the Cert. For 2015, only one WLRootID is valid: WLRootID-iKGF-Key-0 = 0 */
|
||||
sgx_ec256_public_t pub_key; /* ( 8) ECDSA public key of the Enclave Signing Key White List Provider identified by WLProviderID */
|
||||
sgx_ec256_signature_t signature; /* (72) ECDSA Signature by WL Root CA identified by WLRootID */
|
||||
}wl_provider_cert_t;
|
||||
se_static_assert(sizeof(wl_provider_cert_t) == 136);
|
||||
typedef struct _wl_cert_chain_t
|
||||
{
|
||||
wl_provider_cert_t wl_provider_cert;
|
||||
wl_cert_t wl_cert;
|
||||
}wl_cert_chain_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif/*_SE_ARCH_H_*/
|
38
common/inc/internal/cpprt_internal.h
Normal file
38
common/inc/internal/cpprt_internal.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#ifndef CPPRT_INTERNAL_H
|
||||
#define CPPRT_INTERNAL_H
|
||||
|
||||
#include "sgx_defs.h"
|
||||
/*call new_handl function when new memory failed*/
|
||||
int SGXAPI call_newh();
|
||||
|
||||
#endif
|
65
common/inc/internal/cpputil.h
Normal file
65
common/inc/internal/cpputil.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#ifndef _CPPUTIL_H__
|
||||
#define _CPPUTIL_H__
|
||||
|
||||
#include <assert.h>
|
||||
#include <utility>
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
void delete_ptrs_from_container(T& vec)
|
||||
{
|
||||
typename T::iterator iter = vec.begin();
|
||||
typename T::iterator end = vec.end();
|
||||
typename T::iterator this_iter;
|
||||
|
||||
while (iter != end)
|
||||
{
|
||||
this_iter = iter;
|
||||
++iter;
|
||||
delete *this_iter;
|
||||
}
|
||||
}
|
||||
|
||||
/* Each pair is well-formed (p.first <= p.second) */
|
||||
template <typename T>
|
||||
bool is_overlap(const std::pair<T, T>& p1,
|
||||
const std::pair<T, T>& p2)
|
||||
{
|
||||
assert(p1.first <= p1.second);
|
||||
assert(p2.first <= p2.second);
|
||||
|
||||
return ((p1.first <= p2.second) && (p2.first <= p1.second));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
38
common/inc/internal/cpuid.h
Normal file
38
common/inc/internal/cpuid.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CPUID_H_
|
||||
#define _CPUID_H_
|
||||
|
||||
#include "linux/cpuid_gnu.h"
|
||||
|
||||
|
||||
#endif /* _CPUID_H_ */
|
43
common/inc/internal/dh.h
Normal file
43
common/inc/internal/dh.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _DH_H
|
||||
#define _DH_H
|
||||
|
||||
#include "utility.h"
|
||||
|
||||
/*return true if encrypt message successfully */
|
||||
bool encrypt_msg(pse_message_t* pse_msg, uint8_t* data, sgx_key_128bit_t* authenticated_encryption_key);
|
||||
|
||||
/*return true if decrypt message successfully */
|
||||
bool decrypt_msg(pse_message_t* pse_msg, uint8_t* data, sgx_key_128bit_t* authenticated_encryption_key);
|
||||
#endif
|
50
common/inc/internal/driver_api.h
Normal file
50
common/inc/internal/driver_api.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _DRIVER_API_H_
|
||||
#define _DRIVER_API_H_
|
||||
|
||||
#include "arch.h"
|
||||
#include "sgx_eid.h"
|
||||
|
||||
/*
|
||||
@enclave_id identify the unique enclave;
|
||||
@start_addr is the linear address that driver allocate for app;
|
||||
*/
|
||||
int create_enclave(secs_t *secs, sgx_enclave_id_t *enclave_id, void **start_addr);
|
||||
/*
|
||||
*@attr can be REMOVABLE
|
||||
*/
|
||||
int add_enclave_page(sgx_enclave_id_t enclave_id, void *source, size_t offset, const sec_info_t &secinfo, uint32_t attr);
|
||||
int init_enclave(sgx_enclave_id_t enclave_id, enclave_css_t *enclave_css, token_t *launch);
|
||||
int destroy_enclave(sgx_enclave_id_t enclave_id);
|
||||
|
||||
#endif
|
53
common/inc/internal/ecp_interface.h
Normal file
53
common/inc/internal/ecp_interface.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _ECP_INTERFACE_H
|
||||
#define _ECP_INTERFACE_H
|
||||
|
||||
#include "sgx_ecp_types.h"
|
||||
#include "sgx_tcrypto.h"
|
||||
|
||||
//Key Derivation Function ID : 0x0001 AES-CMAC Entropy Extraction and Key Expansion
|
||||
const uint16_t AES_CMAC_KDF_ID = 0x0001;
|
||||
|
||||
sgx_status_t derive_key(
|
||||
const sgx_ec256_dh_shared_t* shared_key,
|
||||
const char* label,
|
||||
uint32_t label_length,
|
||||
sgx_ec_key_128bit_t* derived_key);
|
||||
|
||||
#ifndef INTERNAL_SGX_ERROR_CODE_CONVERTOR
|
||||
#define INTERNAL_SGX_ERROR_CODE_CONVERTOR(x) if(x != SGX_ERROR_OUT_OF_MEMORY){x = SGX_ERROR_UNEXPECTED;}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
72
common/inc/internal/elf_util.h
Normal file
72
common/inc/internal/elf_util.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#ifndef _ELF_UTIL_H_
|
||||
#define _ELF_UTIL_H_
|
||||
|
||||
#include "elfheader/elf_common.h"
|
||||
#include "elfheader/elfstructs.h"
|
||||
|
||||
#ifndef __ELF_NATIVE_CLASS
|
||||
# if defined(_M_X64) || defined(__x86_64) || defined(__amd64)
|
||||
# include <limits.h> /* for UINT_MAX */
|
||||
# define __ELF_NATIVE_CLASS 64
|
||||
# else
|
||||
# define __ELF_NATIVE_CLASS 32
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if __ELF_NATIVE_CLASS == 64
|
||||
# define Rel Rela
|
||||
|
||||
# define RTS_DT_REL DT_RELA
|
||||
# define RTS_DT_RELSZ DT_RELASZ
|
||||
# define RTS_DT_RELENT DT_RELAENT
|
||||
# else
|
||||
# define RTS_DT_REL DT_REL
|
||||
# define RTS_DT_RELSZ DT_RELSZ
|
||||
# define RTS_DT_RELENT DT_RELENT
|
||||
#endif
|
||||
|
||||
/* We use this macro to refer to ELF types independent of the native wordsize.
|
||||
`ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
|
||||
#define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
|
||||
|
||||
/* We use this macro to refer to ELF macro constants. For example,
|
||||
`ELFW(R_SYM)' is used in place of `ELF32_R_SYM' or `ELF64_R_SYM'. */
|
||||
#define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type)
|
||||
|
||||
#define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
|
||||
#define _ElfW_1(e,w,t) e##w##t
|
||||
|
||||
/* GNU header uses `JUMP_SLOT' while `JMP_SLOT' in FreeBSD. */
|
||||
#define R_X86_64_JUMP_SLOT R_X86_64_JMP_SLOT
|
||||
|
||||
#endif
|
59
common/inc/internal/elfheader/README.txt
Normal file
59
common/inc/internal/elfheader/README.txt
Normal file
@ -0,0 +1,59 @@
|
||||
Note, the files `elf_common.h' and `elfstructs.h' are from FreeBSD.
|
||||
git://github.com/freebsd/freebsd.git
|
||||
|
||||
But with slight modifications shown below:
|
||||
|
||||
diff --git a/sys/sys/elf_common.h b/sys/sys/elf_common.h
|
||||
index 8f02ef1..7601abb 100644
|
||||
--- a/sys/sys/elf_common.h
|
||||
+++ b/sys/sys/elf_common.h
|
||||
@@ -30,6 +30,9 @@
|
||||
#ifndef _SYS_ELF_COMMON_H_
|
||||
#define _SYS_ELF_COMMON_H_ 1
|
||||
|
||||
+typedef uint32_t u_int32_t;
|
||||
+typedef uint32_t Elf_Symndx;
|
||||
+
|
||||
/*
|
||||
* ELF definitions that are independent of architecture or word size.
|
||||
*/
|
||||
@@ -117,9 +120,6 @@ typedef struct {
|
||||
#define ELFOSABI_ARM 97 /* ARM */
|
||||
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
|
||||
|
||||
-#define ELFOSABI_SYSV ELFOSABI_NONE /* symbol used in old spec */
|
||||
-#define ELFOSABI_MONTEREY ELFOSABI_AIX /* Monterey */
|
||||
-
|
||||
/* e_ident */
|
||||
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
||||
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
||||
@@ -242,7 +242,6 @@ typedef struct {
|
||||
#define EM_486 6 /* Intel i486. */
|
||||
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||
#define EM_ALPHA_STD 41 /* Digital Alpha (standard value). */
|
||||
-#define EM_ALPHA 0x9026 /* Alpha (written in the absence of an ABI) */
|
||||
|
||||
/* Special section indexes. */
|
||||
#define SHN_UNDEF 0 /* Undefined, missing, irrelevant. */
|
||||
@@ -441,6 +440,8 @@ typedef struct {
|
||||
#define DT_MOVETAB 0x6ffffefe /* move table */
|
||||
#define DT_SYMINFO 0x6ffffeff /* syminfo table */
|
||||
#define DT_ADDRRNGHI 0x6ffffeff
|
||||
+#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */
|
||||
+#define DT_ADDRNUM 11
|
||||
|
||||
#define DT_VERSYM 0x6ffffff0 /* Address of versym section. */
|
||||
#define DT_RELACOUNT 0x6ffffff9 /* number of RELATIVE relocations */
|
||||
@@ -505,12 +506,9 @@ typedef struct {
|
||||
#define STT_FILE 4 /* Source file. */
|
||||
#define STT_COMMON 5 /* Uninitialized common block. */
|
||||
#define STT_TLS 6 /* TLS object. */
|
||||
-#define STT_NUM 7
|
||||
#define STT_LOOS 10 /* Reserved range for operating system */
|
||||
#define STT_GNU_IFUNC 10
|
||||
#define STT_HIOS 12 /* specific semantics. */
|
||||
-#define STT_LOPROC 13 /* reserved range for processor */
|
||||
-#define STT_HIPROC 15 /* specific semantics. */
|
||||
|
||||
/* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */
|
||||
#define STV_DEFAULT 0x0 /* Default visibility (see binding). */
|
975
common/inc/internal/elfheader/elf_common.h
Normal file
975
common/inc/internal/elfheader/elf_common.h
Normal file
@ -0,0 +1,975 @@
|
||||
/*-
|
||||
* Copyright (c) 2000, 2001, 2008, 2011, David E. O'Brien
|
||||
* Copyright (c) 1998 John D. Polstra.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _SYS_ELF_COMMON_H_
|
||||
#define _SYS_ELF_COMMON_H_ 1
|
||||
|
||||
typedef uint32_t u_int32_t;
|
||||
typedef uint32_t Elf_Symndx;
|
||||
|
||||
/*
|
||||
* ELF definitions that are independent of architecture or word size.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Note header. The ".note" section contains an array of notes. Each
|
||||
* begins with this header, aligned to a word boundary. Immediately
|
||||
* following the note header is n_namesz bytes of name, padded to the
|
||||
* next word boundary. Then comes n_descsz bytes of descriptor, again
|
||||
* padded to a word boundary. The values of n_namesz and n_descsz do
|
||||
* not include the padding.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
u_int32_t n_namesz; /* Length of name. */
|
||||
u_int32_t n_descsz; /* Length of descriptor. */
|
||||
u_int32_t n_type; /* Type of this note. */
|
||||
} Elf_Note;
|
||||
|
||||
/*
|
||||
* The header for GNU-style hash sections.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
u_int32_t gh_nbuckets; /* Number of hash buckets. */
|
||||
u_int32_t gh_symndx; /* First visible symbol in .dynsym. */
|
||||
u_int32_t gh_maskwords; /* #maskwords used in bloom filter. */
|
||||
u_int32_t gh_shift2; /* Bloom filter shift count. */
|
||||
} Elf_GNU_Hash_Header;
|
||||
|
||||
/* Indexes into the e_ident array. Keep synced with
|
||||
http://www.sco.com/developers/gabi/latest/ch4.eheader.html */
|
||||
#define EI_MAG0 0 /* Magic number, byte 0. */
|
||||
#define EI_MAG1 1 /* Magic number, byte 1. */
|
||||
#define EI_MAG2 2 /* Magic number, byte 2. */
|
||||
#define EI_MAG3 3 /* Magic number, byte 3. */
|
||||
#define EI_CLASS 4 /* Class of machine. */
|
||||
#define EI_DATA 5 /* Data format. */
|
||||
#define EI_VERSION 6 /* ELF format version. */
|
||||
#define EI_OSABI 7 /* Operating system / ABI identification */
|
||||
#define EI_ABIVERSION 8 /* ABI version */
|
||||
#define OLD_EI_BRAND 8 /* Start of architecture identification. */
|
||||
#define EI_PAD 9 /* Start of padding (per SVR4 ABI). */
|
||||
#define EI_NIDENT 16 /* Size of e_ident array. */
|
||||
|
||||
/* Values for the magic number bytes. */
|
||||
#define ELFMAG0 0x7f
|
||||
#define ELFMAG1 'E'
|
||||
#define ELFMAG2 'L'
|
||||
#define ELFMAG3 'F'
|
||||
#define ELFMAG "\177ELF" /* magic string */
|
||||
#define SELFMAG 4 /* magic string size */
|
||||
|
||||
/* Values for e_ident[EI_VERSION] and e_version. */
|
||||
#define EV_NONE 0
|
||||
#define EV_CURRENT 1
|
||||
|
||||
/* Values for e_ident[EI_CLASS]. */
|
||||
#define ELFCLASSNONE 0 /* Unknown class. */
|
||||
#define ELFCLASS32 1 /* 32-bit architecture. */
|
||||
#define ELFCLASS64 2 /* 64-bit architecture. */
|
||||
|
||||
/* Values for e_ident[EI_DATA]. */
|
||||
#define ELFDATANONE 0 /* Unknown data format. */
|
||||
#define ELFDATA2LSB 1 /* 2's complement little-endian. */
|
||||
#define ELFDATA2MSB 2 /* 2's complement big-endian. */
|
||||
|
||||
/* Values for e_ident[EI_OSABI]. */
|
||||
#define ELFOSABI_NONE 0 /* UNIX System V ABI */
|
||||
#define ELFOSABI_HPUX 1 /* HP-UX operating system */
|
||||
#define ELFOSABI_NETBSD 2 /* NetBSD */
|
||||
#define ELFOSABI_LINUX 3 /* GNU/Linux */
|
||||
#define ELFOSABI_HURD 4 /* GNU/Hurd */
|
||||
#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */
|
||||
#define ELFOSABI_SOLARIS 6 /* Solaris */
|
||||
#define ELFOSABI_AIX 7 /* AIX */
|
||||
#define ELFOSABI_IRIX 8 /* IRIX */
|
||||
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
|
||||
#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
|
||||
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
|
||||
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
|
||||
#define ELFOSABI_OPENVMS 13 /* Open VMS */
|
||||
#define ELFOSABI_NSK 14 /* HP Non-Stop Kernel */
|
||||
#define ELFOSABI_AROS 15 /* Amiga Research OS */
|
||||
#define ELFOSABI_ARM 97 /* ARM */
|
||||
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
|
||||
|
||||
/* e_ident */
|
||||
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
||||
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
||||
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
|
||||
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
||||
|
||||
/* Values for e_type. */
|
||||
#define ET_NONE 0 /* Unknown type. */
|
||||
#define ET_REL 1 /* Relocatable. */
|
||||
#define ET_EXEC 2 /* Executable. */
|
||||
#define ET_DYN 3 /* Shared object. */
|
||||
#define ET_CORE 4 /* Core file. */
|
||||
#define ET_LOOS 0xfe00 /* First operating system specific. */
|
||||
#define ET_HIOS 0xfeff /* Last operating system-specific. */
|
||||
#define ET_LOPROC 0xff00 /* First processor-specific. */
|
||||
#define ET_HIPROC 0xffff /* Last processor-specific. */
|
||||
|
||||
/* Values for e_machine. */
|
||||
#define EM_NONE 0 /* Unknown machine. */
|
||||
#define EM_M32 1 /* AT&T WE32100. */
|
||||
#define EM_SPARC 2 /* Sun SPARC. */
|
||||
#define EM_386 3 /* Intel i386. */
|
||||
#define EM_68K 4 /* Motorola 68000. */
|
||||
#define EM_88K 5 /* Motorola 88000. */
|
||||
#define EM_860 7 /* Intel i860. */
|
||||
#define EM_MIPS 8 /* MIPS R3000 Big-Endian only. */
|
||||
#define EM_S370 9 /* IBM System/370. */
|
||||
#define EM_MIPS_RS3_LE 10 /* MIPS R3000 Little-Endian. */
|
||||
#define EM_PARISC 15 /* HP PA-RISC. */
|
||||
#define EM_VPP500 17 /* Fujitsu VPP500. */
|
||||
#define EM_SPARC32PLUS 18 /* SPARC v8plus. */
|
||||
#define EM_960 19 /* Intel 80960. */
|
||||
#define EM_PPC 20 /* PowerPC 32-bit. */
|
||||
#define EM_PPC64 21 /* PowerPC 64-bit. */
|
||||
#define EM_S390 22 /* IBM System/390. */
|
||||
#define EM_V800 36 /* NEC V800. */
|
||||
#define EM_FR20 37 /* Fujitsu FR20. */
|
||||
#define EM_RH32 38 /* TRW RH-32. */
|
||||
#define EM_RCE 39 /* Motorola RCE. */
|
||||
#define EM_ARM 40 /* ARM. */
|
||||
#define EM_SH 42 /* Hitachi SH. */
|
||||
#define EM_SPARCV9 43 /* SPARC v9 64-bit. */
|
||||
#define EM_TRICORE 44 /* Siemens TriCore embedded processor. */
|
||||
#define EM_ARC 45 /* Argonaut RISC Core. */
|
||||
#define EM_H8_300 46 /* Hitachi H8/300. */
|
||||
#define EM_H8_300H 47 /* Hitachi H8/300H. */
|
||||
#define EM_H8S 48 /* Hitachi H8S. */
|
||||
#define EM_H8_500 49 /* Hitachi H8/500. */
|
||||
#define EM_IA_64 50 /* Intel IA-64 Processor. */
|
||||
#define EM_MIPS_X 51 /* Stanford MIPS-X. */
|
||||
#define EM_COLDFIRE 52 /* Motorola ColdFire. */
|
||||
#define EM_68HC12 53 /* Motorola M68HC12. */
|
||||
#define EM_MMA 54 /* Fujitsu MMA. */
|
||||
#define EM_PCP 55 /* Siemens PCP. */
|
||||
#define EM_NCPU 56 /* Sony nCPU. */
|
||||
#define EM_NDR1 57 /* Denso NDR1 microprocessor. */
|
||||
#define EM_STARCORE 58 /* Motorola Star*Core processor. */
|
||||
#define EM_ME16 59 /* Toyota ME16 processor. */
|
||||
#define EM_ST100 60 /* STMicroelectronics ST100 processor. */
|
||||
#define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ processor. */
|
||||
#define EM_X86_64 62 /* Advanced Micro Devices x86-64 */
|
||||
#define EM_AMD64 EM_X86_64 /* Advanced Micro Devices x86-64 (compat) */
|
||||
#define EM_PDSP 63 /* Sony DSP Processor. */
|
||||
#define EM_FX66 66 /* Siemens FX66 microcontroller. */
|
||||
#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16
|
||||
microcontroller. */
|
||||
#define EM_ST7 68 /* STmicroelectronics ST7 8-bit
|
||||
microcontroller. */
|
||||
#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller. */
|
||||
#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller. */
|
||||
#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller. */
|
||||
#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller. */
|
||||
#define EM_SVX 73 /* Silicon Graphics SVx. */
|
||||
#define EM_ST19 74 /* STMicroelectronics ST19 8-bit mc. */
|
||||
#define EM_VAX 75 /* Digital VAX. */
|
||||
#define EM_CRIS 76 /* Axis Communications 32-bit embedded
|
||||
processor. */
|
||||
#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded
|
||||
processor. */
|
||||
#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor. */
|
||||
#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor. */
|
||||
#define EM_MMIX 80 /* Donald Knuth's educational 64-bit proc. */
|
||||
#define EM_HUANY 81 /* Harvard University machine-independent
|
||||
object files. */
|
||||
#define EM_PRISM 82 /* SiTera Prism. */
|
||||
#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller. */
|
||||
#define EM_FR30 84 /* Fujitsu FR30. */
|
||||
#define EM_D10V 85 /* Mitsubishi D10V. */
|
||||
#define EM_D30V 86 /* Mitsubishi D30V. */
|
||||
#define EM_V850 87 /* NEC v850. */
|
||||
#define EM_M32R 88 /* Mitsubishi M32R. */
|
||||
#define EM_MN10300 89 /* Matsushita MN10300. */
|
||||
#define EM_MN10200 90 /* Matsushita MN10200. */
|
||||
#define EM_PJ 91 /* picoJava. */
|
||||
#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor. */
|
||||
#define EM_ARC_A5 93 /* ARC Cores Tangent-A5. */
|
||||
#define EM_XTENSA 94 /* Tensilica Xtensa Architecture. */
|
||||
#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor. */
|
||||
#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose
|
||||
Processor. */
|
||||
#define EM_NS32K 97 /* National Semiconductor 32000 series. */
|
||||
#define EM_TPC 98 /* Tenor Network TPC processor. */
|
||||
#define EM_SNP1K 99 /* Trebia SNP 1000 processor. */
|
||||
#define EM_ST200 100 /* STMicroelectronics ST200 microcontroller. */
|
||||
#define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family. */
|
||||
#define EM_MAX 102 /* MAX Processor. */
|
||||
#define EM_CR 103 /* National Semiconductor CompactRISC
|
||||
microprocessor. */
|
||||
#define EM_F2MC16 104 /* Fujitsu F2MC16. */
|
||||
#define EM_MSP430 105 /* Texas Instruments embedded microcontroller
|
||||
msp430. */
|
||||
#define EM_BLACKFIN 106 /* Analog Devices Blackfin (DSP) processor. */
|
||||
#define EM_SE_C33 107 /* S1C33 Family of Seiko Epson processors. */
|
||||
#define EM_SEP 108 /* Sharp embedded microprocessor. */
|
||||
#define EM_ARCA 109 /* Arca RISC Microprocessor. */
|
||||
#define EM_UNICORE 110 /* Microprocessor series from PKU-Unity Ltd.
|
||||
and MPRC of Peking University */
|
||||
|
||||
/* Non-standard or deprecated. */
|
||||
#define EM_486 6 /* Intel i486. */
|
||||
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||
#define EM_ALPHA_STD 41 /* Digital Alpha (standard value). */
|
||||
|
||||
/* Special section indexes. */
|
||||
#define SHN_UNDEF 0 /* Undefined, missing, irrelevant. */
|
||||
#define SHN_LORESERVE 0xff00 /* First of reserved range. */
|
||||
#define SHN_LOPROC 0xff00 /* First processor-specific. */
|
||||
#define SHN_HIPROC 0xff1f /* Last processor-specific. */
|
||||
#define SHN_LOOS 0xff20 /* First operating system-specific. */
|
||||
#define SHN_HIOS 0xff3f /* Last operating system-specific. */
|
||||
#define SHN_ABS 0xfff1 /* Absolute values. */
|
||||
#define SHN_COMMON 0xfff2 /* Common data. */
|
||||
#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere. */
|
||||
#define SHN_HIRESERVE 0xffff /* Last of reserved range. */
|
||||
|
||||
/* sh_type */
|
||||
#define SHT_NULL 0 /* inactive */
|
||||
#define SHT_PROGBITS 1 /* program defined information */
|
||||
#define SHT_SYMTAB 2 /* symbol table section */
|
||||
#define SHT_STRTAB 3 /* string table section */
|
||||
#define SHT_RELA 4 /* relocation section with addends */
|
||||
#define SHT_HASH 5 /* symbol hash table section */
|
||||
#define SHT_DYNAMIC 6 /* dynamic section */
|
||||
#define SHT_NOTE 7 /* note section */
|
||||
#define SHT_NOBITS 8 /* no space section */
|
||||
#define SHT_REL 9 /* relocation section - no addends */
|
||||
#define SHT_SHLIB 10 /* reserved - purpose unknown */
|
||||
#define SHT_DYNSYM 11 /* dynamic symbol table section */
|
||||
#define SHT_INIT_ARRAY 14 /* Initialization function pointers. */
|
||||
#define SHT_FINI_ARRAY 15 /* Termination function pointers. */
|
||||
#define SHT_PREINIT_ARRAY 16 /* Pre-initialization function ptrs. */
|
||||
#define SHT_GROUP 17 /* Section group. */
|
||||
#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX). */
|
||||
#define SHT_LOOS 0x60000000 /* First of OS specific semantics */
|
||||
#define SHT_LOSUNW 0x6ffffff4
|
||||
#define SHT_SUNW_dof 0x6ffffff4
|
||||
#define SHT_SUNW_cap 0x6ffffff5
|
||||
#define SHT_SUNW_SIGNATURE 0x6ffffff6
|
||||
#define SHT_GNU_HASH 0x6ffffff6
|
||||
#define SHT_SUNW_ANNOTATE 0x6ffffff7
|
||||
#define SHT_SUNW_DEBUGSTR 0x6ffffff8
|
||||
#define SHT_SUNW_DEBUG 0x6ffffff9
|
||||
#define SHT_SUNW_move 0x6ffffffa
|
||||
#define SHT_SUNW_COMDAT 0x6ffffffb
|
||||
#define SHT_SUNW_syminfo 0x6ffffffc
|
||||
#define SHT_SUNW_verdef 0x6ffffffd
|
||||
#define SHT_GNU_verdef 0x6ffffffd /* Symbol versions provided */
|
||||
#define SHT_SUNW_verneed 0x6ffffffe
|
||||
#define SHT_GNU_verneed 0x6ffffffe /* Symbol versions required */
|
||||
#define SHT_SUNW_versym 0x6fffffff
|
||||
#define SHT_GNU_versym 0x6fffffff /* Symbol version table */
|
||||
#define SHT_HISUNW 0x6fffffff
|
||||
#define SHT_HIOS 0x6fffffff /* Last of OS specific semantics */
|
||||
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define SHT_AMD64_UNWIND 0x70000001 /* unwind information */
|
||||
#define SHT_MIPS_REGINFO 0x70000006
|
||||
#define SHT_MIPS_OPTIONS 0x7000000d
|
||||
#define SHT_MIPS_DWARF 0x7000001e /* MIPS gcc uses MIPS_DWARF */
|
||||
#define SHT_HIPROC 0x7fffffff /* specific section header types */
|
||||
#define SHT_LOUSER 0x80000000 /* reserved range for application */
|
||||
#define SHT_HIUSER 0xffffffff /* specific indexes */
|
||||
|
||||
/* Flags for sh_flags. */
|
||||
#define SHF_WRITE 0x1 /* Section contains writable data. */
|
||||
#define SHF_ALLOC 0x2 /* Section occupies memory. */
|
||||
#define SHF_EXECINSTR 0x4 /* Section contains instructions. */
|
||||
#define SHF_MERGE 0x10 /* Section may be merged. */
|
||||
#define SHF_STRINGS 0x20 /* Section contains strings. */
|
||||
#define SHF_INFO_LINK 0x40 /* sh_info holds section index. */
|
||||
#define SHF_LINK_ORDER 0x80 /* Special ordering requirements. */
|
||||
#define SHF_OS_NONCONFORMING 0x100 /* OS-specific processing required. */
|
||||
#define SHF_GROUP 0x200 /* Member of section group. */
|
||||
#define SHF_TLS 0x400 /* Section contains TLS data. */
|
||||
#define SHF_MASKOS 0x0ff00000 /* OS-specific semantics. */
|
||||
#define SHF_MASKPROC 0xf0000000 /* Processor-specific semantics. */
|
||||
|
||||
/* Values for p_type. */
|
||||
#define PT_NULL 0 /* Unused entry. */
|
||||
#define PT_LOAD 1 /* Loadable segment. */
|
||||
#define PT_DYNAMIC 2 /* Dynamic linking information segment. */
|
||||
#define PT_INTERP 3 /* Pathname of interpreter. */
|
||||
#define PT_NOTE 4 /* Auxiliary information. */
|
||||
#define PT_SHLIB 5 /* Reserved (not used). */
|
||||
#define PT_PHDR 6 /* Location of program header itself. */
|
||||
#define PT_TLS 7 /* Thread local storage segment */
|
||||
#define PT_LOOS 0x60000000 /* First OS-specific. */
|
||||
#define PT_SUNW_UNWIND 0x6464e550 /* amd64 UNWIND program header */
|
||||
#define PT_GNU_EH_FRAME 0x6474e550
|
||||
#define PT_GNU_STACK 0x6474e551
|
||||
#define PT_GNU_RELRO 0x6474e552
|
||||
#define PT_LOSUNW 0x6ffffffa
|
||||
#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */
|
||||
#define PT_SUNWSTACK 0x6ffffffb /* describes the stack segment */
|
||||
#define PT_SUNWDTRACE 0x6ffffffc /* private */
|
||||
#define PT_SUNWCAP 0x6ffffffd /* hard/soft capabilities segment */
|
||||
#define PT_HISUNW 0x6fffffff
|
||||
#define PT_HIOS 0x6fffffff /* Last OS-specific. */
|
||||
#define PT_LOPROC 0x70000000 /* First processor-specific type. */
|
||||
#define PT_HIPROC 0x7fffffff /* Last processor-specific type. */
|
||||
|
||||
/* Values for p_flags. */
|
||||
#define PF_X 0x1 /* Executable. */
|
||||
#define PF_W 0x2 /* Writable. */
|
||||
#define PF_R 0x4 /* Readable. */
|
||||
#define PF_MASKOS 0x0ff00000 /* Operating system-specific. */
|
||||
#define PF_MASKPROC 0xf0000000 /* Processor-specific. */
|
||||
|
||||
/* Extended program header index. */
|
||||
#define PN_XNUM 0xffff
|
||||
|
||||
/* Values for d_tag. */
|
||||
#define DT_NULL 0 /* Terminating entry. */
|
||||
#define DT_NEEDED 1 /* String table offset of a needed shared
|
||||
library. */
|
||||
#define DT_PLTRELSZ 2 /* Total size in bytes of PLT relocations. */
|
||||
#define DT_PLTGOT 3 /* Processor-dependent address. */
|
||||
#define DT_HASH 4 /* Address of symbol hash table. */
|
||||
#define DT_STRTAB 5 /* Address of string table. */
|
||||
#define DT_SYMTAB 6 /* Address of symbol table. */
|
||||
#define DT_RELA 7 /* Address of ElfNN_Rela relocations. */
|
||||
#define DT_RELASZ 8 /* Total size of ElfNN_Rela relocations. */
|
||||
#define DT_RELAENT 9 /* Size of each ElfNN_Rela relocation entry. */
|
||||
#define DT_STRSZ 10 /* Size of string table. */
|
||||
#define DT_SYMENT 11 /* Size of each symbol table entry. */
|
||||
#define DT_INIT 12 /* Address of initialization function. */
|
||||
#define DT_FINI 13 /* Address of finalization function. */
|
||||
#define DT_SONAME 14 /* String table offset of shared object
|
||||
name. */
|
||||
#define DT_RPATH 15 /* String table offset of library path. [sup] */
|
||||
#define DT_SYMBOLIC 16 /* Indicates "symbolic" linking. [sup] */
|
||||
#define DT_REL 17 /* Address of ElfNN_Rel relocations. */
|
||||
#define DT_RELSZ 18 /* Total size of ElfNN_Rel relocations. */
|
||||
#define DT_RELENT 19 /* Size of each ElfNN_Rel relocation. */
|
||||
#define DT_PLTREL 20 /* Type of relocation used for PLT. */
|
||||
#define DT_DEBUG 21 /* Reserved (not used). */
|
||||
#define DT_TEXTREL 22 /* Indicates there may be relocations in
|
||||
non-writable segments. [sup] */
|
||||
#define DT_JMPREL 23 /* Address of PLT relocations. */
|
||||
#define DT_BIND_NOW 24 /* [sup] */
|
||||
#define DT_INIT_ARRAY 25 /* Address of the array of pointers to
|
||||
initialization functions */
|
||||
#define DT_FINI_ARRAY 26 /* Address of the array of pointers to
|
||||
termination functions */
|
||||
#define DT_INIT_ARRAYSZ 27 /* Size in bytes of the array of
|
||||
initialization functions. */
|
||||
#define DT_FINI_ARRAYSZ 28 /* Size in bytes of the array of
|
||||
termination functions. */
|
||||
#define DT_RUNPATH 29 /* String table offset of a null-terminated
|
||||
library search path string. */
|
||||
#define DT_FLAGS 30 /* Object specific flag values. */
|
||||
#define DT_ENCODING 32 /* Values greater than or equal to DT_ENCODING
|
||||
and less than DT_LOOS follow the rules for
|
||||
the interpretation of the d_un union
|
||||
as follows: even == 'd_ptr', odd == 'd_val'
|
||||
or none */
|
||||
#define DT_PREINIT_ARRAY 32 /* Address of the array of pointers to
|
||||
pre-initialization functions. */
|
||||
#define DT_PREINIT_ARRAYSZ 33 /* Size in bytes of the array of
|
||||
pre-initialization functions. */
|
||||
#define DT_MAXPOSTAGS 34 /* number of positive tags */
|
||||
#define DT_LOOS 0x6000000d /* First OS-specific */
|
||||
#define DT_SUNW_AUXILIARY 0x6000000d /* symbol auxiliary name */
|
||||
#define DT_SUNW_RTLDINF 0x6000000e /* ld.so.1 info (private) */
|
||||
#define DT_SUNW_FILTER 0x6000000f /* symbol filter name */
|
||||
#define DT_SUNW_CAP 0x60000010 /* hardware/software */
|
||||
#define DT_HIOS 0x6ffff000 /* Last OS-specific */
|
||||
|
||||
/*
|
||||
* DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the
|
||||
* Dyn.d_un.d_val field of the Elf*_Dyn structure.
|
||||
*/
|
||||
#define DT_VALRNGLO 0x6ffffd00
|
||||
#define DT_CHECKSUM 0x6ffffdf8 /* elf checksum */
|
||||
#define DT_PLTPADSZ 0x6ffffdf9 /* pltpadding size */
|
||||
#define DT_MOVEENT 0x6ffffdfa /* move table entry size */
|
||||
#define DT_MOVESZ 0x6ffffdfb /* move table size */
|
||||
#define DT_FEATURE_1 0x6ffffdfc /* feature holder */
|
||||
#define DT_POSFLAG_1 0x6ffffdfd /* flags for DT_* entries, effecting */
|
||||
/* the following DT_* entry. */
|
||||
/* See DF_P1_* definitions */
|
||||
#define DT_SYMINSZ 0x6ffffdfe /* syminfo table size (in bytes) */
|
||||
#define DT_SYMINENT 0x6ffffdff /* syminfo entry size (in bytes) */
|
||||
#define DT_VALRNGHI 0x6ffffdff
|
||||
|
||||
/*
|
||||
* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the
|
||||
* Dyn.d_un.d_ptr field of the Elf*_Dyn structure.
|
||||
*
|
||||
* If any adjustment is made to the ELF object after it has been
|
||||
* built, these entries will need to be adjusted.
|
||||
*/
|
||||
#define DT_ADDRRNGLO 0x6ffffe00
|
||||
#define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table */
|
||||
#define DT_CONFIG 0x6ffffefa /* configuration information */
|
||||
#define DT_DEPAUDIT 0x6ffffefb /* dependency auditing */
|
||||
#define DT_AUDIT 0x6ffffefc /* object auditing */
|
||||
#define DT_PLTPAD 0x6ffffefd /* pltpadding (sparcv9) */
|
||||
#define DT_MOVETAB 0x6ffffefe /* move table */
|
||||
#define DT_SYMINFO 0x6ffffeff /* syminfo table */
|
||||
#define DT_ADDRRNGHI 0x6ffffeff
|
||||
#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */
|
||||
#define DT_ADDRNUM 11
|
||||
|
||||
#define DT_VERSYM 0x6ffffff0 /* Address of versym section. */
|
||||
#define DT_RELACOUNT 0x6ffffff9 /* number of RELATIVE relocations */
|
||||
#define DT_RELCOUNT 0x6ffffffa /* number of RELATIVE relocations */
|
||||
#define DT_FLAGS_1 0x6ffffffb /* state flags - see DF_1_* defs */
|
||||
#define DT_VERDEF 0x6ffffffc /* Address of verdef section. */
|
||||
#define DT_VERDEFNUM 0x6ffffffd /* Number of elems in verdef section */
|
||||
#define DT_VERNEED 0x6ffffffe /* Address of verneed section. */
|
||||
#define DT_VERNEEDNUM 0x6fffffff /* Number of elems in verneed section */
|
||||
|
||||
#define DT_LOPROC 0x70000000 /* First processor-specific type. */
|
||||
#define DT_DEPRECATED_SPARC_REGISTER 0x7000001
|
||||
#define DT_AUXILIARY 0x7ffffffd /* shared library auxiliary name */
|
||||
#define DT_USED 0x7ffffffe /* ignored - same as needed */
|
||||
#define DT_FILTER 0x7fffffff /* shared library filter name */
|
||||
#define DT_HIPROC 0x7fffffff /* Last processor-specific type. */
|
||||
|
||||
/* Values for DT_FLAGS */
|
||||
#define DF_ORIGIN 0x0001 /* Indicates that the object being loaded may
|
||||
make reference to the $ORIGIN substitution
|
||||
string */
|
||||
#define DF_SYMBOLIC 0x0002 /* Indicates "symbolic" linking. */
|
||||
#define DF_TEXTREL 0x0004 /* Indicates there may be relocations in
|
||||
non-writable segments. */
|
||||
#define DF_BIND_NOW 0x0008 /* Indicates that the dynamic linker should
|
||||
process all relocations for the object
|
||||
containing this entry before transferring
|
||||
control to the program. */
|
||||
#define DF_STATIC_TLS 0x0010 /* Indicates that the shared object or
|
||||
executable contains code using a static
|
||||
thread-local storage scheme. */
|
||||
|
||||
/* Values for DT_FLAGS_1 */
|
||||
#define DF_1_BIND_NOW 0x00000001 /* Same as DF_BIND_NOW */
|
||||
#define DF_1_GLOBAL 0x00000002 /* Set the RTLD_GLOBAL for object */
|
||||
#define DF_1_NODELETE 0x00000008 /* Set the RTLD_NODELETE for object */
|
||||
#define DF_1_LOADFLTR 0x00000010 /* Immediate loading of filtees */
|
||||
#define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */
|
||||
#define DF_1_ORIGIN 0x00000080 /* Process $ORIGIN */
|
||||
#define DF_1_NODEFLIB 0x00000800 /* Do not search default paths */
|
||||
|
||||
/* Values for n_type. Used in core files. */
|
||||
#define NT_PRSTATUS 1 /* Process status. */
|
||||
#define NT_FPREGSET 2 /* Floating point registers. */
|
||||
#define NT_PRPSINFO 3 /* Process state info. */
|
||||
#define NT_THRMISC 7 /* Thread miscellaneous info. */
|
||||
|
||||
/* Symbol Binding - ELFNN_ST_BIND - st_info */
|
||||
#define STB_LOCAL 0 /* Local symbol */
|
||||
#define STB_GLOBAL 1 /* Global symbol */
|
||||
#define STB_WEAK 2 /* like global - lower precedence */
|
||||
#define STB_LOOS 10 /* Reserved range for operating system */
|
||||
#define STB_HIOS 12 /* specific semantics. */
|
||||
#define STB_LOPROC 13 /* reserved range for processor */
|
||||
#define STB_HIPROC 15 /* specific semantics. */
|
||||
|
||||
/* Symbol type - ELFNN_ST_TYPE - st_info */
|
||||
#define STT_NOTYPE 0 /* Unspecified type. */
|
||||
#define STT_OBJECT 1 /* Data object. */
|
||||
#define STT_FUNC 2 /* Function. */
|
||||
#define STT_SECTION 3 /* Section. */
|
||||
#define STT_FILE 4 /* Source file. */
|
||||
#define STT_COMMON 5 /* Uninitialized common block. */
|
||||
#define STT_TLS 6 /* TLS object. */
|
||||
#define STT_LOOS 10 /* Reserved range for operating system */
|
||||
#define STT_GNU_IFUNC 10
|
||||
#define STT_HIOS 12 /* specific semantics. */
|
||||
|
||||
/* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */
|
||||
#define STV_DEFAULT 0x0 /* Default visibility (see binding). */
|
||||
#define STV_INTERNAL 0x1 /* Special meaning in relocatable objects. */
|
||||
#define STV_HIDDEN 0x2 /* Not visible. */
|
||||
#define STV_PROTECTED 0x3 /* Visible but not preemptible. */
|
||||
#define STV_EXPORTED 0x4
|
||||
#define STV_SINGLETON 0x5
|
||||
#define STV_ELIMINATE 0x6
|
||||
|
||||
/* Special symbol table indexes. */
|
||||
#define STN_UNDEF 0 /* Undefined symbol index. */
|
||||
|
||||
/* Symbol versioning flags. */
|
||||
#define VER_DEF_CURRENT 1
|
||||
#define VER_DEF_IDX(x) VER_NDX(x)
|
||||
|
||||
#define VER_FLG_BASE 0x01
|
||||
#define VER_FLG_WEAK 0x02
|
||||
|
||||
#define VER_NEED_CURRENT 1
|
||||
#define VER_NEED_WEAK (1u << 15)
|
||||
#define VER_NEED_HIDDEN VER_NDX_HIDDEN
|
||||
#define VER_NEED_IDX(x) VER_NDX(x)
|
||||
|
||||
#define VER_NDX_LOCAL 0
|
||||
#define VER_NDX_GLOBAL 1
|
||||
#define VER_NDX_GIVEN 2
|
||||
|
||||
#define VER_NDX_HIDDEN (1u << 15)
|
||||
#define VER_NDX(x) ((x) & ~(1u << 15))
|
||||
|
||||
#define CA_SUNW_NULL 0
|
||||
#define CA_SUNW_HW_1 1 /* first hardware capabilities entry */
|
||||
#define CA_SUNW_SF_1 2 /* first software capabilities entry */
|
||||
|
||||
/*
|
||||
* Syminfo flag values
|
||||
*/
|
||||
#define SYMINFO_FLG_DIRECT 0x0001 /* symbol ref has direct association */
|
||||
/* to object containing defn. */
|
||||
#define SYMINFO_FLG_PASSTHRU 0x0002 /* ignored - see SYMINFO_FLG_FILTER */
|
||||
#define SYMINFO_FLG_COPY 0x0004 /* symbol is a copy-reloc */
|
||||
#define SYMINFO_FLG_LAZYLOAD 0x0008 /* object containing defn should be */
|
||||
/* lazily-loaded */
|
||||
#define SYMINFO_FLG_DIRECTBIND 0x0010 /* ref should be bound directly to */
|
||||
/* object containing defn. */
|
||||
#define SYMINFO_FLG_NOEXTDIRECT 0x0020 /* don't let an external reference */
|
||||
/* directly bind to this symbol */
|
||||
#define SYMINFO_FLG_FILTER 0x0002 /* symbol ref is associated to a */
|
||||
#define SYMINFO_FLG_AUXILIARY 0x0040 /* standard or auxiliary filter */
|
||||
|
||||
/*
|
||||
* Syminfo.si_boundto values.
|
||||
*/
|
||||
#define SYMINFO_BT_SELF 0xffff /* symbol bound to self */
|
||||
#define SYMINFO_BT_PARENT 0xfffe /* symbol bound to parent */
|
||||
#define SYMINFO_BT_NONE 0xfffd /* no special symbol binding */
|
||||
#define SYMINFO_BT_EXTERN 0xfffc /* symbol defined as external */
|
||||
#define SYMINFO_BT_LOWRESERVE 0xff00 /* beginning of reserved entries */
|
||||
|
||||
/*
|
||||
* Syminfo version values.
|
||||
*/
|
||||
#define SYMINFO_NONE 0 /* Syminfo version */
|
||||
#define SYMINFO_CURRENT 1
|
||||
#define SYMINFO_NUM 2
|
||||
|
||||
/*
|
||||
* Relocation types.
|
||||
*
|
||||
* All machine architectures are defined here to allow tools on one to
|
||||
* handle others.
|
||||
*/
|
||||
|
||||
#define R_386_NONE 0 /* No relocation. */
|
||||
#define R_386_32 1 /* Add symbol value. */
|
||||
#define R_386_PC32 2 /* Add PC-relative symbol value. */
|
||||
#define R_386_GOT32 3 /* Add PC-relative GOT offset. */
|
||||
#define R_386_PLT32 4 /* Add PC-relative PLT offset. */
|
||||
#define R_386_COPY 5 /* Copy data from shared object. */
|
||||
#define R_386_GLOB_DAT 6 /* Set GOT entry to data address. */
|
||||
#define R_386_JMP_SLOT 7 /* Set GOT entry to code address. */
|
||||
#define R_386_RELATIVE 8 /* Add load address of shared object. */
|
||||
#define R_386_GOTOFF 9 /* Add GOT-relative symbol address. */
|
||||
#define R_386_GOTPC 10 /* Add PC-relative GOT table address. */
|
||||
#define R_386_TLS_TPOFF 14 /* Negative offset in static TLS block */
|
||||
#define R_386_TLS_IE 15 /* Absolute address of GOT for -ve static TLS */
|
||||
#define R_386_TLS_GOTIE 16 /* GOT entry for negative static TLS block */
|
||||
#define R_386_TLS_LE 17 /* Negative offset relative to static TLS */
|
||||
#define R_386_TLS_GD 18 /* 32 bit offset to GOT (index,off) pair */
|
||||
#define R_386_TLS_LDM 19 /* 32 bit offset to GOT (index,zero) pair */
|
||||
#define R_386_TLS_GD_32 24 /* 32 bit offset to GOT (index,off) pair */
|
||||
#define R_386_TLS_GD_PUSH 25 /* pushl instruction for Sun ABI GD sequence */
|
||||
#define R_386_TLS_GD_CALL 26 /* call instruction for Sun ABI GD sequence */
|
||||
#define R_386_TLS_GD_POP 27 /* popl instruction for Sun ABI GD sequence */
|
||||
#define R_386_TLS_LDM_32 28 /* 32 bit offset to GOT (index,zero) pair */
|
||||
#define R_386_TLS_LDM_PUSH 29 /* pushl instruction for Sun ABI LD sequence */
|
||||
#define R_386_TLS_LDM_CALL 30 /* call instruction for Sun ABI LD sequence */
|
||||
#define R_386_TLS_LDM_POP 31 /* popl instruction for Sun ABI LD sequence */
|
||||
#define R_386_TLS_LDO_32 32 /* 32 bit offset from start of TLS block */
|
||||
#define R_386_TLS_IE_32 33 /* 32 bit offset to GOT static TLS offset entry */
|
||||
#define R_386_TLS_LE_32 34 /* 32 bit offset within static TLS block */
|
||||
#define R_386_TLS_DTPMOD32 35 /* GOT entry containing TLS index */
|
||||
#define R_386_TLS_DTPOFF32 36 /* GOT entry containing TLS offset */
|
||||
#define R_386_TLS_TPOFF32 37 /* GOT entry of -ve static TLS offset */
|
||||
#define R_386_IRELATIVE 42 /* PLT entry resolved indirectly at runtime */
|
||||
|
||||
#define R_ARM_NONE 0 /* No relocation. */
|
||||
#define R_ARM_PC24 1
|
||||
#define R_ARM_ABS32 2
|
||||
#define R_ARM_REL32 3
|
||||
#define R_ARM_PC13 4
|
||||
#define R_ARM_ABS16 5
|
||||
#define R_ARM_ABS12 6
|
||||
#define R_ARM_THM_ABS5 7
|
||||
#define R_ARM_ABS8 8
|
||||
#define R_ARM_SBREL32 9
|
||||
#define R_ARM_THM_PC22 10
|
||||
#define R_ARM_THM_PC8 11
|
||||
#define R_ARM_AMP_VCALL9 12
|
||||
#define R_ARM_SWI24 13
|
||||
#define R_ARM_THM_SWI8 14
|
||||
#define R_ARM_XPC25 15
|
||||
#define R_ARM_THM_XPC22 16
|
||||
/* TLS relocations */
|
||||
#define R_ARM_TLS_DTPMOD32 17 /* ID of module containing symbol */
|
||||
#define R_ARM_TLS_DTPOFF32 18 /* Offset in TLS block */
|
||||
#define R_ARM_TLS_TPOFF32 19 /* Offset in static TLS block */
|
||||
#define R_ARM_COPY 20 /* Copy data from shared object. */
|
||||
#define R_ARM_GLOB_DAT 21 /* Set GOT entry to data address. */
|
||||
#define R_ARM_JUMP_SLOT 22 /* Set GOT entry to code address. */
|
||||
#define R_ARM_RELATIVE 23 /* Add load address of shared object. */
|
||||
#define R_ARM_GOTOFF 24 /* Add GOT-relative symbol address. */
|
||||
#define R_ARM_GOTPC 25 /* Add PC-relative GOT table address. */
|
||||
#define R_ARM_GOT32 26 /* Add PC-relative GOT offset. */
|
||||
#define R_ARM_PLT32 27 /* Add PC-relative PLT offset. */
|
||||
#define R_ARM_GNU_VTENTRY 100
|
||||
#define R_ARM_GNU_VTINHERIT 101
|
||||
#define R_ARM_RSBREL32 250
|
||||
#define R_ARM_THM_RPC22 251
|
||||
#define R_ARM_RREL32 252
|
||||
#define R_ARM_RABS32 253
|
||||
#define R_ARM_RPC24 254
|
||||
#define R_ARM_RBASE 255
|
||||
|
||||
/* Name Value Field Calculation */
|
||||
#define R_IA_64_NONE 0 /* None */
|
||||
#define R_IA_64_IMM14 0x21 /* immediate14 S + A */
|
||||
#define R_IA_64_IMM22 0x22 /* immediate22 S + A */
|
||||
#define R_IA_64_IMM64 0x23 /* immediate64 S + A */
|
||||
#define R_IA_64_DIR32MSB 0x24 /* word32 MSB S + A */
|
||||
#define R_IA_64_DIR32LSB 0x25 /* word32 LSB S + A */
|
||||
#define R_IA_64_DIR64MSB 0x26 /* word64 MSB S + A */
|
||||
#define R_IA_64_DIR64LSB 0x27 /* word64 LSB S + A */
|
||||
#define R_IA_64_GPREL22 0x2a /* immediate22 @gprel(S + A) */
|
||||
#define R_IA_64_GPREL64I 0x2b /* immediate64 @gprel(S + A) */
|
||||
#define R_IA_64_GPREL32MSB 0x2c /* word32 MSB @gprel(S + A) */
|
||||
#define R_IA_64_GPREL32LSB 0x2d /* word32 LSB @gprel(S + A) */
|
||||
#define R_IA_64_GPREL64MSB 0x2e /* word64 MSB @gprel(S + A) */
|
||||
#define R_IA_64_GPREL64LSB 0x2f /* word64 LSB @gprel(S + A) */
|
||||
#define R_IA_64_LTOFF22 0x32 /* immediate22 @ltoff(S + A) */
|
||||
#define R_IA_64_LTOFF64I 0x33 /* immediate64 @ltoff(S + A) */
|
||||
#define R_IA_64_PLTOFF22 0x3a /* immediate22 @pltoff(S + A) */
|
||||
#define R_IA_64_PLTOFF64I 0x3b /* immediate64 @pltoff(S + A) */
|
||||
#define R_IA_64_PLTOFF64MSB 0x3e /* word64 MSB @pltoff(S + A) */
|
||||
#define R_IA_64_PLTOFF64LSB 0x3f /* word64 LSB @pltoff(S + A) */
|
||||
#define R_IA_64_FPTR64I 0x43 /* immediate64 @fptr(S + A) */
|
||||
#define R_IA_64_FPTR32MSB 0x44 /* word32 MSB @fptr(S + A) */
|
||||
#define R_IA_64_FPTR32LSB 0x45 /* word32 LSB @fptr(S + A) */
|
||||
#define R_IA_64_FPTR64MSB 0x46 /* word64 MSB @fptr(S + A) */
|
||||
#define R_IA_64_FPTR64LSB 0x47 /* word64 LSB @fptr(S + A) */
|
||||
#define R_IA_64_PCREL60B 0x48 /* immediate60 form1 S + A - P */
|
||||
#define R_IA_64_PCREL21B 0x49 /* immediate21 form1 S + A - P */
|
||||
#define R_IA_64_PCREL21M 0x4a /* immediate21 form2 S + A - P */
|
||||
#define R_IA_64_PCREL21F 0x4b /* immediate21 form3 S + A - P */
|
||||
#define R_IA_64_PCREL32MSB 0x4c /* word32 MSB S + A - P */
|
||||
#define R_IA_64_PCREL32LSB 0x4d /* word32 LSB S + A - P */
|
||||
#define R_IA_64_PCREL64MSB 0x4e /* word64 MSB S + A - P */
|
||||
#define R_IA_64_PCREL64LSB 0x4f /* word64 LSB S + A - P */
|
||||
#define R_IA_64_LTOFF_FPTR22 0x52 /* immediate22 @ltoff(@fptr(S + A)) */
|
||||
#define R_IA_64_LTOFF_FPTR64I 0x53 /* immediate64 @ltoff(@fptr(S + A)) */
|
||||
#define R_IA_64_LTOFF_FPTR32MSB 0x54 /* word32 MSB @ltoff(@fptr(S + A)) */
|
||||
#define R_IA_64_LTOFF_FPTR32LSB 0x55 /* word32 LSB @ltoff(@fptr(S + A)) */
|
||||
#define R_IA_64_LTOFF_FPTR64MSB 0x56 /* word64 MSB @ltoff(@fptr(S + A)) */
|
||||
#define R_IA_64_LTOFF_FPTR64LSB 0x57 /* word64 LSB @ltoff(@fptr(S + A)) */
|
||||
#define R_IA_64_SEGREL32MSB 0x5c /* word32 MSB @segrel(S + A) */
|
||||
#define R_IA_64_SEGREL32LSB 0x5d /* word32 LSB @segrel(S + A) */
|
||||
#define R_IA_64_SEGREL64MSB 0x5e /* word64 MSB @segrel(S + A) */
|
||||
#define R_IA_64_SEGREL64LSB 0x5f /* word64 LSB @segrel(S + A) */
|
||||
#define R_IA_64_SECREL32MSB 0x64 /* word32 MSB @secrel(S + A) */
|
||||
#define R_IA_64_SECREL32LSB 0x65 /* word32 LSB @secrel(S + A) */
|
||||
#define R_IA_64_SECREL64MSB 0x66 /* word64 MSB @secrel(S + A) */
|
||||
#define R_IA_64_SECREL64LSB 0x67 /* word64 LSB @secrel(S + A) */
|
||||
#define R_IA_64_REL32MSB 0x6c /* word32 MSB BD + A */
|
||||
#define R_IA_64_REL32LSB 0x6d /* word32 LSB BD + A */
|
||||
#define R_IA_64_REL64MSB 0x6e /* word64 MSB BD + A */
|
||||
#define R_IA_64_REL64LSB 0x6f /* word64 LSB BD + A */
|
||||
#define R_IA_64_LTV32MSB 0x74 /* word32 MSB S + A */
|
||||
#define R_IA_64_LTV32LSB 0x75 /* word32 LSB S + A */
|
||||
#define R_IA_64_LTV64MSB 0x76 /* word64 MSB S + A */
|
||||
#define R_IA_64_LTV64LSB 0x77 /* word64 LSB S + A */
|
||||
#define R_IA_64_PCREL21BI 0x79 /* immediate21 form1 S + A - P */
|
||||
#define R_IA_64_PCREL22 0x7a /* immediate22 S + A - P */
|
||||
#define R_IA_64_PCREL64I 0x7b /* immediate64 S + A - P */
|
||||
#define R_IA_64_IPLTMSB 0x80 /* function descriptor MSB special */
|
||||
#define R_IA_64_IPLTLSB 0x81 /* function descriptor LSB speciaal */
|
||||
#define R_IA_64_SUB 0x85 /* immediate64 A - S */
|
||||
#define R_IA_64_LTOFF22X 0x86 /* immediate22 special */
|
||||
#define R_IA_64_LDXMOV 0x87 /* immediate22 special */
|
||||
#define R_IA_64_TPREL14 0x91 /* imm14 @tprel(S + A) */
|
||||
#define R_IA_64_TPREL22 0x92 /* imm22 @tprel(S + A) */
|
||||
#define R_IA_64_TPREL64I 0x93 /* imm64 @tprel(S + A) */
|
||||
#define R_IA_64_TPREL64MSB 0x96 /* word64 MSB @tprel(S + A) */
|
||||
#define R_IA_64_TPREL64LSB 0x97 /* word64 LSB @tprel(S + A) */
|
||||
#define R_IA_64_LTOFF_TPREL22 0x9a /* imm22 @ltoff(@tprel(S+A)) */
|
||||
#define R_IA_64_DTPMOD64MSB 0xa6 /* word64 MSB @dtpmod(S + A) */
|
||||
#define R_IA_64_DTPMOD64LSB 0xa7 /* word64 LSB @dtpmod(S + A) */
|
||||
#define R_IA_64_LTOFF_DTPMOD22 0xaa /* imm22 @ltoff(@dtpmod(S+A)) */
|
||||
#define R_IA_64_DTPREL14 0xb1 /* imm14 @dtprel(S + A) */
|
||||
#define R_IA_64_DTPREL22 0xb2 /* imm22 @dtprel(S + A) */
|
||||
#define R_IA_64_DTPREL64I 0xb3 /* imm64 @dtprel(S + A) */
|
||||
#define R_IA_64_DTPREL32MSB 0xb4 /* word32 MSB @dtprel(S + A) */
|
||||
#define R_IA_64_DTPREL32LSB 0xb5 /* word32 LSB @dtprel(S + A) */
|
||||
#define R_IA_64_DTPREL64MSB 0xb6 /* word64 MSB @dtprel(S + A) */
|
||||
#define R_IA_64_DTPREL64LSB 0xb7 /* word64 LSB @dtprel(S + A) */
|
||||
#define R_IA_64_LTOFF_DTPREL22 0xba /* imm22 @ltoff(@dtprel(S+A)) */
|
||||
|
||||
#define R_MIPS_NONE 0 /* No reloc */
|
||||
#define R_MIPS_16 1 /* Direct 16 bit */
|
||||
#define R_MIPS_32 2 /* Direct 32 bit */
|
||||
#define R_MIPS_REL32 3 /* PC relative 32 bit */
|
||||
#define R_MIPS_26 4 /* Direct 26 bit shifted */
|
||||
#define R_MIPS_HI16 5 /* High 16 bit */
|
||||
#define R_MIPS_LO16 6 /* Low 16 bit */
|
||||
#define R_MIPS_GPREL16 7 /* GP relative 16 bit */
|
||||
#define R_MIPS_LITERAL 8 /* 16 bit literal entry */
|
||||
#define R_MIPS_GOT16 9 /* 16 bit GOT entry */
|
||||
#define R_MIPS_PC16 10 /* PC relative 16 bit */
|
||||
#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */
|
||||
#define R_MIPS_GPREL32 12 /* GP relative 32 bit */
|
||||
#define R_MIPS_GOTHI16 21 /* GOT HI 16 bit */
|
||||
#define R_MIPS_GOTLO16 22 /* GOT LO 16 bit */
|
||||
#define R_MIPS_CALLHI16 30 /* upper 16 bit GOT entry for function */
|
||||
#define R_MIPS_CALLLO16 31 /* lower 16 bit GOT entry for function */
|
||||
|
||||
#define R_PPC_NONE 0 /* No relocation. */
|
||||
#define R_PPC_ADDR32 1
|
||||
#define R_PPC_ADDR24 2
|
||||
#define R_PPC_ADDR16 3
|
||||
#define R_PPC_ADDR16_LO 4
|
||||
#define R_PPC_ADDR16_HI 5
|
||||
#define R_PPC_ADDR16_HA 6
|
||||
#define R_PPC_ADDR14 7
|
||||
#define R_PPC_ADDR14_BRTAKEN 8
|
||||
#define R_PPC_ADDR14_BRNTAKEN 9
|
||||
#define R_PPC_REL24 10
|
||||
#define R_PPC_REL14 11
|
||||
#define R_PPC_REL14_BRTAKEN 12
|
||||
#define R_PPC_REL14_BRNTAKEN 13
|
||||
#define R_PPC_GOT16 14
|
||||
#define R_PPC_GOT16_LO 15
|
||||
#define R_PPC_GOT16_HI 16
|
||||
#define R_PPC_GOT16_HA 17
|
||||
#define R_PPC_PLTREL24 18
|
||||
#define R_PPC_COPY 19
|
||||
#define R_PPC_GLOB_DAT 20
|
||||
#define R_PPC_JMP_SLOT 21
|
||||
#define R_PPC_RELATIVE 22
|
||||
#define R_PPC_LOCAL24PC 23
|
||||
#define R_PPC_UADDR32 24
|
||||
#define R_PPC_UADDR16 25
|
||||
#define R_PPC_REL32 26
|
||||
#define R_PPC_PLT32 27
|
||||
#define R_PPC_PLTREL32 28
|
||||
#define R_PPC_PLT16_LO 29
|
||||
#define R_PPC_PLT16_HI 30
|
||||
#define R_PPC_PLT16_HA 31
|
||||
#define R_PPC_SDAREL16 32
|
||||
#define R_PPC_SECTOFF 33
|
||||
#define R_PPC_SECTOFF_LO 34
|
||||
#define R_PPC_SECTOFF_HI 35
|
||||
#define R_PPC_SECTOFF_HA 36
|
||||
|
||||
/*
|
||||
* 64-bit relocations
|
||||
*/
|
||||
#define R_PPC64_ADDR64 38
|
||||
#define R_PPC64_ADDR16_HIGHER 39
|
||||
#define R_PPC64_ADDR16_HIGHERA 40
|
||||
#define R_PPC64_ADDR16_HIGHEST 41
|
||||
#define R_PPC64_ADDR16_HIGHESTA 42
|
||||
#define R_PPC64_UADDR64 43
|
||||
#define R_PPC64_REL64 44
|
||||
#define R_PPC64_PLT64 45
|
||||
#define R_PPC64_PLTREL64 46
|
||||
#define R_PPC64_TOC16 47
|
||||
#define R_PPC64_TOC16_LO 48
|
||||
#define R_PPC64_TOC16_HI 49
|
||||
#define R_PPC64_TOC16_HA 50
|
||||
#define R_PPC64_TOC 51
|
||||
#define R_PPC64_DTPMOD64 68
|
||||
#define R_PPC64_TPREL64 73
|
||||
#define R_PPC64_DTPREL64 78
|
||||
|
||||
/*
|
||||
* TLS relocations
|
||||
*/
|
||||
#define R_PPC_TLS 67
|
||||
#define R_PPC_DTPMOD32 68
|
||||
#define R_PPC_TPREL16 69
|
||||
#define R_PPC_TPREL16_LO 70
|
||||
#define R_PPC_TPREL16_HI 71
|
||||
#define R_PPC_TPREL16_HA 72
|
||||
#define R_PPC_TPREL32 73
|
||||
#define R_PPC_DTPREL16 74
|
||||
#define R_PPC_DTPREL16_LO 75
|
||||
#define R_PPC_DTPREL16_HI 76
|
||||
#define R_PPC_DTPREL16_HA 77
|
||||
#define R_PPC_DTPREL32 78
|
||||
#define R_PPC_GOT_TLSGD16 79
|
||||
#define R_PPC_GOT_TLSGD16_LO 80
|
||||
#define R_PPC_GOT_TLSGD16_HI 81
|
||||
#define R_PPC_GOT_TLSGD16_HA 82
|
||||
#define R_PPC_GOT_TLSLD16 83
|
||||
#define R_PPC_GOT_TLSLD16_LO 84
|
||||
#define R_PPC_GOT_TLSLD16_HI 85
|
||||
#define R_PPC_GOT_TLSLD16_HA 86
|
||||
#define R_PPC_GOT_TPREL16 87
|
||||
#define R_PPC_GOT_TPREL16_LO 88
|
||||
#define R_PPC_GOT_TPREL16_HI 89
|
||||
#define R_PPC_GOT_TPREL16_HA 90
|
||||
|
||||
/*
|
||||
* The remaining relocs are from the Embedded ELF ABI, and are not in the
|
||||
* SVR4 ELF ABI.
|
||||
*/
|
||||
|
||||
#define R_PPC_EMB_NADDR32 101
|
||||
#define R_PPC_EMB_NADDR16 102
|
||||
#define R_PPC_EMB_NADDR16_LO 103
|
||||
#define R_PPC_EMB_NADDR16_HI 104
|
||||
#define R_PPC_EMB_NADDR16_HA 105
|
||||
#define R_PPC_EMB_SDAI16 106
|
||||
#define R_PPC_EMB_SDA2I16 107
|
||||
#define R_PPC_EMB_SDA2REL 108
|
||||
#define R_PPC_EMB_SDA21 109
|
||||
#define R_PPC_EMB_MRKREF 110
|
||||
#define R_PPC_EMB_RELSEC16 111
|
||||
#define R_PPC_EMB_RELST_LO 112
|
||||
#define R_PPC_EMB_RELST_HI 113
|
||||
#define R_PPC_EMB_RELST_HA 114
|
||||
#define R_PPC_EMB_BIT_FLD 115
|
||||
#define R_PPC_EMB_RELSDA 116
|
||||
|
||||
#define R_SPARC_NONE 0
|
||||
#define R_SPARC_8 1
|
||||
#define R_SPARC_16 2
|
||||
#define R_SPARC_32 3
|
||||
#define R_SPARC_DISP8 4
|
||||
#define R_SPARC_DISP16 5
|
||||
#define R_SPARC_DISP32 6
|
||||
#define R_SPARC_WDISP30 7
|
||||
#define R_SPARC_WDISP22 8
|
||||
#define R_SPARC_HI22 9
|
||||
#define R_SPARC_22 10
|
||||
#define R_SPARC_13 11
|
||||
#define R_SPARC_LO10 12
|
||||
#define R_SPARC_GOT10 13
|
||||
#define R_SPARC_GOT13 14
|
||||
#define R_SPARC_GOT22 15
|
||||
#define R_SPARC_PC10 16
|
||||
#define R_SPARC_PC22 17
|
||||
#define R_SPARC_WPLT30 18
|
||||
#define R_SPARC_COPY 19
|
||||
#define R_SPARC_GLOB_DAT 20
|
||||
#define R_SPARC_JMP_SLOT 21
|
||||
#define R_SPARC_RELATIVE 22
|
||||
#define R_SPARC_UA32 23
|
||||
#define R_SPARC_PLT32 24
|
||||
#define R_SPARC_HIPLT22 25
|
||||
#define R_SPARC_LOPLT10 26
|
||||
#define R_SPARC_PCPLT32 27
|
||||
#define R_SPARC_PCPLT22 28
|
||||
#define R_SPARC_PCPLT10 29
|
||||
#define R_SPARC_10 30
|
||||
#define R_SPARC_11 31
|
||||
#define R_SPARC_64 32
|
||||
#define R_SPARC_OLO10 33
|
||||
#define R_SPARC_HH22 34
|
||||
#define R_SPARC_HM10 35
|
||||
#define R_SPARC_LM22 36
|
||||
#define R_SPARC_PC_HH22 37
|
||||
#define R_SPARC_PC_HM10 38
|
||||
#define R_SPARC_PC_LM22 39
|
||||
#define R_SPARC_WDISP16 40
|
||||
#define R_SPARC_WDISP19 41
|
||||
#define R_SPARC_GLOB_JMP 42
|
||||
#define R_SPARC_7 43
|
||||
#define R_SPARC_5 44
|
||||
#define R_SPARC_6 45
|
||||
#define R_SPARC_DISP64 46
|
||||
#define R_SPARC_PLT64 47
|
||||
#define R_SPARC_HIX22 48
|
||||
#define R_SPARC_LOX10 49
|
||||
#define R_SPARC_H44 50
|
||||
#define R_SPARC_M44 51
|
||||
#define R_SPARC_L44 52
|
||||
#define R_SPARC_REGISTER 53
|
||||
#define R_SPARC_UA64 54
|
||||
#define R_SPARC_UA16 55
|
||||
#define R_SPARC_TLS_GD_HI22 56
|
||||
#define R_SPARC_TLS_GD_LO10 57
|
||||
#define R_SPARC_TLS_GD_ADD 58
|
||||
#define R_SPARC_TLS_GD_CALL 59
|
||||
#define R_SPARC_TLS_LDM_HI22 60
|
||||
#define R_SPARC_TLS_LDM_LO10 61
|
||||
#define R_SPARC_TLS_LDM_ADD 62
|
||||
#define R_SPARC_TLS_LDM_CALL 63
|
||||
#define R_SPARC_TLS_LDO_HIX22 64
|
||||
#define R_SPARC_TLS_LDO_LOX10 65
|
||||
#define R_SPARC_TLS_LDO_ADD 66
|
||||
#define R_SPARC_TLS_IE_HI22 67
|
||||
#define R_SPARC_TLS_IE_LO10 68
|
||||
#define R_SPARC_TLS_IE_LD 69
|
||||
#define R_SPARC_TLS_IE_LDX 70
|
||||
#define R_SPARC_TLS_IE_ADD 71
|
||||
#define R_SPARC_TLS_LE_HIX22 72
|
||||
#define R_SPARC_TLS_LE_LOX10 73
|
||||
#define R_SPARC_TLS_DTPMOD32 74
|
||||
#define R_SPARC_TLS_DTPMOD64 75
|
||||
#define R_SPARC_TLS_DTPOFF32 76
|
||||
#define R_SPARC_TLS_DTPOFF64 77
|
||||
#define R_SPARC_TLS_TPOFF32 78
|
||||
#define R_SPARC_TLS_TPOFF64 79
|
||||
|
||||
#define R_X86_64_NONE 0 /* No relocation. */
|
||||
#define R_X86_64_64 1 /* Add 64 bit symbol value. */
|
||||
#define R_X86_64_PC32 2 /* PC-relative 32 bit signed sym value. */
|
||||
#define R_X86_64_GOT32 3 /* PC-relative 32 bit GOT offset. */
|
||||
#define R_X86_64_PLT32 4 /* PC-relative 32 bit PLT offset. */
|
||||
#define R_X86_64_COPY 5 /* Copy data from shared object. */
|
||||
#define R_X86_64_GLOB_DAT 6 /* Set GOT entry to data address. */
|
||||
#define R_X86_64_JMP_SLOT 7 /* Set GOT entry to code address. */
|
||||
#define R_X86_64_RELATIVE 8 /* Add load address of shared object. */
|
||||
#define R_X86_64_GOTPCREL 9 /* Add 32 bit signed pcrel offset to GOT. */
|
||||
#define R_X86_64_32 10 /* Add 32 bit zero extended symbol value */
|
||||
#define R_X86_64_32S 11 /* Add 32 bit sign extended symbol value */
|
||||
#define R_X86_64_16 12 /* Add 16 bit zero extended symbol value */
|
||||
#define R_X86_64_PC16 13 /* Add 16 bit signed extended pc relative symbol value */
|
||||
#define R_X86_64_8 14 /* Add 8 bit zero extended symbol value */
|
||||
#define R_X86_64_PC8 15 /* Add 8 bit signed extended pc relative symbol value */
|
||||
#define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */
|
||||
#define R_X86_64_DTPOFF64 17 /* Offset in TLS block */
|
||||
#define R_X86_64_TPOFF64 18 /* Offset in static TLS block */
|
||||
#define R_X86_64_TLSGD 19 /* PC relative offset to GD GOT entry */
|
||||
#define R_X86_64_TLSLD 20 /* PC relative offset to LD GOT entry */
|
||||
#define R_X86_64_DTPOFF32 21 /* Offset in TLS block */
|
||||
#define R_X86_64_GOTTPOFF 22 /* PC relative offset to IE GOT entry */
|
||||
#define R_X86_64_TPOFF32 23 /* Offset in static TLS block */
|
||||
#define R_X86_64_IRELATIVE 37
|
||||
|
||||
|
||||
#endif /* !_SYS_ELF_COMMON_H_ */
|
527
common/inc/internal/elfheader/elfstructs.h
Normal file
527
common/inc/internal/elfheader/elfstructs.h
Normal file
@ -0,0 +1,527 @@
|
||||
#ifndef __XEN_PUBLIC_ELFSTRUCTS_H__
|
||||
#define __XEN_PUBLIC_ELFSTRUCTS_H__ 1
|
||||
/*
|
||||
* Copyright (c) 1995, 1996 Erik Theisen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
typedef uint8_t Elf_Byte;
|
||||
|
||||
typedef uint32_t Elf32_Addr; /* Unsigned program address */
|
||||
typedef uint32_t Elf32_Off; /* Unsigned file offset */
|
||||
typedef int32_t Elf32_Sword; /* Signed large integer */
|
||||
typedef uint32_t Elf32_Word; /* Unsigned large integer */
|
||||
typedef uint16_t Elf32_Half; /* Unsigned medium integer */
|
||||
|
||||
typedef uint64_t Elf64_Addr;
|
||||
typedef uint64_t Elf64_Off;
|
||||
typedef int32_t Elf64_Shalf;
|
||||
|
||||
typedef int32_t Elf64_Sword;
|
||||
typedef uint32_t Elf64_Word;
|
||||
|
||||
typedef int64_t Elf64_Sxword;
|
||||
typedef uint64_t Elf64_Xword;
|
||||
|
||||
typedef uint32_t Elf64_Half;
|
||||
typedef uint16_t Elf64_Quarter;
|
||||
|
||||
/*
|
||||
* e_ident[] identification indexes
|
||||
* See http://www.caldera.com/developers/gabi/2000-07-17/ch4.eheader.html
|
||||
*/
|
||||
#define EI_MAG0 0 /* file ID */
|
||||
#define EI_MAG1 1 /* file ID */
|
||||
#define EI_MAG2 2 /* file ID */
|
||||
#define EI_MAG3 3 /* file ID */
|
||||
#define EI_CLASS 4 /* file class */
|
||||
#define EI_DATA 5 /* data encoding */
|
||||
#define EI_VERSION 6 /* ELF header version */
|
||||
#define EI_OSABI 7 /* OS/ABI ID */
|
||||
#define EI_ABIVERSION 8 /* ABI version */
|
||||
#define EI_PAD 9 /* start of pad bytes */
|
||||
#define EI_NIDENT 16 /* Size of e_ident[] */
|
||||
|
||||
/* e_ident[] magic number */
|
||||
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
|
||||
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
|
||||
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
|
||||
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
|
||||
#define ELFMAG "\177ELF" /* magic */
|
||||
#define SELFMAG 4 /* size of magic */
|
||||
|
||||
/* e_ident[] file class */
|
||||
#define ELFCLASSNONE 0 /* invalid */
|
||||
#define ELFCLASS32 1 /* 32-bit objs */
|
||||
#define ELFCLASS64 2 /* 64-bit objs */
|
||||
#define ELFCLASSNUM 3 /* number of classes */
|
||||
|
||||
/* e_ident[] data encoding */
|
||||
#define ELFDATANONE 0 /* invalid */
|
||||
#define ELFDATA2LSB 1 /* Little-Endian */
|
||||
#define ELFDATA2MSB 2 /* Big-Endian */
|
||||
#define ELFDATANUM 3 /* number of data encode defines */
|
||||
|
||||
/* e_ident[] Operating System/ABI */
|
||||
#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
|
||||
#define ELFOSABI_HPUX 1 /* HP-UX operating system */
|
||||
#define ELFOSABI_NETBSD 2 /* NetBSD */
|
||||
#define ELFOSABI_LINUX 3 /* GNU/Linux */
|
||||
#define ELFOSABI_HURD 4 /* GNU/Hurd */
|
||||
#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */
|
||||
#define ELFOSABI_SOLARIS 6 /* Solaris */
|
||||
#define ELFOSABI_MONTEREY 7 /* Monterey */
|
||||
#define ELFOSABI_IRIX 8 /* IRIX */
|
||||
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
|
||||
#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
|
||||
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
|
||||
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
|
||||
#define ELFOSABI_ARM 97 /* ARM */
|
||||
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
|
||||
|
||||
/* e_ident */
|
||||
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
||||
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
||||
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
|
||||
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
||||
|
||||
/* ELF Header */
|
||||
typedef struct elfhdr {
|
||||
unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
|
||||
Elf32_Half e_type; /* object file type */
|
||||
Elf32_Half e_machine; /* machine */
|
||||
Elf32_Word e_version; /* object file version */
|
||||
Elf32_Addr e_entry; /* virtual entry point */
|
||||
Elf32_Off e_phoff; /* program header table offset */
|
||||
Elf32_Off e_shoff; /* section header table offset */
|
||||
Elf32_Word e_flags; /* processor-specific flags */
|
||||
Elf32_Half e_ehsize; /* ELF header size */
|
||||
Elf32_Half e_phentsize; /* program header entry size */
|
||||
Elf32_Half e_phnum; /* number of program header entries */
|
||||
Elf32_Half e_shentsize; /* section header entry size */
|
||||
Elf32_Half e_shnum; /* number of section header entries */
|
||||
Elf32_Half e_shstrndx; /* section header table's "section
|
||||
header string table" entry offset */
|
||||
} Elf32_Ehdr;
|
||||
|
||||
typedef struct {
|
||||
unsigned char e_ident[EI_NIDENT]; /* Id bytes */
|
||||
Elf64_Quarter e_type; /* file type */
|
||||
Elf64_Quarter e_machine; /* machine type */
|
||||
Elf64_Half e_version; /* version number */
|
||||
Elf64_Addr e_entry; /* entry point */
|
||||
Elf64_Off e_phoff; /* Program hdr offset */
|
||||
Elf64_Off e_shoff; /* Section hdr offset */
|
||||
Elf64_Half e_flags; /* Processor flags */
|
||||
Elf64_Quarter e_ehsize; /* sizeof ehdr */
|
||||
Elf64_Quarter e_phentsize; /* Program header entry size */
|
||||
Elf64_Quarter e_phnum; /* Number of program headers */
|
||||
Elf64_Quarter e_shentsize; /* Section header entry size */
|
||||
Elf64_Quarter e_shnum; /* Number of section headers */
|
||||
Elf64_Quarter e_shstrndx; /* String table index */
|
||||
} Elf64_Ehdr;
|
||||
|
||||
/* e_type */
|
||||
#define ET_NONE 0 /* No file type */
|
||||
#define ET_REL 1 /* relocatable file */
|
||||
#define ET_EXEC 2 /* executable file */
|
||||
#define ET_DYN 3 /* shared object file */
|
||||
#define ET_CORE 4 /* core file */
|
||||
#define ET_NUM 5 /* number of types */
|
||||
#define ET_LOPROC 0xff00 /* reserved range for processor */
|
||||
#define ET_HIPROC 0xffff /* specific e_type */
|
||||
|
||||
/* e_machine */
|
||||
#define EM_NONE 0 /* No Machine */
|
||||
#define EM_M32 1 /* AT&T WE 32100 */
|
||||
#define EM_SPARC 2 /* SPARC */
|
||||
#define EM_386 3 /* Intel 80386 */
|
||||
#define EM_68K 4 /* Motorola 68000 */
|
||||
#define EM_88K 5 /* Motorola 88000 */
|
||||
#define EM_486 6 /* Intel 80486 - unused? */
|
||||
#define EM_860 7 /* Intel 80860 */
|
||||
#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
|
||||
/*
|
||||
* Don't know if EM_MIPS_RS4_BE,
|
||||
* EM_SPARC64, EM_PARISC,
|
||||
* or EM_PPC are ABI compliant
|
||||
*/
|
||||
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||
#define EM_SPARC64 11 /* SPARC v9 64-bit unoffical */
|
||||
#define EM_PARISC 15 /* HPPA */
|
||||
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
|
||||
#define EM_PPC 20 /* PowerPC */
|
||||
#define EM_PPC64 21 /* PowerPC 64-bit */
|
||||
#define EM_ARM 40 /* Advanced RISC Machines ARM */
|
||||
#define EM_ALPHA 41 /* DEC ALPHA */
|
||||
#define EM_SPARCV9 43 /* SPARC version 9 */
|
||||
#define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */
|
||||
#define EM_IA_64 50 /* Intel Merced */
|
||||
#define EM_X86_64 62 /* AMD x86-64 architecture */
|
||||
#define EM_VAX 75 /* DEC VAX */
|
||||
|
||||
/* Version */
|
||||
#define EV_NONE 0 /* Invalid */
|
||||
#define EV_CURRENT 1 /* Current */
|
||||
#define EV_NUM 2 /* number of versions */
|
||||
|
||||
/* Section Header */
|
||||
typedef struct {
|
||||
Elf32_Word sh_name; /* name - index into section header
|
||||
string table section */
|
||||
Elf32_Word sh_type; /* type */
|
||||
Elf32_Word sh_flags; /* flags */
|
||||
Elf32_Addr sh_addr; /* address */
|
||||
Elf32_Off sh_offset; /* file offset */
|
||||
Elf32_Word sh_size; /* section size */
|
||||
Elf32_Word sh_link; /* section header table index link */
|
||||
Elf32_Word sh_info; /* extra information */
|
||||
Elf32_Word sh_addralign; /* address alignment */
|
||||
Elf32_Word sh_entsize; /* section entry size */
|
||||
} Elf32_Shdr;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Half sh_name; /* section name */
|
||||
Elf64_Half sh_type; /* section type */
|
||||
Elf64_Xword sh_flags; /* section flags */
|
||||
Elf64_Addr sh_addr; /* virtual address */
|
||||
Elf64_Off sh_offset; /* file offset */
|
||||
Elf64_Xword sh_size; /* section size */
|
||||
Elf64_Half sh_link; /* link to another */
|
||||
Elf64_Half sh_info; /* misc info */
|
||||
Elf64_Xword sh_addralign; /* memory alignment */
|
||||
Elf64_Xword sh_entsize; /* table entry size */
|
||||
} Elf64_Shdr;
|
||||
|
||||
/* Special Section Indexes */
|
||||
#define SHN_UNDEF 0 /* undefined */
|
||||
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
|
||||
#define SHN_LOPROC 0xff00 /* reserved range for processor */
|
||||
#define SHN_HIPROC 0xff1f /* specific section indexes */
|
||||
#define SHN_ABS 0xfff1 /* absolute value */
|
||||
#define SHN_COMMON 0xfff2 /* common symbol */
|
||||
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
|
||||
|
||||
/* sh_type */
|
||||
#define SHT_NULL 0 /* inactive */
|
||||
#define SHT_PROGBITS 1 /* program defined information */
|
||||
#define SHT_SYMTAB 2 /* symbol table section */
|
||||
#define SHT_STRTAB 3 /* string table section */
|
||||
#define SHT_RELA 4 /* relocation section with addends*/
|
||||
#define SHT_HASH 5 /* symbol hash table section */
|
||||
#define SHT_DYNAMIC 6 /* dynamic section */
|
||||
#define SHT_NOTE 7 /* note section */
|
||||
#define SHT_NOBITS 8 /* no space section */
|
||||
#define SHT_REL 9 /* relation section without addends */
|
||||
#define SHT_SHLIB 10 /* reserved - purpose unknown */
|
||||
#define SHT_DYNSYM 11 /* dynamic symbol table section */
|
||||
#define SHT_NUM 12 /* number of section types */
|
||||
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define SHT_HIPROC 0x7fffffff /* specific section header types */
|
||||
#define SHT_LOUSER 0x80000000 /* reserved range for application */
|
||||
#define SHT_HIUSER 0xffffffff /* specific indexes */
|
||||
|
||||
/* Section names */
|
||||
#define ELF_BSS ".bss" /* uninitialized data */
|
||||
#define ELF_DATA ".data" /* initialized data */
|
||||
#define ELF_DEBUG ".debug" /* debug */
|
||||
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
|
||||
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
|
||||
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
|
||||
#define ELF_FINI ".fini" /* termination code */
|
||||
#define ELF_GOT ".got" /* global offset table */
|
||||
#define ELF_HASH ".hash" /* symbol hash table */
|
||||
#define ELF_INIT ".init" /* initialization code */
|
||||
#define ELF_REL_DATA ".rel.data" /* relocation data */
|
||||
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
|
||||
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
|
||||
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
|
||||
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
|
||||
#define ELF_REL_TEXT ".rel.text" /* relocation code */
|
||||
#define ELF_RODATA ".rodata" /* read-only data */
|
||||
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
|
||||
#define ELF_STRTAB ".strtab" /* string table */
|
||||
#define ELF_SYMTAB ".symtab" /* symbol table */
|
||||
#define ELF_TEXT ".text" /* code */
|
||||
|
||||
|
||||
/* Section Attribute Flags - sh_flags */
|
||||
#define SHF_WRITE 0x1 /* Writable */
|
||||
#define SHF_ALLOC 0x2 /* occupies memory */
|
||||
#define SHF_EXECINSTR 0x4 /* executable */
|
||||
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||
/* specific section attributes */
|
||||
|
||||
/* Symbol Table Entry */
|
||||
typedef struct elf32_sym {
|
||||
Elf32_Word st_name; /* name - index into string table */
|
||||
Elf32_Addr st_value; /* symbol value */
|
||||
Elf32_Word st_size; /* symbol size */
|
||||
unsigned char st_info; /* type and binding */
|
||||
unsigned char st_other; /* 0 - no defined meaning */
|
||||
Elf32_Half st_shndx; /* section header index */
|
||||
} Elf32_Sym;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Half st_name; /* Symbol name index in str table */
|
||||
Elf_Byte st_info; /* type / binding attrs */
|
||||
Elf_Byte st_other; /* unused */
|
||||
Elf64_Quarter st_shndx; /* section index of symbol */
|
||||
Elf64_Xword st_value; /* value of symbol */
|
||||
Elf64_Xword st_size; /* size of symbol */
|
||||
} Elf64_Sym;
|
||||
|
||||
/* Symbol table index */
|
||||
#define STN_UNDEF 0 /* undefined */
|
||||
|
||||
/* Extract symbol info - st_info */
|
||||
#define ELF32_ST_BIND(x) ((x) >> 4)
|
||||
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
||||
#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
|
||||
|
||||
#define ELF64_ST_BIND(x) ((x) >> 4)
|
||||
#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
||||
#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
|
||||
|
||||
/* Symbol Binding - ELF32_ST_BIND - st_info */
|
||||
#define STB_LOCAL 0 /* Local symbol */
|
||||
#define STB_GLOBAL 1 /* Global symbol */
|
||||
#define STB_WEAK 2 /* like global - lower precedence */
|
||||
#define STB_NUM 3 /* number of symbol bindings */
|
||||
#define STB_LOPROC 13 /* reserved range for processor */
|
||||
#define STB_HIPROC 15 /* specific symbol bindings */
|
||||
|
||||
/* Symbol type - ELF32_ST_TYPE - st_info */
|
||||
#define STT_NOTYPE 0 /* not specified */
|
||||
#define STT_OBJECT 1 /* data object */
|
||||
#define STT_FUNC 2 /* function */
|
||||
#define STT_SECTION 3 /* section */
|
||||
#define STT_FILE 4 /* file */
|
||||
#define STT_NUM 5 /* number of symbol types */
|
||||
#define STT_LOPROC 13 /* reserved range for processor */
|
||||
#define STT_HIPROC 15 /* specific symbol types */
|
||||
|
||||
/* Relocation entry with implicit addend */
|
||||
typedef struct {
|
||||
Elf32_Addr r_offset; /* offset of relocation */
|
||||
Elf32_Word r_info; /* symbol table index and type */
|
||||
} Elf32_Rel;
|
||||
|
||||
/* Relocation entry with explicit addend */
|
||||
typedef struct {
|
||||
Elf32_Addr r_offset; /* offset of relocation */
|
||||
Elf32_Word r_info; /* symbol table index and type */
|
||||
Elf32_Sword r_addend;
|
||||
} Elf32_Rela;
|
||||
|
||||
/* Extract relocation info - r_info */
|
||||
#define ELF32_R_SYM(i) ((i) >> 8)
|
||||
#define ELF32_R_TYPE(i) ((unsigned char) (i))
|
||||
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
|
||||
|
||||
typedef struct {
|
||||
Elf64_Xword r_offset; /* where to do it */
|
||||
Elf64_Xword r_info; /* index & type of relocation */
|
||||
} Elf64_Rel;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Xword r_offset; /* where to do it */
|
||||
Elf64_Xword r_info; /* index & type of relocation */
|
||||
Elf64_Sxword r_addend; /* adjustment value */
|
||||
} Elf64_Rela;
|
||||
|
||||
#define ELF64_R_SYM(info) ((info) >> 32)
|
||||
#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF)
|
||||
#define ELF64_R_INFO(s,t) (((s) << 32) + (u_int32_t)(t))
|
||||
|
||||
/* Program Header */
|
||||
typedef struct {
|
||||
Elf32_Word p_type; /* segment type */
|
||||
Elf32_Off p_offset; /* segment offset */
|
||||
Elf32_Addr p_vaddr; /* virtual address of segment */
|
||||
Elf32_Addr p_paddr; /* physical address - ignored? */
|
||||
Elf32_Word p_filesz; /* number of bytes in file for seg. */
|
||||
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
|
||||
Elf32_Word p_flags; /* flags */
|
||||
Elf32_Word p_align; /* memory alignment */
|
||||
} Elf32_Phdr;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Half p_type; /* entry type */
|
||||
Elf64_Half p_flags; /* flags */
|
||||
Elf64_Off p_offset; /* offset */
|
||||
Elf64_Addr p_vaddr; /* virtual address */
|
||||
Elf64_Addr p_paddr; /* physical address */
|
||||
Elf64_Xword p_filesz; /* file size */
|
||||
Elf64_Xword p_memsz; /* memory size */
|
||||
Elf64_Xword p_align; /* memory & file alignment */
|
||||
} Elf64_Phdr;
|
||||
|
||||
/* Segment types - p_type */
|
||||
#define PT_NULL 0 /* unused */
|
||||
#define PT_LOAD 1 /* loadable segment */
|
||||
#define PT_DYNAMIC 2 /* dynamic linking section */
|
||||
#define PT_INTERP 3 /* the RTLD */
|
||||
#define PT_NOTE 4 /* auxiliary information */
|
||||
#define PT_SHLIB 5 /* reserved - purpose undefined */
|
||||
#define PT_PHDR 6 /* program header */
|
||||
#define PT_NUM 7 /* Number of segment types */
|
||||
#define PT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define PT_HIPROC 0x7fffffff /* specific segment types */
|
||||
|
||||
/* Segment flags - p_flags */
|
||||
#define PF_X 0x1 /* Executable */
|
||||
#define PF_W 0x2 /* Writable */
|
||||
#define PF_R 0x4 /* Readable */
|
||||
#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||
/* specific segment flags */
|
||||
|
||||
/* Dynamic structure */
|
||||
typedef struct {
|
||||
Elf32_Sword d_tag; /* controls meaning of d_val */
|
||||
union {
|
||||
Elf32_Word d_val; /* Multiple meanings - see d_tag */
|
||||
Elf32_Addr d_ptr; /* program virtual address */
|
||||
} d_un;
|
||||
} Elf32_Dyn;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Xword d_tag; /* controls meaning of d_val */
|
||||
union {
|
||||
Elf64_Addr d_ptr;
|
||||
Elf64_Xword d_val;
|
||||
} d_un;
|
||||
} Elf64_Dyn;
|
||||
|
||||
/* Dynamic Array Tags - d_tag */
|
||||
#define DT_NULL 0 /* marks end of _DYNAMIC array */
|
||||
#define DT_NEEDED 1 /* string table offset of needed lib */
|
||||
#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
|
||||
#define DT_PLTGOT 3 /* address PLT/GOT */
|
||||
#define DT_HASH 4 /* address of symbol hash table */
|
||||
#define DT_STRTAB 5 /* address of string table */
|
||||
#define DT_SYMTAB 6 /* address of symbol table */
|
||||
#define DT_RELA 7 /* address of relocation table */
|
||||
#define DT_RELASZ 8 /* size of relocation table */
|
||||
#define DT_RELAENT 9 /* size of relocation entry */
|
||||
#define DT_STRSZ 10 /* size of string table */
|
||||
#define DT_SYMENT 11 /* size of symbol table entry */
|
||||
#define DT_INIT 12 /* address of initialization func. */
|
||||
#define DT_FINI 13 /* address of termination function */
|
||||
#define DT_SONAME 14 /* string table offset of shared obj */
|
||||
#define DT_RPATH 15 /* string table offset of library
|
||||
search path */
|
||||
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
|
||||
#define DT_REL 17 /* address of rel. tbl. w addends */
|
||||
#define DT_RELSZ 18 /* size of DT_REL relocation table */
|
||||
#define DT_RELENT 19 /* size of DT_REL relocation entry */
|
||||
#define DT_PLTREL 20 /* PLT referenced relocation entry */
|
||||
#define DT_DEBUG 21 /* bugger */
|
||||
#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
|
||||
#define DT_JMPREL 23 /* add. of PLT's relocation entries */
|
||||
#define DT_BIND_NOW 24 /* Bind now regardless of env setting */
|
||||
#define DT_NUM 25 /* Number used. */
|
||||
#define DT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
|
||||
|
||||
/* Standard ELF hashing function */
|
||||
unsigned int elf_hash(const unsigned char *name);
|
||||
|
||||
/*
|
||||
* Note Definitions
|
||||
*/
|
||||
typedef struct {
|
||||
Elf32_Word namesz;
|
||||
Elf32_Word descsz;
|
||||
Elf32_Word type;
|
||||
} Elf32_Note;
|
||||
|
||||
typedef struct {
|
||||
Elf64_Half namesz;
|
||||
Elf64_Half descsz;
|
||||
Elf64_Half type;
|
||||
} Elf64_Note;
|
||||
|
||||
|
||||
#if defined(ELFSIZE)
|
||||
#define CONCAT(x,y) __CONCAT(x,y)
|
||||
#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
|
||||
#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
|
||||
#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE))
|
||||
#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
|
||||
#endif
|
||||
|
||||
#if defined(ELFSIZE) && (ELFSIZE == 32)
|
||||
#define Elf_Ehdr Elf32_Ehdr
|
||||
#define Elf_Phdr Elf32_Phdr
|
||||
#define Elf_Shdr Elf32_Shdr
|
||||
#define Elf_Sym Elf32_Sym
|
||||
#define Elf_Rel Elf32_Rel
|
||||
#define Elf_RelA Elf32_Rela
|
||||
#define Elf_Dyn Elf32_Dyn
|
||||
#define Elf_Word Elf32_Word
|
||||
#define Elf_Sword Elf32_Sword
|
||||
#define Elf_Addr Elf32_Addr
|
||||
#define Elf_Off Elf32_Off
|
||||
#define Elf_Nhdr Elf32_Nhdr
|
||||
#define Elf_Note Elf32_Note
|
||||
|
||||
#define ELF_R_SYM ELF32_R_SYM
|
||||
#define ELF_R_TYPE ELF32_R_TYPE
|
||||
#define ELF_R_INFO ELF32_R_INFO
|
||||
#define ELFCLASS ELFCLASS32
|
||||
|
||||
#define ELF_ST_BIND ELF32_ST_BIND
|
||||
#define ELF_ST_TYPE ELF32_ST_TYPE
|
||||
#define ELF_ST_INFO ELF32_ST_INFO
|
||||
|
||||
#define AuxInfo Aux32Info
|
||||
#elif defined(ELFSIZE) && (ELFSIZE == 64)
|
||||
#define Elf_Ehdr Elf64_Ehdr
|
||||
#define Elf_Phdr Elf64_Phdr
|
||||
#define Elf_Shdr Elf64_Shdr
|
||||
#define Elf_Sym Elf64_Sym
|
||||
#define Elf_Rel Elf64_Rel
|
||||
#define Elf_RelA Elf64_Rela
|
||||
#define Elf_Dyn Elf64_Dyn
|
||||
#define Elf_Word Elf64_Word
|
||||
#define Elf_Sword Elf64_Sword
|
||||
#define Elf_Addr Elf64_Addr
|
||||
#define Elf_Off Elf64_Off
|
||||
#define Elf_Nhdr Elf64_Nhdr
|
||||
#define Elf_Note Elf64_Note
|
||||
|
||||
#define ELF_R_SYM ELF64_R_SYM
|
||||
#define ELF_R_TYPE ELF64_R_TYPE
|
||||
#define ELF_R_INFO ELF64_R_INFO
|
||||
#define ELFCLASS ELFCLASS64
|
||||
|
||||
#define ELF_ST_BIND ELF64_ST_BIND
|
||||
#define ELF_ST_TYPE ELF64_ST_TYPE
|
||||
#define ELF_ST_INFO ELF64_ST_INFO
|
||||
|
||||
#define AuxInfo Aux64Info
|
||||
#endif
|
||||
|
||||
#endif /* __XEN_PUBLIC_ELFSTRUCTS_H__ */
|
85
common/inc/internal/enclave_creator.h
Normal file
85
common/inc/internal/enclave_creator.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* File: enclave_creator.h
|
||||
* Description: this header file defines the interface used by Enclave loader to create the Enclave
|
||||
*
|
||||
* The hardware, simulation and signing mode shall inherit from this class and
|
||||
* implement all the virtual functions
|
||||
*/
|
||||
|
||||
#ifndef _ENCLAVE_CREATOR_H
|
||||
#define _ENCLAVE_CREATOR_H
|
||||
|
||||
#include "arch.h"
|
||||
#include "sgx_eid.h"
|
||||
#include "metadata.h"
|
||||
#include "sgx_error.h"
|
||||
#include "util.h"
|
||||
#include "launch_checker.h"
|
||||
#include "uncopyable.h"
|
||||
#include <string.h>
|
||||
#include "file.h"
|
||||
|
||||
// this is the interface to both hardware, simulation and signing mode
|
||||
class EnclaveCreator : private Uncopyable
|
||||
{
|
||||
public:
|
||||
/*
|
||||
@quote the EPC reserved;
|
||||
@enclave_id identify the unique enclave;
|
||||
@start_addr is the linear address allocated for Enclave;
|
||||
*/
|
||||
virtual int create_enclave(secs_t *secs, sgx_enclave_id_t *enclave_id, void **start_addr, bool ae = false) = 0;
|
||||
/*
|
||||
*@attr can be REMOVABLE
|
||||
*/
|
||||
virtual int add_enclave_page(sgx_enclave_id_t enclave_id, void *source, uint64_t offset, const sec_info_t &sinfo, uint32_t attr) = 0;
|
||||
virtual int init_enclave(sgx_enclave_id_t enclave_id, enclave_css_t *enclave_css, SGXLaunchToken *lc, le_prd_css_file_t *prd_css_file = NULL) = 0;
|
||||
virtual int destroy_enclave(sgx_enclave_id_t enclave_id) = 0;
|
||||
virtual int initialize(sgx_enclave_id_t enclave_id) = 0;
|
||||
virtual bool use_se_hw() const = 0;
|
||||
|
||||
virtual int get_misc_attr(sgx_misc_attribute_t *sgx_misc_attr, metadata_t *metadata, SGXLaunchToken * const lc, uint32_t flag) = 0;
|
||||
virtual bool get_plat_cap(sgx_misc_attribute_t *se_attr) = 0;
|
||||
#ifdef SE_1P5_VERTICAL
|
||||
virtual uint32_t handle_page_fault(uint64_t pf_address) { UNUSED(pf_address); return (uint32_t)SGX_ERROR_UNEXPECTED; }
|
||||
#endif
|
||||
// destructor
|
||||
virtual ~EnclaveCreator() {};
|
||||
};
|
||||
|
||||
EnclaveCreator* get_enclave_creator(void);
|
||||
|
||||
extern EnclaveCreator* g_enclave_creator;
|
||||
|
||||
#endif
|
70
common/inc/internal/global_data.h
Normal file
70
common/inc/internal/global_data.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* File: global_data.h
|
||||
* Description:
|
||||
* The file defines the structure global_data_t.
|
||||
*/
|
||||
|
||||
#ifndef _TRTS_GLOBAL_DATA_H_
|
||||
#define _TRTS_GLOBAL_DATA_H_
|
||||
|
||||
#include "se_types.h"
|
||||
#include "thread_data.h"
|
||||
|
||||
typedef struct _global_data_t
|
||||
{
|
||||
sys_word_t enclave_size;
|
||||
sys_word_t heap_offset;
|
||||
sys_word_t heap_size;
|
||||
uint32_t thread_policy;
|
||||
uint32_t reserved;
|
||||
thread_data_t td_template;
|
||||
} global_data_t;
|
||||
|
||||
#define ENCLAVE_INIT_NOT_STARTED 0
|
||||
#define ENCLAVE_INIT_IN_PROGRESS 1
|
||||
#define ENCLAVE_INIT_DONE 2
|
||||
#define ENCLAVE_CRASHED 3
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern SE_DECLSPEC_EXPORT global_data_t const volatile g_global_data;
|
||||
extern uint32_t g_enclave_state;
|
||||
extern uint8_t __ImageBase;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
48
common/inc/internal/global_init.h
Normal file
48
common/inc/internal/global_init.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GLOBAL_INIT_H
|
||||
#define GLOBAL_INIT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void init_global_object(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
60
common/inc/internal/inst.h
Normal file
60
common/inc/internal/inst.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_ARCH_H_
|
||||
# error "never include inst.h directly; use arch.h instead."
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef _SE_INST_H_
|
||||
#define _SE_INST_H_
|
||||
|
||||
#define ENCLU 0xd7010f
|
||||
|
||||
typedef enum {
|
||||
SE_EREPORT = 0x0,
|
||||
SE_EGETKEY,
|
||||
SE_EENTER,
|
||||
SE_ERESUME,
|
||||
SE_EEXIT,
|
||||
SE_LAST_RING3,
|
||||
|
||||
SE_ECREATE = 0x0,
|
||||
SE_EADD,
|
||||
SE_EINIT,
|
||||
SE_EREMOVE,
|
||||
SE_EDBGRD,
|
||||
SE_EDBGWR,
|
||||
SE_EEXTEND,
|
||||
SE_LAST_RING0
|
||||
} se_opcode_t;
|
||||
|
||||
#endif
|
89
common/inc/internal/ipp_wrapper.h
Normal file
89
common/inc/internal/ipp_wrapper.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _IPP_WRAPPER_H
|
||||
#define _IPP_WRAPPER_H
|
||||
|
||||
#include "ippcp.h"
|
||||
|
||||
#ifndef SAFE_FREE_MM
|
||||
#define SAFE_FREE_MM(ptr) {\
|
||||
if(ptr != NULL) \
|
||||
{ \
|
||||
free(ptr); \
|
||||
ptr = NULL; \
|
||||
}}
|
||||
#endif
|
||||
|
||||
#ifndef ERROR_BREAK
|
||||
#define ERROR_BREAK(x) if(x != ippStsNoErr){break;}
|
||||
#endif
|
||||
#ifndef NULL_BREAK
|
||||
#define NULL_BREAK(x) if(!x){break;}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
IppStatus newBN(const Ipp32u *data, int size_in_bytes, IppsBigNumState **p_new_BN);
|
||||
|
||||
IppStatus create_rsa_priv1_key(int n_byte_size, int d_byte_size, const Ipp32u *n, const Ipp32u *d, IppsRSAPrivateKeyState **new_pri_key1);
|
||||
|
||||
IppStatus create_rsa_priv2_key(int p_byte_size, const Ipp32u *p, const Ipp32u *q,
|
||||
const Ipp32u *dmp1, const Ipp32u *dmq1, const Ipp32u *iqmp,
|
||||
IppsRSAPrivateKeyState **new_pri_key2);
|
||||
|
||||
IppStatus create_rsa_pub_key(int n_byte_size, int e_byte_size, const Ipp32u *n, const Ipp32u *e, IppsRSAPublicKeyState **new_pub_key);
|
||||
|
||||
IppStatus create_validate_rsa_key_pair(int n_byte_size, int e_byte_size, const Ipp32u *n, const Ipp32u *d, const Ipp32u *e, const Ipp32u *p, const Ipp32u *q,
|
||||
const Ipp32u *dmp1, const Ipp32u *dmq1, const Ipp32u *iqmp,
|
||||
IppsRSAPrivateKeyState **new_pri_key, IppsRSAPublicKeyState **new_pub_key, int *validate_result);
|
||||
|
||||
IppStatus get_pub_key(const IppsRSAPublicKeyState *pub_key, int *e_byte_size, Ipp32u *e, int *n_byte_size, Ipp32u *n);
|
||||
|
||||
void secure_free_BN(IppsBigNumState *pBN, int size_in_bytes);
|
||||
|
||||
void secure_free_rsa_pri1_key(int n_byte_size, int d_byte_size, IppsRSAPrivateKeyState *pri_key1);
|
||||
|
||||
void secure_free_rsa_pri2_key(int p_byte_size, IppsRSAPrivateKeyState *pri_key2);
|
||||
|
||||
void secure_free_rsa_pub_key(int n_byte_size, int e_byte_size, IppsRSAPublicKeyState *pub_key);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
76
common/inc/internal/linux/cpuid_gnu.h
Normal file
76
common/inc/internal/linux/cpuid_gnu.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CPUID_GNU_H_
|
||||
#define _CPUID_GNU_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This is a PIC-compliant version of CPUID */
|
||||
static inline void cpuid(int *eax, int *ebx, int *ecx, int *edx)
|
||||
{
|
||||
#if defined(__x86_64__)
|
||||
asm("cpuid"
|
||||
: "=a" (*eax),
|
||||
"=b" (*ebx),
|
||||
"=c" (*ecx),
|
||||
"=d" (*edx)
|
||||
: "0" (*eax), "2" (*ecx));
|
||||
|
||||
#else
|
||||
/*on 32bit, ebx can NOT be used as PIC code*/
|
||||
asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
|
||||
: "=a" (*eax), "=r" (*ebx), "=c" (*ecx), "=d" (*edx)
|
||||
: "0" (*eax), "2" (*ecx));
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void __cpuid(int a[4], int b)
|
||||
{
|
||||
a[0] = b;
|
||||
a[2] = 0;
|
||||
cpuid(&a[0], &a[1], &a[2], &a[3]);
|
||||
}
|
||||
|
||||
static inline void __cpuidex(int a[4], int b, int c)
|
||||
{
|
||||
a[0] = b;
|
||||
a[2] = c;
|
||||
cpuid(&a[0], &a[1], &a[2], &a[3]);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_CPUID_GNU_H_*/
|
272
common/inc/internal/linux/linux-regs.h
Normal file
272
common/inc/internal/linux/linux-regs.h
Normal file
@ -0,0 +1,272 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This header wraps the register names for x86/x64.
|
||||
*/
|
||||
|
||||
#ifndef LINUX_REGS_H__
|
||||
#define LINUX_REGS_H__
|
||||
|
||||
#if defined(__i386) || defined(__i386__)
|
||||
# define LINUX32 1
|
||||
# define SE_WORDSIZE 4
|
||||
|
||||
/* Generic argument picker for `naked' functions */
|
||||
# define naked_arg0 4(%esp)
|
||||
# define naked_arg1 8(%esp)
|
||||
# define naked_arg2 12(%esp)
|
||||
# define naked_arg3 16(%esp)
|
||||
|
||||
# define xax eax
|
||||
# define xbx ebx
|
||||
# define xcx ecx
|
||||
# define xdx edx
|
||||
|
||||
# define xsi esi
|
||||
# define xdi edi
|
||||
# define xbp ebp
|
||||
# define xsp esp
|
||||
#elif defined(__x86_64) || defined(__x86_64__)
|
||||
# define LINUX64 1
|
||||
# define SE_WORDSIZE 8
|
||||
|
||||
/* For x86_64, the first six parameters are passed by
|
||||
* rdi, rsi, rdx, rcx, r8, r9.
|
||||
*/
|
||||
# define naked_arg0 %rdi
|
||||
# define naked_arg1 %rsi
|
||||
# define naked_arg2 %rdx
|
||||
# define naked_arg3 %rcx
|
||||
|
||||
# define xax rax
|
||||
# define xbx rbx
|
||||
# define xcx rcx
|
||||
# define xdx rdx
|
||||
|
||||
# define xsi rsi
|
||||
# define xdi rdi
|
||||
# define xbp rbp
|
||||
# define xsp rsp
|
||||
#else
|
||||
# error unknown platform!
|
||||
#endif
|
||||
|
||||
/* SE instructions - needs to be sync-up with inst70.h */
|
||||
#define SE_EREPORT 0
|
||||
#define SE_EGETKEY 1
|
||||
#define SE_EENTER 2
|
||||
#define SE_EEXIT 4
|
||||
|
||||
#define SE_ECREATE 0
|
||||
#define SE_EADD 1
|
||||
#define SE_EINIT 2
|
||||
#define SE_EREMOVE 3
|
||||
|
||||
/*
|
||||
* Macros for GNU assembly
|
||||
*/
|
||||
.macro ENCLU
|
||||
#ifdef SE_SIM
|
||||
cmp $SE_EEXIT, %xax
|
||||
jne 1f
|
||||
|
||||
/* if leaf is EEXIT, xbp and xsp need to be passed by xdx and xcx */
|
||||
mov %xbp, %xdx
|
||||
mov %xsp, %xcx
|
||||
1:
|
||||
push %xdi
|
||||
push %xsi
|
||||
push %xdx
|
||||
push %xcx
|
||||
push %xbx
|
||||
push %xax
|
||||
|
||||
# ifdef LINUX64
|
||||
pop %rdi
|
||||
pop %rsi
|
||||
pop %rdx
|
||||
pop %rcx
|
||||
pop %r8
|
||||
pop %r9
|
||||
# endif
|
||||
|
||||
.type _SE3,@function
|
||||
.protected _SE3
|
||||
call _SE3
|
||||
|
||||
# ifdef LINUX32
|
||||
add $(SE_WORDSIZE * 6), %esp
|
||||
# endif
|
||||
|
||||
#else /* SE_SIM */
|
||||
.byte 0x0f, 0x01, 0xd7 /* 0xf3 */
|
||||
#endif /* !SE_SIM */
|
||||
.endm
|
||||
|
||||
/* declare a function with default visibility */
|
||||
.macro DECLARE_GLOBAL_FUNC name
|
||||
.globl \name
|
||||
.type \name, @function
|
||||
\name:
|
||||
.endm
|
||||
|
||||
/* declare a function with visibility='hidden' */
|
||||
.macro DECLARE_LOCAL_FUNC name
|
||||
.globl \name
|
||||
.hidden \name
|
||||
.type \name, @function
|
||||
\name:
|
||||
.endm
|
||||
|
||||
.macro NAKED_PROLOG
|
||||
push %xbp
|
||||
mov %xsp, %xbp
|
||||
sub $(7 * SE_WORDSIZE), %xsp
|
||||
.endm
|
||||
|
||||
.macro NAKED_EPILOG
|
||||
mov %xbp, %xsp
|
||||
pop %xbp
|
||||
.endm
|
||||
|
||||
/* `paramN' (N = 1,2,3,4) should be registers. */
|
||||
.macro SET_PARAMS param1:req, param2, param3, param4
|
||||
#if defined(LINUX32)
|
||||
|
||||
.ifnb \param4
|
||||
mov \param4, 3*SE_WORDSIZE(%esp)
|
||||
.endif
|
||||
|
||||
.ifnb \param3
|
||||
mov \param3, 2*SE_WORDSIZE(%esp)
|
||||
.endif
|
||||
|
||||
.ifnb \param2
|
||||
mov \param2, 1*SE_WORDSIZE(%esp)
|
||||
.endif
|
||||
|
||||
mov \param1, 0*SE_WORDSIZE(%esp)
|
||||
|
||||
#else /* LINUX32 */
|
||||
|
||||
.ifnb \param4
|
||||
.ifnc \param4, %rcx
|
||||
mov \param4, %rcx
|
||||
.endif
|
||||
.endif
|
||||
|
||||
.ifnb \param3
|
||||
.ifnc \param3, %rdx
|
||||
mov \param3, %rdx
|
||||
.endif
|
||||
.endif
|
||||
|
||||
.ifnb \param2
|
||||
.ifnc \param2, %rsi
|
||||
mov \param2, %rsi
|
||||
.endif
|
||||
.endif
|
||||
|
||||
.ifnc \param1, %rdi
|
||||
mov \param1, %rdi
|
||||
.endif
|
||||
|
||||
#endif /* LINUX64 */
|
||||
.endm
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
.macro SE_PROLOG
|
||||
.cfi_startproc
|
||||
|
||||
#ifdef LINUX32
|
||||
pushl %ebp
|
||||
movl %esp, %ebp
|
||||
#endif
|
||||
|
||||
push %xbx
|
||||
push %xcx
|
||||
push %xdx
|
||||
|
||||
#if defined LINUX64
|
||||
movq %rdi, %rbx
|
||||
movq %rsi, %rcx
|
||||
/* rdx remains the same, rdi/rsi is not used by _SE0
|
||||
*/
|
||||
#elif defined LINUX32
|
||||
movl 2*SE_WORDSIZE(%ebp), %ebx
|
||||
movl 3*SE_WORDSIZE(%ebp), %ecx
|
||||
movl 4*SE_WORDSIZE(%ebp), %edx
|
||||
#endif
|
||||
|
||||
.endm
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
.macro SE_EPILOG
|
||||
pop %xdx
|
||||
pop %xcx
|
||||
pop %xbx
|
||||
|
||||
#ifdef LINUX32
|
||||
movl %ebp, %esp
|
||||
popl %ebp
|
||||
#endif
|
||||
|
||||
ret
|
||||
.cfi_endproc
|
||||
.endm
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
/* load the address of `symbol' to the register `reg' in PIC way. */
|
||||
.macro lea_pic symbol, reg
|
||||
#ifdef LINUX64
|
||||
lea \symbol(%rip), \reg
|
||||
#else
|
||||
/* The real code on x86 would look like this (get `bar' from `foo'):
|
||||
*
|
||||
* 00000198 <bar>:
|
||||
* 198: c3 ret
|
||||
*
|
||||
* 00000199 <foo>:
|
||||
* 199: e8 00 00 00 00 call 19e <foo+0x5>
|
||||
* 19e: 58 pop %eax
|
||||
* 19f: 8d 40 fa lea -0x6(%eax),%eax
|
||||
*/
|
||||
call . + 0x5 /* No label here to avoid interfering w/ calling code */
|
||||
pop \reg
|
||||
lea (\symbol - . + 1)(\reg), \reg
|
||||
#endif
|
||||
.endm
|
||||
|
||||
#endif /* LINUX_REGS_H__ */
|
92
common/inc/internal/linux/xsave_gnu.h
Normal file
92
common/inc/internal/linux/xsave_gnu.h
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _XSAVE_GNU_H_
|
||||
#define _XSAVE_GNU_H_
|
||||
|
||||
#include "se_types.h"
|
||||
|
||||
#ifdef __x86_64__
|
||||
# define ASM_FXSAVE "rex64/fxsave"
|
||||
# define ASM_FXRSTR "rex64/fxrstor"
|
||||
# define ASM_XSAVE "rex64/xsave"
|
||||
# define ASM_XRSTR ".byte 0x48,0x0f,0xae,0x2f"
|
||||
#else
|
||||
# define ASM_FXSAVE "fxsave"
|
||||
# define ASM_FXRSTR "fxrstor"
|
||||
# define ASM_XSAVE "xsave"
|
||||
# define ASM_XRSTR ".byte 0x0f,0xae,0x2f"
|
||||
#endif
|
||||
|
||||
static inline void do_fwait(void)
|
||||
{
|
||||
asm volatile("fwait");
|
||||
}
|
||||
|
||||
static inline void do_fxsave(void *buffer)
|
||||
{
|
||||
asm volatile(ASM_FXSAVE" (%0)" : : "r"(buffer) : "memory");
|
||||
}
|
||||
|
||||
static inline void do_fxrstor(const void *buffer)
|
||||
{
|
||||
asm volatile(ASM_FXRSTR" (%0)" : : "r"(buffer));
|
||||
}
|
||||
|
||||
static inline void do_xsave(void *buffer)
|
||||
{
|
||||
asm volatile(ASM_XSAVE
|
||||
:
|
||||
: "D" (buffer), "a" (-1), "d" (-1)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline void _do_xrstor(const void *buffer, uint64_t mask)
|
||||
{
|
||||
uint32_t lmask = (uint32_t)mask;
|
||||
uint32_t hmask = (uint32_t)(mask >> 32);
|
||||
|
||||
asm volatile(ASM_XRSTR
|
||||
:
|
||||
: "D" (buffer), "a" (lmask), "d" (hmask));
|
||||
}
|
||||
|
||||
static inline void do_xrstor(const void *buffer)
|
||||
{
|
||||
_do_xrstor(buffer, 0xffffffffffffffffULL);
|
||||
}
|
||||
|
||||
static inline void do_vzeroupper()
|
||||
{
|
||||
asm volatile("vzeroupper");
|
||||
}
|
||||
|
||||
#endif
|
150
common/inc/internal/metadata.h
Normal file
150
common/inc/internal/metadata.h
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _METADATA_H_
|
||||
#define _METADATA_H_
|
||||
#include "arch.h"
|
||||
#include "se_macro.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
/* version of metadata */
|
||||
#define MAJOR_VERSION 1 /* MAJOR_VERSION should not larger than 0ffffffff */
|
||||
#define MINOR_VERSION 3 /* MINOR_VERSION should not larger than 0ffffffff */
|
||||
|
||||
#define META_DATA_MAKE_VERSION(major, minor) (((uint64_t)major)<<32 | minor)
|
||||
|
||||
#define METADATA_MAGIC 0x86A80294635D0E4CULL
|
||||
#define METADATA_SIZE 0x1000
|
||||
/* TCS Policy bit masks */
|
||||
#define TCS_POLICY_BIND 0x00000000 /* If set, the TCS is bound to the application thread */
|
||||
#define TCS_POLICY_UNBIND 0x00000001
|
||||
|
||||
#define MAX_SAVE_BUF_SIZE 2632
|
||||
|
||||
#define TCS_NUM_MIN 1
|
||||
#define SSA_NUM_MIN 2
|
||||
#define SSA_FRAME_SIZE_MIN 1
|
||||
#define SSA_FRAME_SIZE_MAX 2
|
||||
#define STACK_SIZE_MIN 0x1000
|
||||
#define HEAP_SIZE_MIN 0
|
||||
#define DEFAULT_MISC_SELECT 0
|
||||
#define DEFAULT_MISC_MASK 0xFFFFFFFF
|
||||
|
||||
typedef struct _data_directory_t
|
||||
{
|
||||
uint32_t offset;
|
||||
uint32_t size;
|
||||
} data_directory_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DIR_PATCH,
|
||||
DIR_LAYOUT,
|
||||
DIR_NUM,
|
||||
} dir_index_t;
|
||||
|
||||
#define GROUP_FLAG (1<<12)
|
||||
#define GROUP_ID(x) (GROUP_FLAG | x)
|
||||
#define IS_GROUP_ID(x) !!((x) & GROUP_FLAG)
|
||||
#define LAYOUT_ID_HEAP 1
|
||||
#define LAYOUT_ID_TCS 2
|
||||
#define LAYOUT_ID_TD 3
|
||||
#define LAYOUT_ID_SSA 4
|
||||
#define LAYOUT_ID_STACK 5
|
||||
#define LAYOUT_ID_THREAD_GROUP GROUP_ID(6)
|
||||
#define LAYOUT_ID_GUARD 7
|
||||
|
||||
/*
|
||||
** layout table example
|
||||
** entry0 - entry1 - entry2 - group3 (entry_count=2, load_times=3) ...
|
||||
** the load sequence should be:
|
||||
** entry0 - entry1 - entry2 - entry1 - entry2 - entry1 - entry2 - entry1 - entry2 ...
|
||||
** -------------- -------------- --------------
|
||||
** group3 1st time group3 2nd time group3 3rd time
|
||||
*/
|
||||
typedef struct _layout_entry_t
|
||||
{
|
||||
uint16_t id; /* unique ID to identify the purpose for this entry */
|
||||
uint16_t attributes; /* EADD/EEXTEND/EREMOVE... */
|
||||
uint32_t page_count; /* map size in page. Biggest chunk = 2^32 pages = 2^44 bytes. */
|
||||
uint64_t rva; /* map offset, relative to encalve base */
|
||||
uint32_t content_size; /* if content_offset = 0, content_size is the initial data to fill the whole page. */
|
||||
uint32_t content_offset; /* offset to the initial content, relative to metadata */
|
||||
si_flags_t si_flags; /* security info, R/W/X, SECS/TCS/REG/VA */
|
||||
} layout_entry_t;
|
||||
|
||||
typedef struct _layout_group_t
|
||||
{
|
||||
uint16_t id; /* unique ID to identify the purpose for this entry */
|
||||
uint16_t entry_count; /* reversely count entry_count entries for the group loading. */
|
||||
uint32_t load_times; /* the repeated times of loading */
|
||||
uint64_t load_step; /* the group size. the entry load rva should be adjusted with the load_step */
|
||||
/* rva = entry.rva + group.load_step * load_times */
|
||||
uint32_t reserved[4];
|
||||
} layout_group_t;
|
||||
|
||||
typedef union _layout_t
|
||||
{
|
||||
layout_entry_t entry;
|
||||
layout_group_t group;
|
||||
} layout_t;
|
||||
|
||||
typedef struct _patch_entry_t
|
||||
{
|
||||
uint64_t dst; /* relative to enclave file base */
|
||||
uint32_t src; /* relative to metadata base */
|
||||
uint32_t size; /* patched size */
|
||||
uint32_t reserved[4];
|
||||
} patch_entry_t;
|
||||
|
||||
typedef struct _metadata_t
|
||||
{
|
||||
uint64_t magic_num; /* The magic number identifying the file as a signed enclave image */
|
||||
uint64_t version; /* The metadata version */
|
||||
uint32_t size; /* The size of this structure */
|
||||
uint32_t tcs_policy; /* TCS management policy */
|
||||
uint32_t ssa_frame_size; /* The size of SSA frame in page */
|
||||
uint32_t max_save_buffer_size; /* Max buffer size is 2632 */
|
||||
uint32_t desired_misc_select;
|
||||
uint32_t reserved;
|
||||
uint64_t enclave_size; /* enclave virtual size */
|
||||
sgx_attributes_t attributes; /* XFeatureMask to be set in SECS. */
|
||||
enclave_css_t enclave_css; /* The enclave signature */
|
||||
data_directory_t dirs[DIR_NUM];
|
||||
uint8_t data[2208];
|
||||
}metadata_t;
|
||||
|
||||
se_static_assert(sizeof(metadata_t) == METADATA_SIZE);
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif
|
125
common/inc/internal/oal/uae_oal_api.h
Normal file
125
common/inc/internal/oal/uae_oal_api.h
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#ifndef _UAE_OAL_H
|
||||
#define _UAE_OAL_H
|
||||
|
||||
#include "sgx_quote.h"
|
||||
#include "sgx_error.h"
|
||||
#include "sgx_urts.h"
|
||||
#include <arch.h>
|
||||
#include <aesm_error.h>
|
||||
|
||||
typedef enum{
|
||||
UAE_OAL_SUCCESS = 0,
|
||||
UAE_OAL_ERROR_UNEXPECTED ,
|
||||
UAE_OAL_ERROR_AESM_UNAVAILABLE ,
|
||||
UAE_OAL_ERROR_TIMEOUT ,
|
||||
} uae_oal_status_t;
|
||||
|
||||
/*OAL methods from here forward */
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
uae_oal_status_t SGXAPI oal_get_launch_token(
|
||||
const enclave_css_t* signature,
|
||||
const sgx_attributes_t* attribute,
|
||||
sgx_launch_token_t* launch_token,
|
||||
uint32_t timeout_usec,
|
||||
aesm_error_t *result);
|
||||
|
||||
|
||||
uae_oal_status_t SGXAPI oal_init_quote(
|
||||
sgx_target_info_t *p_target_info,
|
||||
sgx_epid_group_id_t *p_gid,
|
||||
uint32_t timeout_usec,
|
||||
aesm_error_t *result);
|
||||
|
||||
|
||||
uae_oal_status_t SGXAPI oal_get_quote(
|
||||
const sgx_report_t *p_report,
|
||||
sgx_quote_sign_type_t quote_type,
|
||||
const sgx_spid_t *p_spid,
|
||||
const sgx_quote_nonce_t *p_nonce,
|
||||
const uint8_t *p_sig_rl,
|
||||
uint32_t sig_rl_size,
|
||||
sgx_report_t *p_qe_report,
|
||||
sgx_quote_t *p_quote,
|
||||
uint32_t quote_size,
|
||||
uint32_t timeout_usec,
|
||||
aesm_error_t *result);
|
||||
|
||||
uae_oal_status_t SGXAPI oal_get_ps_cap(
|
||||
uint64_t* p_ps_cap,
|
||||
uint32_t timeout_usec,
|
||||
aesm_error_t *result);
|
||||
|
||||
uae_oal_status_t SGXAPI oal_report_attestation_status(
|
||||
const sgx_platform_info_t* p_platform_info,
|
||||
int attestation_status,
|
||||
sgx_update_info_bit_t* p_update_info,
|
||||
uint32_t timeout_usec,
|
||||
aesm_error_t *result);
|
||||
|
||||
uae_oal_status_t oal_create_session(
|
||||
uint32_t *session_id,
|
||||
uint8_t *se_dh_msg1,
|
||||
uint32_t dh_msg1_size,
|
||||
uint32_t timeout_usec,
|
||||
aesm_error_t *result);
|
||||
|
||||
uae_oal_status_t oal_exchange_report(
|
||||
uint32_t session_id,
|
||||
const uint8_t *se_dh_msg2,
|
||||
uint32_t dh_msg2_size,
|
||||
uint8_t *se_dh_msg3,
|
||||
uint32_t dh_msg3_size,
|
||||
uint32_t timeout_usec,
|
||||
aesm_error_t *result);
|
||||
|
||||
uae_oal_status_t oal_close_session(
|
||||
uint32_t session_id,
|
||||
uint32_t timeout_usec,
|
||||
aesm_error_t *result);
|
||||
|
||||
uae_oal_status_t oal_invoke_service(
|
||||
const uint8_t *pse_message_req,
|
||||
uint32_t pse_message_req_size,
|
||||
uint8_t *pse_message_resp,
|
||||
uint32_t pse_message_resp_size,
|
||||
uint32_t timeout_usec,
|
||||
aesm_error_t *response);
|
||||
|
||||
sgx_status_t oal_map_status(uae_oal_status_t status);
|
||||
sgx_status_t oal_map_result(aesm_error_t result);
|
||||
|
||||
} /* end of extern "C" */
|
||||
#endif
|
55
common/inc/internal/routine.h
Normal file
55
common/inc/internal/routine.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _ROUTINE_H_
|
||||
#define _ROUTINE_H_
|
||||
#include "sgx_eid.h"
|
||||
#include "sgx_error.h"
|
||||
#include "sgx_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _ocall_table_t
|
||||
{
|
||||
uint32_t count;
|
||||
void *ocall[];
|
||||
} sgx_ocall_table_t;
|
||||
|
||||
sgx_status_t SGXAPI sgx_ecall(const sgx_enclave_id_t enclave_id, const int proc, const void *ocall_table, void *ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
74
common/inc/internal/rts.h
Normal file
74
common/inc/internal/rts.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RTS_H_
|
||||
#define _RTS_H_
|
||||
|
||||
#include "se_types.h"
|
||||
#include "rts_cmd.h"
|
||||
|
||||
typedef struct _ocall_context_t
|
||||
{
|
||||
uintptr_t shadow0;
|
||||
uintptr_t shadow1;
|
||||
uintptr_t shadow2;
|
||||
uintptr_t shadow3;
|
||||
uintptr_t ocall_flag;
|
||||
uintptr_t ocall_index;
|
||||
uintptr_t pre_last_sp;
|
||||
uintptr_t r15;
|
||||
uintptr_t r14;
|
||||
uintptr_t r13;
|
||||
uintptr_t r12;
|
||||
uintptr_t xbp;
|
||||
uintptr_t xdi;
|
||||
uintptr_t xsi;
|
||||
uintptr_t xbx;
|
||||
uintptr_t reserved[3];
|
||||
uintptr_t ocall_depth;
|
||||
uintptr_t ocall_ret;
|
||||
} ocall_context_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SDK_VERSION_1_5,
|
||||
SDK_VERSION_2_0
|
||||
} sdk_version_t;
|
||||
|
||||
typedef struct _cpu_feature_sdk_version
|
||||
{
|
||||
uint64_t cpu_features;
|
||||
sdk_version_t version;
|
||||
}cpu_sdk_info_t;
|
||||
|
||||
#define OCALL_FLAG 0x4F434944
|
||||
|
||||
#endif
|
40
common/inc/internal/rts_cmd.h
Normal file
40
common/inc/internal/rts_cmd.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/* ECALL command */
|
||||
#define ECMD_ECALL 0
|
||||
#define ECMD_INIT_ENCLAVE -1
|
||||
#define ECMD_ORET -2
|
||||
#define ECMD_EXCEPT -3
|
||||
|
||||
/* OCALL command */
|
||||
#define OCMD_ERET -1
|
||||
|
60
common/inc/internal/se_atomic.h
Normal file
60
common/inc/internal/se_atomic.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_ATOMIC_H_
|
||||
#define _SE_ATOMIC_H_
|
||||
|
||||
|
||||
inline uint32_t se_atomic_inc(volatile uint32_t *mem)
|
||||
{
|
||||
int ret;
|
||||
|
||||
__asm__ __volatile__ ("lock; xaddl %0, %1"
|
||||
: "=r" (ret), "=m" (*mem)
|
||||
: "0" (1), "m" (*mem)
|
||||
);
|
||||
|
||||
return ret + 1;
|
||||
}
|
||||
|
||||
inline uint32_t se_atomic_dec(uint32_t volatile *mem)
|
||||
{
|
||||
int ret;
|
||||
|
||||
__asm__ __volatile__ ("lock; xaddl %0, %1"
|
||||
: "=r" (ret), "=m" (*mem)
|
||||
: "0" (-1), "m" (*mem)
|
||||
);
|
||||
|
||||
return ret - 1;
|
||||
}
|
||||
|
||||
#endif
|
103
common/inc/internal/se_cdefs.h
Normal file
103
common/inc/internal/se_cdefs.h
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SE_CDEFS_H_
|
||||
#define _SE_CDEFS_H_
|
||||
|
||||
|
||||
#define SGX_WEAK __attribute__((weak))
|
||||
|
||||
# if (__GNUC__ >= 3)
|
||||
# define likely(x) __builtin_expect ((x), 1)
|
||||
# define unlikely(x) __builtin_expect ((x), 0)
|
||||
# else
|
||||
# define likely(x) (x)
|
||||
# define unlikely(x) (x)
|
||||
# endif
|
||||
|
||||
#ifndef SE_DECLSPEC_EXPORT
|
||||
#define SE_DECLSPEC_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
#ifndef SE_DECLSPEC_IMPORT
|
||||
#define SE_DECLSPEC_IMPORT
|
||||
#endif
|
||||
|
||||
#ifndef SE_DECLSPEC_ALIGN
|
||||
#define SE_DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
|
||||
#ifndef SE_DECLSPEC_THREAD
|
||||
#define SE_DECLSPEC_THREAD /*__thread*/
|
||||
#endif
|
||||
|
||||
/* disable __try, __except on linux */
|
||||
#ifndef __try
|
||||
#define __try try
|
||||
#endif
|
||||
|
||||
#ifndef __except
|
||||
#define __except(x) catch(...)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SE_DRIVER
|
||||
|
||||
# define SE_GNU
|
||||
# if defined(__x86_64__)
|
||||
# define SE_64
|
||||
# define SE_GNU64
|
||||
# else
|
||||
# define SE_32
|
||||
# define SE_GNU32
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#define INITIALIZER(f) \
|
||||
static void f(void) __attribute__((constructor));
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define MY_EXTERN extern "C"
|
||||
#else
|
||||
#define MY_EXTERN extern
|
||||
#endif
|
||||
|
||||
#define SGX_ACCESS_VERSION(libname, num) \
|
||||
MY_EXTERN const char *sgx_##libname##_version; \
|
||||
const char * __attribute__((destructor)) libname##_access_version_dummy##num() \
|
||||
{ \
|
||||
return sgx_##libname##_version; \
|
||||
}
|
||||
|
||||
|
||||
#endif
|
49
common/inc/internal/se_cpu_feature.h
Normal file
49
common/inc/internal/se_cpu_feature.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SE_CPU_FEATURE_H_
|
||||
#define _SE_CPU_FEATURE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "se_cpu_feature_defs.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" uint64_t g_cpu_feature_indicator;
|
||||
#else
|
||||
extern uint64_t g_cpu_feature_indicator;
|
||||
#endif
|
||||
|
||||
#define TEST_CPU_HAS_RDRAND (g_cpu_feature_indicator & CPU_FEATURE_RDRND)
|
||||
|
||||
|
||||
#endif
|
294
common/inc/internal/se_cpu_feature_defs.h
Normal file
294
common/inc/internal/se_cpu_feature_defs.h
Normal file
@ -0,0 +1,294 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_CPU_FEATURE_DEFS_H_
|
||||
#define _SE_CPU_FEATURE_DEFS_H_
|
||||
|
||||
/*
|
||||
* Different extended model + model values for Silverthorn.
|
||||
*/
|
||||
#define CPU_ATOM1 0x1c
|
||||
#define CPU_ATOM2 0x26
|
||||
#define CPU_ATOM3 0x27
|
||||
|
||||
/*
|
||||
* The processor family is an 8-bit value obtained by adding the
|
||||
* Extended Family field of the processor signature returned by
|
||||
* CPUID Function 1 with the Family field.
|
||||
* F = (CPUID(1).EAX[27:20] >> 20) + (CPUID(1).EAX[11:8] >> 8)
|
||||
*/
|
||||
#define CPU_FAMILY(x) (((((x) >> 20) & 0xffU) | (((x) >> 8) & 0xfU)) & 0xffU)
|
||||
|
||||
/* The processor model is an 8-bit value obtained by shifting left 4
|
||||
* the Extended Model field of the processor signature returned by
|
||||
* CPUID Function 1 then adding the Model field.
|
||||
* M = (CPUID(1).EAX[19:16] >> 12) + (CPUID(1).EAX[7:4] >> 4)
|
||||
*/
|
||||
#define CPU_MODEL(x) ((((x) >> 12) & 0xf0U) | (((x) >> 4) & 0xfU))
|
||||
#define CPU_STEPPING(x) (((x) >> 0) & 0xf)
|
||||
|
||||
#define CPU_HAS_MMX(x) (((x) & (1 << 23)) != 0)
|
||||
#define CPU_HAS_FXSAVE(x) (((x) & (1 << 24)) != 0)
|
||||
#define CPU_HAS_SSE(x) (((x) & (1 << 25)) != 0)
|
||||
#define CPU_HAS_SSE2(x) (((x) & (1 << 26)) != 0)
|
||||
#define CPU_HAS_PNI(x) (((x) & (1 << 0)) != 0)
|
||||
#define CPU_HAS_MNI(x) (((x) & (1 << 9)) != 0)
|
||||
#define CPU_HAS_SNI(x) (((x) & (1 << 19)) != 0)
|
||||
#define CPU_HAS_MOVBE(x) (((x) & (1 << 22)) != 0)
|
||||
#define CPU_HAS_SSE4_2(x) (((x) & (1 << 20)) != 0)
|
||||
#define CPU_HAS_POPCNT(x) (((x) & (1 << 23)) != 0)
|
||||
#define CPU_HAS_PCLMULQDQ(x) (((x) & (1 << 1)) != 0)
|
||||
#define CPU_HAS_AES(x) (((x) & (1 << 25)) != 0)
|
||||
#define CPU_HAS_XSAVE(x) (((x) & (1 << 27)) != 0)
|
||||
#define CPU_HAS_AVX(x) (((x) & (1 << 28)) != 0)
|
||||
#define XFEATURE_ENABLED_AVX(x) \
|
||||
(((x) & 0x06) == 0x06)
|
||||
#define CPU_HAS_F16C(x) (((x) & (1 << 29)) != 0)
|
||||
#define CPU_HAS_RDRAND(x) (((x) & (1 << 30)) != 0)
|
||||
#define CPU_HAS_IVB(x) (CPU_HAS_F16C(x) && CPU_HAS_RDRAND(x))
|
||||
#define CPU_HAS_IVB_NORDRAND(x) (CPU_HAS_F16C(x))
|
||||
#define CPU_HAS_AVX2(x) (((x) & (1 << 5)) != 0)
|
||||
#define CPU_HAS_HLE(x) (((x) & (1 << 4)) != 0)
|
||||
#define CPU_HAS_RTM(x) (((x) & (1 << 11)) != 0)
|
||||
#define CPU_HAS_ADCOX(x) (((x) & (1 << 19)) != 0)
|
||||
#define CPU_HAS_RDSEED(x) (((x) & (1 << 18)) != 0)
|
||||
#define CPU_HAS_BMI(x) (((x) & (1 << 3)) != 0 && \
|
||||
((x) & (1 << 8)) != 0)
|
||||
#define CPU_HAS_LZCNT(x) (((x) & (1 << 5)) != 0)
|
||||
#define CPU_HAS_PREFETCHW(x) (((x) & (1 << 8)) != 0)
|
||||
#define CPU_HAS_FMA(x) (((x) & (1 << 12)) != 0)
|
||||
#define CPU_HAS_HSW(cpuid7_ebx, ecpuid1_ecx, cpuid1_ecx) \
|
||||
(CPU_HAS_AVX2(cpuid7_ebx) && CPU_HAS_BMI(cpuid7_ebx) && \
|
||||
CPU_HAS_LZCNT(ecpuid1_ecx) && CPU_HAS_FMA(cpuid1_ecx) && \
|
||||
CPU_HAS_HLE(cpuid7_ebx) && CPU_HAS_RTM(cpuid7_ebx))
|
||||
|
||||
#define CPU_HAS_FPU(x) (((x) & (1 << 0)) != 0)
|
||||
#define CPU_HAS_CMOV(x) (((x) & (1 << 15)) != 0)
|
||||
|
||||
#define CPU_HAS_SSE3(x) (((x) & (1 << 0)) != 0)
|
||||
#define CPU_HAS_SSSE3(x) (((x) & (1 << 9)) != 0)
|
||||
|
||||
#define CPU_HAS_SSE4_1(x) (((x) & (1 << 19)) != 0)
|
||||
|
||||
#define CPU_HAS_LRBNI(x) (((x) & (1 << 1)) != 0)
|
||||
#define CPU_HAS_LRB2(x) (((x) & (1 << 4)) != 0)
|
||||
|
||||
|
||||
#define CPU_GENU_VAL ('G' << 0 | 'e' << 8 | 'n' << 16 | 'u' << 24)
|
||||
#define CPU_INEI_VAL ('i' << 0 | 'n' << 8 | 'e' << 16 | 'I' << 24)
|
||||
#define CPU_NTEL_VAL ('n' << 0 | 't' << 8 | 'e' << 16 | 'l' << 24)
|
||||
|
||||
/*
|
||||
* These values must be in sync with dev/proton/globals/glob_cpu_info.c
|
||||
* c_legacy_cpu_set_xxx constants.
|
||||
*/
|
||||
#define CPU_GENERIC 0x1
|
||||
#define CPU_PENTIUM 0x2
|
||||
#define CPU_PENTIUM_PRO 0x4
|
||||
#define CPU_PENTIUM_MMX 0x8
|
||||
#define CPU_PENTIUM_II 0x10
|
||||
#define CPU_PENTIUM_II_FXSV 0x20
|
||||
#define CPU_PENTIUM_III 0x40
|
||||
#define CPU_PENTIUM_III_SSE 0x80
|
||||
#define CPU_PENTIUM_4 0x100
|
||||
#define CPU_PENTIUM_4_SSE2 0x200
|
||||
#define CPU_BNI 0x400
|
||||
#define CPU_PENTIUM_4_PNI 0x800
|
||||
#define CPU_MNI 0x1000
|
||||
#define CPU_SNI 0x2000
|
||||
#define CPU_BNL 0x4000
|
||||
#define CPU_NHM 0x8000
|
||||
#define CPU_WSM 0x10000
|
||||
#define CPU_SNB 0x20000
|
||||
#define CPU_IVB 0x40000
|
||||
#define CPU_HSW 0x400000
|
||||
|
||||
#define CPU_PENTIUM_FAMILY 5
|
||||
#define CPU_PPRO_FAMILY 6
|
||||
#define CPU_WMT_FAMILY 15
|
||||
|
||||
/*
|
||||
* The processor is a generic IA32 CPU
|
||||
*/
|
||||
#define CPU_FEATURE_GENERIC_IA32 0x00000001ULL
|
||||
|
||||
/*
|
||||
* Floating point unit is on-chip.
|
||||
*/
|
||||
#define CPU_FEATURE_FPU 0x00000002ULL
|
||||
|
||||
/*
|
||||
* Conditional mov instructions are supported.
|
||||
*/
|
||||
#define CPU_FEATURE_CMOV 0x00000004ULL
|
||||
|
||||
/*
|
||||
* The processor supports the MMX technology instruction set extensions
|
||||
* to Intel Architecture.
|
||||
*/
|
||||
#define CPU_FEATURE_MMX 0x00000008ULL
|
||||
|
||||
/*
|
||||
* The FXSAVE and FXRSTOR instructions are supported for fast
|
||||
* save and restore of the floating point context.
|
||||
*/
|
||||
#define CPU_FEATURE_FXSAVE 0x00000010ULL
|
||||
|
||||
/*
|
||||
* Indicates the processor supports the Streaming SIMD Extensions Instructions.
|
||||
*/
|
||||
#define CPU_FEATURE_SSE 0x00000020ULL
|
||||
|
||||
/*
|
||||
* Indicates the processor supports the Streaming SIMD
|
||||
* Extensions 2 Instructions.
|
||||
*/
|
||||
#define CPU_FEATURE_SSE2 0x00000040ULL
|
||||
|
||||
/*
|
||||
* Indicates the processor supports the Streaming SIMD
|
||||
* Extensions 3 Instructions. (PNI)
|
||||
*/
|
||||
#define CPU_FEATURE_SSE3 0x00000080ULL
|
||||
|
||||
/*
|
||||
* The processor supports the Supplemental Streaming SIMD Extensions 3
|
||||
* instructions. (MNI)
|
||||
*/
|
||||
#define CPU_FEATURE_SSSE3 0x00000100ULL
|
||||
|
||||
/*
|
||||
* The processor supports the Streaming SIMD Extensions 4.1 instructions.(SNI)
|
||||
*/
|
||||
#define CPU_FEATURE_SSE4_1 0x00000200ULL
|
||||
|
||||
/*
|
||||
* The processor supports the Streaming SIMD Extensions 4.1 instructions.
|
||||
* (NNI + STTNI)
|
||||
*/
|
||||
#define CPU_FEATURE_SSE4_2 0x00000400ULL
|
||||
|
||||
|
||||
/*
|
||||
* The processor supports POPCNT instruction.
|
||||
*/
|
||||
#define CPU_FEATURE_POPCNT 0x00000800ULL
|
||||
|
||||
/*
|
||||
* The processor supports MOVBE instruction.
|
||||
*/
|
||||
#define CPU_FEATURE_MOVBE 0x00001000ULL
|
||||
|
||||
/*
|
||||
* The processor supports PCLMULQDQ instruction.
|
||||
*/
|
||||
#define CPU_FEATURE_PCLMULQDQ 0x00002000ULL
|
||||
|
||||
/*
|
||||
* The processor supports instruction extension for encryption.
|
||||
*/
|
||||
#define CPU_FEATURE_AES 0x00004000ULL
|
||||
|
||||
/*
|
||||
* The processor supports 16-bit floating-point conversions instructions.
|
||||
*/
|
||||
#define CPU_FEATURE_F16C 0x00008000ULL
|
||||
|
||||
/*
|
||||
* The processor supports AVX instruction extension.
|
||||
*/
|
||||
#define CPU_FEATURE_AVX 0x00010000ULL
|
||||
|
||||
/*
|
||||
* The processor supports RDRND (read random value) instruction.
|
||||
*/
|
||||
#define CPU_FEATURE_RDRND 0x00020000ULL
|
||||
|
||||
/*
|
||||
* The processor supports FMA instructions.
|
||||
*/
|
||||
#define CPU_FEATURE_FMA 0x00040000ULL
|
||||
|
||||
/*
|
||||
* The processor supports two groups of advanced bit manipulation extensions. - Haswell introduced, AVX2 related
|
||||
*/
|
||||
#define CPU_FEATURE_BMI 0x00080000ULL
|
||||
|
||||
/*
|
||||
* The processor supports LZCNT instruction (counts the number of leading zero
|
||||
* bits). - Haswell introduced
|
||||
*/
|
||||
#define CPU_FEATURE_LZCNT 0x00100000ULL
|
||||
|
||||
/*
|
||||
* The processor supports HLE extension (hardware lock elision). - Haswell introduced
|
||||
*/
|
||||
#define CPU_FEATURE_HLE 0x00200000ULL
|
||||
|
||||
/*
|
||||
* The processor supports RTM extension (restricted transactional memory) - Haswell AVX2 related.
|
||||
*/
|
||||
#define CPU_FEATURE_RTM 0x00400000ULL
|
||||
|
||||
/*
|
||||
* The processor supports AVX2 instruction extension.
|
||||
*/
|
||||
#define CPU_FEATURE_AVX2 0x00800000ULL
|
||||
|
||||
/*
|
||||
* The processor supports AVX512 instruction extension.
|
||||
*/
|
||||
#define CPU_FEATURE_AVX512 0x01000000ULL
|
||||
|
||||
/*
|
||||
* The processor supports the PREFETCHW instruction.
|
||||
*/
|
||||
#define CPU_FEATURE_PREFETCHW 0x02000000ULL
|
||||
|
||||
/*
|
||||
* The processor supports RDSEED instruction.
|
||||
*/
|
||||
#define CPU_FEATURE_RDSEED 0x04000000ULL
|
||||
|
||||
/*
|
||||
* The processor supports ADCX and ADOX instructions.
|
||||
*/
|
||||
#define CPU_FEATURE_ADCOX 0x08000000ULL
|
||||
|
||||
/*
|
||||
* The processor is a full inorder (Silverthorne) processor
|
||||
*/
|
||||
#define CPU_FEATURE_FULL_INORDER 0x10000000ULL
|
||||
|
||||
/* Reserved feature bits which includes the unset bit CPU_FEATURE_AVX512 */
|
||||
#define RESERVED_CPU_FEATURE_BIT ((~(0x20000000ULL - 1)) | 0x01000000ULL)
|
||||
|
||||
#endif
|
115
common/inc/internal/se_debugger_lib.h
Normal file
115
common/inc/internal/se_debugger_lib.h
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SEDEBUGGERLIB_H_
|
||||
#define _SEDEBUGGERLIB_H_
|
||||
|
||||
#include "arch.h"
|
||||
#include "se_types.h"
|
||||
#include "se_macro.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define URTS_EXCEPTION_PRECREATEENCLAVE 0xa1a01ec0
|
||||
#define URTS_EXCEPTION_POSTINITENCLAVE 0xa1a01ec1
|
||||
#define URTS_EXCEPTION_PREREMOVEENCLAVE 0xa1a01ec3
|
||||
#define URTS_EXCEPTION_PREEENTER 0xa1a01ec7
|
||||
|
||||
#define FIRST_CHANCE_EXCEPTION 1
|
||||
#define SECOND_CHANCE_EXCEPTION 0
|
||||
|
||||
#define DBWIN_BUFFER 0xa1a01ec5
|
||||
#define CXX_EXCEPTION 0xe06d7363
|
||||
|
||||
#define SE_UNICODE 1
|
||||
#define SE_ANSI 0
|
||||
#define DEBUGGER_ENABLED 1
|
||||
|
||||
#define DEBUG_INFO_STRUCT_VERSION 0x83d0ce23
|
||||
|
||||
const size_t BUF_SIZE = sizeof(void*);
|
||||
|
||||
typedef struct _debug_tcs_info_t
|
||||
{
|
||||
struct _debug_tcs_info_t* next_tcs_info;
|
||||
void* TCS_address;
|
||||
uintptr_t ocall_frame; /* ocall_frame_t** */
|
||||
unsigned long thread_id;
|
||||
}debug_tcs_info_t;
|
||||
|
||||
|
||||
#define DEBUG_INFO_MAX_PARAMETERS 10
|
||||
typedef struct _debug_info_t
|
||||
{
|
||||
uintptr_t param_array[DEBUG_INFO_MAX_PARAMETERS];
|
||||
}debug_info_t;
|
||||
|
||||
//enclave_type bit map
|
||||
#define ET_SIM_SHIFT 0 /*bits[0]=0 hw, bits[0]=1 sim*/
|
||||
#define ET_DEBUG_SHIFT 1 /*bits[1]=0 product enclave, bits[1]=1 debug enclave*/
|
||||
#define ET_SIM (1 << ET_SIM_SHIFT)
|
||||
#define ET_DEBUG (1 << ET_DEBUG_SHIFT)
|
||||
|
||||
typedef struct _debug_enclave_info_t
|
||||
{
|
||||
PADDED_POINTER(struct _debug_enclave_info_t, next_enclave_info);
|
||||
PADDED_POINTER(void, start_addr);
|
||||
PADDED_POINTER(debug_tcs_info_t, tcs_list);
|
||||
uint32_t enclave_type;
|
||||
uint32_t file_name_size;
|
||||
PADDED_POINTER(void, lpFileName);
|
||||
PADDED_POINTER(void, g_peak_heap_used_addr);
|
||||
PADDED_POINTER(void, dyn_sec);
|
||||
sgx_misc_select_t misc_select;
|
||||
/* The following members are optional or unused */
|
||||
uint32_t struct_version;
|
||||
uint32_t unicode;
|
||||
}debug_enclave_info_t;
|
||||
typedef struct _ocall_frame_t
|
||||
{
|
||||
uintptr_t pre_last_frame;
|
||||
uintptr_t index;
|
||||
uintptr_t xbp;
|
||||
uintptr_t ret;
|
||||
}ocall_frame_t;
|
||||
|
||||
static inline void destory_debug_info(debug_enclave_info_t *debug_info)
|
||||
{
|
||||
if(debug_info->lpFileName)
|
||||
{
|
||||
free(debug_info->lpFileName);
|
||||
debug_info->lpFileName = NULL;
|
||||
}
|
||||
|
||||
/*tcs_list is just a pointer, the instance is maintained in CTrustThread, so don't free it.*/
|
||||
debug_info->tcs_list = NULL;
|
||||
}
|
||||
#endif /*_SEDEBUGGERLIB_H_*/
|
||||
|
41
common/inc/internal/se_enclave_type.h
Normal file
41
common/inc/internal/se_enclave_type.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_ENCLAVE_TYPE_H_
|
||||
#define _SE_ENCLAVE_TYPE_H_
|
||||
|
||||
typedef enum
|
||||
{
|
||||
enclave_type_general = 0,
|
||||
enclave_type_architecture,
|
||||
} enclave_type_t;
|
||||
|
||||
#endif
|
90
common/inc/internal/se_error_internal.h
Normal file
90
common/inc/internal/se_error_internal.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_ERROR_INTERNAL_H_
|
||||
#define _SE_ERROR_INTERNAL_H_
|
||||
|
||||
#include "sgx_error.h"
|
||||
|
||||
/*
|
||||
bit[31:30] - main module id
|
||||
00 - external error
|
||||
11---internal error
|
||||
bit[29:16] - reserved
|
||||
bit[15:12] - sub-module id
|
||||
bit[11:0] - specific error
|
||||
*/
|
||||
|
||||
#define MAIN_MOD_SHIFT 30
|
||||
#define SUB_MOD_SHIFT 12
|
||||
|
||||
#define INTERNAL_ERROR 3
|
||||
#define EXTERNAL_ERROR 0
|
||||
|
||||
#define SE_INTERNAL_ERROR(x) (0xC0000000|(x))
|
||||
|
||||
typedef enum _se_status_internal_t
|
||||
{
|
||||
SE_ERROR_SUCCESS = 0, /*same value as SGX_SUCCESS*/
|
||||
/*error code for driver return to uRTS*/
|
||||
SE_ERROR_DRIVER_UNEXPECTED = SE_INTERNAL_ERROR(0X2001),
|
||||
SE_ERROR_DRIVER_INVALID_ID = SE_INTERNAL_ERROR(0X2002),
|
||||
SE_ERROR_DRIVER_INVALID_PARAMETER = SE_INTERNAL_ERROR(0X2003),
|
||||
SE_ERROR_DRIVER_INVALID_REQUEST = SE_INTERNAL_ERROR(0X2004),
|
||||
SE_ERROR_DRIVER_OUTOF_MEMORY_R0 = SE_INTERNAL_ERROR(0X2005),
|
||||
SE_ERROR_DRIVER_OUTOF_MEMORY_R3 = SE_INTERNAL_ERROR(0X2006),
|
||||
SE_ERROR_DRIVER_OUTOF_EPC = SE_INTERNAL_ERROR(0X2007),
|
||||
SE_ERROR_DRIVER_HW_CAPABILITY = SE_INTERNAL_ERROR(0X2008),
|
||||
SE_ERROR_DRIVER_MEMORY_MAP_CONFLICT = SE_INTERNAL_ERROR(0X2009),
|
||||
SE_ERROR_DRIVER_POWER = SE_INTERNAL_ERROR(0X200a),
|
||||
SE_ERROR_DRIVER_INVALID_PRIVILEGE = SE_INTERNAL_ERROR(0X200b),
|
||||
SE_ERROR_DRIVER_INVALID_ISVSVNLE = SE_INTERNAL_ERROR(0X200c),
|
||||
|
||||
SE_ERROR_DRIVER_INVALID_SIG_STRUCT = SE_INTERNAL_ERROR(0X2100),
|
||||
SE_ERROR_DRIVER_INVALID_ATTRIBUTE = SE_INTERNAL_ERROR(0X2101),
|
||||
SE_ERROR_DRIVER_INVALID_MEASUREMENT = SE_INTERNAL_ERROR(0X2102),
|
||||
SE_ERROR_DRIVER_INVALID_SIGNATURE = SE_INTERNAL_ERROR(0X2103),
|
||||
SE_ERROR_DRIVER_INVALID_LAUNCH_TOKEN= SE_INTERNAL_ERROR(0X2104),
|
||||
SE_ERROR_DRIVER_INVALID_CPUSVN = SE_INTERNAL_ERROR(0X2105),
|
||||
SE_ERROR_DRIVER_UNMASKED_EVENT = SE_INTERNAL_ERROR(0X2106),
|
||||
|
||||
SE_ERROR_INVALID_LAUNCH_TOKEN = SE_INTERNAL_ERROR(0x2200), /* the license is invalid*/
|
||||
SE_ERROR_INVALID_MEASUREMENT = SE_INTERNAL_ERROR(0x2201), /* The measurement of the enclave is invalid. May caused by signature or launch token*/
|
||||
SE_ERROR_READ_LOCK_FAIL = SE_INTERNAL_ERROR(0x2202),
|
||||
SE_ERROR_INVALID_ISVSVNLE = SE_INTERNAL_ERROR(0X2203),
|
||||
|
||||
/*error code for untrusted event of SE mutex*/
|
||||
SE_ERROR_MUTEX_GET_EVENT = SE_INTERNAL_ERROR(0x3001),
|
||||
SE_ERROR_MUTEX_WAIT_EVENT = SE_INTERNAL_ERROR(0x3002),
|
||||
SE_ERROR_MUTEX_WAKE_EVENT = SE_INTERNAL_ERROR(0x3003),
|
||||
} se_status_internal_t;
|
||||
|
||||
#endif
|
61
common/inc/internal/se_event.h
Normal file
61
common/inc/internal/se_event.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_EVENT_H_
|
||||
#define _SE_EVENT_H_
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <sys/syscall.h>
|
||||
typedef void * se_handle_t;
|
||||
|
||||
#include "sgx_defs.h"
|
||||
|
||||
#define SE_MUTEX_SUCCESS 0x0
|
||||
#define SE_MUTEX_INVALID 0x1
|
||||
#define SE_MUTEX_ERROR_WAKE 0x2
|
||||
#define SE_MUTEX_ERROR_WAIT 0x3
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
se_handle_t SGXAPI se_event_init(void);
|
||||
void SGXAPI se_event_destroy(se_handle_t);
|
||||
|
||||
int SGXAPI se_event_wait(se_handle_t);
|
||||
int SGXAPI se_event_wake(se_handle_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
61
common/inc/internal/se_lock.hpp
Normal file
61
common/inc/internal/se_lock.hpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/* This file implement lock guard */
|
||||
|
||||
#ifndef SE_LOCK_HPP
|
||||
#define SE_LOCK_HPP
|
||||
|
||||
#include "util.h"
|
||||
#include "se_thread.h"
|
||||
#include "uncopyable.h"
|
||||
|
||||
class Mutex: private Uncopyable
|
||||
{
|
||||
public:
|
||||
Mutex(){se_mutex_init(&m_mutex);}
|
||||
~Mutex(){se_mutex_destroy(&m_mutex);}
|
||||
void lock(){se_mutex_lock(&m_mutex);}
|
||||
void unlock(){se_mutex_unlock(&m_mutex);}
|
||||
private:
|
||||
se_mutex_t m_mutex;
|
||||
};
|
||||
|
||||
class LockGuard: private Uncopyable
|
||||
{
|
||||
public:
|
||||
LockGuard(Mutex* mutex):m_mutex(mutex){m_mutex->lock();}
|
||||
~LockGuard(){m_mutex->unlock();}
|
||||
private:
|
||||
Mutex* m_mutex;
|
||||
};
|
||||
|
||||
#endif
|
40
common/inc/internal/se_macro.h
Normal file
40
common/inc/internal/se_macro.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SE_MACRO_H_
|
||||
#define SE_MACRO_H_
|
||||
|
||||
#ifndef SGX_HYPERV_ECO
|
||||
#define SGX_HYPERV_ECO
|
||||
#endif
|
||||
|
||||
#endif
|
67
common/inc/internal/se_map.h
Normal file
67
common/inc/internal/se_map.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_MAP_H_
|
||||
#define _SE_MAP_H_
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "se_types.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
typedef int se_file_handle_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t* base_addr; /* pointer to the mapped area */
|
||||
size_t length; /* the length of the mapping */
|
||||
} map_handle_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Map a file to memory and get its size. */
|
||||
map_handle_t* map_file(se_file_handle_t fd, uint32_t *size);
|
||||
|
||||
/* Unmap a mapped file. */
|
||||
void unmap_file(map_handle_t* mh);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
54
common/inc/internal/se_memcpy.h
Normal file
54
common/inc/internal/se_memcpy.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_MEMCPY_H_
|
||||
#define _SE_MEMCPY_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* memcpy_s always return 0 under Linux */
|
||||
|
||||
#ifndef _ERRNO_T_DEFINED
|
||||
#define _ERRNO_T_DEFINED
|
||||
typedef int errno_t;
|
||||
#endif
|
||||
|
||||
static inline errno_t memcpy_s(void *dest, size_t numberOfElements, const void *src, size_t count)
|
||||
{
|
||||
if(numberOfElements<count)
|
||||
return -1;
|
||||
memcpy(dest, src, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif /* _SE_MEMCPY_H_ */
|
136
common/inc/internal/se_memory.h
Normal file
136
common/inc/internal/se_memory.h
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_MEMORY_H_
|
||||
#define _SE_MEMORY_H_
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define _LARGEFILE64_SOURCE 1
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef MEM_COMMIT
|
||||
#define MEM_COMMIT 0x1000
|
||||
#endif
|
||||
|
||||
#ifndef MEM_RESERVE
|
||||
#define MEM_RESERVE 0x2000
|
||||
#endif
|
||||
|
||||
#ifdef MEM_RELEASE
|
||||
#warning "MEM_RELEASE define conflict"
|
||||
#else
|
||||
#define MEM_RELEASE 0x8000
|
||||
#endif
|
||||
|
||||
#ifdef MEM_DECOMMIT
|
||||
#warning "MEM_DECOMMIT define conflict"
|
||||
#else
|
||||
#define MEM_DECOMMIT 0x4000
|
||||
#endif
|
||||
|
||||
#include "se_types.h"
|
||||
#include "arch.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
Reserves or commits a region of pages in the virtual address space of the calling process.
|
||||
Memory allocated by this function is automatically initialized to zero, unless MEM_RESET is specified.
|
||||
@address: the starting address of the region to allocate.
|
||||
@size: size of region in bytes.
|
||||
@type: Only MEM_COMMIT accepted.
|
||||
MEM_COMMIT - Allocates memory charges for the specified reserved memory pages.
|
||||
Actual physical pages are not allocated until the virtual addresses are actually accessed.
|
||||
The function initializes the memory to zero.
|
||||
@return value: If the function succeeds, the return value is the base address of the allocated region of pages.
|
||||
If the function fails, the return value is NULL.
|
||||
*/
|
||||
void* se_virtual_alloc(void* address, size_t size, uint32_t type);
|
||||
/*
|
||||
Releases, decommits, or releases and decommits a region of pages within the virtual address space of the calling process.
|
||||
@address:A pointer to the base address of the region of pages to be freed. If the dwFreeType parameter is MEM_RELEASE,
|
||||
this parameter must be the base address returned by the se_virtual_alloc function when the region of pages is reserved.
|
||||
@size: The size of the region of memory to be freed, in bytes.
|
||||
@type: Only MEM_RELEASE accepted
|
||||
MEM_RELEASE - releases the specified region of pages. After this operation, the pages are in the free state.
|
||||
@return value:If the function succeeds, the return value is nonzero.If the function fails, the return value is zero.
|
||||
*/
|
||||
int se_virtual_free(void* address, size_t size, uint32_t type);
|
||||
/*
|
||||
Locks the specified region of the process's virtual address space into physical memory, ensuring that subsequent access to the region will not incur a page fault.
|
||||
@address: A pointer to the base address of the region of pages to be locked.
|
||||
The region of affected pages includes all pages that contain one or more bytes in the range from the address parameter to (address+size).
|
||||
@size: The size of the region to be locked, in bytes.
|
||||
@return value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
|
||||
*/
|
||||
int se_virtual_lock(void* address, size_t size);
|
||||
/*
|
||||
Changes the protection on a region of committed pages in the virtual address space of the calling process.
|
||||
@address: A pointer an address that describes the starting page of the region of pages whose access protection attributes are to be changed.
|
||||
@size: The size of the region whose access protection attributes are to be changed, in bytes.
|
||||
@prot: The memory protection option. The option can be SI_FLAG_R, SI_FLAG_W, SI_FLAG_X.
|
||||
@return value: If the function succeeds, the return value is nonzero.If the function fails, the return value is zero.
|
||||
*/
|
||||
|
||||
#define SGX_PROT_NONE PROT_NONE
|
||||
|
||||
int se_virtual_protect(void* address, size_t size, uint32_t prot);
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
typedef pid_t se_proc_t;
|
||||
|
||||
/*
|
||||
@return value: on success, return TRUE else return FALSE
|
||||
*/
|
||||
se_proc_t get_self_proc(void);
|
||||
/*
|
||||
** If the function succeeds, the return value is nonzero.
|
||||
** If the function fails, the return value is zero.
|
||||
*/
|
||||
int put_self_proc(se_proc_t proc);
|
||||
int se_read_process_mem(se_proc_t proc, void* base_addr, void* buffer, size_t size, size_t* read_nr);
|
||||
int se_write_process_mem(se_proc_t proc, void* base_addr, void* buffer, size_t size, size_t* write_ndr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
47
common/inc/internal/se_page_attr.h
Normal file
47
common/inc/internal/se_page_attr.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_PAGE_ATTR_H_
|
||||
#define _SE_PAGE_ATTR_H_
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DoEADD = 0,
|
||||
DoEEXTEND,
|
||||
} ATTRIBUTE_BITS_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ADD_PAGE_ONLY = 1<<DoEADD,
|
||||
ADD_EXTEND_PAGE = 1<<DoEADD|1<<DoEEXTEND,
|
||||
} EADD_BUFFER_IN_ATTRIBUTE_t;
|
||||
|
||||
#endif
|
73
common/inc/internal/se_quote_internal.h
Normal file
73
common/inc/internal/se_quote_internal.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_QUOTE_INTERNAL_H_
|
||||
#define _SE_QUOTE_INTERNAL_H_
|
||||
|
||||
#include "se_types.h"
|
||||
#include "epid_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define QUOTE_IV_SIZE 12
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct _se_wrap_key_t {
|
||||
uint8_t encrypted_key[256];
|
||||
uint8_t key_hash[32];
|
||||
} se_wrap_key_t;
|
||||
|
||||
typedef struct _se_encrypted_sign
|
||||
{
|
||||
se_wrap_key_t wrap_key; /* 0 */
|
||||
uint8_t iv[QUOTE_IV_SIZE]; /* 288 */
|
||||
uint32_t payload_size; /* 300 */
|
||||
BasicSignature basic_sign; /* 304, this field is encrypted, and contributes to the mac */
|
||||
uint32_t rl_ver; /* 656, this field is encrypted, and contributes to the mac */
|
||||
uint32_t rl_num; /* 660, this field is encrypted, and contributes to the mac */
|
||||
uint8_t nrp_mac[]; /* 664, this filed contains the encrypted nrps followed by the mac */
|
||||
}se_encrypted_sign_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
#define SE_QUOTE_LENGTH_WITHOUT_SIG (sizeof(sgx_quote_t) \
|
||||
+ sizeof(se_wrap_key_t) \
|
||||
+ QUOTE_IV_SIZE \
|
||||
+ sizeof(uint32_t) \
|
||||
+ sizeof(sgx_mac_t))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
56
common/inc/internal/se_rwlock.h
Normal file
56
common/inc/internal/se_rwlock.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RWLOCK_H_
|
||||
#define _RWLOCK_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
typedef pthread_rwlock_t se_rwlock_t;
|
||||
typedef pthread_rwlock_t* se_prwlock_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void se_wtlock(se_prwlock_t);
|
||||
void se_wtunlock(se_prwlock_t);
|
||||
int se_try_rdlock(se_prwlock_t);
|
||||
void se_rdlock(se_prwlock_t lock);
|
||||
void se_rdunlock(se_prwlock_t);
|
||||
void se_init_rwlock(se_prwlock_t lock);
|
||||
void se_fini_rwlock(se_prwlock_t lock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _RWLOCK_H_ */
|
155
common/inc/internal/se_stdio.h
Normal file
155
common/inc/internal/se_stdio.h
Normal 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef SE_STDIO_H
|
||||
#define SE_STDIO_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include "se_memcpy.h"
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef MAX_PATH
|
||||
#define MAX_PATH 260
|
||||
#endif
|
||||
|
||||
static inline int se_delete_file(const char *path_name)
|
||||
{
|
||||
return unlink(path_name);
|
||||
}
|
||||
|
||||
#define se_delete_tfile se_delete_file
|
||||
|
||||
static inline int sprintf_s(char *dst_buf, size_t size_in_bytes, const char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
int cnt;
|
||||
va_start(argptr, format);
|
||||
cnt = vsnprintf(dst_buf, size_in_bytes, format, argptr);
|
||||
va_end(argptr);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static inline int _snprintf_s(char *dst_buf, size_t size_in_bytes, size_t max_count, const char *format, ...)
|
||||
{
|
||||
(void) size_in_bytes;
|
||||
va_list argptr;
|
||||
int cnt;
|
||||
va_start(argptr, format);
|
||||
cnt = vsnprintf(dst_buf, max_count, format, argptr);
|
||||
va_end(argptr);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static inline errno_t fopen_s(FILE **f, const char *filename, const char *mode)
|
||||
{
|
||||
errno_t err = 0;
|
||||
*f = fopen(filename, mode);
|
||||
if(*f==NULL){
|
||||
err = -1;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline int se_copy_file(const char *dst_name, const char *src_name)
|
||||
{
|
||||
int dest = -1;
|
||||
int source = -1;
|
||||
ssize_t nr_read;
|
||||
struct stat stat_buf;
|
||||
|
||||
#ifndef BUF_SIZE
|
||||
#define BUF_SIZE 4096
|
||||
#endif
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
/* open the input file */
|
||||
source = open(src_name, O_RDONLY);
|
||||
if(source < 0)
|
||||
goto error;
|
||||
|
||||
/* get size and permissions of the prebuild DB file */
|
||||
if (fstat(source, &stat_buf) != 0)
|
||||
goto error;
|
||||
|
||||
dest = open(dst_name, O_WRONLY|O_CREAT|O_TRUNC, stat_buf.st_mode);
|
||||
if(dest < 0)
|
||||
goto error;
|
||||
|
||||
while ((nr_read = read(source, buf, BUF_SIZE)) > 0)
|
||||
{
|
||||
if (write(dest, buf, nr_read) != nr_read)
|
||||
goto error;
|
||||
}
|
||||
#undef BUF_SIZE
|
||||
|
||||
close(dest);
|
||||
close(source);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if(dest>=0)close(dest);
|
||||
if(source>=0)close(source);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
template <size_t _Size>
|
||||
int sprintf_s(char (&dst)[_Size], const char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
int cnt;
|
||||
va_start(argptr, format);
|
||||
cnt = vsprintf(dst, format, argptr);
|
||||
va_end(argptr);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
template<size_t _Size>
|
||||
int _snprintf_s(char (&dst)[_Size], size_t max_count, const char *format, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
int cnt;
|
||||
va_start(argptr, format);
|
||||
cnt = vsnprintf(dst, max_count, format, argptr);
|
||||
va_end(argptr);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
73
common/inc/internal/se_string.h
Normal file
73
common/inc/internal/se_string.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_STRING_H_
|
||||
#define _SE_STRING_H_
|
||||
|
||||
#include "se_memcpy.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifndef _ERRNO_T_DEFINED
|
||||
#define _ERRNO_T_DEFINED
|
||||
typedef int errno_t;
|
||||
#endif
|
||||
|
||||
static inline errno_t strcat_s(char *dst, size_t max_size, const char *src)
|
||||
{
|
||||
if(strlen(dst)+strlen(src)+1>max_size)return -1;
|
||||
strcat(dst, src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline errno_t strcpy_s(char *dst, size_t max_size, const char *src)
|
||||
{
|
||||
if(strnlen(src, max_size)+1>max_size)return -1;
|
||||
strcpy(dst, src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define _strnicmp strncasecmp
|
||||
static inline errno_t strncat_s(char *dst, size_t max_size, const char *src, size_t max_count)
|
||||
{
|
||||
size_t len = strnlen(src,max_count);
|
||||
len+=strnlen(dst, max_size)+1;
|
||||
if(len>max_size)return -1;
|
||||
strncat(dst, src, max_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define _strdup strdup
|
||||
#define strnlen_s strnlen
|
||||
|
||||
|
||||
|
||||
#endif
|
75
common/inc/internal/se_thread.h
Normal file
75
common/inc/internal/se_thread.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _SE_THREAD_H_
|
||||
#define _SE_THREAD_H_
|
||||
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE /* for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP */
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <pthread.h>
|
||||
typedef pthread_mutex_t se_mutex_t;
|
||||
typedef pid_t se_thread_id_t;
|
||||
typedef pthread_key_t se_tls_index_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
@mutex: A pointer to the critical section object.
|
||||
@return value: If the function succeeds, the return value is nonzero.If the function fails, the return value is zero.
|
||||
*/
|
||||
void se_mutex_init(se_mutex_t* mutex);
|
||||
int se_mutex_lock(se_mutex_t* mutex);
|
||||
int se_mutex_unlock(se_mutex_t* mutex);
|
||||
int se_mutex_destroy(se_mutex_t* mutex);
|
||||
|
||||
unsigned int se_get_threadid(void);
|
||||
|
||||
/* tls functions */
|
||||
int se_tls_alloc(se_tls_index_t *tls_index);
|
||||
int se_tls_free(se_tls_index_t tls_index);
|
||||
void * se_tls_get_value(se_tls_index_t tls_index);
|
||||
int se_tls_set_value(se_tls_index_t tls_index, void *tls_value);
|
||||
|
||||
/* se_thread_handle_t se_create_thread(size_t stack_size, thread_start_routine_t start_routine, void *param, se_thread_t* thread); */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
52
common/inc/internal/se_time.h
Normal file
52
common/inc/internal/se_time.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_TIME_H_
|
||||
#define _SE_TIME_H_
|
||||
|
||||
#include "se_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
*@milli_seconds: the time range for sleep. It is milliseconds.
|
||||
*/
|
||||
void se_sleep(uint32_t milli_seconds);
|
||||
uint64_t se_get_tick_count_freq(void);
|
||||
uint64_t se_get_tick_count(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
89
common/inc/internal/se_trace.h
Normal file
89
common/inc/internal/se_trace.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*This file wrapper some trace output.
|
||||
*/
|
||||
|
||||
#ifndef _SE_DEBUG_H_
|
||||
#define _SE_DEBUG_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SE_TRACE_ERROR,
|
||||
SE_TRACE_WARNING,
|
||||
SE_TRACE_NOTICE,
|
||||
SE_TRACE_DEBUG
|
||||
} se_trace_t;
|
||||
|
||||
#ifndef SE_DEBUG_LEVEL
|
||||
/* Each module need define their own SE_DEBUG_LEVEL */
|
||||
#define SE_DEBUG_LEVEL SE_TRACE_ERROR
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int se_trace_internal(int debug_level, const char *fmt, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* For libraries, we usually define DISABLE_TRACE to disable any trace. */
|
||||
/* For apps, we usually enable trace. */
|
||||
#ifdef DISABLE_TRACE
|
||||
#define SE_TRACE(...)
|
||||
#define se_trace(...)
|
||||
#else /* DISABLE_TRACE */
|
||||
#define se_trace(debug_level, fmt, ...) \
|
||||
do { \
|
||||
if(debug_level <= SE_DEBUG_LEVEL) \
|
||||
se_trace_internal(debug_level, fmt, ##__VA_ARGS__); \
|
||||
}while(0)
|
||||
|
||||
/* For compatibility, SE_TRACE/se_trace is used in old code. */
|
||||
/* New code should use SE_TRACE_DEBUG, SE_TRACE_NOTICE, SE_TRACE_WARNING, SE_TRACE_ERROR */
|
||||
#define SE_TRACE(debug_level, fmt, ...) \
|
||||
se_trace(debug_level, "[%s %s:%d] " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#endif/* DISABLE_TRACE */
|
||||
|
||||
/* SE_TRACE_DEBUG and SE_TRACE_NOTICE print the debug information plus message. */
|
||||
#define SE_TRACE_DEBUG(fmt, ...) se_trace(SE_TRACE_DEBUG, "[%s %s:%d] " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#define SE_TRACE_NOTICE(fmt, ...) se_trace(SE_TRACE_NOTICE, "[%s %s:%d] " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
/* SE_TRACE_WARNING and SE_TRACE_ERROR only print message. */
|
||||
#define SE_TRACE_WARNING(fmt, ...) se_trace(SE_TRACE_WARNING, fmt, ##__VA_ARGS__)
|
||||
#define SE_TRACE_ERROR(fmt, ...) se_trace(SE_TRACE_ERROR, fmt, ##__VA_ARGS__)
|
||||
|
||||
#endif
|
93
common/inc/internal/se_types.h
Normal file
93
common/inc/internal/se_types.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is to define some types that is platform independent.
|
||||
*/
|
||||
|
||||
#ifndef _SE_TYPE_H_
|
||||
#define _SE_TYPE_H_
|
||||
#include "se_cdefs.h"
|
||||
|
||||
#ifdef SE_DRIVER
|
||||
|
||||
typedef INT8 int8_t;
|
||||
typedef UINT8 uint8_t;
|
||||
typedef INT16 int16_t;
|
||||
typedef UINT16 uint16_t;
|
||||
typedef INT32 int32_t;
|
||||
typedef UINT32 uint32_t;
|
||||
typedef INT64 int64_t;
|
||||
typedef UINT64 uint64_t;
|
||||
|
||||
#else
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(SE_64)
|
||||
|
||||
#define PADDED_POINTER(t, p) t* p
|
||||
#define PADDED_DWORD(d) uint64_t d
|
||||
#define PADDED_LONG(l) int64_t l
|
||||
#define REG(name) r##name
|
||||
#ifdef SE_SIM_EXCEPTION
|
||||
#define REG_ALIAS(name) R##name
|
||||
#endif
|
||||
#define REGISTER(name) uint64_t REG(name)
|
||||
|
||||
#else /* !defined(SE_64) */
|
||||
|
||||
#define PADDED_POINTER(t, p) t* p; void* ___##p##_pad_to64_bit
|
||||
#define PADDED_DWORD(d) uint32_t d; uint32_t ___##d##_pad_to64_bit
|
||||
#define PADDED_LONG(l) int32_t l; int32_t ___##l##_pad_to64_bit
|
||||
|
||||
#define REG(name) e##name
|
||||
|
||||
#ifdef SE_SIM_EXCEPTION
|
||||
#define REG_ALIAS(name) E##name
|
||||
#endif
|
||||
|
||||
#define REGISTER(name) uint32_t REG(name); uint32_t ___##e##name##_pad_to64_bit
|
||||
|
||||
#endif /* !defined(SE_64) */
|
||||
|
||||
#endif
|
38
common/inc/internal/se_vendor.h
Normal file
38
common/inc/internal/se_vendor.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_VENDOR_H_
|
||||
#define _SE_VENDOR_H_
|
||||
|
||||
#define INTEL_VENDOR_ID 0x8086
|
||||
#define AE_PRODUCT_ID 0x1
|
||||
|
||||
#endif
|
32
common/inc/internal/se_version.h
Normal file
32
common/inc/internal/se_version.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#define STRFILEVER "1.5.80.33399"
|
||||
|
50
common/inc/internal/se_wrapper.h
Normal file
50
common/inc/internal/se_wrapper.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*This file wrapper all the head file that is platform dependent.
|
||||
*/
|
||||
#ifndef _SE_WRAPPER_H_
|
||||
#define _SE_WRAPPER_H_
|
||||
|
||||
#include "se_cdefs.h"
|
||||
#include "se_types.h"
|
||||
#include "se_thread.h"
|
||||
#include "se_trace.h"
|
||||
#include "se_time.h"
|
||||
#include "se_event.h"
|
||||
#include "se_rwlock.h"
|
||||
#include "se_atomic.h"
|
||||
#include "se_memcpy.h"
|
||||
#include "se_string.h"
|
||||
#include "se_stdio.h"
|
||||
|
||||
#endif
|
40
common/inc/internal/sgx_memset_s.h
Normal file
40
common/inc/internal/sgx_memset_s.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SE_MEMSET_S_H
|
||||
#define _SE_MEMSET_S_H
|
||||
#include <cstddef>
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
int memset_s(void *s, size_t smax, int c, size_t n);
|
||||
|
||||
#endif
|
104
common/inc/internal/sgx_profile.h
Normal file
104
common/inc/internal/sgx_profile.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Some notes for using the profiling macros
|
||||
|
||||
1. Define _PROFILE_ before including "sgx_profile.h" will enable the profiling,
|
||||
also need to include sgx_profile.cpp in the compiling process
|
||||
2. When use it in multi-threaded application, please don't trigger profiling in multiple threads at the same time.
|
||||
The implementation is not thread-safe now, to avoid additional latency introduced by locks
|
||||
3. PROFILE_OUTPUT macro should only be used once before application exits
|
||||
4. PROFILE_START and PROFILE_END should be paired, otherwise PROFILE_OUTPUT will abort the program when detects the mismatch
|
||||
|
||||
A simple example to use PROFILE macro
|
||||
|
||||
#define _PROFILE_
|
||||
#include "sgx_profile.h"
|
||||
|
||||
...
|
||||
PROFILE_INIT();
|
||||
...
|
||||
|
||||
PROFILE_START("func1");
|
||||
func1();
|
||||
PROFILE_END("func1");
|
||||
|
||||
...
|
||||
|
||||
PROFILE_START("func2");
|
||||
func2();
|
||||
PROFILE_END("func2");
|
||||
|
||||
...
|
||||
|
||||
PROFILE_OUTPUT("C:\\work\\output.csv");
|
||||
...
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SGX_PROFILE_H_
|
||||
#define _SGX_PROFILE_H_
|
||||
|
||||
|
||||
#if defined(_PROFILE_)
|
||||
#define PRO_START 0
|
||||
#define PRO_END 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void profile_init();
|
||||
void profile_start(const char* str); /* 'str' must be global string. Do not use string in stack. */
|
||||
void profile_end(const char * str);
|
||||
void profile_output(const char* filename);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#define PROFILE_INIT() profile_init()
|
||||
#define PROFILE_START(x) profile_start(x)
|
||||
#define PROFILE_END(x) profile_end(x)
|
||||
#define PROFILE_OUTPUT(x) profile_output(x)
|
||||
|
||||
#else
|
||||
#define PROFILE_INIT()
|
||||
#define PROFILE_START(x)
|
||||
#define PROFILE_END(x)
|
||||
#define PROFILE_OUTPUT(x)
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
40
common/inc/internal/sgx_read_rand.h
Normal file
40
common/inc/internal/sgx_read_rand.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __SGX_READ_RAND_H__
|
||||
#define __SGX_READ_RAND_H__
|
||||
#include "sgx.h"
|
||||
#include "sgx_defs.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
sgx_status_t SGXAPI sgx_read_rand(unsigned char *buf, size_t size);
|
||||
#endif
|
64
common/inc/internal/sgx_tcrypto_internal.h
Normal file
64
common/inc/internal/sgx_tcrypto_internal.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SGX_TCRYPTO_INTERNAL_H_
|
||||
#define _SGX_TCRYPTO_INTERNAL_H_
|
||||
|
||||
#include "sgx_tcrypto.h"
|
||||
|
||||
typedef struct _sgx_ec256_dh_shared512_t
|
||||
{
|
||||
uint8_t x[SGX_ECP256_KEY_SIZE];
|
||||
uint8_t y[SGX_ECP256_KEY_SIZE];
|
||||
} sgx_ec256_dh_shared512_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Computes 512-bit DH shared key based on private B key (local) and remote public Ga Key
|
||||
* Parameters:
|
||||
* Return: sgx_status_t - SGX_SUCCESS or failure as defined in sgx_error.h
|
||||
* Inputs: sgx_ecc_state_handle_t ecc_handle - Handle to the ECC crypto system
|
||||
* sgx_ec256_private_t *p_private_b - Pointer to the local private key
|
||||
* sgx_ec256_public_t *p_public_ga - Pointer to the remote public key
|
||||
* Output: sgx_ec256_dh_shared512_t *p_shared_key - Pointer to the 512-bit shared DH key
|
||||
*/
|
||||
sgx_status_t SGXAPI sgx_ecc256_compute_shared_dhkey512(sgx_ec256_private_t *p_private_b,
|
||||
sgx_ec256_public_t *p_public_ga,
|
||||
sgx_ec256_dh_shared512_t *p_shared_key,
|
||||
sgx_ecc_state_handle_t ecc_handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
61
common/inc/internal/tae_service_internal.h
Normal file
61
common/inc/internal/tae_service_internal.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _TAE_SERVICE_INTERNAL_H_
|
||||
#define _TAE_SERVICE_INTERNAL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "sgx.h"
|
||||
#include "arch.h"
|
||||
#include "sgx_tae_service.h"
|
||||
#include "pse_types.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct _se_ps_sec_prop_desc_internal
|
||||
{
|
||||
uint32_t desc_type; /* Type of this descriptor. Must be 0 */
|
||||
sgx_prod_id_t pse_prod_id; /* REPORT(PSE).ProdID */
|
||||
sgx_isv_svn_t pse_isvsvn; /* REPORT(PSE).ISVSVN */
|
||||
uint32_t pse_miscselect; /* REPORT(PSE).MISC_SELECT */
|
||||
uint32_t reserved1; /* For DESC_TYPE=0, MBZ */
|
||||
sgx_attributes_t pse_attributes; /* REPORT(PSE).ATTRIBUTES */
|
||||
sgx_measurement_t pse_mr_signer; /* REPORT(PSE).MRSIGNER */
|
||||
uint32_t reserved2[16];
|
||||
/*the following will be provided by PSE from CSE_SEC_PROP */
|
||||
cse_sec_prop_t cse_sec_prop;
|
||||
} se_ps_sec_prop_desc_internal_t;
|
||||
|
||||
se_static_assert(sizeof(se_ps_sec_prop_desc_internal_t) == sizeof(sgx_ps_sec_prop_desc_t));
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif
|
125
common/inc/internal/thread_data.h
Normal file
125
common/inc/internal/thread_data.h
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _THREAD_DATA_H_
|
||||
#define _THREAD_DATA_H_
|
||||
|
||||
#include "se_types.h"
|
||||
#include "se_cdefs.h"
|
||||
|
||||
#ifdef TD_SUPPORT_MULTI_PLATFORM
|
||||
/* To enable the SignTool to sign both 32/64-bit Enclave for ELF,
|
||||
* we need to make the struct `thread_data_t' have a consistent
|
||||
* definition for 32/64-bit compiler.
|
||||
*
|
||||
* We achieve it by forcing the compiler to check pre-defined macros
|
||||
* `RTS_SYSTEM_WORDSIZE'
|
||||
*
|
||||
* |--------------------------+-------|
|
||||
* | RTS_SYSTEM_WORDSIZE = 32 | ELF32 |
|
||||
* |--------------------------+-------|
|
||||
* | RTS_SYSTEM_WORDSIZE = 64 | ELF64 |
|
||||
*
|
||||
*/
|
||||
# ifndef RTS_SYSTEM_WORDSIZE
|
||||
# error RTS_SYSTEM_WORDSIZE should be pre-defined.
|
||||
# endif
|
||||
|
||||
/* Avoid to use `uintptr_t' in the struct `thread_data_t' and its members. */
|
||||
# if RTS_SYSTEM_WORDSIZE == 32
|
||||
typedef uint32_t sys_word_t;
|
||||
# elif RTS_SYSTEM_WORDSIZE == 64
|
||||
typedef uint64_t sys_word_t;
|
||||
# else
|
||||
# error Invalid value for 'RTS_SYSTEM_WORDSIZE'.
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
/* For uRTS, there is no need to define the macro 'TD_SUPPORT_MULTI_PLATFORM' */
|
||||
typedef size_t sys_word_t;
|
||||
|
||||
/* SE_32 and SE_64 are defined in "se_cdefs.h" */
|
||||
# ifdef SE_32
|
||||
# define RTS_SYSTEM_WORDSIZE 32
|
||||
# elif defined(SE_64)
|
||||
# define RTS_SYSTEM_WORDSIZE 64
|
||||
# else
|
||||
# error Unknown system word size.
|
||||
# endif
|
||||
|
||||
#endif /* ! TD_SUPPORT_MULTI_PLATFORM */
|
||||
|
||||
/* The data structure currently is naturally aligned regardless of the value of
|
||||
* RTS_SYSTEM_WORDSIZE.
|
||||
*
|
||||
* However, we need to take care when modifying the data structure in future.
|
||||
*/
|
||||
|
||||
typedef struct _thread_data_t
|
||||
{
|
||||
sys_word_t self_addr;
|
||||
sys_word_t last_sp; /* set by urts, relative to TCS */
|
||||
sys_word_t stack_base_addr; /* set by urts, relative to TCS */
|
||||
sys_word_t stack_limit_addr; /* set by urts, relative to TCS */
|
||||
sys_word_t first_ssa_gpr; /* set by urts, relative to TCS */
|
||||
sys_word_t stack_guard; /* GCC expects start_guard at 0x14 on x86 and 0x28 on x64 */
|
||||
|
||||
sys_word_t reserved;
|
||||
sys_word_t ssa_frame_size; /* set by urts, in pages (se_ptrace.c needs to know its offset). */
|
||||
sys_word_t last_error; /* init to be 0. Used by trts. */
|
||||
|
||||
#ifdef TD_SUPPORT_MULTI_PLATFORM
|
||||
sys_word_t m_next; /* next TD used by trusted thread library (of type "struct _thread_data *") */
|
||||
#else
|
||||
struct _thread_data_t *m_next;
|
||||
#endif
|
||||
sys_word_t tls_addr; /* points to TLS pages */
|
||||
sys_word_t tls_array; /* points to TD.tls_addr relative to TCS */
|
||||
#ifdef TD_SUPPORT_MULTI_PLATFORM
|
||||
sys_word_t exception_flag; /* mark how many exceptions are being handled */
|
||||
#else
|
||||
intptr_t exception_flag;
|
||||
#endif
|
||||
sys_word_t cxx_thread_info[6];
|
||||
} thread_data_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
thread_data_t *get_thread_data(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
70
common/inc/internal/trts_inst.h
Normal file
70
common/inc/internal/trts_inst.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _TRTS_INST_H_
|
||||
#define _TRTS_INST_H_
|
||||
|
||||
#include "sgx.h"
|
||||
|
||||
/* Attention:
|
||||
* if the following alignment requirement changes, go to selib to
|
||||
* review the memory allocation of sgx_create_report and sgx_get_key.
|
||||
*/
|
||||
#define TARGET_INFO_ALIGN_SIZE 512
|
||||
#define REPORT_DATA_ALIGN_SIZE 128
|
||||
#define REPORT_ALIGN_SIZE 512
|
||||
#define KEY_REQUEST_ALIGN_SIZE 512
|
||||
#define KEY_ALIGN_SIZE 16
|
||||
|
||||
#define BIT_ERROR(x) (1 << (x))
|
||||
|
||||
typedef enum _egetkey_status_t
|
||||
{
|
||||
EGETKEY_SUCCESS = 0,
|
||||
EGETKEY_INVALID_ATTRIBUTE = BIT_ERROR(1),
|
||||
EGETKEY_INVALID_CPUSVN = BIT_ERROR(5),
|
||||
EGETKEY_INVALID_ISVSVN = BIT_ERROR(6),
|
||||
EGETKEY_INVALID_KEYNAME = BIT_ERROR(8),
|
||||
} egetkey_status_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void do_ereport(const sgx_target_info_t *target_info, const sgx_report_data_t *report_data, sgx_report_t *report);
|
||||
int do_egetkey(const sgx_key_request_t *key_request, sgx_key_128bit_t *key);
|
||||
uint32_t do_rdrand(uint32_t *rand);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
74
common/inc/internal/uae_service_internal.h
Normal file
74
common/inc/internal/uae_service_internal.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _UAE_SERVICE_INTERNAL_H_
|
||||
#define _UAE_SERVICE_INTERNAL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "arch.h"
|
||||
#include "sgx_urts.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/**
|
||||
* Function to get launch token of a enclave
|
||||
*
|
||||
* @param signature[in] Signature of enclave to be launched.
|
||||
* @param attribute[in] Attribute of enclave to be launched.
|
||||
* @param launch_token[out] Vontains launch token.
|
||||
* @return if a launch token is generated,return SGX_SCCUESS, otherwise return general error code SGX_ERROR_SERVICE_UNAVAILABLE
|
||||
* SGX_ERROR_SERVICE_TIMEOUT, or SGX_ERROR_SERVICE_INVALID_PRIVILEGE, SGX_ERROR_INVALID_PARAMETER
|
||||
* to indicate special error condition.
|
||||
*/
|
||||
sgx_status_t SGXAPI get_launch_token(const enclave_css_t* signature, const sgx_attributes_t* attribute, sgx_launch_token_t* launch_token);
|
||||
|
||||
/* Return SGX_SUCCESS on success */
|
||||
sgx_status_t create_session_ocall(uint32_t* sid, uint8_t* dh_msg1, uint32_t dh_msg1_size, uint32_t timeout);
|
||||
|
||||
/* Return SGX_SUCCESS on success */
|
||||
sgx_status_t exchange_report_ocall(uint32_t sid, const uint8_t* dh_msg2, uint32_t dh_msg2_size, uint8_t* dh_msg3, uint32_t dh_msg3_size, uint32_t timeout);
|
||||
|
||||
/* Return SGX_SUCCESS on success */
|
||||
sgx_status_t close_session_ocall(uint32_t sid, uint32_t timeout);
|
||||
|
||||
/* Return SGX_SUCCESS on success */
|
||||
sgx_status_t invoke_service_ocall(
|
||||
const uint8_t* pse_message_req, uint32_t pse_message_req_size,
|
||||
uint8_t* pse_message_resp, uint32_t pse_message_resp_size,
|
||||
uint32_t timeout
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
47
common/inc/internal/uncopyable.h
Normal file
47
common/inc/internal/uncopyable.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _UNCOPYABLE_H_
|
||||
#define _UNCOPYABLE_H_
|
||||
|
||||
/* Similiar to boost::noncopyable */
|
||||
class Uncopyable {
|
||||
protected:
|
||||
Uncopyable() {}
|
||||
~Uncopyable() {}
|
||||
|
||||
private:
|
||||
/* Disable copying */
|
||||
Uncopyable(const Uncopyable&);
|
||||
Uncopyable& operator=(const Uncopyable&);
|
||||
};
|
||||
|
||||
#endif
|
79
common/inc/internal/util.h
Normal file
79
common/inc/internal/util.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
|
||||
#include "arch.h"
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define GET_PTR(t, p, offset) reinterpret_cast<t*>( reinterpret_cast<size_t>(p) + static_cast<size_t>(offset) )
|
||||
#define PTR_DIFF(p1, p2) ((reinterpret_cast<size_t>(p1) - reinterpret_cast<size_t>(p2)))
|
||||
#else
|
||||
#define GET_PTR(t, p, offset) (t*)( (size_t)(p) + (size_t)(offset) )
|
||||
#define PTR_DIFF(p1, p2) ((size_t)(p1) - (size_t)(p2))
|
||||
#endif
|
||||
|
||||
#define DIFF(p1, p2) (assert((size_t)(p1) >= (size_t)(p2)), ((size_t)(p1) - (size_t)(p2)))
|
||||
#define DIFF64(p1, p2) (assert((uint64_t)(p1) >= (uint64_t)(p2)), ((uint64_t)(p1) - (uint64_t)(p2)))
|
||||
|
||||
#define SE_PAGE_SHIFT 12
|
||||
#define SE_BULK_PAGE_FRAME_SHIFT 4
|
||||
#define SE_BULK_PAGE_FRAME_SIZE (1 << SE_BULK_PAGE_FRAME_SHIFT)
|
||||
#define SE_BULK_PAGE_FRAME_MASK (SE_BULK_PAGE_FRAME_SIZE-1)
|
||||
#define SE_BULK_PAGE_SHIFT (SE_PAGE_SHIFT + SE_BULK_PAGE_FRAME_SHIFT)
|
||||
#define SE_BULK_PAGE_SIZE (1 << SE_BULK_PAGE_SHIFT)
|
||||
#define SE_GUARD_PAGE_SHIFT SE_PAGE_SHIFT
|
||||
#define SE_GUARD_PAGE_SIZE SE_PAGE_SIZE
|
||||
|
||||
#define ROUND_TO(x, align) (((x) + ((align)-1)) & ~((align)-1))
|
||||
#define ROUND_TO_PAGE(x) ROUND_TO(x, SE_PAGE_SIZE)
|
||||
#define TRIM_TO_PAGE(x) ((x) & ~(SE_PAGE_SIZE-1))
|
||||
#ifdef __cplusplus
|
||||
#define PAGE_ALIGN(t, x) reinterpret_cast<t*>((reinterpret_cast<size_t>(x)+(SE_PAGE_SIZE-1)) & (~(SE_PAGE_SIZE-1)))
|
||||
#else
|
||||
#define PAGE_ALIGN(t, x) (t*)( ((size_t)(x)+(SE_PAGE_SIZE-1)) & (~(SE_PAGE_SIZE-1)) )
|
||||
#endif
|
||||
|
||||
#define IS_PAGE_ALIGNED(x) (!((size_t)(x)&(SE_PAGE_SIZE-1)))
|
||||
|
||||
#define MIN(x, y) (((x)>(y))?(y):(x))
|
||||
#define MAX(x, y) (((x)>(y))?(x):(y))
|
||||
#define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
/* used to eliminate `unused variable' warning */
|
||||
#define UNUSED(val) (void)(val)
|
||||
|
||||
#include <stddef.h>
|
||||
#define container_of(ptr, type, member) (type *)( (char *)(ptr) - offsetof(type,member) )
|
||||
|
||||
#endif
|
63
common/inc/internal/xsave.h
Normal file
63
common/inc/internal/xsave.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _XSAVE_H_
|
||||
#define _XSAVE_H_
|
||||
|
||||
#include "se_types.h"
|
||||
|
||||
|
||||
#define XSAVE_ALIGN_SIZE 64
|
||||
#define FXSAVE_ALIGN_SIZE 16
|
||||
#define FXSAVE_SIZE 528
|
||||
/* 512 + 16, the alignment is handled in internal functions */
|
||||
|
||||
#define CLEAN_XFEATURE_REGS save_and_clean_xfeature_regs(NULL);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "linux/xsave_gnu.h"
|
||||
|
||||
/* implemented in urts_xsave.cpp/trts_xsave.cpp */
|
||||
void save_and_clean_xfeature_regs(uint8_t *buffer);
|
||||
void restore_xfeature_regs(const uint8_t *buffer);
|
||||
|
||||
/* trts_xsave.cpp */
|
||||
uint64_t get_xfeature_state();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user