From bcc64336503b43faa39cb0eed59ea30dc3d4c476 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 22 Mar 2023 10:39:24 -0700 Subject: [PATCH] [Wasm64] Check argument names in convertPointerParams. NFC Without this `convertPointerParams` will silently generate invalid output. --- src/jsifier.js | 8 ++++++-- src/library_async.js | 8 ++++---- src/library_idbstore.js | 8 ++++---- src/library_sdl.js | 34 +++++++++++++++++----------------- src/library_syscall.js | 12 ++++++------ src/library_webgl.js | 16 ++++++++++++---- src/library_xlib.js | 12 ++++++------ 7 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/jsifier.js b/src/jsifier.js index 2503ae9f9e550..889b326eb1108 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -87,7 +87,7 @@ function runJSify() { } } - function convertPointerParams(snippet, sig) { + function convertPointerParams(symbol, snippet, sig) { // Automatically convert any incoming pointer arguments from BigInt // to double (this limits the range to int53). // And convert the return value if the function returns a pointer. @@ -99,6 +99,10 @@ function runJSify() { let argConvertions = ''; for (let i = 1; i < sig.length; i++) { const name = argNames[i - 1]; + if (!name) { + error(`convertPointerParams: missing name for argument ${i} in ${symbol}`); + return snippet; + } if (sig[i] == 'p') { argConvertions += ` ${name} = Number(${name});\n`; newArgs.push(`Number(${name})`); @@ -182,7 +186,7 @@ function ${name}(${args}) { if (MEMORY64) { const sig = LibraryManager.library[symbol + '__sig']; if (sig && sig.includes('p')) { - snippet = convertPointerParams(snippet, sig); + snippet = convertPointerParams(symbol, snippet, sig); } } diff --git a/src/library_async.js b/src/library_async.js index bb713e4222636..82c57b741f8a8 100644 --- a/src/library_async.js +++ b/src/library_async.js @@ -647,13 +647,13 @@ mergeInto(LibraryManager.library, { emscripten_sleep: function() { throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_sleep'; }, - emscripten_wget: function() { + emscripten_wget: function(url, file) { throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_wget'; }, - emscripten_wget_data: function() { + emscripten_wget_data: function(url, pbuffer, pnum, perror) { throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_wget_data'; }, - emscripten_scan_registers: function() { + emscripten_scan_registers: function(func) { throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_scan_registers'; }, emscripten_fiber_init: function() { @@ -662,7 +662,7 @@ mergeInto(LibraryManager.library, { emscripten_fiber_init_from_current_context: function() { throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_fiber_init_from_current_context'; }, - emscripten_fiber_swap: function() { + emscripten_fiber_swap: function(oldFiber, newFiber) { throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_fiber_swap'; }, #endif // ASYNCIFY diff --git a/src/library_idbstore.js b/src/library_idbstore.js index 872787c6d7f96..c28da22e7f7a1 100644 --- a/src/library_idbstore.js +++ b/src/library_idbstore.js @@ -157,16 +157,16 @@ var LibraryIDBStore = { IDBStore.blobs[blobId] = null; }, #else - emscripten_idb_load: function() { + emscripten_idb_load: function(db, id, pbuffer, pnum, perror) { throw 'Please compile your program with async support in order to use synchronous operations like emscripten_idb_load, etc.'; }, - emscripten_idb_store: function() { + emscripten_idb_store: function(db, id, ptr, num, perror) { throw 'Please compile your program with async support in order to use synchronous operations like emscripten_idb_store, etc.'; }, - emscripten_idb_delete: function() { + emscripten_idb_delete: function(db, id, perror) { throw 'Please compile your program with async support in order to use synchronous operations like emscripten_idb_delete, etc.'; }, - emscripten_idb_exists: function() { + emscripten_idb_exists: function(db, id, pexists, perror) { throw 'Please compile your program with async support in order to use synchronous operations like emscripten_idb_exists, etc.'; }, #endif // ASYNCIFY diff --git a/src/library_sdl.js b/src/library_sdl.js index 66a59e5d5e279..0d97cab60935d 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1843,7 +1843,7 @@ var LibrarySDL = { return SDL.errorMessage; }, - SDL_SetError: function() {}, + SDL_SetError: function(fmt, varargs) {}, SDL_CreateRGBSurface__deps: ['malloc', 'free'], SDL_CreateRGBSurface__proxy: 'sync', @@ -2657,14 +2657,14 @@ var LibrarySDL = { SDL_UnlockAudio: function() {}, SDL_CreateMutex: function() { return 0 }, - SDL_mutexP: function() { return 0 }, - SDL_mutexV: function() { return 0 }, - SDL_DestroyMutex: function() {}, + SDL_mutexP: function(mutex) { return 0 }, + SDL_mutexV: function(mutex) { return 0 }, + SDL_DestroyMutex: function(mutex) {}, SDL_CreateCond: function() { return 0 }, - SDL_CondSignal: function() {}, - SDL_CondWait: function() {}, - SDL_DestroyCond: function() {}, + SDL_CondSignal: function(cond) {}, + SDL_CondWait: function(cond, mutex) {}, + SDL_DestroyCond: function(cond) {}, SDL_StartTextInput__proxy: 'sync', SDL_StartTextInput__sig: 'v', @@ -3716,30 +3716,30 @@ var LibrarySDL = { }, // TODO: - SDL_CreateThread: function() { + SDL_CreateThread: function(fs, data, pfnBeginThread, pfnEndThread) { 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.' }, - SDL_WaitThread: function() { throw 'SDL_WaitThread' }, - SDL_GetThreadID: function() { throw 'SDL_GetThreadID' }, + SDL_WaitThread: function(thread, status) { throw 'SDL_WaitThread' }, + SDL_GetThreadID: function(thread) { throw 'SDL_GetThreadID' }, SDL_ThreadID: function() { return 0; }, SDL_AllocRW: function() { throw 'SDL_AllocRW: TODO' }, - SDL_CondBroadcast: function() { throw 'SDL_CondBroadcast: TODO' }, - SDL_CondWaitTimeout: function() { throw 'SDL_CondWaitTimeout: TODO' }, + SDL_CondBroadcast: function(cond) { throw 'SDL_CondBroadcast: TODO' }, + SDL_CondWaitTimeout: function(cond, mutex, ms) { throw 'SDL_CondWaitTimeout: TODO' }, SDL_WM_IconifyWindow: function() { throw 'SDL_WM_IconifyWindow TODO' }, - Mix_SetPostMix: function() { warnOnce('Mix_SetPostMix: TODO') }, + Mix_SetPostMix: function(func, arg) { warnOnce('Mix_SetPostMix: TODO') }, Mix_VolumeChunk: function(chunk, volume) { throw 'Mix_VolumeChunk: TODO' }, Mix_SetPosition: function(channel, angle, distance) { throw 'Mix_SetPosition: TODO' }, - Mix_QuerySpec: function() { throw 'Mix_QuerySpec: TODO' }, - Mix_FadeInChannelTimed: function() { throw 'Mix_FadeInChannelTimed' }, + Mix_QuerySpec: function(frequency, format, channels) { throw 'Mix_QuerySpec: TODO' }, + Mix_FadeInChannelTimed: function(channel, chunk, loop, ms, ticks) { throw 'Mix_FadeInChannelTimed' }, Mix_FadeOutChannel: function() { throw 'Mix_FadeOutChannel' }, Mix_Linked_Version: function() { throw 'Mix_Linked_Version: TODO' }, - SDL_SaveBMP_RW: function() { throw 'SDL_SaveBMP_RW: TODO' }, + SDL_SaveBMP_RW: function(surface, dst, freedst) { throw 'SDL_SaveBMP_RW: TODO' }, - SDL_WM_SetIcon: function() { /* This function would set the application window icon surface, which doesn't apply for web canvases, so a no-op. */ }, + 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. */ }, SDL_HasRDTSC: function() { return 0; }, SDL_HasMMX: function() { return 0; }, SDL_HasMMXExt: function() { return 0; }, diff --git a/src/library_syscall.js b/src/library_syscall.js index 109f554825b53..e9b69cbd06b99 100644 --- a/src/library_syscall.js +++ b/src/library_syscall.js @@ -305,7 +305,7 @@ var SyscallsLibrary = { return sock.stream.fd; }, __syscall_getsockname__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'], - __syscall_getsockname: function(fd, addr, addrlen) { + __syscall_getsockname: function(fd, addr, addrlen, d1, d2, d3) { err("__syscall_getsockname " + fd); var sock = getSocketFromFD(fd); // TODO: sock.saddr should never be undefined, see TODO in websocket_sock_ops.getname @@ -316,7 +316,7 @@ var SyscallsLibrary = { return 0; }, __syscall_getpeername__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'], - __syscall_getpeername: function(fd, addr, addrlen) { + __syscall_getpeername: function(fd, addr, addrlen, d1, d2, d3) { var sock = getSocketFromFD(fd); if (!sock.daddr) { return -{{{ cDefs.ENOTCONN }}}; // The socket is not connected. @@ -341,7 +341,7 @@ var SyscallsLibrary = { return -{{{ cDefs.ENOSYS }}}; // unsupported feature }, __syscall_accept4__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'], - __syscall_accept4: function(fd, addr, addrlen, flags) { + __syscall_accept4: function(fd, addr, addrlen, flags, d1, d2) { var sock = getSocketFromFD(fd); var newsock = sock.sock_ops.accept(sock); if (addr) { @@ -393,7 +393,7 @@ var SyscallsLibrary = { return sock.sock_ops.sendmsg(sock, {{{ heapAndOffset('HEAP8', 'message') }}}, length, dest.addr, dest.port); }, __syscall_getsockopt__deps: ['$getSocketFromFD'], - __syscall_getsockopt: function(fd, level, optname, optval, optlen) { + __syscall_getsockopt: function(fd, level, optname, optval, optlen, d1) { var sock = getSocketFromFD(fd); // Minimal getsockopt aimed at resolving https://github.com/emscripten-core/emscripten/issues/2211 // so only supports SOL_SOCKET with SO_ERROR. @@ -408,7 +408,7 @@ var SyscallsLibrary = { return -{{{ cDefs.ENOPROTOOPT }}}; // The option is unknown at the level indicated. }, __syscall_sendmsg__deps: ['$getSocketFromFD', '$readSockaddr', '$DNS'], - __syscall_sendmsg: function(fd, message, flags) { + __syscall_sendmsg: function(fd, message, flags, d1, d2, d3) { var sock = getSocketFromFD(fd); var iov = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iov, '*') }}}; var num = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iovlen, 'i32') }}}; @@ -440,7 +440,7 @@ var SyscallsLibrary = { return sock.sock_ops.sendmsg(sock, view, 0, total, addr, port); }, __syscall_recvmsg__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'], - __syscall_recvmsg: function(fd, message, flags) { + __syscall_recvmsg: function(fd, message, flags, d1, d2, d3) { var sock = getSocketFromFD(fd); var iov = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iov, POINTER_TYPE) }}}; var num = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iovlen, 'i32') }}}; diff --git a/src/library_webgl.js b/src/library_webgl.js index 17ec5a5eb7527..7e7012379fbfc 100644 --- a/src/library_webgl.js +++ b/src/library_webgl.js @@ -3710,10 +3710,18 @@ var LibraryGL = { #if !LEGACY_GL_EMULATION - 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.'; }, - 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.'; }, - 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.'; }, - 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.'; }, + glVertexPointer: function(size, type, stride, ptr) { + 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.'; + }, + 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.'; + }, + 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.'; + }, + 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.'; + }, #endif // LEGACY_GL_EMULATION diff --git a/src/library_xlib.js b/src/library_xlib.js index 8afc763f8e3a3..60c477e420feb 100644 --- a/src/library_xlib.js +++ b/src/library_xlib.js @@ -5,7 +5,7 @@ */ var LibraryXlib = { - XOpenDisplay: function() { + XOpenDisplay: function(name) { return 1; // We support 1 display, the canvas }, @@ -16,12 +16,12 @@ var LibraryXlib = { return 2; }, - XChangeWindowAttributes: function(){}, - XSetWMHints: function(){}, - XMapWindow: function(){}, - XStoreName: function(){}, + XChangeWindowAttributes: function(display, window, valuemask, attributes){}, + XSetWMHints: function(display, win, hints){}, + XMapWindow: function(display, win){}, + XStoreName: function(display, win, name){}, XInternAtom: function(display, name_, hmm) { return 0 }, - XSendEvent: function(){}, + XSendEvent: function(display, win, propagate, event_mask, even_send){}, XPending: function(display) { return 0 }, };