FEX-Emu / FEX-Emu/FEX

Work on removing global static initializers

Open
#3,943 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8k
Forks
351
Avg merge
12h 31m
Merged PRs (30d)
102

Description

Global static initializers have problems under FEX. They have a couple of problems, mostly centered around memory allocation

- They can allocate untracked memory upfront that FEX can't control.
- This means it has memory originally allocated through jemalloc before the allocation hooks are setup
- They can register `atexit` handlers that can crash on application close
- This is used to cleanup the memory allocated before FEX can track it

FEX currently works around these previous problems by leaking all memory allocated on process shutdown and letting the kernel clean it up.

A major issue that occurs is when the static initializer allocates memory pre-hook, then once the hooks are installed, it allocates new memory through the FEX hooks, having a mix of pre-hook and post-hook memory allocations. On munmap this tracking will get confused and leak memory.

In the case of mixed-allocation and /not/ leaking, it can result in a crash but it's been a couple years since we enabled the leaking, so I don't quite remember why the crashes come.

From the on and off work over the past few years, we have removed most static initializers but there are still a handful sprinkled throughout the FEX codebase.

- ~~A bunch from vixl. With the disassembler disabled we should be able to remove most of these #3962~~
- ~~One from Thunks.cpp #4021~~
- One from Config.cpp
- One from IoctlEmulation.cpp
- One from Allocator.cpp

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.