Skip to content

Commit ac75bb0

Browse files
authored
[Wasm64] Check argument names in convertPointerParams. NFC (#19039)
Without this `convertPointerParams` will silently generate invalid output.
1 parent 676ef72 commit ac75bb0

File tree

7 files changed

+55
-43
lines changed

7 files changed

+55
-43
lines changed

src/jsifier.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function runJSify() {
8787
}
8888
}
8989

90-
function convertPointerParams(snippet, sig) {
90+
function convertPointerParams(symbol, snippet, sig) {
9191
// Automatically convert any incoming pointer arguments from BigInt
9292
// to double (this limits the range to int53).
9393
// And convert the return value if the function returns a pointer.
@@ -99,6 +99,10 @@ function runJSify() {
9999
let argConvertions = '';
100100
for (let i = 1; i < sig.length; i++) {
101101
const name = argNames[i - 1];
102+
if (!name) {
103+
error(`convertPointerParams: missing name for argument ${i} in ${symbol}`);
104+
return snippet;
105+
}
102106
if (sig[i] == 'p') {
103107
argConvertions += ` ${name} = Number(${name});\n`;
104108
newArgs.push(`Number(${name})`);
@@ -182,7 +186,7 @@ function ${name}(${args}) {
182186
if (MEMORY64) {
183187
const sig = LibraryManager.library[symbol + '__sig'];
184188
if (sig && sig.includes('p')) {
185-
snippet = convertPointerParams(snippet, sig);
189+
snippet = convertPointerParams(symbol, snippet, sig);
186190
}
187191
}
188192

src/library_async.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,13 @@ mergeInto(LibraryManager.library, {
647647
emscripten_sleep: function() {
648648
throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_sleep';
649649
},
650-
emscripten_wget: function() {
650+
emscripten_wget: function(url, file) {
651651
throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_wget';
652652
},
653-
emscripten_wget_data: function() {
653+
emscripten_wget_data: function(url, pbuffer, pnum, perror) {
654654
throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_wget_data';
655655
},
656-
emscripten_scan_registers: function() {
656+
emscripten_scan_registers: function(func) {
657657
throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_scan_registers';
658658
},
659659
emscripten_fiber_init: function() {
@@ -662,7 +662,7 @@ mergeInto(LibraryManager.library, {
662662
emscripten_fiber_init_from_current_context: function() {
663663
throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_fiber_init_from_current_context';
664664
},
665-
emscripten_fiber_swap: function() {
665+
emscripten_fiber_swap: function(oldFiber, newFiber) {
666666
throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_fiber_swap';
667667
},
668668
#endif // ASYNCIFY

src/library_idbstore.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ var LibraryIDBStore = {
157157
IDBStore.blobs[blobId] = null;
158158
},
159159
#else
160-
emscripten_idb_load: function() {
160+
emscripten_idb_load: function(db, id, pbuffer, pnum, perror) {
161161
throw 'Please compile your program with async support in order to use synchronous operations like emscripten_idb_load, etc.';
162162
},
163-
emscripten_idb_store: function() {
163+
emscripten_idb_store: function(db, id, ptr, num, perror) {
164164
throw 'Please compile your program with async support in order to use synchronous operations like emscripten_idb_store, etc.';
165165
},
166-
emscripten_idb_delete: function() {
166+
emscripten_idb_delete: function(db, id, perror) {
167167
throw 'Please compile your program with async support in order to use synchronous operations like emscripten_idb_delete, etc.';
168168
},
169-
emscripten_idb_exists: function() {
169+
emscripten_idb_exists: function(db, id, pexists, perror) {
170170
throw 'Please compile your program with async support in order to use synchronous operations like emscripten_idb_exists, etc.';
171171
},
172172
#endif // ASYNCIFY

src/library_sdl.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ var LibrarySDL = {
18431843
return SDL.errorMessage;
18441844
},
18451845

1846-
SDL_SetError: function() {},
1846+
SDL_SetError: function(fmt, varargs) {},
18471847

18481848
SDL_CreateRGBSurface__deps: ['malloc', 'free'],
18491849
SDL_CreateRGBSurface__proxy: 'sync',
@@ -2657,14 +2657,14 @@ var LibrarySDL = {
26572657
SDL_UnlockAudio: function() {},
26582658

26592659
SDL_CreateMutex: function() { return 0 },
2660-
SDL_mutexP: function() { return 0 },
2661-
SDL_mutexV: function() { return 0 },
2662-
SDL_DestroyMutex: function() {},
2660+
SDL_mutexP: function(mutex) { return 0 },
2661+
SDL_mutexV: function(mutex) { return 0 },
2662+
SDL_DestroyMutex: function(mutex) {},
26632663

26642664
SDL_CreateCond: function() { return 0 },
2665-
SDL_CondSignal: function() {},
2666-
SDL_CondWait: function() {},
2667-
SDL_DestroyCond: function() {},
2665+
SDL_CondSignal: function(cond) {},
2666+
SDL_CondWait: function(cond, mutex) {},
2667+
SDL_DestroyCond: function(cond) {},
26682668

26692669
SDL_StartTextInput__proxy: 'sync',
26702670
SDL_StartTextInput__sig: 'v',
@@ -3716,30 +3716,30 @@ var LibrarySDL = {
37163716
},
37173717

37183718
// TODO:
3719-
SDL_CreateThread: function() {
3719+
SDL_CreateThread: function(fs, data, pfnBeginThread, pfnEndThread) {
37203720
throw 'SDL threads cannot be supported in the web platform because they assume shared state. See emscripten_create_worker etc. for a message-passing concurrency model that does let you run code in another thread.'
37213721
},
37223722

3723-
SDL_WaitThread: function() { throw 'SDL_WaitThread' },
3724-
SDL_GetThreadID: function() { throw 'SDL_GetThreadID' },
3723+
SDL_WaitThread: function(thread, status) { throw 'SDL_WaitThread' },
3724+
SDL_GetThreadID: function(thread) { throw 'SDL_GetThreadID' },
37253725
SDL_ThreadID: function() { return 0; },
37263726
SDL_AllocRW: function() { throw 'SDL_AllocRW: TODO' },
3727-
SDL_CondBroadcast: function() { throw 'SDL_CondBroadcast: TODO' },
3728-
SDL_CondWaitTimeout: function() { throw 'SDL_CondWaitTimeout: TODO' },
3727+
SDL_CondBroadcast: function(cond) { throw 'SDL_CondBroadcast: TODO' },
3728+
SDL_CondWaitTimeout: function(cond, mutex, ms) { throw 'SDL_CondWaitTimeout: TODO' },
37293729
SDL_WM_IconifyWindow: function() { throw 'SDL_WM_IconifyWindow TODO' },
37303730

3731-
Mix_SetPostMix: function() { warnOnce('Mix_SetPostMix: TODO') },
3731+
Mix_SetPostMix: function(func, arg) { warnOnce('Mix_SetPostMix: TODO') },
37323732

37333733
Mix_VolumeChunk: function(chunk, volume) { throw 'Mix_VolumeChunk: TODO' },
37343734
Mix_SetPosition: function(channel, angle, distance) { throw 'Mix_SetPosition: TODO' },
3735-
Mix_QuerySpec: function() { throw 'Mix_QuerySpec: TODO' },
3736-
Mix_FadeInChannelTimed: function() { throw 'Mix_FadeInChannelTimed' },
3735+
Mix_QuerySpec: function(frequency, format, channels) { throw 'Mix_QuerySpec: TODO' },
3736+
Mix_FadeInChannelTimed: function(channel, chunk, loop, ms, ticks) { throw 'Mix_FadeInChannelTimed' },
37373737
Mix_FadeOutChannel: function() { throw 'Mix_FadeOutChannel' },
37383738

37393739
Mix_Linked_Version: function() { throw 'Mix_Linked_Version: TODO' },
3740-
SDL_SaveBMP_RW: function() { throw 'SDL_SaveBMP_RW: TODO' },
3740+
SDL_SaveBMP_RW: function(surface, dst, freedst) { throw 'SDL_SaveBMP_RW: TODO' },
37413741

3742-
SDL_WM_SetIcon: function() { /* This function would set the application window icon surface, which doesn't apply for web canvases, so a no-op. */ },
3742+
SDL_WM_SetIcon: function(icon, mask) { /* This function would set the application window icon surface, which doesn't apply for web canvases, so a no-op. */ },
37433743
SDL_HasRDTSC: function() { return 0; },
37443744
SDL_HasMMX: function() { return 0; },
37453745
SDL_HasMMXExt: function() { return 0; },

src/library_syscall.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ var SyscallsLibrary = {
305305
return sock.stream.fd;
306306
},
307307
__syscall_getsockname__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'],
308-
__syscall_getsockname: function(fd, addr, addrlen) {
308+
__syscall_getsockname: function(fd, addr, addrlen, d1, d2, d3) {
309309
err("__syscall_getsockname " + fd);
310310
var sock = getSocketFromFD(fd);
311311
// TODO: sock.saddr should never be undefined, see TODO in websocket_sock_ops.getname
@@ -316,7 +316,7 @@ var SyscallsLibrary = {
316316
return 0;
317317
},
318318
__syscall_getpeername__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'],
319-
__syscall_getpeername: function(fd, addr, addrlen) {
319+
__syscall_getpeername: function(fd, addr, addrlen, d1, d2, d3) {
320320
var sock = getSocketFromFD(fd);
321321
if (!sock.daddr) {
322322
return -{{{ cDefs.ENOTCONN }}}; // The socket is not connected.
@@ -341,7 +341,7 @@ var SyscallsLibrary = {
341341
return -{{{ cDefs.ENOSYS }}}; // unsupported feature
342342
},
343343
__syscall_accept4__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'],
344-
__syscall_accept4: function(fd, addr, addrlen, flags) {
344+
__syscall_accept4: function(fd, addr, addrlen, flags, d1, d2) {
345345
var sock = getSocketFromFD(fd);
346346
var newsock = sock.sock_ops.accept(sock);
347347
if (addr) {
@@ -393,7 +393,7 @@ var SyscallsLibrary = {
393393
return sock.sock_ops.sendmsg(sock, {{{ heapAndOffset('HEAP8', 'message') }}}, length, dest.addr, dest.port);
394394
},
395395
__syscall_getsockopt__deps: ['$getSocketFromFD'],
396-
__syscall_getsockopt: function(fd, level, optname, optval, optlen) {
396+
__syscall_getsockopt: function(fd, level, optname, optval, optlen, d1) {
397397
var sock = getSocketFromFD(fd);
398398
// Minimal getsockopt aimed at resolving https://github.com/emscripten-core/emscripten/issues/2211
399399
// so only supports SOL_SOCKET with SO_ERROR.
@@ -408,7 +408,7 @@ var SyscallsLibrary = {
408408
return -{{{ cDefs.ENOPROTOOPT }}}; // The option is unknown at the level indicated.
409409
},
410410
__syscall_sendmsg__deps: ['$getSocketFromFD', '$readSockaddr', '$DNS'],
411-
__syscall_sendmsg: function(fd, message, flags) {
411+
__syscall_sendmsg: function(fd, message, flags, d1, d2, d3) {
412412
var sock = getSocketFromFD(fd);
413413
var iov = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iov, '*') }}};
414414
var num = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iovlen, 'i32') }}};
@@ -440,7 +440,7 @@ var SyscallsLibrary = {
440440
return sock.sock_ops.sendmsg(sock, view, 0, total, addr, port);
441441
},
442442
__syscall_recvmsg__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'],
443-
__syscall_recvmsg: function(fd, message, flags) {
443+
__syscall_recvmsg: function(fd, message, flags, d1, d2, d3) {
444444
var sock = getSocketFromFD(fd);
445445
var iov = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iov, POINTER_TYPE) }}};
446446
var num = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iovlen, 'i32') }}};

src/library_webgl.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3710,10 +3710,18 @@ var LibraryGL = {
37103710

37113711
#if !LEGACY_GL_EMULATION
37123712

3713-
glVertexPointer: function(){ throw 'Legacy GL function (glVertexPointer) called. If you want legacy GL emulation, you need to compile with -sLEGACY_GL_EMULATION to enable legacy GL emulation.'; },
3714-
glMatrixMode: function(){ throw 'Legacy GL function (glMatrixMode) called. If you want legacy GL emulation, you need to compile with -sLEGACY_GL_EMULATION to enable legacy GL emulation.'; },
3715-
glBegin: function(){ throw 'Legacy GL function (glBegin) called. If you want legacy GL emulation, you need to compile with -sLEGACY_GL_EMULATION to enable legacy GL emulation.'; },
3716-
glLoadIdentity: function(){ throw 'Legacy GL function (glLoadIdentity) called. If you want legacy GL emulation, you need to compile with -sLEGACY_GL_EMULATION to enable legacy GL emulation.'; },
3713+
glVertexPointer: function(size, type, stride, ptr) {
3714+
throw 'Legacy GL function (glVertexPointer) called. If you want legacy GL emulation, you need to compile with -sLEGACY_GL_EMULATION to enable legacy GL emulation.';
3715+
},
3716+
glMatrixMode: function() {
3717+
throw 'Legacy GL function (glMatrixMode) called. If you want legacy GL emulation, you need to compile with -sLEGACY_GL_EMULATION to enable legacy GL emulation.';
3718+
},
3719+
glBegin: function() {
3720+
throw 'Legacy GL function (glBegin) called. If you want legacy GL emulation, you need to compile with -sLEGACY_GL_EMULATION to enable legacy GL emulation.';
3721+
},
3722+
glLoadIdentity: function() {
3723+
throw 'Legacy GL function (glLoadIdentity) called. If you want legacy GL emulation, you need to compile with -sLEGACY_GL_EMULATION to enable legacy GL emulation.';
3724+
},
37173725

37183726
#endif // LEGACY_GL_EMULATION
37193727

src/library_xlib.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
var LibraryXlib = {
8-
XOpenDisplay: function() {
8+
XOpenDisplay: function(name) {
99
return 1; // We support 1 display, the canvas
1010
},
1111

@@ -16,12 +16,12 @@ var LibraryXlib = {
1616
return 2;
1717
},
1818

19-
XChangeWindowAttributes: function(){},
20-
XSetWMHints: function(){},
21-
XMapWindow: function(){},
22-
XStoreName: function(){},
19+
XChangeWindowAttributes: function(display, window, valuemask, attributes){},
20+
XSetWMHints: function(display, win, hints){},
21+
XMapWindow: function(display, win){},
22+
XStoreName: function(display, win, name){},
2323
XInternAtom: function(display, name_, hmm) { return 0 },
24-
XSendEvent: function(){},
24+
XSendEvent: function(display, win, propagate, event_mask, even_send){},
2525
XPending: function(display) { return 0 },
2626
};
2727

0 commit comments

Comments
 (0)