Skip to content

Savestate restore fails with Bad file descriptor trying to reallocate [stack] #684

@jakobhellermann

Description

@jakobhellermann

Save: http://0x0.st/K9tb.txt
Restore http://0x0.st/K9tq.txt

[f:1 t:48218M] DEBUG: Region 0x7ffc59594000 ([stack]) with size 8380416 must be deallocated
[f:1 t:48218M] DEBUG: Region 0x7ffc59595000 ([stack]) with size 8376320 must be allocated
[f:1 t:48218M] DEBUG: Restoring non-anonymous area, 8376320 bytes at 0x7ffc59595000 from [stack] + 0
[f:1 t:48218M] FATAL (/home/jakob/dev/contrib/libTAS-cmake/src/library/checkpoint/Checkpoint.cpp:612): Mapping 8376320 bytes at 0x7ffc59595000 failed: Bad file descriptor (flags=AREA_PRIV|AREA_STACK, mmap=MAP_PRIVATE|MAP_FIXED)
[f:1 t:48218M] FATAL (/home/jakob/dev/contrib/libTAS-cmake/src/library/checkpoint/Checkpoint.cpp:616): Area at 0x7ffc59595000 got mmapped to 0xffffffffffffffff

No idea why the stack is moving by a page.

The code does mmap(addr, size, prot, MAP_FIXED|MAP_PRIVATE, fd=-1, offset).

LOG(LL_FATAL, LCF_CHECKPOINT, "Mapping %d bytes at %p failed: errno %d", saved_area->size, saved_area->addr, errno);

If the stack is merely resized and stays at the addr it is special cased to do a mremap.

Hacking a simple if (flags & AREA_STACK) mf |= MAP_ANONYMOUS into Area::toMmapFlag fixes the crash and I get to All threads resumed, but the program still hangs with gdb pointing to stopThisThread waitForAllRestored(current_thread).

waitForAllRestored(current_thread);

The program is the one I usually use for testing (rust, bevy game engine, winit windowing library, x11) and I'm pretty sure it worked before.
Other programs like hollowknight also work fine.
Maybe something changed in the rust compiler recently? I could bisect.

uname -a
Linux jj 6.17.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Sun, 02 Nov 2025 17:27:22 +0000 x86_64 GNU/Linux

rustc --version
rustc 1.93.0-nightly (278a90913 2025-10-28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions