Commit Graph
154 Commits
Author SHA1 Message Date
Tony Wasserka 3524117c23 Thunks: Unindent code blocks from previous patch 2022-08-08 16:08:46 +02:00
Tony Wasserka e8ad1ca0a0 Thunks: Use signature-based thunking of guest function pointers
This changes how host trampolines for guest functions are created. Instead
of doing this purely on the guest-side, it's either the host-side that
creates them in a single step *or* a cooperative two-step initialization
process must be used. In the latter, trampolines are allocated and partially
initialized on the guest and must be finalized on the host before use.
2022-08-08 16:08:46 +02:00
Tony Wasserka de92624c9a Thunks: Use stronger types for interfaces 2022-08-08 16:08:45 +02:00
Tony Wasserka 5fd00e31bb Thunks/X11: Distinguish between host and guest pointers in XFree
This function must be able to handle both guest heap pointers *and* host heap
pointers, so it only forwards to the native host library for the latter.

This is because Xlibint users allocate memory using internal macros aliasing
to libc's malloc but then they free using the function XFree. For libX11,
this is not a problem since the allocation happens in a thunked API function
(and hence on the host heap), but if a function from an unthunked library
accesses Xlibint, it will allocate on the guest heap.

One notable example where this was encountered is XF86VidModeGetAllModeLines.
2022-07-27 12:05:07 +02:00
Ryan Houdek ba0887defa Misc: Convert assert logs to assume+assert that can be
Most of these won't make a performance difference. But we should be
using the assume version everywhere we can.
2022-07-17 12:51:43 -07:00
Ryan Houdek aec5b21d2a Merge pull request #1833 from neobrain/feature_generic_callbacks
Thunks: Implement generic callback support
2022-07-07 10:02:02 -07:00
Tony Wasserka 66f74a431f Thunks/gen: Clean up implementation of generic callbacks 2022-07-07 17:33:31 +02:00
Tony Wasserka 57bae90c69 Thunks: Fix generic callbacks on ARM hosts 2022-07-07 17:20:28 +02:00
Tony Wasserka f69c53d294 Thunks: Soften error condition to be non-fatal
Dota Underlords hit this when querying Vulkan two different symbols
that resolve to the same function. Ignoring the error in that specific
case is safe, since the linked guest functions have the same implementation.
2022-07-07 11:33:01 +02:00
Tony Wasserka 7eb8409f71 Thunks: Move definitions for LoadLib and IsLibLoaded together 2022-07-06 18:41:53 +02:00
Stefanos Kornilios Misis Poiitidis 9c01dd9d9f Thunks: PoC Callbacks using sha256 exports from host 2022-07-06 18:41:53 +02:00
Ryan Houdek 3ffc301dd0 Thunks: Fix std::set crash
std::string_view was sticking around for longer than libraries being
loaded.
This was causing a crash.
Change this to a std::string directly until we support cleanly removing
this data on library unload.
2022-07-05 21:25:40 -07:00
Stefanos Kornilios Misis Poiitidis 21fc6bedcb Thunks: Add fex:is_lib_loaded 2022-06-29 19:20:08 +03:00
Tony Wasserka 599f8f99ed Thunks/gen: Add support for thunking APIs that return host function pointers
Interface definitions must enable this functionality by enclosing functions
that may be called through function pointers in a namespace annotated with
`fexgen::indirect_guest_calls`. The guest thunk must further link any host
function pointers to a guest-side instance of CallHostThunkFromRuntimePointer.
2022-06-24 11:56:36 +02:00
Tony Wasserka 5542360948 Thunks: Fail if thunking is enabled for a library that isn't installed
Previously, the host thunk would seemingly succeed to load even when
the corresponding host library could not be loaded, leading to obscure
crashes later throughout execution.
2021-11-30 17:39:01 +01:00
Lioncash 75b2f226f6 General: Migrate over to fmt where possible
Migrates lingering instances of the old logger over to fmt where
applicable. This allows removing some of the old defines and functions.

The only remaining usages of the printf-based variant of the logger is
in Tests/LinuxSyscalls/Syscalls.cpp for the strace handling.
2021-11-23 12:51:57 -05:00
Ryan Houdek 0d0ce38050 Thunks: Disable malloc libraries
Keeping this in the commit history to go back to later.
While these are required for static-pie builds to work, with the glibc
bug we can't use those yet.
Disable for now since it is is unnecessary.
2021-10-06 11:53:48 -07:00
Ryan Houdek cb21f52f93 Thunks: Have the ThunkHandler load the FEX malloc symbol libraries
If the thunk configuration is enabled then preemptively load the
libraries. Since they will need to be loaded for any thunking library.

This is because we need to ALWAYS share the allocators to the thunks.
2021-10-05 23:51:26 -07:00
Ryan Houdek f161e3bfb0 Massive amount of IWYU cleanup
This isn't quite a 100% clean sweep of IWYU.
There are some false positives where clang fails.
Additionally there are still a few missed in the frontend side of things
that I didn't get to
2021-08-28 00:32:15 -07:00
Ryan Houdek 304db72d6b Fixes Callback interface to take a thread argument
This was using the implicit thread TLS object. All users of this
have access to the thread object directly.

Use that instead. Fixes a subtle bug were the frontend could be trying
to do a callback and TLS sections weren't correctly set.
2021-08-26 01:23:17 -07:00
Stefanos Kornilios Mitsis Poiitidis 942b8549c6 Docs: Add tags to the source code 2021-03-30 12:21:18 +03:00
Stefanos Kornilios Mitsis Poiitidis f0d3004363 Thunks: Add Thunk json, thunk guest folder 2021-03-10 15:51:34 +02:00
Scott Mansell 35c01038ba Seperate per-thread and per-frame state 2021-03-09 20:27:44 +13:00
Ryan Houdek a3ba1ae199 Deduplicates some configuration data
Configuration mapping was duplicated between three different tables.
Additionally default configuration values were strewn about. Making it confusing as to what the default value would end up being

Adds a new ConfigValues.inl header that defines a few things right next to each other.
Defines the enum name as usual.
Defines the JSON config option name.
Defines the Environment config option name
Defines the default value that the configuration should be
2021-03-08 22:53:41 -08:00
Stefanos Kornilios Mitsis Poiitidis 56d10dcbbb IR: Make OP_THUNK use an inline sha256 hash of the thunk name, update thunk scripts 2021-02-23 12:08:57 +02:00
Ryan Houdek 37983006f0 Moves FEXCore's SignalDelegator and SyscallHandler to the frontend
Sadly these things can't be split without breaking functionality so it
turns in to a bit of a mess.

SyscallHandler is very much something that is a Linux only construct and
shouldn't be in FEXCore itself. Lets the frontend register a
Syscallhandler with FEXCore. FEXCore itself is then aware of the current
syscall ABI and handles the ABI in an optimal fashion.
So it is not a 100% clean break otherwise we would lose performance.

The SignalDelegator then needs to move to the frontend since the
SyscallHandler requires it for signal based syscalls.
The CPU backend signal handling still needs to happen in FEXCore because
it is a very tight coupling with the CPU backend.
Once we need to support more Signal handling we can give the backends
cleaner support to select which specific OS handler to handle.
2020-12-13 22:38:04 -08:00
Ryan Houdek 36b24ad141 Removes all uses of non-unified memory and SHM regions
Let's just delete the whole thing!
2020-12-10 02:09:52 -08:00
Ryan Houdek 01831ec264 Check for binfmt_misc install and run directly only if installed
If we want to execve files directly we need to ensure that the
binfmt_misc interpreter path is installed.
If it isn't installed then we need to fall down the regular path of
pushing FEX to the front of the argument list.
2020-12-09 20:34:03 -08:00
Ryan Houdek 61641dcc92 Adds interpreter handling to the x86 execve path
Will fix the same bugs as the 64bit path
2020-12-08 07:28:50 -08:00
Ryan Houdek 9882447ed5 Adds interpreter handling to the x64 execve path
Will fix some application launching problems
2020-12-08 07:28:50 -08:00
Ryan Houdek 3d21aaf617 Adds config option to syscall handler for determining if we're
interpreter
2020-12-08 07:28:50 -08:00
Ryan Houdek f091878100 More 32bit syscall fixes
fstatfs64 and statfs64 was wrong, the syscall doesn't quite match the
glibc definition

Fixes recvmsg. Specifically the aux data was failing, thus SCM_RIGHTS
wasn't getting passed correctly.

Fixes a couple of time syscalls where their arguments are optional.
2020-12-04 09:30:33 -08:00
Ryan Houdek 310252b97d A wackload of new 32bit syscall support
This implements a bunch of new 32bit syscalls which almost gets FEX to
be able to run Steam.

The main missing syscalls are mremap, shmat, and ioctl for supporting
Steam execution.
2020-12-03 20:03:15 -08:00
Stefanos Kornilios Mitsis Poiitidis d481bd4ffc Merge pull request #541 from Sonicadvance1/remove_sonicutils
Moves SonicUtils in to FEXCore
2020-12-03 16:54:56 +02:00
Stefanos Kornilios Mitsis Poiitidis 7c40083106 Merge pull request #539 from Sonicadvance1/more_64bit_syscall_movement
Moves 64bit sigaltstack and execve to 64bit files
2020-12-03 16:51:38 +02:00
Ryan Houdek a28df9f5c1 Moves SonicUtils in to FEXCore
Removes the extraneous and dead VM CPU backend
2020-11-29 00:30:28 -08:00
Ryan Houdek 638201254a Moves 64bit sigaltstack and execve to 64bit files
These need specific 32bit handling
2020-11-27 20:33:23 -08:00
Ryan Houdek 94b034db6c Moves shmat to 64bit memory specific file
This removes the bad attempt to keep shm regions in our 64GB shm region

This will need to be handled specially on the 32bit side through its
memory management once we have that wired up
2020-11-27 00:32:25 -08:00
Ryan Houdek e23ae78795 Merge pull request #537 from Sonicadvance1/move_memory_x64
Moves some memory op implementations to x64 file
2020-11-27 00:20:10 -08:00
Ryan Houdek 516db28a20 Moves some memory op implementations to x64 file
These will need to be unique for 32bit
2020-11-26 18:06:27 -08:00
Ryan Houdek b228d6bad1 Moves the getdents implementations for x64
These end up being different for x32 so move them now
2020-11-26 17:58:32 -08:00
Ryan Houdek 71a9f2cb71 Captures another CPU count file
Some application was using this to determine CPU count as well
2020-11-17 12:56:18 -08:00
Ryan Houdek a42bdd9c2f Fixes 64bit ppoll
32bit ppoll is completely wrong here.
Will be fixed in upcoming PR
2020-10-20 18:33:46 -07:00
Ryan Houdek db77d5f580 Shuffles more x86-64 specific syscalls to the correct folder 2020-10-13 16:56:09 -07:00
Ryan Houdek ee55204eaa Fixes 32bit syscalls
This doesn't change behaviour on the 64bit side of things.

Currently the 32bit syscall implementation is "best effort".
Anything that easily maps is passed through, and a few minor ones that
rely on iovec are handled.

Still around 80 syscalls that aren't punched through yet.

Few of these changes could have been split up so it's a bit of a
nightmare.
2020-10-06 18:46:26 -07:00
Ryan Houdek c39781275f Merge pull request #396 from FEX-Emu/skmp/execve-only-existing-files
syscalls: execve should fail on missing files
2020-09-22 15:25:08 -07:00
Stefanos Kornilios Mitsis Poiitidis a8a0a270f6 Syscalls: Execve should fail for not existing files 2020-09-23 01:22:14 +03:00
Stefanos Kornilios Mitsis Poiitidis 2425ab994b Thunks: Generation script refactor, generic callbacks 2020-09-22 14:35:38 +03:00
Ryan Houdek d0de92f97a Removes error and die in multithreaded forks
This can result in some terrible behaviour if something doesn't
immediately execve once it forks. Allow it instead of crashing out
though.
2020-09-16 11:29:57 -07:00
Ryan Houdek ddecec12ec Spam out a wackload more syscalls
Almost all of these end up being simple passthrough.
This covers most syscalls, the remaining ones are signal related, exec
related, or rseq required.

All of these syscalls exist prior to Linux 5.0. We are using these with
the expectation still that the host Linux implementation is 5.0 or
higher.
Once we implement newer syscalls we will need to start checking for host
Linux version. We don't really have a care about devices shipping older
4.x kernels atm.
2020-09-16 10:48:56 -07:00