Skip to content

Commit ceec2c0

Browse files
committed
[wasm64] Fix and run run all pthread browser tests
1 parent a0a3f24 commit ceec2c0

19 files changed

+84
-36
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ jobs:
820820
browser64.test_fetch_xhr_abort
821821
browser64.test_fetch_sync_xhr
822822
browser64.test_fetch_implicit_append
823+
browser64.test_pthread_*
823824
"
824825
test-browser-firefox:
825826
executor: bionic

src/jsifier.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,13 @@ function(${args}) {
246246
if (oneliner) {
247247
body = `return ${body}`;
248248
}
249+
const rtnType = sig && sig.length ? sig[0] : null;
250+
const proxyFunc = (MEMORY64 && rtnType == 'p') ? 'proxyToMainThreadPtr' : 'proxyToMainThread';
251+
deps.push('$' + proxyFunc);
249252
return `
250253
function(${args}) {
251254
if (ENVIRONMENT_IS_PTHREAD)
252-
return proxyToMainThread(${proxiedFunctionTable.length}, ${+sync}${args ? ', ' : ''}${args});
255+
return ${proxyFunc}(${proxiedFunctionTable.length}, ${+sync}${args ? ', ' : ''}${args});
253256
${body}
254257
}\n`
255258
});

src/library_pthread.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,15 @@ var LibraryPThread = {
948948
_exit(returnCode);
949949
},
950950
951-
$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_on_main_thread_js'],
951+
#if MEMORY64
952+
// Calls proxyToMainThread but returns a bigint rather than a number
953+
$proxyToMainThreadPtr__deps: ['$proxyToMainThread'],
954+
$proxyToMainThreadPtr: function() {
955+
return BigInt(proxyToMainThread.apply(null, arguments));
956+
},
957+
#endif
958+
959+
$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_on_main_thread_js'].concat(i53ConversionDeps),
952960
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...(number|boolean))} */',
953961
$proxyToMainThread: function(index, sync) {
954962
// Additional arguments are passed after those two, which are the actual
@@ -1032,6 +1040,19 @@ var LibraryPThread = {
10321040
PThread.currentProxiedOperationCallerThread = callingThread;
10331041
var rtn = func.apply(null, proxiedJSCallArgs);
10341042
PThread.currentProxiedOperationCallerThread = 0;
1043+
#if MEMORY64
1044+
// In memory64 mode some proxied functions return bigint/pointer but
1045+
// our return type is i53/double.
1046+
if (typeof rtn == "bigint") {
1047+
rtn = bigintToI53Checked(rtn);
1048+
}
1049+
#endif
1050+
#if ASSERTIONS
1051+
// Proxied functions can return any type except bigint. All other types
1052+
// cooerce to f64/double (the return type of this function in C) but not
1053+
// bigint.
1054+
assert(typeof rtn != "bigint");
1055+
#endif
10351056
return rtn;
10361057
},
10371058

src/preamble_minimal.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ if (!ENVIRONMENT_IS_PTHREAD) {
100100
Module['mem'] ||
101101
#endif
102102
new WebAssembly.Memory({
103-
'initial': {{{ INITIAL_MEMORY >>> 16 }}}
103+
'initial': {{{ INITIAL_MEMORY >>> 16 }}},
104104
#if SHARED_MEMORY || !ALLOW_MEMORY_GROWTH || MAXIMUM_MEMORY != FOUR_GB
105-
, 'maximum': {{{ (ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != FOUR_GB ? MAXIMUM_MEMORY : INITIAL_MEMORY) >>> 16 }}}
105+
'maximum': {{{ (ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != FOUR_GB ? MAXIMUM_MEMORY : INITIAL_MEMORY) >>> 16 }}},
106106
#endif
107107
#if SHARED_MEMORY
108-
, 'shared': true
108+
'shared': true,
109+
#endif
110+
#if MEMORY64 == 1
111+
'index': 'i64',
109112
#endif
110113
});
111114
#if PTHREADS

test/common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ def no_windows(note=''):
169169
return lambda f: f
170170

171171

172+
def no_wasm64(note=''):
173+
assert not callable(note)
174+
175+
def decorated(f):
176+
return skip_if(f, 'is_wasm64', note)
177+
return decorated
178+
179+
172180
def only_windows(note=''):
173181
assert not callable(note)
174182
if not WINDOWS:
@@ -574,6 +582,9 @@ def is_wasm(self):
574582
def is_browser_test(self):
575583
return False
576584

585+
def is_wasm64(self):
586+
return self.get_setting('MEMORY64')
587+
577588
def check_dylink(self):
578589
if self.get_setting('ALLOW_MEMORY_GROWTH') == 1 and not self.is_wasm():
579590
self.skipTest('no dynamic linking with memory growth (without wasm)')

test/pthread/call_sync_on_main_thread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ addToLibrary({
33
// This function returns the inner text of the given element
44
// Because it accesses the DOM, it must be called on the main thread.
55
getDomElementContents__proxy: 'sync',
6-
getDomElementContents__sig: 'viii',
6+
getDomElementContents__sig: 'pp',
77
getDomElementContents__deps: ['$stringToNewUTF8'],
88
getDomElementContents: function(domElementSelector) {
99
var selector = UTF8ToString(domElementSelector);

test/pthread/test_futex_wake_all.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void *WaitingThread(void *arg)
5757

5858
int main()
5959
{
60-
for(int i = 0; i < NUM_THREADS; ++i)
60+
for(intptr_t i = 0; i < NUM_THREADS; ++i)
6161
{
6262
pthread_create(waitingThreads+i, 0, WaitingThread, (void*)i);
6363
}

test/pthread/test_large_pthread_allocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void *thread_start(void *arg)
2121
pthread_exit((void*)0);
2222
}
2323

24-
void CreateThread(int idx) {
24+
void CreateThread(intptr_t idx) {
2525
int rc = pthread_create(&threads[idx], NULL, thread_start, (void*)idx);
2626
assert(rc == 0);
2727
}

test/pthread/test_pthread_barrier.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void *thread_main(void *arg)
4444
}
4545

4646
// Then each thread sums the one intermediate vector.
47-
int totalSum = 0;
47+
intptr_t totalSum = 0;
4848
for(int i = 0; i < N; ++i)
4949
totalSum += intermediate[i];
5050

@@ -70,9 +70,10 @@ int main(int argc, char **argv)
7070
int ret = pthread_barrier_init(&barr, NULL, THREADS);
7171
assert(ret == 0);
7272

73-
for(int i = 0; i < THREADS; ++i) pthread_create(&thr[i], NULL, &thread_main, (void*)i);
74-
for(int i = 0; i < THREADS; ++i)
75-
{
73+
for (intptr_t i = 0; i < THREADS; ++i) {
74+
pthread_create(&thr[i], NULL, &thread_main, (void*)i);
75+
}
76+
for(int i = 0; i < THREADS; ++i) {
7677
int totalSum = 0;
7778
pthread_join(thr[i], (void**)&totalSum);
7879
assert(totalSum == expectedTotalSum);

test/pthread/test_pthread_cancel_cond_wait.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ volatile int res = 43;
2222

2323
static void cleanup_handler(void *arg) {
2424
emscripten_log(EM_LOG_CONSOLE, "Called clean-up handler with arg %p", arg);
25-
int a = reinterpret_cast<int>(arg);
25+
int a = reinterpret_cast<intptr_t>(arg);
2626
res -= a;
2727

2828
pthread_mutex_unlock(&mutex);

0 commit comments

Comments
 (0)