[Partial] Build wasi-libc for Windows (#2338)
Build wasi-libc library on Windows since libuv may be not supported. This PR is a first step to make it working, but there's still a number of changes to get it fully working.
This commit is contained in:
@ -56,6 +56,7 @@ typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
typedef pthread_cond_t korp_cond;
|
||||
typedef pthread_t korp_thread;
|
||||
typedef pthread_rwlock_t korp_rwlock;
|
||||
typedef sem_t korp_sem;
|
||||
|
||||
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
@ -326,6 +326,61 @@ os_cond_broadcast(korp_cond *cond)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_init(korp_rwlock *lock)
|
||||
{
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_init(lock, NULL) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_rdlock(korp_rwlock *lock)
|
||||
{
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_rdlock(lock) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_wrlock(korp_rwlock *lock)
|
||||
{
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_wrlock(lock) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_unlock(korp_rwlock *lock)
|
||||
{
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_unlock(lock) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_destroy(korp_rwlock *lock)
|
||||
{
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_destroy(lock) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_thread_join(korp_tid thread, void **value_ptr)
|
||||
{
|
||||
|
||||
@ -58,6 +58,7 @@ typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
typedef pthread_cond_t korp_cond;
|
||||
typedef pthread_t korp_thread;
|
||||
typedef pthread_rwlock_t korp_rwlock;
|
||||
typedef sem_t korp_sem;
|
||||
|
||||
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
@ -39,6 +39,7 @@ typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
typedef pthread_cond_t korp_cond;
|
||||
typedef pthread_t korp_thread;
|
||||
typedef pthread_rwlock_t korp_rwlock;
|
||||
typedef unsigned int korp_sem;
|
||||
|
||||
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
@ -57,6 +57,7 @@ typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
typedef pthread_cond_t korp_cond;
|
||||
typedef pthread_t korp_thread;
|
||||
typedef pthread_rwlock_t korp_rwlock;
|
||||
typedef sem_t korp_sem;
|
||||
|
||||
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
@ -238,6 +238,56 @@ os_cond_signal(korp_cond *cond);
|
||||
int
|
||||
os_cond_broadcast(korp_cond *cond);
|
||||
|
||||
/**
|
||||
* Initialize readwrite lock object
|
||||
*
|
||||
* @param cond [OUTPUT] pointer to a lock object variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int
|
||||
os_rwlock_init(korp_rwlock *lock);
|
||||
|
||||
/**
|
||||
* Acquire the read lock
|
||||
*
|
||||
* @param lock lock variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int
|
||||
os_rwlock_rdlock(korp_rwlock *lock);
|
||||
|
||||
/**
|
||||
* Acquire the write lock
|
||||
*
|
||||
* @param lock lock variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int
|
||||
os_rwlock_wrlock(korp_rwlock *lock);
|
||||
|
||||
/**
|
||||
* Unlocks the lock object
|
||||
*
|
||||
* @param lock lock variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int
|
||||
os_rwlock_unlock(korp_rwlock *lock);
|
||||
|
||||
/**
|
||||
* Destroy a lock object
|
||||
*
|
||||
* @param lock lock variable
|
||||
*
|
||||
* @return 0 if success
|
||||
*/
|
||||
int
|
||||
os_rwlock_destroy(korp_rwlock *lock);
|
||||
|
||||
/**
|
||||
* Creates a new POSIX-like semaphore or opens an existing
|
||||
* semaphore. The semaphore is identified by name. For details of
|
||||
|
||||
@ -50,6 +50,7 @@ typedef pthread_t korp_thread;
|
||||
typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
typedef pthread_cond_t korp_cond;
|
||||
typedef pthread_rwlock_t korp_rwlock;
|
||||
typedef unsigned int korp_sem;
|
||||
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
|
||||
@ -210,3 +210,68 @@ os_thread_get_stack_boundary()
|
||||
/* TODO: get sgx stack boundary */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_init(korp_rwlock *lock)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_init(lock, NULL) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
#endif
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_rdlock(korp_rwlock *lock)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_rdlock(lock) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
#endif
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_wrlock(korp_rwlock *lock)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_wrlock(lock) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
#endif
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_unlock(korp_rwlock *lock)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_unlock(lock) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
#endif
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_destroy(korp_rwlock *lock)
|
||||
{
|
||||
#ifndef SGX_DISABLE_PTHREAD
|
||||
assert(lock);
|
||||
|
||||
if (pthread_rwlock_destroy(lock) != BHT_OK)
|
||||
return BHT_ERROR;
|
||||
#endif
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
typedef pthread_cond_t korp_cond;
|
||||
typedef pthread_t korp_thread;
|
||||
typedef pthread_rwlock_t korp_rwlock;
|
||||
typedef sem_t korp_sem;
|
||||
|
||||
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
@ -41,6 +41,7 @@ typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
typedef pthread_cond_t korp_cond;
|
||||
typedef pthread_t korp_thread;
|
||||
typedef pthread_rwlock_t korp_rwlock;
|
||||
typedef sem_t korp_sem;
|
||||
|
||||
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
@ -54,6 +54,7 @@ typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
typedef pthread_cond_t korp_cond;
|
||||
typedef pthread_t korp_thread;
|
||||
typedef pthread_rwlock_t korp_rwlock;
|
||||
typedef sem_t korp_sem;
|
||||
|
||||
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
@ -57,6 +57,11 @@ typedef void *korp_tid;
|
||||
typedef void *korp_mutex;
|
||||
typedef void *korp_sem;
|
||||
|
||||
typedef struct {
|
||||
SRWLOCK lock;
|
||||
bool exclusive;
|
||||
} korp_rwlock;
|
||||
|
||||
/**
|
||||
* Create the mutex when os_mutex_lock is called, and no need to
|
||||
* CloseHandle() for the static lock's lifetime, since
|
||||
|
||||
@ -206,6 +206,14 @@ os_socket_inet_network(bool is_ipv4, const char *cp, bh_ip_addr_buffer_t *out)
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_socket_connect(bh_socket_t socket, const char *addr, int port)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
|
||||
return BHT_ERROR;
|
||||
}
|
||||
|
||||
int
|
||||
os_socket_addr_resolve(const char *host, const char *service,
|
||||
uint8_t *hint_is_tcp, uint8_t *hint_is_ipv4,
|
||||
|
||||
@ -541,6 +541,62 @@ os_mutex_unlock(korp_mutex *mutex)
|
||||
return ReleaseMutex(*mutex) ? BHT_OK : BHT_ERROR;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_init(korp_rwlock *lock)
|
||||
{
|
||||
bh_assert(lock);
|
||||
|
||||
InitializeSRWLock(&(lock->lock));
|
||||
lock->exclusive = false;
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_rdlock(korp_rwlock *lock)
|
||||
{
|
||||
bh_assert(lock);
|
||||
|
||||
AcquireSRWLockShared(&(lock->lock));
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_wrlock(korp_rwlock *lock)
|
||||
{
|
||||
bh_assert(lock);
|
||||
|
||||
AcquireSRWLockExclusive(&(lock->lock));
|
||||
lock->exclusive = true;
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_unlock(korp_rwlock *lock)
|
||||
{
|
||||
bh_assert(lock);
|
||||
|
||||
if (lock->exclusive) {
|
||||
lock->exclusive = false;
|
||||
ReleaseSRWLockExclusive(&(lock->lock));
|
||||
}
|
||||
else {
|
||||
ReleaseSRWLockShared(&(lock->lock));
|
||||
}
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_rwlock_destroy(korp_rwlock *lock)
|
||||
{
|
||||
(void)lock;
|
||||
|
||||
return BHT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
os_cond_init(korp_cond *cond)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user