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
82
83
84
85
86
87
88
89
90
91
|
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "platform_api_vmcore.h"
#include "sgx_pthread.h"
#include "sgx_error.h"
#ifndef SGX_DISABLE_WASI
#define TRACE_FUNC() os_printf("undefined %s\n", __FUNCTION__)
#define TRACE_OCALL_FAIL() os_printf("ocall %s failed!\n", __FUNCTION__)
#ifndef SGX_THREAD_LOCK_INITIALIZER /* defined since sgxsdk-2.11 */
/* sgxsdk doesn't support pthread_rwlock related APIs until
version 2.11, we implement them by ourselves. */
int
ocall_pthread_rwlock_init(int *p_ret, void **rwlock, void *attr);
int
ocall_pthread_rwlock_destroy(int *p_ret, void **rwlock);
int
ocall_pthread_rwlock_rdlock(int *p_ret, void **rwlock);
int
ocall_pthread_rwlock_wrlock(int *p_ret, void **rwlock);
int
ocall_pthread_rwlock_unlock(int *p_ret, void **rwlock);
int
pthread_rwlock_init(pthread_rwlock_t *rwlock, void *attr)
{
int ret = -1;
if (ocall_pthread_rwlock_init(&ret, (void **)rwlock, NULL) != SGX_SUCCESS) {
TRACE_OCALL_FAIL();
return -1;
}
(void)attr;
return ret;
}
int
pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
{
int ret = -1;
if (ocall_pthread_rwlock_destroy(&ret, (void *)*rwlock) != SGX_SUCCESS) {
TRACE_OCALL_FAIL();
}
return ret;
}
int
pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
{
int ret = -1;
if (ocall_pthread_rwlock_rdlock(&ret, (void *)*rwlock) != SGX_SUCCESS) {
TRACE_OCALL_FAIL();
}
return ret;
}
int
pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
{
int ret = -1;
if (ocall_pthread_rwlock_wrlock(&ret, (void *)*rwlock) != SGX_SUCCESS) {
TRACE_OCALL_FAIL();
}
return ret;
}
int
pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
{
int ret = -1;
if (ocall_pthread_rwlock_unlock(&ret, (void *)*rwlock) != SGX_SUCCESS) {
TRACE_OCALL_FAIL();
}
return ret;
}
#endif /* end of SGX_THREAD_LOCK_INITIALIZER */
#endif
|