forked from openenclave/openenclave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoe_host_stdlib.h
81 lines (64 loc) · 1.42 KB
/
oe_host_stdlib.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) Open Enclave SDK contributors.
// Licensed under the MIT License.
#ifndef _OE_HOST_STDLIB_H
#define _OE_HOST_STDLIB_H
#include <errno.h>
#include <openenclave/bits/defs.h>
#include <openenclave/bits/types.h>
#include <stdlib.h>
#include <string.h>
#if defined(_MSC_VER)
#include <errno.h>
#include <malloc.h>
#include <openenclave/internal/utils.h>
#include "../host/memalign.h"
#endif
OE_EXTERNC_BEGIN
OE_INLINE
void* oe_malloc(size_t size)
{
return malloc(size);
}
OE_INLINE
void oe_free(void* ptr)
{
free(ptr);
}
OE_INLINE
void* oe_calloc(size_t nmemb, size_t size)
{
return calloc(nmemb, size);
}
OE_INLINE
void* oe_realloc(void* ptr, size_t size)
{
return realloc(ptr, size);
}
/* oe_memalign & oe_memalign_free have implementations on the host side. */
OE_INLINE
int oe_posix_memalign(void** memptr, size_t alignment, size_t size)
{
#if defined(_MSC_VER)
if (!memptr)
return EINVAL;
if (!oe_is_ptrsize_multiple(alignment) || !oe_is_pow2(alignment))
return EINVAL;
if (!(*memptr = oe_memalign(alignment, size)))
return ENOMEM;
return 0;
#else
return posix_memalign(memptr, alignment, size);
#endif
}
OE_INLINE
unsigned long int oe_strtoul(const char* nptr, char** endptr, int base)
{
return strtoul(nptr, endptr, base);
}
OE_INLINE
int oe_atexit(void (*function)(void))
{
return atexit(function);
}
OE_EXTERNC_END
#endif /* _OE_HOST_STDLIB_H */