rusty_racer 0.1.15-arm64-darwin → 0.1.16-arm64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3f48ab81abbba3986d2896101c2c4338506ad0cdedc5c0708c0c68a1ab69011
4
- data.tar.gz: bfdfb68e55ee955c36c3be519dcacc1d7357a9754bb6bc15bcaf7621f22d1265
3
+ metadata.gz: c46ebb9671a5c9073b1ab2e3c5bfa4507e0bad76ddaf0d89c1110738bced7e8e
4
+ data.tar.gz: 6279c5093cb6ed1c1077c7376a15969cefc729e58b0b6cfe080ed9e3e3805af4
5
5
  SHA512:
6
- metadata.gz: 3af17ec8cb46eb299e2fd2e0085a60e0823ce6621f2e189f5558026d89ac367f9ed52c2f661f5db1e77b7399655595a95679f1d6862ea4a5841b22368bd0b6c8
7
- data.tar.gz: e83e9aa3ebe30de8bd20b5113628fb0bd16b1b15efae11399320e843af383c470c2753d78fd49b5a872c56f266466ccbb70513e475aae9016b78d5da09572711
6
+ metadata.gz: 8c389b0146f0e013416a60ee3ba9188d2caecafcd780e718ca7791b2d47ed545c70491e674d4ccd524f26ecd10dac2bf73470dc01bd009f5e919560965c05680
7
+ data.tar.gz: '095eef8c16edce2253f6d000eda31dbaec9daeb734637ef4c3bbac76d717a3b048eae94c47b70c7f08c97454cd3e3a19e205e931b5b8968666224de37c73d7ad'
@@ -5,7 +5,7 @@
5
5
  # links and loads with no custom archive.
6
6
  [package]
7
7
  name = "rusty_racer"
8
- version = "0.1.15"
8
+ version = "0.1.16"
9
9
  edition = "2024"
10
10
  publish = false
11
11
 
@@ -157,8 +157,9 @@ fn native_stack_bounds() -> (usize, usize) {
157
157
  // a deep fiber recursion overflows the real stack and SEGVs the unmapped guard.
158
158
  // (0, 0) if unknown.
159
159
  //
160
- // Cached per native thread, several regions at a time, because a miss re-parses
161
- // all of /proc/self/maps and costs far more than the op it serves: with ONE slot
160
+ // Cached per native thread, several regions at a time, because a miss asks the
161
+ // OS for the whole memory map and costs far more than the op it serves: with ONE
162
+ // slot
162
163
  // a workload that alternates between fibers missed on every single op, and an
163
164
  // eval went from 1.2us to 31us as soon as two fibers took turns (measured on a
164
165
  // 212-line maps; a Rails process has many times that). Ruby pools fiber stacks,
@@ -275,16 +276,16 @@ fn current_region_bounds_cached(addr: usize) -> (usize, usize) {
275
276
  })
276
277
  }
277
278
 
278
- // The [start, end) of the /proc/self/maps mapping containing `addr`. Linux only;
279
- // (0, 0) elsewhere (and the caller falls back). Reads the file fresh slow, so
280
- // only called on a cache miss (a new fiber).
279
+ // The [start, end) of the mapping containing `addr`, or (0, 0) when it can't be
280
+ // established. Only called on a cache miss (a new fiber), because it is slow.
281
281
  //
282
- // Everything that needs a FIBER's real bounds degrades on the (0, 0) platforms,
283
- // macOS being the shipped one: the stack limit drops to a fixed budget below the
284
- // SP (see StackScope::enter), and a nested op can no longer widen its GC-scan
285
- // start to the enclosing op's, so it narrows to its own frame. Both are the
286
- // pre-fiber-support behaviour rather than a crash, but a darwin implementation
287
- // (mach_vm_region on the current task) would close the gap.
282
+ // (0, 0) is the fail-safe answer, not an error: every caller falls back to a
283
+ // fixed budget below the SP, which is what this gem did on every platform before
284
+ // any of these lookups existed. So a platform without an implementation, or a
285
+ // lookup that returns something we can't vouch for, degrades to a smaller JS
286
+ // stack rather than to a wrong one.
287
+ //
288
+ // Linux reads /proc/self/maps fresh each time.
288
289
  #[cfg(target_os = "linux")]
289
290
  fn query_region_bounds(addr: usize) -> (usize, usize) {
290
291
  use std::io::Read;
@@ -314,7 +315,73 @@ fn query_region_bounds(addr: usize) -> (usize, usize) {
314
315
  (0, 0)
315
316
  }
316
317
 
317
- #[cfg(not(target_os = "linux"))]
318
+ // macOS has no /proc, so ask the Mach VM directly. mach_vm_region reports the
319
+ // region containing `addr` — or, when `addr` sits in a hole, the next one ABOVE
320
+ // it — so the answer is checked for containment rather than trusted. It is also
321
+ // checked for being readable and writable: a stack always is, and a protection
322
+ // that isn't tells us we either walked into something that is not a stack or
323
+ // misread the reply, in which case the fixed-budget fallback is the safer answer.
324
+ #[cfg(target_os = "macos")]
325
+ fn query_region_bounds(addr: usize) -> (usize, usize) {
326
+ // Not in libc, which points at the `mach2` crate instead; these are the only
327
+ // entry points we need, so declare them here rather than take the dependency.
328
+ // (libc does carry mach_task_self_, but deprecated for the same reason.)
329
+ unsafe extern "C" {
330
+ static mach_task_self_: libc::mach_port_t;
331
+ fn mach_vm_region(
332
+ target_task: libc::vm_map_t,
333
+ address: *mut libc::mach_vm_address_t,
334
+ size: *mut libc::mach_vm_size_t,
335
+ flavor: libc::c_int,
336
+ info: *mut u32,
337
+ info_count: *mut libc::mach_msg_type_number_t,
338
+ object_name: *mut libc::mach_port_t,
339
+ ) -> libc::kern_return_t;
340
+ fn mach_port_deallocate(
341
+ task: libc::mach_port_t,
342
+ name: libc::mach_port_t,
343
+ ) -> libc::kern_return_t;
344
+ }
345
+ // VM_REGION_BASIC_INFO_64, and the width of vm_region_basic_info_data_64_t
346
+ // in u32s. Only `protection` (its first field) is read.
347
+ const VM_REGION_BASIC_INFO_64: libc::c_int = 9;
348
+ const VM_REGION_BASIC_INFO_COUNT_64: libc::mach_msg_type_number_t = 9;
349
+ const KERN_SUCCESS: libc::kern_return_t = 0;
350
+ const VM_PROT_READ_WRITE: u32 = 0x1 | 0x2;
351
+
352
+ unsafe {
353
+ let mut start = addr as libc::mach_vm_address_t;
354
+ let mut size: libc::mach_vm_size_t = 0;
355
+ let mut info = [0u32; VM_REGION_BASIC_INFO_COUNT_64 as usize];
356
+ let mut count = VM_REGION_BASIC_INFO_COUNT_64;
357
+ let mut object_name: libc::mach_port_t = 0;
358
+ let kr = mach_vm_region(
359
+ mach_task_self_,
360
+ &mut start,
361
+ &mut size,
362
+ VM_REGION_BASIC_INFO_64,
363
+ info.as_mut_ptr(),
364
+ &mut count,
365
+ &mut object_name,
366
+ );
367
+ // Documented to come back MACH_PORT_NULL for this flavor, but a leaked
368
+ // port name in a per-fiber path would accumulate, so hand it back.
369
+ if object_name != 0 {
370
+ mach_port_deallocate(mach_task_self_, object_name);
371
+ }
372
+ if kr != KERN_SUCCESS || size == 0 || info[0] & VM_PROT_READ_WRITE != VM_PROT_READ_WRITE {
373
+ return (0, 0);
374
+ }
375
+ let (lo, hi) = (start as usize, start.saturating_add(size) as usize);
376
+ if addr >= lo && addr < hi {
377
+ (lo, hi)
378
+ } else {
379
+ (0, 0) // `addr` was in a hole; this is the region after it
380
+ }
381
+ }
382
+ }
383
+
384
+ #[cfg(not(any(target_os = "linux", target_os = "macos")))]
318
385
  fn query_region_bounds(_addr: usize) -> (usize, usize) {
319
386
  (0, 0)
320
387
  }
@@ -337,8 +404,8 @@ pub(crate) static STACK_DEBUG: AtomicBool = AtomicBool::new(false);
337
404
  // * Too low (below the real bottom) and a deep recursion grows past the
338
405
  // mapped stack and SEGVs the unmapped guard page below it.
339
406
  // So detect the stack by comparing the SP to the cached native bounds: on the
340
- // native stack, anchor to its pthread bottom; on a fiber, find the bottom of the
341
- // /proc/self/maps region holding the SP (the fiber's real bottom — anchoring to
407
+ // native stack, anchor to its pthread bottom; on a fiber, look up the bottom of
408
+ // the mapping holding the SP (the fiber's real bottom — anchoring to
342
409
  // SP minus a fixed guard punched through the bottom of Avo's small/deep Capybara
343
410
  // fibers and SEGV'd).
344
411
  //
@@ -433,8 +500,8 @@ impl<'a> StackScope<'a> {
433
500
  let limit = if on_native {
434
501
  nbottom + NATIVE_GUARD
435
502
  } else {
436
- // Anchor to the FIBER's real bottom (the /proc/self/maps region
437
- // holding the SP), not the SP: SP - fixed_guard can punch through the
503
+ // Anchor to the FIBER's real bottom (the mapping holding the SP),
504
+ // not the SP: SP - fixed_guard can punch through the
438
505
  // bottom of a small/deep fiber stack and SEGV (Avo's deep Capybara
439
506
  // filter chain). Reserve FIBER_RESERVE above the bottom for the
440
507
  // throw, but keep the limit below the SP so we don't false-overflow;
@@ -448,15 +515,16 @@ impl<'a> StackScope<'a> {
448
515
  if region.0 != 0 {
449
516
  (region.0 + FIBER_RESERVE).min(sp.saturating_sub(8 * 1024))
450
517
  } else {
451
- // Region unknown only Linux can look a fiber's bounds up (see
452
- // query_region_bounds), so this is the macOS path. Best effort:
453
- // hand JS a fixed budget below the SP and hope the fiber is that
518
+ // Region unknown. Both shipped platforms implement the lookup,
519
+ // so reaching this on one of them means the lookup FAILED (see
520
+ // query_region_bounds for what it refuses to vouch for) worth
521
+ // chasing rather than assuming, since the budget here is only a
522
+ // guess: a fixed reserve below the SP, hoping the fiber is that
454
523
  // deep. It usually is for an OUTERMOST fiber op, whose SP sits
455
524
  // near the fiber's top, and much less reliably for a NESTED one,
456
525
  // whose SP is already far down the fiber — there this can land
457
526
  // below the fiber's mapped bottom, and V8 then grows through the
458
- // guard page (SEGV) instead of throwing. Fixing that properly
459
- // means a mach_vm_region lookup for darwin.
527
+ // guard page (SEGV) instead of throwing.
460
528
  sp.saturating_sub(64 * 1024)
461
529
  }
462
530
  };
@@ -519,7 +587,7 @@ impl<'a> StackScope<'a> {
519
587
  // * a fiber we ENTERED (the enclosing op is elsewhere) — this op's
520
588
  // `stack_top`, which keeps the range between two real stack pointers
521
589
  // (marker..stack_top) and so guaranteed mapped. We can't use the
522
- // /proc/maps region top: that mapping isn't reliably contiguous, so
590
+ // looked-up region's top: that mapping isn't reliably contiguous, so
523
591
  // the scan could still hit a hole below it.
524
592
  // * a fiber we were ALREADY on (a nested op under a host callback that
525
593
  // didn't switch stacks) — the enclosing op's start, which is above
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RustyRacer
4
- VERSION = "0.1.15"
4
+ VERSION = "0.1.16"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rusty_racer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - Keita Urashima