encl.c 1.0 KB
Newer Older
1 2 3 4 5
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
// Copyright(c) 2016-18 Intel Corporation.

#include <stddef.h>
#include "defines.h"
6 7
#include "arch.h"
#include "sgx_call.h"
8 9 10 11 12 13 14 15 16 17 18

static void *memcpy(void *dest, const void *src, size_t n)
{
	size_t i;

	for (i = 0; i < n; i++)
		((char *)dest)[i] = ((char *)src)[i];

	return dest;
}

19
static int encl_init(void *dst)
20
{
21 22 23 24 25
	static uint64_t magic = INIT_MAGIC;

	memcpy(dst, &magic, 8);

	return 0;
26
}
27

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
static int encl_get_report(const struct sgx_target_info *target_info,
			   const uint8_t *report_data,
			   struct sgx_report *report)
{
	struct sgx_target_info ti;
	memcpy(&ti, target_info, SGX_TARGET_INFO_SIZE);

	struct sgx_report_data rd;
	memcpy(&rd, report_data, SGX_REPORT_DATA_SIZE);

	struct sgx_report r;

	asm volatile(
		ENCLU "\n\t"
		:: "a" (EREPORT), "b" (&ti), "c" (&rd), "d" (&r)
		: "memory"
	);

	memcpy(report, &r, SGX_REPORT_SIZE);

	return 0;
}

51
unsigned long enclave_call_table[MAX_ECALLS] = {
52 53
	(unsigned long)encl_init,
	(unsigned long)encl_get_report,
54
};