diff --git a/BizHawk.Emulation.Cores/Waterbox/PeRunner.cs b/BizHawk.Emulation.Cores/Waterbox/PeRunner.cs index accda78ffa..5fbf1d1362 100644 --- a/BizHawk.Emulation.Cores/Waterbox/PeRunner.cs +++ b/BizHawk.Emulation.Cores/Waterbox/PeRunner.cs @@ -756,6 +756,19 @@ namespace BizHawk.Emulation.Cores.Waterbox { using (this.EnterExit()) { + // if libco is used, the jmp_buf for the main cothread can have stack stuff in it. + // this isn't a problem, since we only savestate when the core is not running, and + // the next time it's run, that buf will be overridden again. + // but it breaks xor state verification, so when we seal, nuke it. + + // this could be the responsibility of something else other than the PeRunner; I am not sure yet... + IImportResolver libco; + if (_exports.TryGetValue("libco.so", out libco)) + { + Console.WriteLine("Calling co_clean()..."); + Marshal.GetDelegateForFunctionPointer(libco.SafeResolve("co_clean"))(); + } + _sealedheap.Seal(); foreach (var h in _heaps) { diff --git a/output64/dll/libco.so b/output64/dll/libco.so index 8be4a5459f..1a4cad5b71 100644 Binary files a/output64/dll/libco.so and b/output64/dll/libco.so differ diff --git a/waterbox/libco/amd64.c b/waterbox/libco/amd64.c index 5af2246e03..5f5a6cf8ff 100644 --- a/waterbox/libco/amd64.c +++ b/waterbox/libco/amd64.c @@ -9,6 +9,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -23,6 +24,10 @@ static void crash() { assert(0); /* called only if cothread_t entrypoint returns */ } +void co_clean() { + memset(co_active_buffer, 0, sizeof(co_active_buffer)); +} + cothread_t co_active() { if(!co_active_handle) co_active_handle = &co_active_buffer; return co_active_handle; diff --git a/waterbox/libco/libco.so b/waterbox/libco/libco.so index 8be4a5459f..1a4cad5b71 100644 Binary files a/waterbox/libco/libco.so and b/waterbox/libco/libco.so differ