On Thu, Jun 04, 2020 at 04:55:10PM -0400, Andrew Piskorski wrote:
> On Thu, Jun 04, 2020 at 05:26:04PM +0200, Gustaf Neumann wrote:

> > Probably "Ns_ThreadSelf(&tid);" does not work under windows (get the
> > id of the current thread). Ns_ThreadSelf() is defined in the OS specific
> > part (winthread.c). The exception is probably coming from
> > test thread-2.3, it looks to me as if the the thread (here the
> > thread running the tests) is not properly initiated under windows.

>   Assertion failed: tid != NULL, file tclthread.c, line 238

For debugging, I turned test ns_thread-2.6 back on, and added an
assertion inside Ns_ThreadSelf(), so that it was basically doing this:

void Ns_ThreadSelf(Ns_Thread *threadPtr) {
   WinThread *wPtr = TlsGetValue(tlskey);
   *threadPtr = (Ns_Thread) wPtr->self;
   assert(NULL != *threadPtr);
}

That got it to break into Microsoft's WinDbg debugger there, rather
than later in NsTclThreadObjCmd().  The global "tlskey" seems to be
initialized, and so does the "wPtr" WinThread pointer.  But the
"wPtr->self" looks like it's NULL, there is no Ns_Thread structure
stored there!

I see the wPtr WinThread allocation code in DllMain().  That seems to
be working fine.

The wPtr->self Ns_Thread stuff gets set up in NsCreateThread() and
ThreadMain(), but I don't really understand understand what that code
is doing.  Is that the place where something is going wrong?

Btw, The tlskey TLS index value looks like it's a 64-bit DWORD
(unsigned integer), not 32-bit.  So I think Nsthreads_LibInit() should
be checking for TLS_OUT_OF_INDEXES, not the 0xFFFFFFFF (decimal
4294967295, the maximum size of a 32-bit DWORD) it's been checking for
since ancient times.  That's probably a small bug, but it's not the
cause of the problems here.


WinDbug output:
--------------------------------------------------
0:001> .frame 7
07 00000000`0062f150 000007fe`ed490aae nsthread!Ns_ThreadSelf+0x89 
[Z:\src\web\ns-fork-pub\naviserver\nsthread\winthread.c @ 848]
0:001> dt wPtr
Local var @ 0x62f170 Type WinThread*
0x00000000`004706d0 
   +0x000 nextPtr          : (null) 
   +0x008 wakeupPtr        : (null) 
   +0x010 self             : (null) 
   +0x018 event            : 0x00000000`0000015c Void
   +0x020 condwait         : 0n0
   +0x028 slots            : [100] (null) 
0:001> dt threadPtr
Local var @ 0x62f190 Type Ns_Thread_**
0x00000000`0062f208 
 -> (null) 

0:001> ? tlskey
Evaluate expression: 8791677299988 = 000007fe`f8cd6d14
0:001> .formats tlskey
Evaluate expression:
  Hex:     000007fe`f8cd6d14
  Decimal: 8791677299988
  Octal:   0000000177737063266424
  Binary:  00000000 00000000 00000111 11111110 11111000 11001101 01101101 
00010100
  Chars:   ......m.
  Time:    Thu Jan 11 00:12:47.729 1601 (UTC - 4:00)
  Float:   low -3.33323e+034 high 2.86706e-042
  Double:  4.34367e-311
0:001> dt -v tlskey
Got address 000007fef8cd6d14 for symbol
nsthread!tlskey
7

0:001> kb
: Call Site
: ucrtbased!issue_debug_notification+0x45 
[minkernel\crts\ucrt\src\appcrt\internal\report_runtime_error.cpp @ 28]
: ucrtbased!__acrt_report_runtime_error+0x13 
[minkernel\crts\ucrt\src\appcrt\internal\report_runtime_error.cpp @ 154]
: ucrtbased!abort+0x1d [minkernel\crts\ucrt\src\appcrt\startup\abort.cpp @ 61]
: ucrtbased!common_assert_to_stderr_direct+0xe5 
[minkernel\crts\ucrt\src\appcrt\startup\assert.cpp @ 161]
: ucrtbased!common_assert_to_stderr<wchar_t>+0x27 
[minkernel\crts\ucrt\src\appcrt\startup\assert.cpp @ 179]
: ucrtbased!common_assert<wchar_t>+0x68 
[minkernel\crts\ucrt\src\appcrt\startup\assert.cpp @ 420]
: ucrtbased!_wassert+0x2f [minkernel\crts\ucrt\src\appcrt\startup\assert.cpp @ 
444]
: nsthread!Ns_ThreadSelf+0x89 
[Z:\src\web\ns-fork-pub\naviserver\nsthread\winthread.c @ 848]
: libnsd!NsTclThreadObjCmd+0x42e 
[Z:\src\web\ns-fork-pub\naviserver\nsd\tclthread.c @ 238]
: tcl86t!TclNRRunCallbacks+0x63
: tcl86t!Tcl_EvalEx+0x9dd
: tcl86t!Tcl_FSEvalFileEx+0x223
: tcl86t!Tcl_MainEx+0x4be
: libnsd!CmdThread+0x6e [Z:\src\web\ns-fork-pub\naviserver\nsd\nsmain.c @ 1333]
: nsthread!NsThreadMain+0x77 
[Z:\src\web\ns-fork-pub\naviserver\nsthread\thread.c @ 236]
: nsthread!ThreadMain+0x6c 
[Z:\src\web\ns-fork-pub\naviserver\nsthread\winthread.c @ 880]
: ucrtbased!thread_start<unsigned int (__cdecl*)(void *),1>+0x9c 
[minkernel\crts\ucrt\src\appcrt\startup\thread.cpp @ 97]
: kernel32!BaseThreadInitThunk+0xd
: ntdll!RtlUserThreadStart+0x1d
--------------------------------------------------

-- 
Andrew Piskorski <a...@piskorski.com>


_______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

Reply via email to