Files
bun.sh/src/bun.js/event_loop/JSCScheduler.zig
Claude Bot bd90052694 Use low alignment bits instead of truncating high pointer bits
Changed PackedNext implementation to preserve ARM TBI/PAC/MTE pointer metadata:
- Store full usize pointer with auto_delete flag in LOW alignment bit (not high bit)
- ConcurrentTask is 8-byte aligned (contains u64 Task), so low bit is guaranteed zero
- Use enum(usize) { zero = 0, _ } for type safety and clean initialization syntax
- All atomic operations use usize (instead of u64) with @intFromEnum/@enumFromInt
- Masks: AUTO_DELETE_MASK=0x1, POINTER_MASK=~0x1

Benefits:
- Preserves all high pointer metadata (ARM pointer authentication, tagging, etc.)
- Uses guaranteed-zero low alignment bits instead of truncating address space
- Type-safe enum wrapper prevents accidental misuse
- Clean .zero initialization syntax
2025-11-03 03:18:20 +00:00

53 lines
1.6 KiB
Zig

const JSCScheduler = @This();
pub const JSCDeferredWorkTask = opaque {
extern fn Bun__runDeferredWork(task: *JSCScheduler.JSCDeferredWorkTask) void;
pub fn run(task: *JSCScheduler.JSCDeferredWorkTask) bun.JSTerminated!void {
const globalThis = bun.jsc.VirtualMachine.get().global;
var scope: bun.jsc.ExceptionValidationScope = undefined;
scope.init(globalThis, @src());
defer scope.deinit();
Bun__runDeferredWork(task);
try scope.assertNoExceptionExceptTermination();
}
};
export fn Bun__eventLoop__incrementRefConcurrently(jsc_vm: *VirtualMachine, delta: c_int) void {
jsc.markBinding(@src());
if (delta > 0) {
jsc_vm.event_loop.refConcurrently();
} else {
jsc_vm.event_loop.unrefConcurrently();
}
}
export fn Bun__queueJSCDeferredWorkTaskConcurrently(jsc_vm: *VirtualMachine, task: *JSCScheduler.JSCDeferredWorkTask) void {
jsc.markBinding(@src());
var loop = jsc_vm.eventLoop();
const concurrent_task = ConcurrentTask.new(.{
.task = Task.init(task),
.next = .zero,
});
concurrent_task.next.setAutoDelete(true);
loop.enqueueTaskConcurrent(concurrent_task);
}
export fn Bun__tickWhilePaused(paused: *bool) void {
jsc.markBinding(@src());
VirtualMachine.get().eventLoop().tickWhilePaused(paused);
}
comptime {
_ = Bun__eventLoop__incrementRefConcurrently;
_ = Bun__queueJSCDeferredWorkTaskConcurrently;
_ = Bun__tickWhilePaused;
}
const bun = @import("bun");
const jsc = bun.jsc;
const ConcurrentTask = jsc.ConcurrentTask;
const Task = jsc.Task;
const VirtualMachine = jsc.VirtualMachine;