Skip to content

Define an alternate signal handler stack for HHVM threads - #9832

Open
mszabo-wikia wants to merge 1 commit into
meta:masterfrom
mszabo-wikia:sigaltstack-u
Open

mszabo-wikia wants to merge 1 commit into
meta:masterfrom
mszabo-wikia:sigaltstack-u

Conversation

@mszabo-wikia

Copy link
Copy Markdown
Contributor

Today, if an HHVM thread overflows the stack, we try to run the crash reporter and immediately crash due to having overflown the aforementioned stack. It's possible to run into this error state even from userland code, e.g.:

async function bar(): Awaitable<void> {
	$s = new \HH\Lib\Async\Semaphore(10, async (bool $should_wait) ==> {
		if ($should_wait) {
			await \HH\Asio\usleep(1000 * 100000);
		} else {
			await \HH\Asio\later();
		}
	});

	concurrent {
		await $s->waitForAsync(true);
		await async {
			for ($i = 0; $i < 1000000; $i++) {
				await $s->waitForAsync(false);
			}
		};
	}
}

<<__EntryPoint>>
function mymain(): void {
	\HH\Asio\join(bar());
}

This isn't ideal because it prevents reporting tools that process stacktrace files emitted by the crash reporter from accurately reporting these events.

So, use sigaltstack to define an alternate signal handler stack for HHVM threads. The folly::Symbolizer docs suggest anything below 64KiB would be insufficient, so size it 128KiB to be safe.

@meta-cla meta-cla Bot added the CLA Signed label Aug 11, 2026
@meta-codesync

meta-codesync Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D115599844. (Because this pull request was imported automatically, there will not be any future comments.)

Comment thread hphp/runtime/base/crash-reporter.cpp Outdated
Comment on lines +487 to +490
// 128KiB stack space should be plenty.
// See `kSmallSigAltStackSize` in folly/src/folly/debugging/symbolizer/SignalHandler.cpp.
long minSigStackSize = std::max(0l, long(MINSIGSTKSZ));
m_size = std::max(size_t(minSigStackSize), size_t(128*1024));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

128KiB is quite a lot of memory when multiplied by the number of threads. Can this just use SIGSTKSZ (which my machine reports to be 13504)?

folly::SignalHandler specifically checks against kSmallSigAltStackSize to decide which implementation to use. It has an implementation that uses less stack.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It seems I'll need to revisit this anyways because it seems that this logic segfaults anyways on September HHVM, so I might need to change a few things

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK this actually is working fine after re-testing, sorry for the confusion. Made the change!

Comment thread hphp/runtime/base/crash-reporter.cpp Resolved
Today, if an HHVM thread overflows the stack, we try to run the crash
reporter and immediately crash due to having overflown the aforementioned stack.
It's possible to run into this error state even from userland code, e.g.:
```hack
async function bar(): Awaitable<void> {
	$s = new \HH\Lib\Async\Semaphore(10, async (bool $should_wait) ==> {
		if ($should_wait) {
			await \HH\Asio\usleep(1000 * 100000);
		} else {
			await \HH\Asio\later();
		}
	});

	concurrent {
		await $s->waitForAsync(true);
		await async {
			for ($i = 0; $i < 1000000; $i++) {
				await $s->waitForAsync(false);
			}
		};
	}
}

<<__EntryPoint>>
function mymain(): void {
	\HH\Asio\join(bar());
}
```

This isn't ideal because it prevents reporting tools that process
stacktrace files emitted by the crash reporter from accurately reporting
these events.

So, use `sigaltstack` to define an alternate signal handler stack for HHVM threads.
@facebook-github-tools

Copy link
Copy Markdown

@mszabo-wikia has updated the pull request. You must reimport the pull request before landing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants