-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Can't initialize heap: [0x000001e7] Attempt to access invalid address
random segfault on Windown x86
#9650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
related to #8643 and https://bugs.php.net/bug.php?id=77194 (confirmed in https://bugs.php.net/bug.php?id=77194#1548144531) To reproduce, please run couple hundreds of full tests iterations on Windows /w x86 build locally and you should be able to reproduce it, in CI, it is reproducible after a few pushes /w random test failures. |
Zend/tests/function_arguments/argument_count_incorrect_internal_strict.phpt
results in segfault on Win 32 x86Can't initialize heap: [0x000001e7] Attempt to access invalid addresst
random segfault on Win 32 x86
Can't initialize heap: [0x000001e7] Attempt to access invalid addresst
random segfault on Win 32 x86Can't initialize heap: [0x000001e7] Attempt to access invalid address
random segfault on Win 32 x86
Can't initialize heap: [0x000001e7] Attempt to access invalid address
random segfault on Win 32 x86Can't initialize heap: [0x000001e7] Attempt to access invalid address
random segfault on Windown x86
I've seen similar spurious issues in Phan's for a while, using https://ci.appveyor.com/project/TysonAndre/phan/branch/v5/job/1f74k3nsurgxpdgb when php is running in paratest
|
It looks like initializing the memory manager ("Can't initialize heap", If php was compiled for windows with ZEND_MM_ERROR it looks like it would output the error message with the failure reason for VirtualAlloc
https://learn.microsoft.com/en-us/windows/win32/memory/large-page-support This sounds somewhat related, but I'm unfamiliar with win32 programming
// Zend/zend_alloc.c
static zend_mm_heap *zend_mm_init(void)
{
zend_mm_chunk *chunk = (zend_mm_chunk*)zend_mm_chunk_alloc_int(ZEND_MM_CHUNK_SIZE, ZEND_MM_CHUNK_SIZE);
zend_mm_heap *heap;
if (UNEXPECTED(chunk == NULL)) {
#if ZEND_MM_ERROR
#ifdef _WIN32
stderr_last_error("Can't initialize heap");
#else
fprintf(stderr, "\nCan't initialize heap: [%d] %s\n", errno, strerror(errno));
#endif
#endif
return NULL;
} // Zend/zend_alloc.c
static void *zend_mm_mmap(size_t size)
{
#ifdef _WIN32
void *ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (ptr == NULL) {
#if ZEND_MM_ERROR
stderr_last_error("VirtualAlloc() failed");
#endif
return NULL;
}
return ptr;
#else |
If the issue is just in VirtualAlloc and is actually related to starting and stopping thousands of php processes in a short time period, causing virtual memory to be fragmented (not actually sure), then a possible workaround for applications that aren't php-src to in x86(32-bit builds) is to |
Works around `Can't initialize heap: [0x000001e7] Attempt to access invalid address` when running PhanNativePHPSyntaxCheckPlugin. See `https://github.com/php/php-src/issues/9650#issuecomment-1273961567` Docker i386 images can be used to reintroduce 32-bit testing
@TysonAndre thank you very much for looking into it!
I would expect consequent tests then to fail. Currently the failure is more or less random and next test is (p>99%) passing. The fragmentation can be closely related, as in 32-bit address space it is much easier to create some collision than in 64-bit space. Maybe there is some bug also in 64-bit builds, but they are only much more rare. I did some more reseach: https://forum.exetools.com/showthread.php?t=8963 - are we sure we do not increment the address over the alloved range?
"mremp Windows" - https://stackoverflow.com/questions/17197615/no-mremap-for-windows#38502927 can this help? to test is memory remap is a problem, is there any easy way to compile php without or can we reserve (but not commit) like 1GB address space for php mremp on php start at least? based on https://stackoverflow.com/questions/31672069/is-the-mem-reserve-flag-of-virtualalloc-really-useful-today and https://stackoverflow.com/questions/21368429/error-code-487-error-invalid-address-when-using-virtualallocex we should always reserve a memory more links (for later, if the above does not help): https://www.youtube.com/watch?v=MPnsPlDJbhI - can someone with Windows check? using https://stackoverflow.com/questions/55119066/virtualalloc-failed https://bugzilla.mozilla.org/show_bug.cgi?id=1662560 |
I belive I found the problem: https://github.com/php/php-src/pull/9721/files#r992229663 |
* PHP-8.1: Fix GH-9650: Can't initialize heap: [0x000001e7]
* PHP-8.2: Fix GH-9650: Can't initialize heap: [0x000001e7]
Description
CI report: https://github.com/php/php-src/actions/runs/3160522498/jobs/5145079204#step:8:110
here is commit /w Windows CI to reproduce: 37498f9
it seems there is some core problem not specific to the failed test, as later absolutely unrelated push https://github.com/php/php-src/compare/37498f95b5b26d47a03b74b0dcc062d545195a0c..3adb2737355882b3d808cf53630d304374d5bf7e did not produce it. and in another pushes I saw another failed tests like in #8643 and #8450...
PHP Version
PHP 8.0 and probably 8.1+ too
Operating System
Windows x86/32 bit
The text was updated successfully, but these errors were encountered: