|
@@ -8,7 +8,7 @@
|
|
|
#include "bh_memory.h"
|
|
#include "bh_memory.h"
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
-#include <sys/time.h>
|
|
|
|
|
|
|
+#include <sgx_thread.h>
|
|
|
|
|
|
|
|
int _vm_thread_sys_init()
|
|
int _vm_thread_sys_init()
|
|
|
{
|
|
{
|
|
@@ -35,7 +35,7 @@ int _vm_thread_create(korp_tid *tid, thread_start_routine_t start, void *arg,
|
|
|
|
|
|
|
|
korp_tid _vm_self_thread()
|
|
korp_tid _vm_self_thread()
|
|
|
{
|
|
{
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return sgx_thread_self();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void vm_thread_exit(void * code)
|
|
void vm_thread_exit(void * code)
|
|
@@ -43,7 +43,7 @@ void vm_thread_exit(void * code)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// storage for one thread
|
|
// storage for one thread
|
|
|
-static void *_tls_store = NULL;
|
|
|
|
|
|
|
+static __thread void *_tls_store = NULL;
|
|
|
|
|
|
|
|
void *_vm_tls_get(unsigned idx)
|
|
void *_vm_tls_get(unsigned idx)
|
|
|
{
|
|
{
|
|
@@ -59,20 +59,22 @@ int _vm_tls_put(unsigned idx, void * tls)
|
|
|
|
|
|
|
|
int _vm_mutex_init(korp_mutex *mutex)
|
|
int _vm_mutex_init(korp_mutex *mutex)
|
|
|
{
|
|
{
|
|
|
|
|
+ sgx_thread_mutex_t m = SGX_THREAD_MUTEX_INITIALIZER;
|
|
|
|
|
+ *mutex = m;
|
|
|
return BHT_OK;
|
|
return BHT_OK;
|
|
|
- //return BHT_ERROR;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int _vm_recursive_mutex_init(korp_mutex *mutex)
|
|
int _vm_recursive_mutex_init(korp_mutex *mutex)
|
|
|
{
|
|
{
|
|
|
|
|
+ sgx_thread_mutex_t m = SGX_THREAD_RECURSIVE_MUTEX_INITIALIZER;
|
|
|
|
|
+ *mutex = m;
|
|
|
return BHT_OK;
|
|
return BHT_OK;
|
|
|
- //return BHT_ERROR;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int _vm_mutex_destroy(korp_mutex *mutex)
|
|
int _vm_mutex_destroy(korp_mutex *mutex)
|
|
|
{
|
|
{
|
|
|
|
|
+ sgx_thread_mutex_destroy(mutex);
|
|
|
return BHT_OK;
|
|
return BHT_OK;
|
|
|
- //return BHT_ERROR;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Returned error (EINVAL, EAGAIN and EDEADLK) from
|
|
/* Returned error (EINVAL, EAGAIN and EDEADLK) from
|
|
@@ -81,12 +83,12 @@ int _vm_mutex_destroy(korp_mutex *mutex)
|
|
|
Don't try to recover error for an existing unknown error.*/
|
|
Don't try to recover error for an existing unknown error.*/
|
|
|
void vm_mutex_lock(korp_mutex *mutex)
|
|
void vm_mutex_lock(korp_mutex *mutex)
|
|
|
{
|
|
{
|
|
|
|
|
+ sgx_thread_mutex_lock(mutex);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int vm_mutex_trylock(korp_mutex *mutex)
|
|
int vm_mutex_trylock(korp_mutex *mutex)
|
|
|
{
|
|
{
|
|
|
- return BHT_OK;
|
|
|
|
|
- //return BHT_ERROR;
|
|
|
|
|
|
|
+ return (sgx_thread_mutex_trylock(mutex) == 0? BHT_OK: BHT_ERROR);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Returned error (EINVAL, EAGAIN and EPERM) from
|
|
/* Returned error (EINVAL, EAGAIN and EPERM) from
|
|
@@ -95,6 +97,7 @@ int vm_mutex_trylock(korp_mutex *mutex)
|
|
|
Don't try to recover error for an existing unknown error.*/
|
|
Don't try to recover error for an existing unknown error.*/
|
|
|
void vm_mutex_unlock(korp_mutex *mutex)
|
|
void vm_mutex_unlock(korp_mutex *mutex)
|
|
|
{
|
|
{
|
|
|
|
|
+ sgx_thread_mutex_unlock(mutex);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int _vm_sem_init(korp_sem* sem, unsigned int c)
|
|
int _vm_sem_init(korp_sem* sem, unsigned int c)
|