Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/jsc/VirtualMachine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,11 @@ impl VirtualMachine {
VM.get()
}

pub(crate) fn get_main_thread_vm() -> Option<*mut VirtualMachine> {
/// The main thread's VM, from any thread; `None` before it exists. It is
/// never freed, but off its own thread only what is thread-safe may be
/// reached through it: a wakeup of its loop (`PosixSignalHandle`), a field
/// written once at init (`uv_default_loop`).
Comment thread
robobun marked this conversation as resolved.
Outdated
pub fn get_main_thread_vm() -> Option<*mut VirtualMachine> {
let p = MAIN_THREAD_VM.load(core::sync::atomic::Ordering::Acquire);
if p.is_null() { None } else { Some(p) }
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
Expand Down
7 changes: 3 additions & 4 deletions src/jsc/bindings/BunProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
#include <fcntl.h>
#include <signal.h>
#include <sys/resource.h>
// uv-posix-polyfills.c: the version of the libuv headers the posix uv_*
// polyfills implement, for process.versions.uv.
Comment thread
robobun marked this conversation as resolved.
Outdated
extern "C" const char* uv_version_string(void);
#else
#include <uv.h>
#include <io.h>
Expand Down Expand Up @@ -257,11 +260,7 @@ static JSValue constructVersions(VM& vm, JSObject* processObject)
// Use commit hash for zstd (semantic version extraction not working yet)
object->putDirect(vm, JSC::Identifier::fromString(vm, "zstd"_s), JSC::jsOwnedString(vm, ASCIILiteral::fromLiteralUnsafe(BUN_VERSION_ZSTD_HASH)), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "v8"_s), JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(REPORTED_NODEJS_V8_VERSION)))), 0);
#if OS(WINDOWS)
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsOwnedString(vm, String::fromLatin1(uv_version_string()))), 0);
#else
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsOwnedString(vm, String("1.48.0"_s))), 0);
#endif
object->putDirect(vm, JSC::Identifier::fromString(vm, "napi"_s), JSValue(JSC::jsOwnedString(vm, String("10"_s))), 0);

object->putDirect(vm, JSC::Identifier::fromString(vm, "icu"_s), JSValue(JSC::jsOwnedString(vm, String(ASCIILiteral::fromLiteralUnsafe(U_ICU_VERSION)))), 0);
Expand Down
2 changes: 1 addition & 1 deletion src/jsc/bindings/libuv/generate_uv_posix_stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const final_contents = `// GENERATED CODE - DO NOT MODIFY BY HAND
#include "uv-posix-polyfills.h"


#if OS(LINUX) || OS(DARWIN)
#if OS(LINUX) || OS(DARWIN) || OS(FREEBSD)
${parts.map(([stub, _]) => stub).join("\n\n")}
#endif

Expand Down
80 changes: 47 additions & 33 deletions src/jsc/bindings/libuv/generate_uv_posix_stubs_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@ export const test_skipped = [

export const symbols = [
"uv_accept",
"uv_async_init",
"uv_async_send",
// Defined in src/runtime/napi/uv_posix.rs
// "uv_async_init",
// "uv_async_send",
Comment thread
robobun marked this conversation as resolved.
"uv_available_parallelism",
"uv_backend_fd",
"uv_backend_timeout",
"uv_barrier_destroy",
"uv_barrier_init",
"uv_barrier_wait",
"uv_buf_init",
"uv_cancel",
// Defined in src/runtime/napi/uv_posix.rs
// "uv_cancel",
Comment thread
robobun marked this conversation as resolved.
"uv_chdir",
"uv_check_init",
"uv_check_start",
"uv_check_stop",
"uv_clock_gettime",
"uv_close",
// Defined in src/runtime/napi/uv_posix.rs
// "uv_close",
Comment thread
robobun marked this conversation as resolved.
"uv_cond_broadcast",
"uv_cond_destroy",
"uv_cond_init",
Expand All @@ -39,7 +42,8 @@ export const symbols = [
"uv_cpu_info",
"uv_cpumask_size",
"uv_cwd",
"uv_default_loop",
// Defined in src/runtime/napi/uv_posix.rs
// "uv_default_loop",
Comment thread
robobun marked this conversation as resolved.
"uv_disable_stdio_inheritance",
"uv_dlclose",
"uv_dlerror",
Expand Down Expand Up @@ -107,7 +111,8 @@ export const symbols = [
"uv_get_available_memory",
"uv_get_constrained_memory",
"uv_get_free_memory",
"uv_get_osfhandle",
// Defined in uv-posix-polyfills.c
// "uv_get_osfhandle",
Comment thread
robobun marked this conversation as resolved.
"uv_get_process_title",
"uv_get_total_memory",
"uv_getaddrinfo",
Expand All @@ -116,14 +121,16 @@ export const symbols = [
"uv_getrusage_thread",
"uv_gettimeofday",
"uv_guess_handle",
"uv_handle_get_data",
"uv_handle_get_loop",
"uv_handle_get_type",
"uv_handle_set_data",
"uv_handle_size",
"uv_handle_type_name",
"uv_has_ref",
// Defined in uv-posix-polyfills.cpp
// Defined in uv-posix-polyfills.c
// "uv_handle_get_data",
// "uv_handle_get_loop",
// "uv_handle_get_type",
// "uv_handle_set_data",
// "uv_handle_size",
// "uv_handle_type_name",
// Defined in src/runtime/napi/uv_posix.rs
// "uv_has_ref",
// Defined in uv-posix-polyfills.c
Comment thread
robobun marked this conversation as resolved.
// "uv_hrtime",
"uv_idle_init",
"uv_idle_start",
Expand All @@ -138,8 +145,9 @@ export const symbols = [
"uv_ip6_addr",
"uv_ip6_name",
"uv_ip_name",
"uv_is_active",
"uv_is_closing",
// Defined in src/runtime/napi/uv_posix.rs
// "uv_is_active",
// "uv_is_closing",
Comment thread
robobun marked this conversation as resolved.
"uv_is_readable",
"uv_is_writable",
"uv_key_create",
Expand All @@ -155,24 +163,26 @@ export const symbols = [
"uv_loop_configure",
"uv_loop_delete",
"uv_loop_fork",
"uv_loop_get_data",
// Defined in uv-posix-polyfills.c
// "uv_loop_get_data",
Comment thread
robobun marked this conversation as resolved.
"uv_loop_init",
"uv_loop_new",
"uv_loop_set_data",
// Defined in uv-posix-polyfills.c
// "uv_loop_set_data",
Comment thread
robobun marked this conversation as resolved.
"uv_loop_size",
"uv_metrics_idle_time",
"uv_metrics_info",
// Defined in uv-posix-polyfills.cpp
// Defined in uv-posix-polyfills.c
// "uv_mutex_destroy",
// "uv_mutex_init",
// "uv_mutex_init_recursive",
// "uv_mutex_lock",
// "uv_mutex_trylock",
// "uv_mutex_unlock",
"uv_now",
// Defined in uv-posix-polyfills.cpp
// Defined in uv-posix-polyfills.c
// "uv_once",
"uv_open_osfhandle",
// "uv_open_osfhandle",
"uv_os_environ",
"uv_os_free_environ",
"uv_os_free_group",
Expand All @@ -182,9 +192,8 @@ export const symbols = [
"uv_os_get_passwd2",
"uv_os_getenv",
"uv_os_gethostname",
// Defined in uv-posix-polyfills.cpp
// Defined in uv-posix-polyfills.c
// "uv_os_getpid",
// Defined in uv-posix-polyfills.cpp
// "uv_os_getppid",
"uv_os_getpriority",
"uv_os_homedir",
Expand Down Expand Up @@ -217,18 +226,21 @@ export const symbols = [
"uv_print_all_handles",
"uv_process_get_pid",
"uv_process_kill",
"uv_queue_work",
// Defined in src/runtime/napi/uv_posix.rs
// "uv_queue_work",
Comment thread
robobun marked this conversation as resolved.
"uv_random",
"uv_read_start",
"uv_read_stop",
"uv_recv_buffer_size",
"uv_ref",
// Defined in src/runtime/napi/uv_posix.rs
// "uv_ref",
Comment thread
robobun marked this conversation as resolved.
"uv_replace_allocator",
"uv_req_get_data",
"uv_req_get_type",
"uv_req_set_data",
"uv_req_size",
"uv_req_type_name",
// Defined in uv-posix-polyfills.c
// "uv_req_get_data",
// "uv_req_get_type",
// "uv_req_set_data",
// "uv_req_size",
// "uv_req_type_name",
Comment thread
robobun marked this conversation as resolved.
"uv_resident_set_memory",
"uv_run",
"uv_rwlock_destroy",
Expand Down Expand Up @@ -323,13 +335,15 @@ export const symbols = [
"uv_udp_try_send",
"uv_udp_try_send2",
"uv_udp_using_recvmmsg",
"uv_unref",
// Defined in src/runtime/napi/uv_posix.rs
// "uv_unref",
Comment thread
robobun marked this conversation as resolved.
"uv_update_time",
"uv_uptime",
"uv_utf16_length_as_wtf8",
"uv_utf16_to_wtf8",
"uv_version",
"uv_version_string",
// Defined in uv-posix-polyfills.c
// "uv_version",
// "uv_version_string",
Comment thread
robobun marked this conversation as resolved.
"uv_walk",
"uv_write",
"uv_write2",
Expand Down
147 changes: 147 additions & 0 deletions src/jsc/bindings/uv-posix-polyfills.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,151 @@ UV_EXTERN void uv_mutex_unlock(uv_mutex_t* mutex)
abort();
}

// The functions below need nothing but the headers in ./libuv, so they are
// libuv's own definitions (src/version.c, src/uv-common.c,
// src/uv-data-getter-setters.c, src/unix/core.c). The loop-backed functions
// for the same handles and requests (uv_async_*, uv_close, uv_queue_work, ...)
// are in src/runtime/napi/uv_posix.rs.
Comment thread
robobun marked this conversation as resolved.
Outdated

#define UV_STRINGIFY(v) UV_STRINGIFY_HELPER(v)
#define UV_STRINGIFY_HELPER(v) #v

#define UV_VERSION_STRING_BASE UV_STRINGIFY(UV_VERSION_MAJOR) "." UV_STRINGIFY(UV_VERSION_MINOR) "." UV_STRINGIFY(UV_VERSION_PATCH)

#if UV_VERSION_IS_RELEASE
#define UV_VERSION_STRING UV_VERSION_STRING_BASE
#else
#define UV_VERSION_STRING UV_VERSION_STRING_BASE "-" UV_VERSION_SUFFIX
#endif

// The version of the headers these polyfills implement the ABI of, which is
// also the libuv Bun links on Windows. BunProcess.cpp reports it as
// process.versions.uv on every platform.
Comment thread
robobun marked this conversation as resolved.
Outdated
UV_EXTERN unsigned int uv_version(void)
{
return UV_VERSION_HEX;
}

UV_EXTERN const char* uv_version_string(void)
{
return UV_VERSION_STRING;
}

UV_EXTERN size_t uv_handle_size(uv_handle_type type)
{
switch (type) {
#define XX(uc, lc) \
case UV_##uc: \
return sizeof(uv_##lc##_t);
UV_HANDLE_TYPE_MAP(XX)
#undef XX
default:
return (size_t)-1;
}
}

UV_EXTERN size_t uv_req_size(uv_req_type type)
{
switch (type) {
#define XX(uc, lc) \
case UV_##uc: \
return sizeof(uv_##lc##_t);
UV_REQ_TYPE_MAP(XX)
#undef XX
default:
return (size_t)-1;
}
}

UV_EXTERN const char* uv_handle_type_name(uv_handle_type type)
{
switch (type) {
#define XX(uc, lc) \
case UV_##uc: \
return #lc;
UV_HANDLE_TYPE_MAP(XX)
#undef XX
case UV_FILE:
return "file";
case UV_HANDLE_TYPE_MAX:
case UV_UNKNOWN_HANDLE:
return NULL;
}
return NULL;
}

UV_EXTERN const char* uv_req_type_name(uv_req_type type)
{
switch (type) {
#define XX(uc, lc) \
case UV_##uc: \
return #lc;
UV_REQ_TYPE_MAP(XX)
#undef XX
case UV_REQ_TYPE_MAX:
case UV_UNKNOWN_REQ:
default: /* UV_REQ_TYPE_PRIVATE */
break;
}
return NULL;
}

UV_EXTERN uv_handle_type uv_handle_get_type(const uv_handle_t* handle)
{
return handle->type;
}

UV_EXTERN void* uv_handle_get_data(const uv_handle_t* handle)
{
return handle->data;
}

UV_EXTERN uv_loop_t* uv_handle_get_loop(const uv_handle_t* handle)
{
return handle->loop;
}

UV_EXTERN void uv_handle_set_data(uv_handle_t* handle, void* data)
{
handle->data = data;
}

UV_EXTERN uv_req_type uv_req_get_type(const uv_req_t* req)
{
return req->type;
}

UV_EXTERN void* uv_req_get_data(const uv_req_t* req)
{
return req->data;
}

UV_EXTERN void uv_req_set_data(uv_req_t* req, void* data)
{
req->data = data;
}

// A uv_loop_t* is a UvLoop (uv_posix.rs), whose first field is `data` like
// uv_loop_t's, so these are the libuv definitions.
Comment thread
robobun marked this conversation as resolved.
Outdated
UV_EXTERN void* uv_loop_get_data(const uv_loop_t* loop)
{
return loop->data;
}

UV_EXTERN void uv_loop_set_data(uv_loop_t* loop, void* data)
{
loop->data = data;
}

// On unix a uv_os_fd_t is an int: both directions are the identity.
UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd)
{
return fd;
}

UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd)
{
return os_fd;
}

#endif
Loading
Loading