From b4565f0ce543aa22221e72e7c10caddedce6dda4 Mon Sep 17 00:00:00 2001 From: Eduardo Souza Date: Fri, 12 Jul 2024 15:22:11 +1000 Subject: [PATCH] Save registers for conservative scanning (#159) Adding context field to `mmtk__jl_tls_states_t` to reflect the changes in https://github.com/mmtk/julia/pull/61. --- julia/mmtk_julia_types.h | 3 + mmtk/Cargo.toml | 2 +- mmtk/src/julia_types.rs | 467 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 467 insertions(+), 5 deletions(-) diff --git a/julia/mmtk_julia_types.h b/julia/mmtk_julia_types.h index f23f86c4..1bc5a919 100644 --- a/julia/mmtk_julia_types.h +++ b/julia/mmtk_julia_types.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "mmtkMutator.h" typedef __SIZE_TYPE__ size_t; @@ -438,6 +439,8 @@ typedef struct mmtk__jl_tls_states_t { MMTkMutatorContext mmtk_mutator; size_t malloc_sz_since_last_poll; + ucontext_t ctx_at_the_time_gc_started; + // JULIA_DEBUG_SLEEPWAKE( // uint64_t uv_run_enter; // uint64_t uv_run_leave; diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index c72c0db4..fc82be5b 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" [package.metadata.julia] # Our CI matches the following line and extract mmtk/julia. If this line is updated, please check ci yaml files and make sure it works. julia_repo = "https://github.com/mmtk/julia.git" -julia_version = "084d8a08f0cfc2b1d7acae2e000c165e8b11de5b" +julia_version = "045bf87050653aa4ae996d3cdc052b1f3fcad7e6" [lib] crate-type = ["cdylib"] diff --git a/mmtk/src/julia_types.rs b/mmtk/src/julia_types.rs index 4bc1a80a..d448770b 100644 --- a/mmtk/src/julia_types.rs +++ b/mmtk/src/julia_types.rs @@ -1,4 +1,4 @@ -/* automatically generated by rust-bindgen 0.63.0 */ +/* automatically generated by rust-bindgen 0.69.4 */ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] @@ -236,6 +236,12 @@ pub const __have_pthread_attr_t: u32 = 1; pub const PTHREAD_STACK_MIN: u32 = 16384; pub const PTHREAD_ONCE_INIT: u32 = 0; pub const PTHREAD_BARRIER_SERIAL_THREAD: i32 = -1; +pub const _UCONTEXT_H: u32 = 1; +pub const _SYS_UCONTEXT_H: u32 = 1; +pub const __sigset_t_defined: u32 = 1; +pub const __stack_t_defined: u32 = 1; +pub const __NGREG: u32 = 23; +pub const NGREG: u32 = 23; pub const MAX_BUMP_ALLOCATORS: u32 = 6; pub const MAX_LARGE_OBJECT_ALLOCATORS: u32 = 2; pub const MAX_MALLOC_ALLOCATORS: u32 = 1; @@ -2736,6 +2742,449 @@ extern "C" { __child: ::std::option::Option, ) -> ::std::os::raw::c_int; } +pub type sigset_t = __sigset_t; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct stack_t { + pub ss_sp: *mut ::std::os::raw::c_void, + pub ss_flags: ::std::os::raw::c_int, + pub ss_size: usize, +} +#[test] +fn bindgen_test_layout_stack_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(stack_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(stack_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ss_sp) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(stack_t), + "::", + stringify!(ss_sp) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ss_flags) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(stack_t), + "::", + stringify!(ss_flags) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ss_size) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(stack_t), + "::", + stringify!(ss_size) + ) + ); +} +pub type greg_t = ::std::os::raw::c_longlong; +pub type gregset_t = [greg_t; 23usize]; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _libc_fpxreg { + pub significand: [::std::os::raw::c_ushort; 4usize], + pub exponent: ::std::os::raw::c_ushort, + pub __glibc_reserved1: [::std::os::raw::c_ushort; 3usize], +} +#[test] +fn bindgen_test_layout__libc_fpxreg() { + const UNINIT: ::std::mem::MaybeUninit<_libc_fpxreg> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<_libc_fpxreg>(), + 16usize, + concat!("Size of: ", stringify!(_libc_fpxreg)) + ); + assert_eq!( + ::std::mem::align_of::<_libc_fpxreg>(), + 2usize, + concat!("Alignment of ", stringify!(_libc_fpxreg)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).significand) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpxreg), + "::", + stringify!(significand) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).exponent) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpxreg), + "::", + stringify!(exponent) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__glibc_reserved1) as usize - ptr as usize }, + 10usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpxreg), + "::", + stringify!(__glibc_reserved1) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _libc_xmmreg { + pub element: [__uint32_t; 4usize], +} +#[test] +fn bindgen_test_layout__libc_xmmreg() { + const UNINIT: ::std::mem::MaybeUninit<_libc_xmmreg> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<_libc_xmmreg>(), + 16usize, + concat!("Size of: ", stringify!(_libc_xmmreg)) + ); + assert_eq!( + ::std::mem::align_of::<_libc_xmmreg>(), + 4usize, + concat!("Alignment of ", stringify!(_libc_xmmreg)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).element) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_libc_xmmreg), + "::", + stringify!(element) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct _libc_fpstate { + pub cwd: __uint16_t, + pub swd: __uint16_t, + pub ftw: __uint16_t, + pub fop: __uint16_t, + pub rip: __uint64_t, + pub rdp: __uint64_t, + pub mxcsr: __uint32_t, + pub mxcr_mask: __uint32_t, + pub _st: [_libc_fpxreg; 8usize], + pub _xmm: [_libc_xmmreg; 16usize], + pub __glibc_reserved1: [__uint32_t; 24usize], +} +#[test] +fn bindgen_test_layout__libc_fpstate() { + const UNINIT: ::std::mem::MaybeUninit<_libc_fpstate> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<_libc_fpstate>(), + 512usize, + concat!("Size of: ", stringify!(_libc_fpstate)) + ); + assert_eq!( + ::std::mem::align_of::<_libc_fpstate>(), + 8usize, + concat!("Alignment of ", stringify!(_libc_fpstate)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).cwd) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(cwd) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).swd) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(swd) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ftw) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(ftw) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).fop) as usize - ptr as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(fop) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).rip) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(rip) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).rdp) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(rdp) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).mxcsr) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(mxcsr) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).mxcr_mask) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(mxcr_mask) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._st) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(_st) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr)._xmm) as usize - ptr as usize }, + 160usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(_xmm) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__glibc_reserved1) as usize - ptr as usize }, + 416usize, + concat!( + "Offset of field: ", + stringify!(_libc_fpstate), + "::", + stringify!(__glibc_reserved1) + ) + ); +} +pub type fpregset_t = *mut _libc_fpstate; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct mcontext_t { + pub gregs: gregset_t, + pub fpregs: fpregset_t, + pub __reserved1: [::std::os::raw::c_ulonglong; 8usize], +} +#[test] +fn bindgen_test_layout_mcontext_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 256usize, + concat!("Size of: ", stringify!(mcontext_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(mcontext_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).gregs) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(mcontext_t), + "::", + stringify!(gregs) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).fpregs) as usize - ptr as usize }, + 184usize, + concat!( + "Offset of field: ", + stringify!(mcontext_t), + "::", + stringify!(fpregs) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__reserved1) as usize - ptr as usize }, + 192usize, + concat!( + "Offset of field: ", + stringify!(mcontext_t), + "::", + stringify!(__reserved1) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ucontext_t { + pub uc_flags: ::std::os::raw::c_ulong, + pub uc_link: *mut ucontext_t, + pub uc_stack: stack_t, + pub uc_mcontext: mcontext_t, + pub uc_sigmask: sigset_t, + pub __fpregs_mem: _libc_fpstate, + pub __ssp: [::std::os::raw::c_ulonglong; 4usize], +} +#[test] +fn bindgen_test_layout_ucontext_t() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 968usize, + concat!("Size of: ", stringify!(ucontext_t)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ucontext_t)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).uc_flags) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ucontext_t), + "::", + stringify!(uc_flags) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).uc_link) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ucontext_t), + "::", + stringify!(uc_link) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).uc_stack) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ucontext_t), + "::", + stringify!(uc_stack) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).uc_mcontext) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(ucontext_t), + "::", + stringify!(uc_mcontext) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).uc_sigmask) as usize - ptr as usize }, + 296usize, + concat!( + "Offset of field: ", + stringify!(ucontext_t), + "::", + stringify!(uc_sigmask) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__fpregs_mem) as usize - ptr as usize }, + 424usize, + concat!( + "Offset of field: ", + stringify!(ucontext_t), + "::", + stringify!(__fpregs_mem) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).__ssp) as usize - ptr as usize }, + 936usize, + concat!( + "Offset of field: ", + stringify!(ucontext_t), + "::", + stringify!(__ssp) + ) + ); +} +extern "C" { + pub fn getcontext(__ucp: *mut ucontext_t) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn setcontext(__ucp: *const ucontext_t) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn swapcontext(__oucp: *mut ucontext_t, __ucp: *const ucontext_t) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn makecontext( + __ucp: *mut ucontext_t, + __func: ::std::option::Option, + __argc: ::std::os::raw::c_int, + ... + ); +} pub const Allocator_AllocatorDefault: Allocator = 0; pub const Allocator_AllocatorImmortal: Allocator = 1; pub const Allocator_AllocatorLos: Allocator = 2; @@ -3663,7 +4112,6 @@ fn bindgen_test_layout_mmtk__jl_taggedvalue_t() { ); } #[repr(C)] -#[repr(align(2))] #[derive(Debug, Copy, Clone)] pub struct mmtk_jl_array_flags_t { pub _bitfield_align_1: [u16; 0], @@ -6007,6 +6455,7 @@ pub struct mmtk__jl_tls_states_t { pub locks: mmtk_small_arraylist_t, pub mmtk_mutator: MMTkMutatorContext, pub malloc_sz_since_last_poll: usize, + pub ctx_at_the_time_gc_started: ucontext_t, } #[repr(C)] #[derive(Copy, Clone)] @@ -6060,7 +6509,7 @@ fn bindgen_test_layout_mmtk__jl_tls_states_t() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 13448usize, + 14416usize, concat!("Size of: ", stringify!(mmtk__jl_tls_states_t)) ); assert_eq!( @@ -6458,6 +6907,16 @@ fn bindgen_test_layout_mmtk__jl_tls_states_t() { stringify!(malloc_sz_since_last_poll) ) ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ctx_at_the_time_gc_started) as usize - ptr as usize }, + 13448usize, + concat!( + "Offset of field: ", + stringify!(mmtk__jl_tls_states_t), + "::", + stringify!(ctx_at_the_time_gc_started) + ) + ); } pub type mmtk_jl_tls_states_t = mmtk__jl_tls_states_t; #[repr(C)] @@ -6844,7 +7303,7 @@ pub union mmtk___jl_purity_overrides_t { pub overrides: mmtk___jl_purity_overrides_t__bindgen_ty_1, pub bits: u8, } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Copy, Clone)] pub struct mmtk___jl_purity_overrides_t__bindgen_ty_1 { pub _bitfield_align_1: [u8; 0],