diff --git a/src/library_pthread.js b/src/library_pthread.js index 255c60133c54f..e2e088f07aa45 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -580,9 +580,9 @@ var LibraryPThread = { Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.detached }}} >> 2), threadParams.detached); Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.stack_size }}} >> 2), threadParams.stackSize); Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.stack }}} >> 2), stackHigh); - Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} >> 2), threadParams.stackSize); - Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 8 >> 2), stackHigh); - Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 12 >> 2), threadParams.detached); + Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 0/*_a_stacksize*/ >> 2), threadParams.stackSize); + Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 8/*_a_stackaddr*/ >> 2), stackHigh); + Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 12/*_a_detach*/ >> 2), threadParams.detached); #if PTHREADS_PROFILING PThread.createProfilerBlock(pthread.threadInfoStruct); @@ -666,7 +666,7 @@ var LibraryPThread = { // Deduce which WebGL canvases (HTMLCanvasElements or OffscreenCanvases) should be passed over to the // Worker that hosts the spawned pthread. // Comma-delimited list of CSS selectors that must identify canvases by IDs: "#canvas1, #canvas2, ..." - var transferredCanvasNames = attr ? {{{ makeGetValue('attr', 40, POINTER_TYPE) }}} : 0; + var transferredCanvasNames = attr ? {{{ makeGetValue('attr', C_STRUCTS.pthread_attr_t._a_transferredcanvases, POINTER_TYPE) }}} : 0; #if OFFSCREENCANVASES_TO_PTHREAD // Proxied canvases string pointer -1 is used as a special token to fetch // whatever canvases were passed to build in -s @@ -777,7 +777,7 @@ var LibraryPThread = { // When musl creates C11 threads it passes __ATTRP_C11_THREAD (-1) which // treat as if it was NULL. if (attr && attr != {{{ cDefine('__ATTRP_C11_THREAD') }}}) { - stackSize = {{{ makeGetValue('attr', 0, 'i32') }}}; + stackSize = {{{ makeGetValue('attr', 0/*_a_stacksize*/, 'i32') }}}; // Musl has a convention that the stack size that is stored to the pthread // attribute structure is always musl's #define DEFAULT_STACK_SIZE // smaller than the actual created stack size. That is, stored stack size @@ -787,7 +787,7 @@ var LibraryPThread = { // the pthread API. When reading the structure directly on JS side // however, we need to offset the size manually here. stackSize += {{{ cDefine('DEFAULT_STACK_SIZE') }}}; - stackBase = {{{ makeGetValue('attr', 8, 'i32') }}}; + stackBase = {{{ makeGetValue('attr', 8/*_a_stackaddr*/, 'i32') }}}; detached = {{{ makeGetValue('attr', 12/*_a_detach*/, 'i32') }}} !== 0/*PTHREAD_CREATE_JOINABLE*/; } else { // According to diff --git a/src/struct_info_internal.json b/src/struct_info_internal.json index bee9dd6ab800e..f3f6400ddf7df 100644 --- a/src/struct_info_internal.json +++ b/src/struct_info_internal.json @@ -15,6 +15,9 @@ "result", "attr" ], + "pthread_attr_t#": [ + "_a_transferredcanvases" + ], "thread_profiler_block": [ "threadStatus", "currentStatusStartTime", diff --git a/tests/reference_struct_info.json b/tests/reference_struct_info.json index 9f482cf79875e..e730df150a1a5 100644 --- a/tests/reference_struct_info.json +++ b/tests/reference_struct_info.json @@ -1334,6 +1334,10 @@ "stack_size": 76, "threadStatus": 0 }, + "pthread_attr_t": { + "__size__": 44, + "_a_transferredcanvases": 40 + }, "sockaddr": { "__size__": 16, "sa_data": 2, diff --git a/tools/gen_struct_info.py b/tools/gen_struct_info.py index 822bd2ad01618..7d5433926680b 100755 --- a/tools/gen_struct_info.py +++ b/tools/gen_struct_info.py @@ -173,7 +173,7 @@ def parse_c_output(lines): def gen_inspect_code(path, struct, code): if path[0][-1] == '#': - path[0] = path[0][:-1] + path[0] = path[0].rstrip('#') prefix = '' else: prefix = 'struct '