Truly independent web browser
LibJS: Call JIT code with the System V convention on Windows
Aliaksandr Kalenik02b3ea7c81f5
diff --git a/Libraries/LibJS/JIT/ARCHITECTURE.md b/Libraries/LibJS/JIT/ARCHITECTURE.mdindex aebaea331c3..6f9b5886e94 100644--- a/Libraries/LibJS/JIT/ARCHITECTURE.md+++ b/Libraries/LibJS/JIT/ARCHITECTURE.md@@ -433,6 +433,25 @@ predecessor, cold blocks, the verifier.To be written: per-op lowering, slow path calling conventions and the operand record, the callstub, cache probes, the allocation contract, the entry and exit stubs.+### 8.1 The calling convention of JIT code++JIT code uses the System V calling convention on every x86-64 target and AAPCS64 on AArch64, which+keeps code generation the same across operating systems. Windows x86-64 is the one target where+that is not what the platform uses, so everything that crosses into or out of JIT code says so+explicitly:++- Native code enters JIT code through `extern "sysv64"` function pointers (`JitEntry`,+ `EntryTrampoline`). The compiler then treats RSI, RDI and XMM6-15, which are callee-saved on+ Windows only, as clobbered by the call, and takes two-register results where System V returns+ them.+- Every function JIT code calls has the `#[jit_abi]` attribute, which makes it `extern "sysv64"` on+ Windows x86-64 and leaves it `extern "C"` elsewhere. Taking the address of a function erases its+ calling convention, so JIT code gets the addresses of these functions from+ `jit_function_address!`, which does not build for a function that lacks the attribute.+- The interpreter calls the runtime functions in `interpreter::runtime_functions` with the Win64+ convention on Windows, so `runtime_function_addresses()` gives JIT code System V forwarders to+ them there.+## 9. Speculation and exits**Values of bindings.** The snapshot records the object values of global variables, and of thediff --git a/Libraries/LibJS/Rust/generate/runtime_functions.rs b/Libraries/LibJS/Rust/generate/runtime_functions.rsindex 77990b8196a..398e7d3ab04 100644--- a/Libraries/LibJS/Rust/generate/runtime_functions.rs+++ b/Libraries/LibJS/Rust/generate/runtime_functions.rs@@ -8,6 +8,9 @@//! extern "C" entry point for each with exactly the signature the interpreter's call sites assume. The entry points//! translate every calling convention into one Rust signature per kind of call. The methods have no default bodies, so//! the runtime does not build unless it defines every function that the interpreter, in either of its variants, calls.+//!+//! JIT code calls the same functions, with the System V calling convention on every x86-64 target. Only on Windows is+//! that not the one the interpreter uses, so there every entry point has a forwarder for JIT code to call.use std::collections::HashMap;use std::fmt::Write;@@ -81,6 +84,138 @@ impl<'a> Record<'a> {}}+/// Where the interpreter's calling convention is not the one JIT code calls with.+const WINDOWS_X86_64: &str = "all(target_arch = \"x86_64\", windows)";++/// The Rust signature of the entry point of a runtime function.+struct EntryPointSignature {+ is_unsafe: bool,+ /// The name and the type of each parameter.+ parameters: Vec<(String, String)>,+ result: Option<&'static str>,+}++/// Parameters of these names and types.+fn parameters(parameters: &[(&str, &str)]) -> Vec<(String, String)> {+ parameters+ .iter()+ .map(|(name, ty)| (name.to_string(), ty.to_string()))+ .collect()+}++impl EntryPointSignature {+ fn of(kind: &RuntimeFunctionKind) -> Self {+ let instruction_parameters = |op: &str| {+ parameters(&[+ ("vm", "*const Vm"),+ ("pc", "u32"),+ ("instruction", format!("*const op::{op}").as_str()),+ ])+ };+ let (is_unsafe, parameters, result) = match kind {+ RuntimeFunctionKind::SlowPath { op, abi, layout } => {+ let inputs = layout+ .fields+ .iter()+ .filter(|field| field.mode != ParameterMode::Out)+ .map(|field| (field_name(&field.name), "Value".to_string()));+ let mut parameters = instruction_parameters(op);+ match abi {+ SlowPathAbi::Scalar => {+ parameters.extend(inputs);+ (true, parameters, Some("AsmSlowPathResult"))+ }+ SlowPathAbi::Mixed => {+ parameters.push(("outputs".to_string(), format!("*mut op::{op}Values")));+ parameters.extend(inputs);+ (true, parameters, Some("i64"))+ }+ SlowPathAbi::Record => {+ parameters.push(("values".to_string(), format!("*mut op::{op}Values")));+ (true, parameters, Some("i64"))+ }+ }+ }+ RuntimeFunctionKind::Try { op, .. } => {+ let mut parameters = instruction_parameters(op);+ parameters.push(("values".to_string(), format!("*mut op::{op}Values")));+ (true, parameters, Some("i64"))+ }+ RuntimeFunctionKind::BinarySlowPath => (+ true,+ parameters(&[+ ("vm", "*const Vm"),+ ("pc", "u32"),+ ("dst", "*mut Value"),+ ("lhs", "Value"),+ ("rhs", "Value"),+ ]),+ Some("i64"),+ ),+ RuntimeFunctionKind::JumpSlowPath => (+ true,+ parameters(&[+ ("vm", "*const Vm"),+ ("pc", "u32"),+ ("lhs", "Value"),+ ("rhs", "Value"),+ ("true_target", "u32"),+ ("false_target", "u32"),+ ]),+ Some("i64"),+ ),+ RuntimeFunctionKind::Helper => (false, parameters(&[("argument", "u64")]), Some("u64")),+ RuntimeFunctionKind::HelperWithTwoArguments => {+ (false, parameters(&[("first", "u64"), ("second", "u64")]), Some("u64"))+ }+ RuntimeFunctionKind::FallbackHandler => (+ true,+ parameters(&[("vm", "*const Vm"), ("pc", "u32"), ("instruction", "*const u8")]),+ Some("i64"),+ ),+ RuntimeFunctionKind::BreakpointCheck => (true, parameters(&[("vm", "*const Vm"), ("pc", "u32")]), None),+ RuntimeFunctionKind::StackOverflowSlowPath => {+ (true, parameters(&[("vm", "*const Vm"), ("pc", "u32")]), Some("i64"))+ }+ };+ Self {+ is_unsafe,+ parameters,+ result,+ }+ }++ /// The function up to and including its opening brace.+ fn write_header(&self, out: &mut String, abi: &str, name: &str) {+ let safety = if self.is_unsafe { "unsafe " } else { "" };+ let result = self.result.map_or(String::new(), |result| format!(" -> {result}"));+ let parameters = self+ .parameters+ .iter()+ .map(|(name, ty)| format!("{name}: {ty}"))+ .collect::<Vec<_>>()+ .join(", ");+ let _ = writeln!(out, "pub {safety}extern \"{abi}\" fn {name}({parameters}){result} {{");+ }++ fn write_system_v_forwarder(&self, out: &mut String, symbol: &str) {+ let arguments = self+ .parameters+ .iter()+ .map(|(name, _)| name.as_str())+ .collect::<Vec<_>>()+ .join(", ");+ let _ = writeln!(out, "#[cfg({WINDOWS_X86_64})]");+ self.write_header(out, "sysv64", &format!("{symbol}_sysv64"));+ if self.is_unsafe {+ out.push_str(" // SAFETY: JIT code calls this like the interpreter calls the entry point.\n");+ let _ = writeln!(out, " unsafe {{ {symbol}({arguments}) }}\n}}");+ } else {+ let _ = writeln!(out, " {symbol}({arguments})\n}}");+ }+ }+}+pub fn generate(functions: &[RuntimeFunction], ops: &[InstructionDefinition]) -> String {let ops: HashMap<&str, &InstructionDefinition> = ops.iter().map(|op| (op.name.as_str(), op)).collect();let mut methods = String::new();@@ -90,7 +225,9 @@ pub fn generate(functions: &[RuntimeFunction], ops: &[InstructionDefinition]) ->let symbol = &function.symbol;let name = method_name(symbol);let _ = writeln!(methods, " /// Called as `{symbol}`.");+ let signature = EntryPointSignature::of(&function.kind);let _ = writeln!(entry_points, "#[unsafe(no_mangle)]");+ signature.write_header(&mut entry_points, "C", symbol);match &function.kind {RuntimeFunctionKind::SlowPath { op, abi, layout } => {let record = Record::new(op, layout, &ops);@@ -99,7 +236,7 @@ pub fn generate(functions: &[RuntimeFunction], ops: &[InstructionDefinition]) ->" fn {name}(_vm: &Vm, pc: u32, {}) -> SlowPathControl;",record.method_parameters());- generate_slow_path_entry_point(&mut entry_points, symbol, &name, *abi, &record);+ generate_slow_path_entry_point(&mut entry_points, &name, *abi, &record);}RuntimeFunctionKind::Try { op, layout } => {let record = Record::new(op, layout, &ops);@@ -108,10 +245,6 @@ pub fn generate(functions: &[RuntimeFunction], ops: &[InstructionDefinition]) ->" /// Returns whether it handled the instruction; if not, the interpreter takes the instruction's slow path.\n fn {name}(_vm: &Vm, _pc: u32, {}) -> bool;",record.method_parameters());- let _ = writeln!(- entry_points,- "pub unsafe extern \"C\" fn {symbol}(vm: *const Vm, pc: u32, instruction: *const op::{op}, values: *mut op::{op}Values) -> i64 {{"- );entry_points.push_str(" // SAFETY: The interpreter passes its VM and the instruction it is executing.\n");entry_points.push_str(" let (vm, instruction) = unsafe { (&*vm, &*instruction) };\n");@@ -129,7 +262,7 @@ pub fn generate(functions: &[RuntimeFunction], ops: &[InstructionDefinition]) ->);let _ = writeln!(entry_points,- "pub unsafe extern \"C\" fn {symbol}(vm: *const Vm, pc: u32, dst: *mut Value, lhs: Value, rhs: Value) -> i64 {{\n // SAFETY: The interpreter passes its VM and a live value slot.\n let (vm, dst) = unsafe {{ (&*vm, &*dst.cast::<Cell<Value>>()) }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc, dst, lhs, rhs).0\n}}"+ " // SAFETY: The interpreter passes its VM and a live value slot.\n let (vm, dst) = unsafe {{ (&*vm, &*dst.cast::<Cell<Value>>()) }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc, dst, lhs, rhs).0\n}}");}RuntimeFunctionKind::JumpSlowPath => {@@ -139,21 +272,18 @@ pub fn generate(functions: &[RuntimeFunction], ops: &[InstructionDefinition]) ->);let _ = writeln!(entry_points,- "pub unsafe extern \"C\" fn {symbol}(vm: *const Vm, pc: u32, lhs: Value, rhs: Value, true_target: u32, false_target: u32) -> i64 {{\n // SAFETY: The interpreter passes its VM.\n let vm = unsafe {{ &*vm }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc, lhs, rhs, true_target, false_target).0\n}}"+ " // SAFETY: The interpreter passes its VM.\n let vm = unsafe {{ &*vm }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc, lhs, rhs, true_target, false_target).0\n}}");}RuntimeFunctionKind::Helper => {let _ = writeln!(methods, " fn {name}(_argument: u64) -> u64;");- let _ = writeln!(- entry_points,- "pub extern \"C\" fn {symbol}(argument: u64) -> u64 {{\n <Runtime as RuntimeFunctions>::{name}(argument)\n}}"- );+ let _ = writeln!(entry_points, " <Runtime as RuntimeFunctions>::{name}(argument)\n}}");}RuntimeFunctionKind::HelperWithTwoArguments => {let _ = writeln!(methods, " fn {name}(_first: u64, _second: u64) -> u64;");let _ = writeln!(entry_points,- "pub extern \"C\" fn {symbol}(first: u64, second: u64) -> u64 {{\n <Runtime as RuntimeFunctions>::{name}(first, second)\n}}"+ " <Runtime as RuntimeFunctions>::{name}(first, second)\n}}");}RuntimeFunctionKind::FallbackHandler => {@@ -163,24 +293,25 @@ pub fn generate(functions: &[RuntimeFunction], ops: &[InstructionDefinition]) ->);let _ = writeln!(entry_points,- "pub unsafe extern \"C\" fn {symbol}(vm: *const Vm, pc: u32, instruction: *const u8) -> i64 {{\n // SAFETY: The interpreter passes its VM.\n let vm = unsafe {{ &*vm }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc, instruction).0\n}}"+ " // SAFETY: The interpreter passes its VM.\n let vm = unsafe {{ &*vm }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc, instruction).0\n}}");}RuntimeFunctionKind::BreakpointCheck => {let _ = writeln!(methods, " fn {name}(_vm: &Vm, pc: u32);");let _ = writeln!(entry_points,- "pub unsafe extern \"C\" fn {symbol}(vm: *const Vm, pc: u32) {{\n // SAFETY: The interpreter passes its VM.\n let vm = unsafe {{ &*vm }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc);\n}}"+ " // SAFETY: The interpreter passes its VM.\n let vm = unsafe {{ &*vm }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc);\n}}");}RuntimeFunctionKind::StackOverflowSlowPath => {let _ = writeln!(methods, " fn {name}(_vm: &Vm, pc: u32) -> SlowPathControl;");let _ = writeln!(entry_points,- "pub unsafe extern \"C\" fn {symbol}(vm: *const Vm, pc: u32) -> i64 {{\n // SAFETY: The interpreter passes its VM.\n let vm = unsafe {{ &*vm }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc).0\n}}"+ " // SAFETY: The interpreter passes its VM.\n let vm = unsafe {{ &*vm }};\n <Runtime as RuntimeFunctions>::{name}(vm, pc).0\n}}");}}+ signature.write_system_v_forwarder(&mut entry_points, symbol);entry_points.push('\n');}@@ -199,28 +330,34 @@ pub fn generate(functions: &[RuntimeFunction], ops: &[InstructionDefinition]) ->let _ = writeln!(out, " \"{}\",", function.symbol);}out.push_str("];\n\n");- out.push_str("/// The address of every runtime function, by symbol, in the order of RUNTIME_FUNCTION_SYMBOLS.\n");- let _ = writeln!(- out,- "pub fn runtime_function_addresses() -> [(&'static str, usize); {}] {{\n [",- functions.len()- );- for function in functions {- let _ = writeln!(out, " (\"{0}\", {0} as *const () as usize),", function.symbol);+ for (condition, suffix) in [+ (format!("not({WINDOWS_X86_64})"), ""),+ (WINDOWS_X86_64.to_string(), "_sysv64"),+ ] {+ out.push_str(+ "/// The address JIT code calls every runtime function at, by symbol, in the order of RUNTIME_FUNCTION_SYMBOLS.\n",+ );+ let _ = writeln!(out, "#[cfg({condition})]");+ let _ = writeln!(+ out,+ "pub fn runtime_function_addresses() -> [(&'static str, usize); {}] {{\n [",+ functions.len()+ );+ for function in functions {+ let _ = writeln!(+ out,+ " (\"{0}\", {0}{suffix} as *const () as usize),",+ function.symbol+ );+ }+ out.push_str(" ]\n}\n");}- out.push_str(" ]\n}\n");out}-fn generate_slow_path_entry_point(out: &mut String, symbol: &str, name: &str, abi: SlowPathAbi, record: &Record) {+fn generate_slow_path_entry_point(out: &mut String, name: &str, abi: SlowPathAbi, record: &Record) {let op = record.op;let fields = &record.layout.fields;- let inputs: Vec<String> = fields- .iter()- .filter(|field| field.mode != ParameterMode::Out)- .map(|field| field_name(&field.name))- .collect();- let input_parameters: String = inputs.iter().map(|input| format!(", {input}: Value")).collect();let initialize_values = || {let initializers: Vec<String> = fields.iter()@@ -250,10 +387,6 @@ fn generate_slow_path_entry_point(out: &mut String, symbol: &str, name: &str, ab.iter().find(|field| field.mode == ParameterMode::Out && !field.optional).map(|field| field_name(&field.name));- let _ = writeln!(- out,- "pub unsafe extern \"C\" fn {symbol}(vm: *const Vm, pc: u32, instruction: *const op::{op}{input_parameters}) -> AsmSlowPathResult {{"- );out.push_str(bind_vm);out.push_str(&initialize_values());let _ = writeln!(out, " let values = &mut values;\n let control = {call};");@@ -270,10 +403,6 @@ fn generate_slow_path_entry_point(out: &mut String, symbol: &str, name: &str, ab}}SlowPathAbi::Mixed => {- let _ = writeln!(- out,- "pub unsafe extern \"C\" fn {symbol}(vm: *const Vm, pc: u32, instruction: *const op::{op}, outputs: *mut op::{op}Values{input_parameters}) -> i64 {{"- );out.push_str(bind_vm);out.push_str(&initialize_values());let _ = writeln!(out, " let values = &mut values;\n let control = {call};");@@ -285,10 +414,6 @@ fn generate_slow_path_entry_point(out: &mut String, symbol: &str, name: &str, about.push_str(" control.0\n}\n");}SlowPathAbi::Record => {- let _ = writeln!(- out,- "pub unsafe extern \"C\" fn {symbol}(vm: *const Vm, pc: u32, instruction: *const op::{op}, values: *mut op::{op}Values) -> i64 {{"- );out.push_str(bind_vm);record.bind_record(out);let _ = writeln!(out, " {call}.0\n}}");diff --git a/Libraries/LibJS/Rust/macros/src/lib.rs b/Libraries/LibJS/Rust/macros/src/lib.rsindex e219cafba20..9a32e17f526 100644--- a/Libraries/LibJS/Rust/macros/src/lib.rs+++ b/Libraries/LibJS/Rust/macros/src/lib.rs@@ -9,7 +9,75 @@use proc_macro::TokenStream;use proc_macro2::TokenStream as TokenStream2;use quote::{format_ident, quote};-use syn::{Data, DeriveInput, Fields, Index, parse_macro_input};+use syn::{Data, DeriveInput, Fields, Index, ItemFn, parse_macro_input, parse_quote};++/// The name of what `jit_abi` declares next to a function, which `jit_function_address!` checks for.+fn jit_abi_marker(function: &syn::Ident) -> syn::Ident {+ format_ident!("{}_has_jit_abi", function)+}++/// Marks an `extern "C"` function that JIT code calls, and gives it the calling convention JIT code calls with. JIT code+/// uses the System V calling convention on every x86-64 target, so on Windows, the function has that instead of the+/// platform's. Taking the address of a function erases its calling convention, so JIT code gets the address from+/// `jit_function_address!`, which only builds for functions with this attribute.+///+/// NB: This expands to both functions behind `cfg` attributes, since `cfg!` here would see the host and not the target.+#[proc_macro_attribute]+pub fn jit_abi(attributes: TokenStream, item: TokenStream) -> TokenStream {+ if !attributes.is_empty() {+ return syn::Error::new_spanned(TokenStream2::from(attributes), "jit_abi takes no arguments")+ .to_compile_error()+ .into();+ }+ let function = parse_macro_input!(item as ItemFn);+ let is_extern_c = function+ .sig+ .abi+ .as_ref()+ .and_then(|abi| abi.name.as_ref())+ .is_some_and(|name| name.value() == "C");+ if !is_extern_c {+ return syn::Error::new_spanned(&function.sig, "jit_abi only goes on extern \"C\" functions")+ .to_compile_error()+ .into();+ }+ let mut system_v_function = function.clone();+ system_v_function.sig.abi = Some(parse_quote!(extern "sysv64"));+ let visibility = &function.vis;+ let marker = jit_abi_marker(&function.sig.ident);+ quote! {+ #[cfg(all(target_arch = "x86_64", windows))]+ #system_v_function+ #[cfg(not(all(target_arch = "x86_64", windows)))]+ #function+ #[doc(hidden)]+ #[allow(dead_code, non_upper_case_globals)]+ #visibility const #marker: () = ();+ }+ .into()+}++/// The address of a function that JIT code calls, as a `u64`, which only builds if the function has the `jit_abi`+/// attribute: `jit_function_address!(path::to::function)`. The path is the one the function is declared at, since the+/// check looks next to it.+#[proc_macro]+pub fn jit_function_address(input: TokenStream) -> TokenStream {+ let function = parse_macro_input!(input as syn::Path);+ let Some(last) = function.segments.last() else {+ return syn::Error::new_spanned(&function, "jit_function_address! takes the path of a function")+ .to_compile_error()+ .into();+ };+ let mut marker = function.clone();+ marker.segments.last_mut().expect("the path has a segment").ident = jit_abi_marker(&last.ident);+ quote! {+ {+ const _: () = #marker;+ #function as *const () as u64+ }+ }+ .into()+}/// Implements Trace by tracing every field. A field marked #[gc(untraced)] is skipped and holds no cells, or says what/// keeps them alive: #[gc(untraced = "the realm traces the shapes")].diff --git a/Libraries/LibJS/Rust/src/jit/allocation.rs b/Libraries/LibJS/Rust/src/jit/allocation.rsindex d160a6e511f..bf4f2f9c6e1 100644--- a/Libraries/LibJS/Rust/src/jit/allocation.rs+++ b/Libraries/LibJS/Rust/src/jit/allocation.rs@@ -18,6 +18,7 @@ use libjs_jit::snapshot::{ArrayAllocationInfo, CellId, ClosureTemplateSnapshot, EnvironmentTemplateSnapshot, FunctionAllocationInfo,LexicalEnvironmentTemplateSnapshot, ObjectAllocationInfo, ObjectSizeClass, RopeAllocationInfo, StorageSizeClass,};+use libjs_runtime_macros::{jit_abi, jit_function_address};use super::offset;use crate::bytecode::executable::Executable;@@ -115,7 +116,7 @@ pub fn allocation_infos<'d>(vm: &Vm, realm: Gc<Realm>, defer_gc: &'d DeferGc<'_>inline_storage_offset: offset(core::mem::offset_of!(Object, inline_named_storage)),plain_inline_storage_offset: offset(core::mem::offset_of!(Object, indexed_elements)),inline_capacity_offset: offset(core::mem::offset_of!(Object, inline_named_capacity)),- slow_path: libjs_jit_allocate_object as *const () as u64,+ slow_path: jit_function_address!(libjs_jit_allocate_object),..ObjectAllocationInfo::default()};// NB: Free lists are only popped inline where the heap gives their addresses (not in AddressSanitizer builds).@@ -156,7 +157,7 @@ pub fn allocation_infos<'d>(vm: &Vm, realm: Gc<Realm>, defer_gc: &'d DeferGc<'_>storage_template: value_storage::cell_header_template().to_vec(),storage_values_offset: offset(VALUES_OFFSET),storage_capacity_offset: offset(value_storage::CAPACITY_OFFSET),- slow_path: libjs_jit_allocate_array as *const () as u64,+ slow_path: jit_function_address!(libjs_jit_allocate_array),};let rope_template = rope_template(vm);@@ -168,13 +169,13 @@ pub fn allocation_infos<'d>(vm: &Vm, realm: Gc<Realm>, defer_gc: &'d DeferGc<'_>rhs_offset: offset(ROPE_STRING_RHS_OFFSET),length_offset: offset(core::mem::offset_of!(PrimitiveString, length_in_utf16_code_units)),min_length: ROPE_STRING_MIN_LENGTH,- slow_path: libjs_jit_create_rope_string as *const () as u64,+ slow_path: jit_function_address!(libjs_jit_create_rope_string),};let function = FunctionAllocationInfo {allocator: address(heap.local_free_list_of(EcmascriptFunctionObject::CLASS)),cell_size: size(size_of::<EcmascriptFunctionObject>()),- slow_path: libjs_jit_clone_function as *const () as u64,+ slow_path: jit_function_address!(libjs_jit_clone_function),};AllocationInfos {@@ -480,6 +481,7 @@ pub fn lexical_environment_templates(/// capacity)`: what CreateLexicalEnvironment without a catch environment creates, for JIT code.////// JIT code calls this with its VM, a live parent environment and the executable of its frame.+#[jit_abi]pub extern "C" fn libjs_jit_create_lexical_environment(vm: &Vm,parent: Gc<Environment>,@@ -570,6 +572,7 @@ pub fn closure_template_snapshots(/// undefined, with room for `reserve` properties inline if a size class has room for them.////// JIT code calls this with its VM and a live shape.+#[jit_abi]pub extern "C" fn libjs_jit_allocate_object(vm: &Vm, shape: Gc<Shape>, reserve: u32) -> *mut Object {Object::create_with_premade_shape_and_reserve(vm, shape, reserve).as_ptr()}@@ -579,6 +582,7 @@ pub extern "C" fn libjs_jit_allocate_object(vm: &Vm, shape: Gc<Shape>, reserve:////// JIT code calls this with its VM and live non-empty strings, whose lengths add up to at least `ROPE_STRING_MIN_LENGTH`/// and less than `u32::MAX`.+#[jit_abi]pub extern "C" fn libjs_jit_create_rope_string(vm: &Vm,lhs: Gc<PrimitiveString>,@@ -591,6 +595,7 @@ pub extern "C" fn libjs_jit_create_rope_string(/// elements.////// JIT code calls this with its VM.+#[jit_abi]pub extern "C" fn libjs_jit_allocate_array(vm: &Vm, count: u32) -> *mut Array {let realm = vm.current_realm().expect("JIT code runs in a realm");let array = Array::create(vm, realm, 0, None).must();@@ -602,6 +607,7 @@ pub extern "C" fn libjs_jit_allocate_array(vm: &Vm, count: u32) -> *mut Array {/// PrivateEnvironment*)`: a closure like the sample of a closure template, with the given environments.////// JIT code calls this with its VM, a sample it embeds and live environments (or null private environment).+#[jit_abi]pub extern "C" fn libjs_jit_clone_function(vm: &Vm,sample: Gc<EcmascriptFunctionObject>,diff --git a/Libraries/LibJS/Rust/src/jit/calls.rs b/Libraries/LibJS/Rust/src/jit/calls.rsindex cba518fc19f..931753f3a4b 100644--- a/Libraries/LibJS/Rust/src/jit/calls.rs+++ b/Libraries/LibJS/Rust/src/jit/calls.rs@@ -12,6 +12,7 @@ use core::ptr::NonNull;use libjs_abi::register;use libjs_jit::ir::Float64Function;+use libjs_runtime_macros::{jit_abi, jit_function_address};use super::code::EntryStatus;use super::entry_exit::{can_enter_jit_code, enter_jit_code};@@ -614,6 +615,7 @@ fn finish_generic_call(vm: &Vm, site: &JitCallSite, control: SlowPathControl, re/// # Safety////// JIT code calls this with its VM, its frame and the pc of one of its executable's call instructions.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_call(vm: *const Vm, frame: *mut ExecutionContext, pc: u32) -> i64 {// SAFETY: JIT code passes live pointers.let vm = unsafe { &*vm };@@ -793,6 +795,7 @@ fn call_spreading_arguments_from_jit(/// # Safety////// JIT code calls this with its VM, its frame and the pc of such an instruction.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_call_forwarding_arguments(vm: *const Vm,frame: *mut ExecutionContext,@@ -860,6 +863,7 @@ pub unsafe extern "C" fn libjs_jit_call_forwarding_arguments(/// # Safety////// JIT code calls this with its VM and frame, and the pc of the Call instruction.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_finish_direct_call(vm: *const Vm,frame: *mut ExecutionContext,@@ -902,6 +906,7 @@ pub struct CallEnvironment {/// # Safety////// JIT code calls this with its VM and an ECMAScript function that can be called inline.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_prepare_call_environment(vm: *const Vm,function: *const EcmascriptFunctionObject,@@ -949,6 +954,7 @@ pub unsafe extern "C" fn libjs_jit_prepare_call_environment(/// append it to without any observable step, and returns the new length as a value.////// JIT code calls this with a live array whose elements are packed.+#[jit_abi]pub extern "C" fn libjs_jit_array_push(array: &Array, value: u64) -> u64 {assert!(matches!(array.indexed_storage_kind(),@@ -964,6 +970,7 @@ pub extern "C" fn libjs_jit_array_push(array: &Array, value: u64) -> u64 {////// JIT code calls this with a live array whose prototype chain is the realm's default one without indexed properties,/// so that the store runs no code.+#[jit_abi]pub extern "C" fn libjs_jit_store_holey_element(object: &Object, index: u32, value: u64) {// NB: Branches on holey elements take packed ones too.assert!(matches!(@@ -978,6 +985,7 @@ pub extern "C" fn libjs_jit_store_holey_element(object: &Object, index: u32, val/// but the descriptive string of a symbol.////// JIT code calls this with its VM and a primitive.+#[jit_abi]pub extern "C" fn libjs_jit_primitive_to_string(vm: &Vm, primitive: u64) -> u64 {let primitive = Value::from_bits(primitive);assert!(!primitive.is_object());@@ -992,37 +1000,42 @@ pub extern "C" fn libjs_jit_primitive_to_string(vm: &Vm, primitive: u64) -> u64/// The address of the runtime's `double (double...)` function that computes `function`, which JIT code calls with/// numbers (see `Op::CallFloat64Function`).pub fn float64_function_address(function: Float64Function) -> u64 {- let function: *const () = match function {- Float64Function::Exp => libjs_jit_math_exp as *const (),- Float64Function::Log => libjs_jit_math_log as *const (),- Float64Function::Sin => libjs_jit_math_sin as *const (),- Float64Function::Cos => libjs_jit_math_cos as *const (),- Float64Function::Tan => libjs_jit_math_tan as *const (),- Float64Function::Pow => libjs_jit_math_pow as *const (),- };- function as u64+ match function {+ Float64Function::Exp => jit_function_address!(libjs_jit_math_exp),+ Float64Function::Log => jit_function_address!(libjs_jit_math_log),+ Float64Function::Sin => jit_function_address!(libjs_jit_math_sin),+ Float64Function::Cos => jit_function_address!(libjs_jit_math_cos),+ Float64Function::Tan => jit_function_address!(libjs_jit_math_tan),+ Float64Function::Pow => jit_function_address!(libjs_jit_math_pow),+ }}+#[jit_abi]extern "C" fn libjs_jit_math_exp(number: f64) -> f64 {math_object::exp_of_number(number)}+#[jit_abi]extern "C" fn libjs_jit_math_log(number: f64) -> f64 {math_object::log_of_number(number)}+#[jit_abi]extern "C" fn libjs_jit_math_sin(number: f64) -> f64 {math_object::sin_of_number(number)}+#[jit_abi]extern "C" fn libjs_jit_math_cos(number: f64) -> f64 {math_object::cos_of_number(number)}+#[jit_abi]extern "C" fn libjs_jit_math_tan(number: f64) -> f64 {math_object::tan_of_number(number)}+#[jit_abi]extern "C" fn libjs_jit_math_pow(base: f64, exponent: f64) -> f64 {value_conversions::exp_double(base, exponent)}@@ -1031,6 +1044,7 @@ extern "C" fn libjs_jit_math_pow(base: f64, exponent: f64) -> f64 {/// null, as the builtin function `function` makes it, or the empty value if that function is of another realm.////// JIT code calls this with its VM, a function object and such a primitive.+#[jit_abi]pub extern "C" fn libjs_jit_to_object(vm: &Vm, primitive: u64, function: u64) -> u64 {let (function, primitive) = (Value::from_bits(function).as_object(), Value::from_bits(primitive));assert!(!primitive.is_object() && !primitive.is_nullish());@@ -1045,6 +1059,7 @@ pub extern "C" fn libjs_jit_to_object(vm: &Vm, primitive: u64, function: u64) ->/// (the Array constructor) makes it, or the empty value if that function is of another realm.////// JIT code calls this with its VM, a length below 2^31 and a function object.+#[jit_abi]pub extern "C" fn libjs_jit_array_create(vm: &Vm, length: u32, function: u64) -> u64 {let realm = Value::from_bits(function).as_object().shape().realm();if vm.current_realm() != Some(realm) {@@ -1058,6 +1073,7 @@ pub extern "C" fn libjs_jit_array_create(vm: &Vm, length: u32, function: u64) ->/// start)` with the arguments object of the frame, which the code never created, as an array value.////// JIT code calls this with its VM and its frame.+#[jit_abi]pub extern "C" fn libjs_jit_slice_arguments(vm: &Vm, frame: &ExecutionContext, start: i32) -> u64 {// 23.1.3.28 Array.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-array.prototype.slice// NB: The arguments object has every passed argument, and its length is their count.diff --git a/Libraries/LibJS/Rust/src/jit/code.rs b/Libraries/LibJS/Rust/src/jit/code.rsindex 3189b7d2622..64f0ec281f3 100644--- a/Libraries/LibJS/Rust/src/jit/code.rs+++ b/Libraries/LibJS/Rust/src/jit/code.rs@@ -53,11 +53,19 @@ pub struct JitResult {/// `entry(VM*, ExecutionContext* frame)`: the frame is fully built for its executable, at pc 0 with Enter not run yet/// (or, for an on-stack replacement entry, at the loop back edge the entry is for).+#[cfg(not(all(target_arch = "x86_64", windows)))]pub type JitEntry = unsafe extern "C" fn(*const Vm, *mut ExecutionContext) -> JitResult;+#[cfg(all(target_arch = "x86_64", windows))]+pub type JitEntry = unsafe extern "sysv64" fn(*const Vm, *mut ExecutionContext) -> JitResult;/// `JitResult trampoline(VM*, ExecutionContext* frame, JitEntry entry)`: how native code calls JIT code (see/// `libjs_jit::codegen::generate_entry_trampoline()`), which expects the VM in its pinned register.+#[cfg(not(all(target_arch = "x86_64", windows)))]pub type EntryTrampoline = unsafe extern "C" fn(*const Vm, *mut ExecutionContext, JitEntry) -> JitResult;+// NB: JIT code uses the System V calling convention on Windows too. Native code that calls it with that convention+// keeps the registers that are callee-saved only on Windows, and gets the result in two registers.+#[cfg(all(target_arch = "x86_64", windows))]+pub type EntryTrampoline = unsafe extern "sysv64" fn(*const Vm, *mut ExecutionContext, JitEntry) -> JitResult;/// Where an executable is in its JIT compilation.#[derive(Clone, Copy, Debug, PartialEq, Eq)]diff --git a/Libraries/LibJS/Rust/src/jit/entry_exit.rs b/Libraries/LibJS/Rust/src/jit/entry_exit.rsindex c88ece5624b..554ba48b8d8 100644--- a/Libraries/LibJS/Rust/src/jit/entry_exit.rs+++ b/Libraries/LibJS/Rust/src/jit/entry_exit.rs@@ -11,6 +11,7 @@ use core::ptr::NonNull;use libjs_abi::register;use libjs_jit::code::SiteKind;+use libjs_runtime_macros::jit_abi;use super::code::{CompileState, EXIT_COUNT_BEFORE_DISCARD, EXIT_COUNT_BEFORE_DISCARD_FROM_LOOP, EntryStatus, JitEntry, JitResult,@@ -39,6 +40,7 @@ pub fn can_enter_jit_code(vm: &Vm, executable: &Executable) -> bool {/// # Safety////// JIT code calls this with its VM and the frame it built for the callee.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_not_compiled_call_entry(vm: *const Vm, frame: *mut ExecutionContext) -> JitResult {// SAFETY: JIT code passes its live VM.let vm = unsafe { &*vm };@@ -221,6 +223,7 @@ pub fn helper_enter_jit_code(vm: &Vm) -> i64 {/// # Safety////// JIT code calls this with its VM, its frame, one of its code's exit or leave sites and the registers it saved.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_exit(vm: *const Vm,frame: *mut ExecutionContext,@@ -256,6 +259,7 @@ fn call_site_callee_frame(vm: &Vm, root: NonNull<ExecutionContext>) -> NonNull<E/// # Safety////// Compiled code calls this with its VM, its frame, one of its code's inlined call sites and its frame pointer.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_push_inlined_call_frames(vm: *const Vm,frame: *mut ExecutionContext,@@ -276,6 +280,7 @@ pub unsafe extern "C" fn libjs_jit_push_inlined_call_frames(////// Compiled code calls this with its VM, its frame, one of its code's inlined call sites, its frame pointer and the/// callee's status.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_finish_inlined_direct_call(vm: *const Vm,frame: *mut ExecutionContext,@@ -306,6 +311,7 @@ pub unsafe extern "C" fn libjs_jit_finish_inlined_direct_call(////// Compiled code calls this with its VM, its frame, one of its code's inlined call sites, its frame pointer and the/// exception.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_inlined_raw_native_exception(vm: *const Vm,frame: *mut ExecutionContext,@@ -330,6 +336,7 @@ pub unsafe extern "C" fn libjs_jit_inlined_raw_native_exception(/// # Safety////// JIT code calls this with its VM and its frame.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_create_arguments(vm: *const Vm, frame: *mut ExecutionContext, mapped: u32) -> u64 {// SAFETY: JIT code passes live pointers.let (vm, frame) = unsafe { (&*vm, &*frame) };diff --git a/Libraries/LibJS/Rust/src/jit/helper_calls.rs b/Libraries/LibJS/Rust/src/jit/helper_calls.rsindex 26584439206..5aa5c05dc4b 100644--- a/Libraries/LibJS/Rust/src/jit/helper_calls.rs+++ b/Libraries/LibJS/Rust/src/jit/helper_calls.rs@@ -10,6 +10,7 @@//! declines, having done nothing observable.use libjs_jit::snapshot::Intrinsic;+use libjs_runtime_macros::{jit_abi, jit_function_address};use crate::interpreter::vm::Vm;use crate::layout::value::Value;@@ -22,22 +23,22 @@ use crate::utf16::TrimMode;/// The address of the runtime helper of `intrinsic`, or 0 if JIT code calls it in another way. Every intrinsic with a/// `HelperCall` has a helper here.pub fn address(intrinsic: Intrinsic) -> u64 {- let helper: *const () = match intrinsic {- Intrinsic::StringPrototypeIndexOf => string_index_of as *const (),- Intrinsic::StringPrototypeLastIndexOf => string_last_index_of as *const (),- Intrinsic::StringPrototypeIncludes => string_includes as *const (),- Intrinsic::StringPrototypeStartsWith => string_starts_with as *const (),- Intrinsic::StringPrototypeEndsWith => string_ends_with as *const (),- Intrinsic::StringPrototypeSlice => string_slice as *const (),- Intrinsic::StringPrototypeSubstring => string_substring as *const (),- Intrinsic::StringPrototypeToLowerCase => string_to_lowercase as *const (),- Intrinsic::StringPrototypeToUpperCase => string_to_uppercase as *const (),- Intrinsic::StringPrototypeTrim => string_trim as *const (),- Intrinsic::StringPrototypeTrimStart => string_trim_start as *const (),- Intrinsic::StringPrototypeTrimEnd => string_trim_end as *const (),- Intrinsic::RegExpPrototypeExec => regexp_exec as *const (),- Intrinsic::MapPrototypeGet => map_get as *const (),- Intrinsic::MapPrototypeHas => map_has as *const (),+ match intrinsic {+ Intrinsic::StringPrototypeIndexOf => jit_function_address!(string_index_of),+ Intrinsic::StringPrototypeLastIndexOf => jit_function_address!(string_last_index_of),+ Intrinsic::StringPrototypeIncludes => jit_function_address!(string_includes),+ Intrinsic::StringPrototypeStartsWith => jit_function_address!(string_starts_with),+ Intrinsic::StringPrototypeEndsWith => jit_function_address!(string_ends_with),+ Intrinsic::StringPrototypeSlice => jit_function_address!(string_slice),+ Intrinsic::StringPrototypeSubstring => jit_function_address!(string_substring),+ Intrinsic::StringPrototypeToLowerCase => jit_function_address!(string_to_lowercase),+ Intrinsic::StringPrototypeToUpperCase => jit_function_address!(string_to_uppercase),+ Intrinsic::StringPrototypeTrim => jit_function_address!(string_trim),+ Intrinsic::StringPrototypeTrimStart => jit_function_address!(string_trim_start),+ Intrinsic::StringPrototypeTrimEnd => jit_function_address!(string_trim_end),+ Intrinsic::RegExpPrototypeExec => jit_function_address!(regexp_exec),+ Intrinsic::MapPrototypeGet => jit_function_address!(map_get),+ Intrinsic::MapPrototypeHas => jit_function_address!(map_has),Intrinsic::FunctionPrototypeApply| Intrinsic::FunctionPrototypeCall| Intrinsic::ArrayPrototypePush@@ -52,9 +53,8 @@ pub fn address(intrinsic: Intrinsic) -> u64 {| Intrinsic::TypedArrayPrototypeLength| Intrinsic::MathMax| Intrinsic::MathMin- | Intrinsic::MathImul => return 0,- };- helper as u64+ | Intrinsic::MathImul => 0,+ }}/// The string of a value JIT code checked to be a string.@@ -71,6 +71,7 @@ fn int32(value: Value) -> u64 {}/// `string.indexOf(search_string, position)`.+#[jit_abi]extern "C" fn string_index_of(_vm: &Vm, string_value: u64, search_string: u64, position: i32) -> u64 {let (string_value, search_string) = (string(string_value), string(search_string));int32(StringPrototype::index_of_string(@@ -81,16 +82,19 @@ extern "C" fn string_index_of(_vm: &Vm, string_value: u64, search_string: u64, p}/// `string.toLowerCase()`.+#[jit_abi]extern "C" fn string_to_lowercase(vm: &Vm, string_value: u64) -> u64 {StringPrototype::to_lowercase_string(vm, string(string_value).as_string()).0}/// `string.toUpperCase()`.+#[jit_abi]extern "C" fn string_to_uppercase(vm: &Vm, string_value: u64) -> u64 {StringPrototype::to_uppercase_string(vm, string(string_value).as_string()).0}/// `string.lastIndexOf(search_string, position)`.+#[jit_abi]extern "C" fn string_last_index_of(_vm: &Vm, string_value: u64, search_string: u64, position: i32) -> u64 {let (string_value, search_string) = (string(string_value), string(search_string));int32(StringPrototype::last_index_of_string(@@ -101,6 +105,7 @@ extern "C" fn string_last_index_of(_vm: &Vm, string_value: u64, search_string: u}/// `string.includes(search_string, position)`.+#[jit_abi]extern "C" fn string_includes(_vm: &Vm, string_value: u64, search_string: u64, position: i32) -> u64 {let (string_value, search_string) = (string(string_value), string(search_string));u64::from(StringPrototype::includes_string(@@ -111,6 +116,7 @@ extern "C" fn string_includes(_vm: &Vm, string_value: u64, search_string: u64, p}/// `string.startsWith(search_string, position)`.+#[jit_abi]extern "C" fn string_starts_with(_vm: &Vm, string_value: u64, search_string: u64, position: i32) -> u64 {let (string_value, search_string) = (string(string_value), string(search_string));u64::from(StringPrototype::starts_with_string(@@ -121,6 +127,7 @@ extern "C" fn string_starts_with(_vm: &Vm, string_value: u64, search_string: u64}/// `string.endsWith(search_string, end_position)`.+#[jit_abi]extern "C" fn string_ends_with(_vm: &Vm, string_value: u64, search_string: u64, end_position: i32) -> u64 {let (string_value, search_string) = (string(string_value), string(search_string));u64::from(StringPrototype::ends_with_string(@@ -131,32 +138,38 @@ extern "C" fn string_ends_with(_vm: &Vm, string_value: u64, search_string: u64,}/// `string.slice(start, end)`.+#[jit_abi]extern "C" fn string_slice(vm: &Vm, string_value: u64, start: i32, end: i32) -> u64 {StringPrototype::slice_string(vm, string(string_value).as_string(), f64::from(start), f64::from(end)).0}/// `string.substring(start, end)`.+#[jit_abi]extern "C" fn string_substring(vm: &Vm, string_value: u64, start: i32, end: i32) -> u64 {StringPrototype::substring_string(vm, string(string_value).as_string(), f64::from(start), f64::from(end)).0}/// `string.trim()`.+#[jit_abi]extern "C" fn string_trim(vm: &Vm, string_value: u64) -> u64 {trim_primitive_string(vm, string(string_value).as_string(), TrimMode::Both).0}/// `string.trimStart()`.+#[jit_abi]extern "C" fn string_trim_start(vm: &Vm, string_value: u64) -> u64 {trim_primitive_string(vm, string(string_value).as_string(), TrimMode::Left).0}/// `string.trimEnd()`.+#[jit_abi]extern "C" fn string_trim_end(vm: &Vm, string_value: u64) -> u64 {trim_primitive_string(vm, string(string_value).as_string(), TrimMode::Right).0}/// `regexp.exec(string)`, for a RegExp object `regexp` whose exec runs no code (see/// `regexp_builtin_exec_running_no_code()`).+#[jit_abi]extern "C" fn regexp_exec(vm: &Vm, regexp: u64, string_value: u64) -> u64 {regexp_builtin_exec_running_no_code(vm, Value::from_bits(regexp), string(string_value).as_string()).map_or(Value::EMPTY.0, |result| result.0)@@ -172,6 +185,7 @@ fn map(value: u64) -> Option<crate::layout::cell::Gc<Map>> {}/// `map.get(key)`, or the empty value if the `this` value is no Map.+#[jit_abi]extern "C" fn map_get(_vm: &Vm, map_value: u64, key: u64) -> u64 {let Some(map) = map(map_value) else {return Value::EMPTY.0;@@ -182,6 +196,7 @@ extern "C" fn map_get(_vm: &Vm, map_value: u64, key: u64) -> u64 {}/// `map.has(key)`, or the empty value if the `this` value is no Map.+#[jit_abi]extern "C" fn map_has(_vm: &Vm, map_value: u64, key: u64) -> u64 {let Some(map) = map(map_value) else {return Value::EMPTY.0;diff --git a/Libraries/LibJS/Rust/src/jit/intrinsics.rs b/Libraries/LibJS/Rust/src/jit/intrinsics.rsindex f1aee59dd63..0a85e3ed6fd 100644--- a/Libraries/LibJS/Rust/src/jit/intrinsics.rs+++ b/Libraries/LibJS/Rust/src/jit/intrinsics.rs@@ -9,6 +9,7 @@//! code then exits to the interpreter, which runs the instruction itself.use ak::Utf16FlyString;+use libjs_runtime_macros::jit_abi;use crate::bytecode::executable::{KeyedPropertyLookup, KeyedPropertyLookupCache, PropertyLookupCacheEntryType};use crate::gc::class::GcCell;@@ -34,6 +35,7 @@ use crate::utf16::{has_fly_string_storage, to_utf16_fly_string};////// `items` points to `item_count` live, aligned values on the caller's native/// stack, outside any object's element storage, for the duration of the call.+#[jit_abi]pub unsafe extern "C" fn libjs_jit_array_splice(vm: &Vm,receiver: u64,@@ -186,6 +188,7 @@ fn has_own_string_property(vm: &Vm, object: Gc<Object>, name: &Utf16FlyString) -/// `Object.prototype.hasOwnProperty` called on `object` with `key`.////// JIT code calls this with its VM.+#[jit_abi]pub extern "C" fn libjs_jit_has_own_property(vm: &Vm, object: u64, key: u64) -> u64 {let (object, key) = (Value::from_bits(object), Value::from_bits(key));if !object.is_object() || !has_ordinary_lookups(object.as_object()) {@@ -210,6 +213,7 @@ pub extern "C" fn libjs_jit_has_own_property(vm: &Vm, object: u64, key: u64) ->/// `key in object`.////// JIT code calls this with its VM.+#[jit_abi]pub extern "C" fn libjs_jit_has_property(vm: &Vm, key: u64, object: u64) -> u64 {let (key_value, object) = (Value::from_bits(key), Value::from_bits(object));let index_key = key_value.is_int32() && key_value.as_i32() >= 0;@@ -264,6 +268,7 @@ pub extern "C" fn libjs_jit_has_property(vm: &Vm, key: u64, object: u64) -> u64/// empty value otherwise.////// JIT code calls this with its VM.+#[jit_abi]pub extern "C" fn libjs_jit_open_array_iteration(vm: &Vm, iterable: u64) -> u64 {let iterable = Value::from_bits(iterable);if !iterable.is_object() {diff --git a/Libraries/LibJS/Rust/src/jit/mod.rs b/Libraries/LibJS/Rust/src/jit/mod.rsindex adcf559b5b7..c82ebf18812 100644--- a/Libraries/LibJS/Rust/src/jit/mod.rs+++ b/Libraries/LibJS/Rust/src/jit/mod.rs@@ -84,7 +84,8 @@ fn frames_above(vm: &Vm, frame: NonNull<ExecutionContext>) -> Option<Vec<NonNull/// What calls of an executable without JIT code enter through its slot in the JIT entry table.pub fn not_compiled_call_entry() -> *const core::ffi::c_void {- entry_exit::libjs_jit_not_compiled_call_entry as *const core::ffi::c_void+ libjs_runtime_macros::jit_function_address!(entry_exit::libjs_jit_not_compiled_call_entry)+ as *const core::ffi::c_void}/// Which interpreter handlers an executable's frames run with. Each tier's value is the index of its dispatch tablediff --git a/Libraries/LibJS/Rust/src/jit/runtime_info.rs b/Libraries/LibJS/Rust/src/jit/runtime_info.rsindex 90e1ead7c64..e680b46e0ba 100644--- a/Libraries/LibJS/Rust/src/jit/runtime_info.rs+++ b/Libraries/LibJS/Rust/src/jit/runtime_info.rs@@ -18,6 +18,7 @@ use libjs_jit::snapshot::{CellId, DynamicCallLayout, Float64FunctionAddresses, HelperCallAddresses, IntrinsicHelpers, RuntimeInfo,RuntimeLayout, RuntimeOffsets, TypeofStrings,};+use libjs_runtime_macros::jit_function_address;use super::allocation::{AllocationInfos, FUNCTION_ENVIRONMENT_FREE_LIST_COUNT};use super::entry_table::{JIT_ENTRY_SLOT_MASK, JIT_ENTRY_TABLE_OWNERS_OFFSET};@@ -498,44 +499,44 @@ pub fn runtime_info(let mut info = RuntimeInfo {no_htmldda_objects: !vm.jit.htmldda_objects_exist(),slow_paths: Arc::clone(&addresses.slow_paths),- jit_call: super::calls::libjs_jit_call as *const () as u64,- call_forwarding_arguments: super::calls::libjs_jit_call_forwarding_arguments as *const () as u64,- finish_direct_call: super::calls::libjs_jit_finish_direct_call as *const () as u64,+ jit_call: jit_function_address!(super::calls::libjs_jit_call),+ call_forwarding_arguments: jit_function_address!(super::calls::libjs_jit_call_forwarding_arguments),+ finish_direct_call: jit_function_address!(super::calls::libjs_jit_finish_direct_call),raw_native_exception: addresses.raw_native_exception,- push_inlined_call_frames: super::entry_exit::libjs_jit_push_inlined_call_frames as *const () as u64,- finish_inlined_direct_call: super::entry_exit::libjs_jit_finish_inlined_direct_call as *const () as u64,+ push_inlined_call_frames: jit_function_address!(super::entry_exit::libjs_jit_push_inlined_call_frames),+ finish_inlined_direct_call: jit_function_address!(super::entry_exit::libjs_jit_finish_inlined_direct_call),inlined_raw_native_exception: if RAW_NATIVE_FUNCTIONS_RETURN_IN_REGISTERS {- super::entry_exit::libjs_jit_inlined_raw_native_exception as *const () as u64+ jit_function_address!(super::entry_exit::libjs_jit_inlined_raw_native_exception)} else {0},- array_push: super::calls::libjs_jit_array_push as *const () as u64,- array_splice: super::intrinsics::libjs_jit_array_splice as *const () as u64,- store_holey_element: super::calls::libjs_jit_store_holey_element as *const () as u64,- slice_arguments: super::calls::libjs_jit_slice_arguments as *const () as u64,- open_array_iteration: super::intrinsics::libjs_jit_open_array_iteration as *const () as u64,+ array_push: jit_function_address!(super::calls::libjs_jit_array_push),+ array_splice: jit_function_address!(super::intrinsics::libjs_jit_array_splice),+ store_holey_element: jit_function_address!(super::calls::libjs_jit_store_holey_element),+ slice_arguments: jit_function_address!(super::calls::libjs_jit_slice_arguments),+ open_array_iteration: jit_function_address!(super::intrinsics::libjs_jit_open_array_iteration),// NB: Filled in by capture_snapshot(), which lists the cells as embedded cells.array_iterator_next: None,array_iterator_return_watchpoint_set: None,array_iterator_next_watchpoint_set_address: None,array_iterator_method_watchpoint_set_address: None,- jit_exit: super::entry_exit::libjs_jit_exit as *const () as u64,+ jit_exit: jit_function_address!(super::entry_exit::libjs_jit_exit),to_boolean: addresses.to_boolean,- primitive_to_string: super::calls::libjs_jit_primitive_to_string as *const () as u64,+ primitive_to_string: jit_function_address!(super::calls::libjs_jit_primitive_to_string),helper_calls: HelperCallAddresses(super::helper_calls::address),float64_functions: Float64FunctionAddresses(super::calls::float64_function_address),- to_object: super::calls::libjs_jit_to_object as *const () as u64,- array_create: super::calls::libjs_jit_array_create as *const () as u64,+ to_object: jit_function_address!(super::calls::libjs_jit_to_object),+ array_create: jit_function_address!(super::calls::libjs_jit_array_create),intrinsic_helpers: IntrinsicHelpers {- has_own_property: super::intrinsics::libjs_jit_has_own_property as *const () as u64,- has_property: super::intrinsics::libjs_jit_has_property as *const () as u64,+ has_own_property: jit_function_address!(super::intrinsics::libjs_jit_has_own_property),+ has_property: jit_function_address!(super::intrinsics::libjs_jit_has_property),},- create_arguments: super::entry_exit::libjs_jit_create_arguments as *const () as u64,+ create_arguments: jit_function_address!(super::entry_exit::libjs_jit_create_arguments),object_allocation: allocation.object,array_allocation: allocation.array,rope_allocation: allocation.rope,function_allocation: allocation.function,- create_lexical_environment: super::allocation::libjs_jit_create_lexical_environment as *const () as u64,+ create_lexical_environment: jit_function_address!(super::allocation::libjs_jit_create_lexical_environment),realm: CellId(realm.as_ptr() as u64),array_prototype: CellId(realm.array_prototype().as_ptr() as u64),object_prototype: CellId(realm.object_prototype().as_ptr() as u64),@@ -596,7 +597,7 @@ fn dynamic_call_layout(vm: &Vm) -> DynamicCallLayout {native_function_table_index_mask: NATIVE_FUNCTION_TABLE_INDEX_MASK,native_function_table_entry_size: offset(size_of::<NativeFunctionTableEntry>()),native_function_table_entry_function: offset(offset_of!(NativeFunctionTableEntry, function)),- prepare_call_environment: super::calls::libjs_jit_prepare_call_environment as *const () as u64,+ prepare_call_environment: jit_function_address!(super::calls::libjs_jit_prepare_call_environment),shared_data_call_environment_template: offset(offset_of!(SharedFunctionInstanceData,call_environment_template