Crash during InitThread / WideStringManager related / feature request
Original Reporter info from Mantis: Martin @martin_frb
-
Reporter name: Martin Friebe
Original Reporter info from Mantis: Martin @martin_frb
- Reporter name: Martin Friebe
Description:
This issue happens at random and only under the debugger (or when any other external tool causes similar condition)
Under the debugger, if the debugger needs to pause an application an extra thread may get created (happens on windows).
This thread can get created before the widestring-manager is initialized.
Below callstack shows how in the new thread "OpenStdIO is called (at least if the app is compiled with -WC ).
I know this is technically not a bug in the RTL (unless the thread can be caused by anything but the debugger). But it is a real annoyance.
Given that we can not change the Windows debugging API, it would be nice if FPC could contain a check.
Steps to reproduce:
#0 ?? at :0
#1 OPENSTDIO({}, 55217, 156) at ..\inc\text.inc:2670
#2 SYSINITSTDIO at ..\win\syswin.inc:520
#3 INITTHREAD(16777216) at ..\inc\thread.inc:59
#4 EXEC_TLS_CALLBACK(0x400000, 2, 0x0) at ..\win\systlsdir.inc:90
Additional information:
rtl\inc\text.inc
line 2653
procedure OpenStdIO(var f:text;mode:longint;hdl:thandle);
begin
Assign(f,'');
TextRec(f).Handle:=hdl;
TextRec(f).Mode:=mode;
TextRec(f).Closefunc:=@FileCloseFunc;
case mode of
fmInput :
begin
TextRec(f).InOutFunc:=@FileReadFunc;
{$if defined(FPC_HAS_CPSTRING) and defined(FPC_HAS_FEATURE_WIDESTRINGS)}
// CHECK HERE
if WideStringManager <> nil then
TextRec(f).CodePage:=WideStringManager.GetStandardCodePageProc(scpConsoleInput);
else
// appropriate default or nothing?
{$endif}
end;
The uninitalized/default codepage should not be a problem.
Either that only happens for the debugger thread (which should not use STDIO).
Or, if the error can happen outside the debugger, then a real solution is needed anyway.
Mantis conversion info:
- Mantis ID: 34163
- OS: win 10
- OS Build: 10
- Platform: 64bit Intel
- Version: 3.0.4