Commit ·
2387c67
1
Parent(s): 4c1cadb
Skip Node.js processes in LD_PRELOAD hooks — fix gateway SEGV
Browse filesNode.js/V8 crashes with SIGSEGV when starting under the membrane.
Rather than debug V8's allocator, skip Node.js entirely — it's the
gateway process, not the condensation target.
Process detection via /proc/self/exe at init time. If binary name
matches skip list (node, npm, npx), set SKIP_PROCESS flag. Hooked
malloc/free become pure passthrough — single atomic load, zero overhead.
No drain thread started, no atexit registered. The process runs as if
the membrane isn't there.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- rust_core/src/membrane.rs +40 -2
rust_core/src/membrane.rs
CHANGED
|
@@ -455,6 +455,25 @@ static PIPELINE: std::sync::LazyLock<Mutex<Pipeline>> =
|
|
| 455 |
static DRAIN_STARTED: std::sync::atomic::AtomicBool =
|
| 456 |
std::sync::atomic::AtomicBool::new(false);
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
/// Scan counter — run condenser scan every N allocs
|
| 459 |
static SCAN_COUNTER: AtomicU64 = AtomicU64::new(0);
|
| 460 |
const SCAN_INTERVAL: u64 = 1_000;
|
|
@@ -557,11 +576,16 @@ unsafe fn real_free(ptr: *mut c_void) {
|
|
| 557 |
}
|
| 558 |
}
|
| 559 |
|
| 560 |
-
/// Hooked malloc — pushes event to ring buffer, no locks, no pipeline on hot path
|
|
|
|
| 561 |
#[unsafe(no_mangle)]
|
| 562 |
pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
|
| 563 |
let ptr = unsafe { real_malloc(size) };
|
| 564 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
REENTRANT.with(|r| {
|
| 566 |
if r.get() {
|
| 567 |
return;
|
|
@@ -574,13 +598,19 @@ pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
|
|
| 574 |
ptr
|
| 575 |
}
|
| 576 |
|
| 577 |
-
/// Hooked free — pushes event to ring buffer, no locks
|
|
|
|
| 578 |
#[unsafe(no_mangle)]
|
| 579 |
pub unsafe extern "C" fn free(ptr: *mut c_void) {
|
| 580 |
if ptr.is_null() {
|
| 581 |
return;
|
| 582 |
}
|
| 583 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 584 |
REENTRANT.with(|r| {
|
| 585 |
if r.get() {
|
| 586 |
return;
|
|
@@ -628,6 +658,14 @@ static INIT: extern "C" fn() = {
|
|
| 628 |
extern "C" fn init() {
|
| 629 |
INITIALIZED.store(true, Ordering::SeqCst);
|
| 630 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
// Ring buffer is static .bss — no initialization needed.
|
| 632 |
// Start the background drain thread.
|
| 633 |
start_drain_thread();
|
|
|
|
| 455 |
static DRAIN_STARTED: std::sync::atomic::AtomicBool =
|
| 456 |
std::sync::atomic::AtomicBool::new(false);
|
| 457 |
|
| 458 |
+
/// Process skip flag — if true, hooks are no-ops.
|
| 459 |
+
/// Set at init if the process is in the skip list.
|
| 460 |
+
static SKIP_PROCESS: std::sync::atomic::AtomicBool =
|
| 461 |
+
std::sync::atomic::AtomicBool::new(false);
|
| 462 |
+
|
| 463 |
+
/// Processes that should not be hooked.
|
| 464 |
+
const SKIP_NAMES: &[&str] = &["node", "npm", "npx"];
|
| 465 |
+
|
| 466 |
+
/// Check if this process should be skipped
|
| 467 |
+
fn should_skip_process() -> bool {
|
| 468 |
+
// Read /proc/self/exe to get the binary path
|
| 469 |
+
if let Ok(exe) = std::fs::read_link("/proc/self/exe") {
|
| 470 |
+
if let Some(name) = exe.file_name().and_then(|n| n.to_str()) {
|
| 471 |
+
return SKIP_NAMES.iter().any(|skip| name == *skip);
|
| 472 |
+
}
|
| 473 |
+
}
|
| 474 |
+
false
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
/// Scan counter — run condenser scan every N allocs
|
| 478 |
static SCAN_COUNTER: AtomicU64 = AtomicU64::new(0);
|
| 479 |
const SCAN_INTERVAL: u64 = 1_000;
|
|
|
|
| 576 |
}
|
| 577 |
}
|
| 578 |
|
| 579 |
+
/// Hooked malloc — pushes event to ring buffer, no locks, no pipeline on hot path.
|
| 580 |
+
/// Skipped processes get pure passthrough — zero overhead.
|
| 581 |
#[unsafe(no_mangle)]
|
| 582 |
pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
|
| 583 |
let ptr = unsafe { real_malloc(size) };
|
| 584 |
|
| 585 |
+
if SKIP_PROCESS.load(Ordering::Relaxed) {
|
| 586 |
+
return ptr;
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
REENTRANT.with(|r| {
|
| 590 |
if r.get() {
|
| 591 |
return;
|
|
|
|
| 598 |
ptr
|
| 599 |
}
|
| 600 |
|
| 601 |
+
/// Hooked free — pushes event to ring buffer, no locks.
|
| 602 |
+
/// Skipped processes get pure passthrough.
|
| 603 |
#[unsafe(no_mangle)]
|
| 604 |
pub unsafe extern "C" fn free(ptr: *mut c_void) {
|
| 605 |
if ptr.is_null() {
|
| 606 |
return;
|
| 607 |
}
|
| 608 |
|
| 609 |
+
if SKIP_PROCESS.load(Ordering::Relaxed) {
|
| 610 |
+
unsafe { real_free(ptr) }
|
| 611 |
+
return;
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
REENTRANT.with(|r| {
|
| 615 |
if r.get() {
|
| 616 |
return;
|
|
|
|
| 658 |
extern "C" fn init() {
|
| 659 |
INITIALIZED.store(true, Ordering::SeqCst);
|
| 660 |
|
| 661 |
+
// Check if this process should be skipped (Node.js, npm, etc.)
|
| 662 |
+
// Must happen before anything else — skipped processes get
|
| 663 |
+
// pure passthrough with zero overhead.
|
| 664 |
+
if should_skip_process() {
|
| 665 |
+
SKIP_PROCESS.store(true, Ordering::SeqCst);
|
| 666 |
+
return; // No drain thread, no atexit, nothing. Pure passthrough.
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
// Ring buffer is static .bss — no initialization needed.
|
| 670 |
// Start the background drain thread.
|
| 671 |
start_drain_thread();
|