Windows startup modifications
Changes to be committed: modified: include/winprocs.h modified: src/options.c modified: sys/share/pcmain.c new file: sys/share/safeproc.c modified: sys/winnt/Makefile.msc modified: sys/winnt/stubs.c new file: sys/winnt/windmain.c modified: sys/winnt/winnt.c modified: win/win32/vs2017/NetHack.vcxproj modified: win/win32/vs2017/NetHackW.vcxproj modified: win/win32/winhack.c Because multiple window ports are supported on Windows now, even in the same executable and selectable via config file in some cases, some adjustments became necessary. There will likely be some further refining of this over the next day or two. List of changes: Move Windows startup from sys/share/pcmain.c and into its own sys/winnt/windmain.c so that it can be modified to fix some current breakage, and allow altering the order of some things. There is startup processing code that is common to all of the Windows WindowPorts, but that startup processing code needs to have no dependency on any one of those WindowPorts. Yet, during startup processing, some of the initialization routines can end up calling NetHack functions that expect an active Window port underneath, and if there isn't one, routines like pline, impossible, panic can end up invoking null function pointers. Place a new file sys/share/safeproc.c, in which a complete window port is available for early startup processing purposes. It's WindowPort name field is set to "safe-startup" just for reference. The prototypes in include/winprocs.h require that SAFEPROCS be Usage: windowprocs = get_safe_procs(0); initializes a set of winprocs function pointers that ensure none of the function pointers are left null, but that's all it does. windowprocs = get_safe_procs(1); initializes a set of winprocs functions pointers that ensure none of the function pointers are left null, but also provides some basic output and input functionality using nothing other than C stdio routines (no platform or OS specific code). The conditional code related to WIN32 has been removed from sys/share/pcmain.c The code common to all of the Windows WindowPorts calls get_safe_procs() almost immediately to ensure that there is a set of WindowPort winprocs available.
This commit is contained in:
@@ -151,15 +151,16 @@
|
||||
<ClCompile Include="$(SrcDir)zap.c" />
|
||||
<ClCompile Include="$(SysShareDir)cppregex.cpp" />
|
||||
<ClCompile Include="$(SysShareDir)nhlan.c" />
|
||||
<ClCompile Include="$(SysShareDir)pcmain.c" />
|
||||
<ClCompile Include="$(SysShareDir)pcsys.c" />
|
||||
<ClCompile Include="$(SysShareDir)pcunix.c" />
|
||||
<ClCompile Include="$(SysShareDir)random.c" />
|
||||
<ClCompile Include="$(SysShareDir)safeproc.c" />
|
||||
<ClCompile Include="$(SysWinntDir)ntsound.c" />
|
||||
<ClCompile Include="$(SysWinntDir)nttty.c" />
|
||||
<ClCompile Include="$(SysWinntDir)stubs.c">
|
||||
<PreprocessorDefinitions>GUISTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SysWinntDir)windmain.c" />
|
||||
<ClCompile Include="$(SysWinntDir)winnt.c" />
|
||||
<ClCompile Include="$(WinTtyDir)getline.c" />
|
||||
<ClCompile Include="$(WinTtyDir)topl.c" />
|
||||
@@ -254,4 +255,4 @@
|
||||
<Target Name="AfterRebuild">
|
||||
<MSBuild Projects="afternethack.proj" Targets="Build" Properties="Configuration=$(Configuration)" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -146,14 +146,15 @@
|
||||
<ClCompile Include="$(SrcDir)zap.c" />
|
||||
<ClCompile Include="$(SysShareDir)cppregex.cpp" />
|
||||
<ClCompile Include="$(SysShareDir)nhlan.c" />
|
||||
<ClCompile Include="$(SysShareDir)pcmain.c" />
|
||||
<ClCompile Include="$(SysShareDir)pcsys.c" />
|
||||
<ClCompile Include="$(SysShareDir)pcunix.c" />
|
||||
<ClCompile Include="$(SysShareDir)random.c" />
|
||||
<ClCompile Include="$(SysShareDir)safeproc.c" />
|
||||
<ClCompile Include="$(SysWinntDir)ntsound.c" />
|
||||
<ClCompile Include="$(SysWinntDir)stubs.c">
|
||||
<PreprocessorDefinitions>TTYSTUB;</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SysWinntDir)windmain.c" />
|
||||
<ClCompile Include="$(SysWinntDir)winnt.c" />
|
||||
<ClCompile Include="$(SysWinntDir)win10.c" />
|
||||
<ClCompile Include="$(WinWin32Dir)mhaskyn.c" />
|
||||
@@ -200,4 +201,4 @@
|
||||
<Target Name="AfterRebuild">
|
||||
<MSBuild Projects="afternethack.proj" Targets="Build" Properties="Configuration=$(Configuration)" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
#include "mhmain.h"
|
||||
#include "mhmap.h"
|
||||
|
||||
#if !defined(SAFEPROCS)
|
||||
#error You must #define SAFEPROCS to build winhack.c
|
||||
#endif
|
||||
|
||||
/* Borland and MinGW redefine "boolean" in shlwapi.h,
|
||||
so just use the little bit we need */
|
||||
typedef struct _DLLVERSIONINFO {
|
||||
@@ -66,7 +70,7 @@ NHWinApp _nethack_app;
|
||||
#endif
|
||||
|
||||
// Foward declarations of functions included in this code module:
|
||||
extern boolean FDECL(pcmain, (int, char **));
|
||||
extern boolean FDECL(main, (int, char **));
|
||||
static void __cdecl mswin_moveloop(void *);
|
||||
|
||||
#define MAX_CMDLINE_PARAM 255
|
||||
@@ -82,24 +86,44 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
||||
TCHAR *p;
|
||||
TCHAR wbuf[BUFSZ];
|
||||
char buf[BUFSZ];
|
||||
|
||||
DWORD major, minor;
|
||||
boolean resuming;
|
||||
/* OSVERSIONINFO osvi; */
|
||||
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
UNREFERENCED_PARAMETER(nCmdShow);
|
||||
|
||||
/* We must initialize state sufficiently to support calls to panic */
|
||||
/*
|
||||
* Get a set of valid safe windowport function
|
||||
* pointers during early startup initialization.
|
||||
*
|
||||
* When get_safe_procs is called with 0 as the param,
|
||||
* non-functional, but safe function pointers are set
|
||||
* for all windowport routines.
|
||||
*
|
||||
* When get_safe_procs is called with 1 as the param,
|
||||
* raw_print, raw_print_bold, and wait_synch, and nhgetch
|
||||
* are set to use C stdio routines via stdio_raw_print,
|
||||
* stdio_raw_print_bold, stdio_wait_synch, and
|
||||
* stdio_nhgetch.
|
||||
*/
|
||||
windowprocs = *get_safe_procs(0);
|
||||
|
||||
/*
|
||||
* Now we are going to override a couple
|
||||
* of the windowprocs functions so that
|
||||
* error messages are handled in a suitable
|
||||
* way for the graphical version.
|
||||
*/
|
||||
windowprocs.win_raw_print = mswin_raw_print;
|
||||
windowprocs.win_raw_print_bold = mswin_raw_print_bold;
|
||||
windowprocs.win_wait_synch = mswin_wait_synch;
|
||||
|
||||
win10_init();
|
||||
|
||||
sys_early_init();
|
||||
|
||||
/* init applicatio structure */
|
||||
/* init application structure */
|
||||
_nethack_app.hApp = hInstance;
|
||||
_nethack_app.hAccelTable =
|
||||
LoadAccelerators(hInstance, (LPCTSTR) IDC_NETHACKW);
|
||||
@@ -209,10 +233,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
||||
}
|
||||
free(savefile);
|
||||
}
|
||||
resuming = pcmain(argc, argv);
|
||||
|
||||
moveloop(resuming);
|
||||
|
||||
/* let main do the argument processing */
|
||||
(void) main(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user