summary refs log tree commit diff stats
path: root/results/scraper/fex/2189
blob: 9064f0c9fdb6c5c874cf80a4f03a8acb1174f656 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
How can I fix crashed In XSetErrorHandler?
source code:
https://github.com/opengl-tutorials/ogl

how to reproduce:
1. open -DBUILD_THUNKS, build FEXLoader
2. run tutorial01_first_window
3. FEXLoader crashed

Guest Code error position: ogl/external/glfw-3.1.2/src/x11_init.c:680, XSetErrorHandler
```
void _glfwReleaseXErrorHandler(void)
{
    // Synchronize to make sure all commands are processed
    XSync(_glfw.x11.display, False);
    XSetErrorHandler(NULL);
}
```

FEXLoader Crash position: Thunks.cpp:436, FinalizeHostTrampolineForGuestFunction
```
    FEX_DEFAULT_VISIBILITY
    void FinalizeHostTrampolineForGuestFunction(HostToGuestTrampolinePtr* TrampolineAddress, void* HostPacker) {
      auto& Trampoline = GetInstanceInfo(TrampolineAddress);

      LOGMAN_THROW_A_FMT(Trampoline.CallCallback == (uintptr_t)&ThunkHandler_impl::CallCallback,
                        "Invalid trampoline at {} passed to {}", fmt::ptr(TrampolineAddress), __FUNCTION__);

      if (!Trampoline.HostPacker) {
        LogMan::Msg::DFmt("Thunks: Finalizing trampoline at {} with host packer {}", fmt::ptr(TrampolineAddress), fmt::ptr(HostPacker));
        Trampoline.HostPacker = HostPacker;
      }
    }
```

It seems when I pass a callback ptr is NULL to XSetErrorHandler, TrampolineAddress is NULL too, so GetInstanceInfo return error info. and LOGMAN_THROW_A_FMT thow a exception.

so is it right to fix this problem like this, immediate return when TrampolineAddress is NULL:
```
    FEX_DEFAULT_VISIBILITY
    void FinalizeHostTrampolineForGuestFunction(HostToGuestTrampolinePtr* TrampolineAddress, void* HostPacker) {
      if (TrampolineAddress == nullptr) return;

      auto& Trampoline = GetInstanceInfo(TrampolineAddress);

      LOGMAN_THROW_A_FMT(Trampoline.CallCallback == (uintptr_t)&ThunkHandler_impl::CallCallback,
                        "Invalid trampoline at {} passed to {}", fmt::ptr(TrampolineAddress), __FUNCTION__);

      if (!Trampoline.HostPacker) {
        LogMan::Msg::DFmt("Thunks: Finalizing trampoline at {} with host packer {}", fmt::ptr(TrampolineAddress), fmt::ptr(HostPacker));
        Trampoline.HostPacker = HostPacker;
      }
    }
```