forked from openenclave/openenclave
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemory.c
43 lines (36 loc) · 1.43 KB
/
memory.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) Open Enclave SDK contributors.
// Licensed under the MIT License.
#include <openenclave/enclave.h>
#include <openenclave/internal/globals.h>
bool oe_is_within_enclave(const void* p, size_t n)
{
uint64_t range_start = (uint64_t)p;
uint64_t range_end = range_start + (n == 0 ? 1 : n);
uint64_t enclave_start = (uint64_t)__oe_get_enclave_start_address();
uint64_t enclave_end = enclave_start + __oe_get_enclave_size();
// Disallow nullptr and check that arithmetic operations do not wrap
// Check that block lies completely within the enclave
if ((range_start > 0) && (range_end > range_start) &&
(enclave_end > enclave_start) &&
((range_start >= enclave_start) && (range_end <= enclave_end)))
{
return true;
}
return false;
}
bool oe_is_outside_enclave(const void* p, size_t n)
{
uint64_t range_start = (uint64_t)p;
uint64_t range_end = range_start + (n == 0 ? 1 : n);
uint64_t enclave_start = (uint64_t)__oe_get_enclave_start_address();
uint64_t enclave_end = enclave_start + __oe_get_enclave_size();
// Disallow nullptr and check that arithmetic operations do not wrap
// Check that block lies completely outside the enclave
if ((range_start > 0) && (range_end > range_start) &&
(enclave_end > enclave_start) &&
((range_end <= enclave_start) || (range_start >= enclave_end)))
{
return true;
}
return false;
}