How can we reproduce the crash?
Hi,
I would like to report a crash in Bun that can be reproduced using the below PoC:
import ffi from 'ffi-napi';
// NOTE: This PoC intentionally uses a Windows-only DLL name on non-Windows
// platforms to trigger an error path when loading the library or symbol.
const Kernel32_path = process.platform === 'win32' ? 'Kernel32.dll' : 'Kernel32.dll';
let Kernel32_lib;
try {
Kernel32_lib = ffi.Library(Kernel32_path, {
FormatMessageA: [
'uint32',
[
'uint32', // dwFlags
'pointer', // lpSource
'uint32', // dwMessageId
'uint32', // dwLanguageId
'pointer', // lpBuffer
'uint32', // nSize
'pointer', // Arguments
],
],
});
} catch (e) {
console.error('Failed to load library or resolve symbol:', e);
process.exitCode = 1;
process.exit();
}
const err_code = 1400;
// Intentionally pass a JS-managed buffer via a Node Buffer
const buf = Buffer.alloc(8); // 8 bytes ~ Float64Array(1)
try {
const ret = Kernel32_lib.FormatMessageA(
0x00000100 | 0x00001000 | 0x00000200,
ref.NULL_POINTER || null,
err_code,
0,
buf,
0,
ref.NULL_POINTER || null,
);
console.log('Return value:', ret);
} catch (e) {
console.error('Error when calling FFI function:', e);
}
Relevant log output
root@KContainer:~/20072# bun run bug_ffi.mjs
============================================================
Bun Canary v1.3.11-canary.1 (9e93bfa1) Linux x64
Linux Kernel v5.10.0 | glibc v2.35
CPU: sse42 popcnt avx avx2
Args: "bun" "run" "bug_ffi.mjs"
Features: Bun.stderr(2) Bun.stdin(2) Bun.stdout(2) jsc napi_module_register(2) process_dlopen(2) unsupported_uv_function
Builtins: "bun:main" "node:assert" "node:fs" "node:os" "node:path" "node:process" "node:tty" "node:util"
Elapsed: 130ms | User: 95ms | Sys: 14ms
RSS: 1.11GB | Peak: 40.74MB | Commit: 1.11GB | Faults: 0 | Machine: 2.15TB
Bun encountered a crash when running a NAPI module that tried to call
the uv_thread_self libuv function.
Bun is actively working on supporting all libuv functions for POSIX
systems, please see this issue to track our progress:
https://github.com/oven-sh/bun/issues/18546
panic(main thread): unsupported uv function: uv_thread_self
https://bun.report/1.3.11/lr29e93bfaggmIugggCorzrmD6i75vEmu1Do56C89qDqmqtoE_izllkEmsv9jEs9i0sFmo7toE068voE2kqvoE___izllkEmsv9jEs9i0sFmo7toEA0eNorzSsuLSjILypJTVEoLVNIK81LLsnMz7NSKC2LL8koSk1MiS9OzUkDADmWD4A
Illegal instruction
Stack Trace (bun.report)
Bun v1.3.11-canary ([`9e93bfa`](<https://github.com/oven-sh/bun/tree/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8>)) on linux x86_64 [RunCommand]
**panic**: unsupported uv function: uv_thread_self
- [`crash_handler.zig:2265`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/crash_handler.zig#L2265>): `CrashHandler__unsupportedUVFunction`
- [`uv-posix-stubs.c:1750`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/uv-posix-stubs.c#L1750>): `uv_thread_self`
- `??`
- `??`
- `??`
- [`NapiClass.cpp:68`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/NapiClass.cpp#L68>): `long Zig::NapiClass_ConstructorFunction<false>`
- *1 unknown/js code*
- [`ld-temp.o:0`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/ld-temp.o#L0>): `llint_op_call`
- [`ld-temp.o:0`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/ld-temp.o#L0>): `llint_call_javascript`
- [`Interpreter.cpp:1320`](<https://github.com/oven-sh/WebKit/blob/00e825523d549a556d75985f486e4954af6ab8c7/Source/JavaScriptCore/interpreter/Interpreter.cpp#L1320>): `JSC::Interpreter::executeCallImpl`
- [`JSCommonJSModule.cpp:213`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.cpp#L213>): `Bun::evaluateCommonJSModuleOnce`
- [`JSCommonJSModule.cpp:1371`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.cpp#L1371>): `Bun::JSCommonJSModule::evaluate`
- [`JSCommonJSModule.h:94`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.h#L94>): `Bun::JSCommonJSModule::evaluate`
- [`ModuleLoader.cpp:801`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/ModuleLoader.cpp#L801>): `JSC::JSValue Bun::fetchCommonJSModuleNonBuiltin<false>`
- [`ModuleLoader.cpp:778`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/ModuleLoader.cpp#L778>): `Bun::fetchCommonJSModule`
- [`JSCommonJSModule.cpp:1288`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.cpp#L1288>): `Bun::jsFunctionRequireCommonJS`
- *3 unknown/js code*
- [`ld-temp.o:0`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/ld-temp.o#L0>): `llint_op_call`
- [`ld-temp.o:0`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/ld-temp.o#L0>): `llint_call_javascript`
- [`Interpreter.cpp:1320`](<https://github.com/oven-sh/WebKit/blob/00e825523d549a556d75985f486e4954af6ab8c7/Source/JavaScriptCore/interpreter/Interpreter.cpp#L1320>): `JSC::Interpreter::executeCallImpl`
- [`JSCommonJSModule.cpp:213`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.cpp#L213>): `Bun::evaluateCommonJSModuleOnce`
Features: napi\_module\_register, process\_dlopen, unsupported\_uv\_function, Bun.stderr, Bun.stdin, Bun.stdout, jsc
How can we reproduce the crash?
Hi,
I would like to report a crash in Bun that can be reproduced using the below PoC:
Relevant log output
Stack Trace (bun.report)