Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Platforms/emscripten/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ await createEmscriptenModule({

- Threading is disabled by default. The ``configure`` option
``--enable-wasm-pthreads`` adds compiler flag ``-pthread`` and
linker flags ``-sUSE_PTHREADS -sPROXY_TO_PTHREAD``.
linker flags ``-pthread -sPROXY_TO_PTHREAD``.
- pthread support requires WASM threads and SharedArrayBuffer (bulk memory).
The Node.JS runtime keeps a pool of web workers around. Each web worker
uses several file descriptors (eventfd, epoll, pipe).
Expand Down
64 changes: 0 additions & 64 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,70 +70,6 @@ _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int margin_count)
# define Py_C_STACK_SIZE 4000000
#endif

#if defined(__EMSCRIPTEN__)

// Temporary workaround to make `pthread_getattr_np` work on Emscripten.
// Emscripten 4.0.6 will contain a fix:
// https://github.com/emscripten-core/emscripten/pull/23887

#include "emscripten/stack.h"

#define pthread_attr_t workaround_pthread_attr_t
#define pthread_attr_init workaround_pthread_attr_init
#define pthread_getattr_np workaround_pthread_getattr_np
#define pthread_attr_getguardsize workaround_pthread_attr_getguardsize
#define pthread_attr_getstack workaround_pthread_attr_getstack
#define pthread_attr_destroy workaround_pthread_attr_destroy

typedef struct {
void *_a_stackaddr;
size_t _a_stacksize, _a_guardsize;
} pthread_attr_t;

extern __attribute__((__visibility__("hidden"))) unsigned __default_guardsize;

int pthread_attr_init(pthread_attr_t *a)
{
return 0;
}

// Modified version of pthread_getattr_np from the upstream PR.

int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr) {
attr->_a_stackaddr = (void*)emscripten_stack_get_base();
attr->_a_stacksize = emscripten_stack_get_base() - emscripten_stack_get_end();
attr->_a_guardsize = __default_guardsize;
return 0;
}

// These three functions copied without any changes from Emscripten libc.

int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size)
{
*size = a->_a_guardsize;
return 0;
}

int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size)
{
/// XXX musl is not standard-conforming? It should not report EINVAL if _a_stackaddr is zero, and it should
/// report EINVAL if a is null: http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_attr_getstack.html
if (!a) return EINVAL;
// if (!a->_a_stackaddr)
// return EINVAL;

*size = a->_a_stacksize;
*addr = (void *)(a->_a_stackaddr - *size);
return 0;
}

int pthread_attr_destroy(pthread_attr_t *a)
{
return 0;
}

#endif

static void
hardware_stack_limits(uintptr_t *base, uintptr_t *top, uintptr_t sp)
{
Expand Down
6 changes: 3 additions & 3 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1153,12 +1153,12 @@ if test -z "$CFLAGS"; then
fi

dnl Emscripten SDK and WASI SDK default to wasm32.
dnl On Emscripten use MEMORY64 setting to build target wasm64-emscripten.
dnl On Emscripten use -m64 to build target wasm64-emscripten.
dnl for wasm64.
AS_CASE([$host],
[wasm64-*-emscripten], [
AS_VAR_APPEND([CFLAGS], [" -sMEMORY64=1"])
AS_VAR_APPEND([LDFLAGS], [" -sMEMORY64=1"])
AS_VAR_APPEND([CFLAGS], [" -m64"])
AS_VAR_APPEND([LDFLAGS], [" -m64"])
],
)

Expand Down Expand Up @@ -2659,7 +2659,7 @@ AS_CASE([$ac_sys_system],
AS_VAR_IF([enable_wasm_pthreads], [yes], [
AS_VAR_APPEND([CFLAGS_NODIST], [" -pthread"])
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sUSE_PTHREADS"])
AS_VAR_APPEND([LDFLAGS_NODIST], [" -pthread"])
AS_VAR_APPEND([LINKFORSHARED], [" -sPROXY_TO_PTHREAD"])
])
dnl not completely sure whether or not we want -sEXIT_RUNTIME, keeping it for now.
Expand Down
Loading