Re[8]: [Gc]: mingw32ce patch

Ivan Maidanski ivmai at mail.ru
Thu Oct 1 03:25:38 PDT 2009


Hi!

"Vincent R." <forumer at smartmobili.com> wrote:
> >> 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.

At least not in nkarm/mips/x86.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 

I don't understand. Is GC_get_stack_base() your one or taken from GC os_dep.c

The terminology across GC is:
- stack top is what is pointed by "sp" register;
- stack bottom is opposite to top (and roughly pointed by "sp" when a thread is started);
- stack min is the minimum address of the committed stack region.

For windows, the stack is assumed to grow down (this is hard-coded in GC), so
stack_bottom should be > sp.

> 
> 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.

In your sample, it returns the start of the stack region which is the current stack_min in our terminology. So, to get "real" stack_bottom, you need to add the size of the region - how you could do it w/o VirtualQuery?

> 
> 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)

Why not to use _WIN32_WCE >= 0x500 instead of _WIN32_WCE > 0x420?

> 
> 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

Bye.


More information about the Gc mailing list