[fpc-pascal] Re: Stack checking in dynamic libraries

cobines cobines at gmail.com
Sun Nov 8 18:22:38 CET 2009


A followup from the previous mail. I have expanded the program to
query pthreads library directly for thread's stack info. Here are the
results (the lines containing "Pthr" string have values reported by
the pthreads library):

MainThreadId      : 3076675264
< main thread, main program >
CurrentThreadId      : 3076675264
Thread ID            : 3078065408
Stack ptr            : BFC4B964
Stack top            : 00000000
Stack bottom         : BF44BA8C
Stack length         : 8388608
Pthr ThreadId        : 3076675264
Pthr Stack ptr       : BFC4B928
Pthr Stack top       : BFC4D000
Pthr Stack bot       : BF44D000
Pthr Stack Len       : 8388608
< main thread, library >
Libr. CurrentThreadId: 3076675264
Libr. ThreadId       : 3078065408
Libr. Stack ptr      : BFC4B964
Libr. Stack top      : 00000000
Libr. Stack bottom   : BF44B694
Libr. Stack length   : 8388608
Libr. Pthr ThreadId  : 3076675264
Libr. Pthr Stack ptr : BFC4B928
Libr. Pthr Stack top : BFC4D000
Libr. Pthr Stack bot : BF44D000
Libr. Pthr Stack Len : 8388608
< worker thread, main program >
CurrentThreadId      : 3075664752
Thread ID            : 3075664752
Stack ptr            : B752E17C
Stack top            : 00000000
Stack bottom         : B712E300
Stack length         : 4194304
Pthr ThreadId        : 3075664752
Pthr Stack ptr       : B752E140
Pthr Stack top       : B752F000
Pthr Stack bot       : B712E000
Pthr Stack Len       : 4198400
< worker thread, library >
Libr. CurrentThreadId: 3075664752
Libr. ThreadId       : 3078065408
Libr. Stack ptr      : B752E17C
Libr. Stack top      : 00000000
Libr. Stack bottom   : BF44B694
Libr. Stack length   : 8388608
Libr. Pthr ThreadId  : 3075664752
Libr. Pthr Stack ptr : B752E140
Libr. Pthr Stack top : B752F000
Libr. Pthr Stack bot : B712E000
Libr. Pthr Stack Len : 4198400

The values for < worker thread, library > reported by pthreads appear
to be correct.
First, the stack size is ~ 4MB, which is the worker thread's stack
size, although I'm don't know why the discrepancy:  4194304 vs 4198400
bytes.
Second, the stack address begins with B7.... (address of the main
thread's stack begins with BF.....).
Third, the stack pointer is well within the stack limits: B712E000 <
B752E140 < B752F000.

I have to conclude that the values in rtl/inc/systemh.inc: StackTop,
StackBottom, StackLength are not behaving as thread-specific variables
in the library, even though they are declared using ThreadVar. The
IsMultiThread value in < worker thread, main program > is TRUE, but in
< worker thread, library > it is FALSE. Do I have to initialize
multithreading in the dynamic library somehow?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: checkthreadinfoPThreads.tar.gz
Type: application/x-gzip
Size: 4539 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20091108/4e45437e/attachment.bin>


More information about the fpc-pascal mailing list