waterbox libsnes cothreads: set TEB/TIB stuff
some bsnes cothreads call callbacks that hit managed threads. We shouldn't do that, but we do, and sometimes those threads run MSVC's __stkchk which can, depending on circumstances, blow up if the thread extents aren't set. This also means that we cannot save space on a lot of cothread stacks because __stkchck will blow up any detection guards we try
This commit is contained in:
parent
69ade58d2a
commit
6e366b7590
Binary file not shown.
|
@ -161,8 +161,39 @@ void co_delete(cothread_t handle)
|
||||||
free_thread(handle);
|
free_thread(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint64_t hoststart;
|
||||||
|
static uint64_t hostend;
|
||||||
|
|
||||||
void co_switch(cothread_t handle)
|
void co_switch(cothread_t handle)
|
||||||
{
|
{
|
||||||
|
uint64_t start;
|
||||||
|
uint64_t end;
|
||||||
|
if (co_active_handle == &co_host_buffer)
|
||||||
|
{
|
||||||
|
// migrating off of real thread; save stack params
|
||||||
|
__asm__("movq %%gs:0x08, %0": "=r"(end));
|
||||||
|
__asm__("movq %%gs:0x10, %0": "=r"(start));
|
||||||
|
hoststart = start;
|
||||||
|
hostend = end;
|
||||||
|
}
|
||||||
|
if (handle == &co_host_buffer)
|
||||||
|
{
|
||||||
|
// migrating onto real thread; load stack params
|
||||||
|
start = hoststart;
|
||||||
|
end = hostend;
|
||||||
|
hoststart = 0;
|
||||||
|
hostend = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// migrating onto cothread; compute its extents we allocated them
|
||||||
|
cothread_impl* co = handle;
|
||||||
|
start = (uintptr_t)co->stack_bottom;
|
||||||
|
end = (uintptr_t)co->stack_top;
|
||||||
|
}
|
||||||
|
__asm__("movq %0, %%gs:0x08":: "r"(end));
|
||||||
|
__asm__("movq %0, %%gs:0x10":: "r"(start));
|
||||||
|
|
||||||
register cothread_t co_previous_handle = co_active_handle;
|
register cothread_t co_previous_handle = co_active_handle;
|
||||||
co_swap(co_active_handle = handle, co_previous_handle);
|
co_swap(co_active_handle = handle, co_previous_handle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
./configure-for-waterbox
|
||||||
|
make clean
|
||||||
|
make libz.a
|
||||||
|
./install-for-waterbox
|
Loading…
Reference in New Issue