File threads.cpp

namespace wasm

SYSCALL NUMBERING

Have a look in the sysroot at include/bits/syscall.h to determine the system call numbering.

Functions

void threadsLink()
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_create", I32, pthread_create, I32 pthreadPtr, I32 attrPtr, I32 entryFunc, I32 argsPtr)

We intercept the pthread API at a high level, hence we control the whole lifecycle. For this reason, we mostly ignore the contents of the pthread struct and pthread attrs.

We just use the int value of the pthread pointer to act as its ID (to be passed around the different pthread functions).

In the “chain” threading mode, we spawn threads as chained function calls, which may get executed on another host. To enable this we create a zygote from which these “thread” calls can be spawned on another host.

Parameters
  • pthreadPtr – - pointer to the pthread struct

  • attrPtr – - pointer to the pthread attr struct

  • entryFunc – - function table index for the entrypoint

  • argsPtr – - args pointer for the function

WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_join", I32, pthread_join, I32 pthreadPtr, I32 resPtrPtr)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_exit", void, pthread_exit, I32 code)
I32 s__futex(I32 uaddrPtr, I32 futex_op, I32 val, I32 timeoutPtr, I32 uaddr2Ptr, I32 other)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_mutex_init", I32, pthread_mutex_init, I32 mx, I32 attr)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_mutex_lock", I32, pthread_mutex_lock, I32 mx)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_mutex_trylock", I32, s__pthread_mutex_trylock, I32 mx)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_mutex_unlock", I32, pthread_mutex_unlock, I32 mx)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_mutex_destroy", I32, pthread_mutex_destroy, I32 mx)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_mutexattr_init", I32, pthread_mutexattr_init, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_mutexattr_destroy", I32, pthread_mutexattr_destroy, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_cond_init", I32, pthread_cond_init, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_cond_signal", I32, pthread_cond_signal, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_self", I32, pthread_self)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_key_create", I32, s__pthread_key_create, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_key_delete", I32, s__pthread_key_delete, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_getspecific", I32, s__pthread_getspecific, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_setspecific", I32, s__pthread_setspecific, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_cond_destroy", I32, pthread_cond_destroy, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_cond_broadcast", I32, pthread_cond_broadcast, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_equal", I32, pthread_equal, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_cond_timedwait", I32, pthread_cond_timedwait, I32 a, I32 b, I32 c)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_cond_wait", I32, pthread_cond_wait, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_attr_init", I32, s__pthread_attr_init, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_attr_setstacksize", I32, s__pthread_attr_setstacksize, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_attr_destroy", I32, s__pthread_attr_destroy, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_detach", I32, s__pthread_detach, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "pthread_once", I32, s__pthread_once, I32 a, I32 b)