[Gc]: mingw32ce patch

Vincent R. forumer at smartmobili.com
Thu Oct 1 02:56:40 PDT 2009


>> 
>> struct Thread {
>>     ...
>>     DWORD       dwOrigBase; /* 0x1C: Original stack base */
>>     ...
>> };
> 
> Where is it defined?

If you download Platform Builder 5 (Actually it seems Microsoft removed it
from download
but I am sure you can find it somewhere) definitions are inside files
called nkarm.h and
kernel.h.

> 
> Just to refine, dwOrigBase == ~sp at thread start (dwOrigBase is not
stack
> minimum), right?
> 
A simple example, hope it will answer your  question :

int _tmain(int argc, _TCHAR* argv[])
{
	void* addr = GC_get_stack_base(); // Stack_base

	addr = _alloca(4);  //Allocate 4 bytes on stack
	addr = _alloca(4);  //Allocate 4 bytes on stack

	return 0;
}

When running on Windows Mobile 5 I get the following values :

addr = 0x1c020000 {void*} : Sp = 0x1c02fbe0 

addr = 0x1c02fbdc {void*} : Sp = 0x1c02fbdc
addr = 0x1c02fbd8 {void*} : Sp = 0x1c02fbd8

So from what I understand GC_get_stack_base() returns the bottom of the
stack
because at start Sp register = 0x1c02fbe0 and if I substract with
0x1c020000 I get
64480 =~ 65536 = 64 KB.

Actually I don't remember exactly how memory is mapped on wince so I need
to study again ;-)




Anyway here is the function (tested only with VS2005)

// Works from wince 5.0 through wince 5.x (ie Windows Mobile 5 -> Windows
Mobile 6.5) 
#if (_WIN32_WCE > 0x420 && _WIN32_WCE <= 0x502)

extern "C" BOOL SetKMode(BOOL bMode);

void* GC_get_stack_base()
{
	DWORD dwStackBase;
	BOOL bKmode;

	LPBYTE kernStart = (LPBYTE)0x00005800; //address for all arch. except on
arm
	DWORD dwThreadOffset;

#if defined(__arm__) || defined(_ARM_) || defined(__thumb__)
	kernStart = PUserKData ;
	dwThreadOffset = 0x094;
#endif /* arm */

#if defined(_M_MRX000) || defined(_MIPS_)
	dwThreadOffset = 0x2c0;
#endif /* mips */

#if defined(_M_IX86) || defined(x86)
	dwThreadOffset = 0x098;
#endif /* x86 */

bKmode = SetKMode(TRUE);
dwStackBase = *((DWORD*) (*((DWORD*)(kernStart + dwThreadOffset))+0x1C));
SetKMode(bKmode);

	return (void *)dwStackBase;
}
#endif


More information about the Gc mailing list