summaryrefslogtreecommitdiffstats
path: root/private/crt32/dllstuff
diff options
context:
space:
mode:
authorAdam <you@example.com>2020-05-17 05:51:50 +0200
committerAdam <you@example.com>2020-05-17 05:51:50 +0200
commite611b132f9b8abe35b362e5870b74bce94a1e58e (patch)
treea5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/crt32/dllstuff
downloadNT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip
Diffstat (limited to '')
-rw-r--r--private/crt32/dllstuff/cinitexe.c92
-rw-r--r--private/crt32/dllstuff/crtdll.c376
-rw-r--r--private/crt32/dllstuff/crtexe.c215
-rw-r--r--private/crt32/dllstuff/crtexew.c4
-rw-r--r--private/crt32/dllstuff/crtlib.c258
-rw-r--r--private/crt32/dllstuff/dllargv.c49
-rw-r--r--private/crt32/dllstuff/i386/dllsupp.asm39
-rw-r--r--private/crt32/dllstuff/makefile6
-rw-r--r--private/crt32/dllstuff/sources44
9 files changed, 1083 insertions, 0 deletions
diff --git a/private/crt32/dllstuff/cinitexe.c b/private/crt32/dllstuff/cinitexe.c
new file mode 100644
index 000000000..ac7c875af
--- /dev/null
+++ b/private/crt32/dllstuff/cinitexe.c
@@ -0,0 +1,92 @@
+/***
+*cinitexe.asm - C Run-Time Startup Initialization for WIN32
+*
+* Copyright (c) 1992-1994, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* Do C++ initialization segment declarations for the EXE in CRT DLL
+* model
+*
+*Notes:
+* The C++ initializers will exist in the user EXE's data segment
+* so the special segments to contain them must be in the user EXE.
+*
+*Revision History:
+* 03-19-92 SKS Module created (based on CRT0INIT.ASM)
+* 08-06-92 SKS Revised to use new section names and macros
+* 04-12-93 CFW Added xia..xiz initializers.
+* 10-20-93 SKS Add .DiRECTiVE section for MIPS, too!
+* 10-28-93 GJF Rewritten in C
+* 10-28-94 SKS Add user32.lib as a default library
+* 02-27-95 CFW Remove user32.lib as a default library
+*
+*******************************************************************************/
+
+#ifdef _WIN32
+
+#ifdef _MSC_VER
+
+#include <stdio.h>
+#include <internal.h>
+
+#pragma data_seg(".CRT$XCA")
+_PVFV __xc_a[] = { NULL };
+
+#pragma data_seg(".CRT$XCZ")
+_PVFV __xc_z[] = { NULL };
+
+#pragma data_seg(".drectve")
+static char __drectve_win32lib[] =
+ "-merge:.CRT=.rdata";
+#pragma data_seg() /* reset */
+
+#endif /* _MSC_VER */
+
+#else /* _WIN32 */
+
+#include <cruntime.h>
+#include <msdos.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <internal.h>
+#include <fltintrn.h>
+#include <mpw.h>
+#include <mtdll.h>
+#include <macos\types.h>
+#include <macos\segload.h>
+#include <macos\gestalte.h>
+#include <macos\osutils.h>
+#include <macos\traps.h>
+
+/*
+ * pointers to initialization functions
+ */
+
+#pragma data_seg(".CRT$XIA")
+PFV __xi_a = 0; /* C initializers */
+
+#pragma data_seg(".CRT$XIZ")
+PFV __xi_z = 0;
+
+#pragma data_seg(".CRT$XCA")
+PFV __xc_a = 0; /* C++ initializers */
+
+#pragma data_seg(".CRT$XCZ")
+PFV __xc_z = 0;
+
+#pragma data_seg(".CRT$XPA")
+PFV __xp_a = 0; /* C pre-terminators */
+
+#pragma data_seg(".CRT$XPZ")
+PFV __xp_z = 0;
+
+#pragma data_seg(".CRT$XTA")
+PFV __xt_a = 0; /* C terminators */
+
+#pragma data_seg(".CRT$XTZ")
+PFV __xt_z = 0;
+
+#pragma data_seg()
+
+
+#endif
diff --git a/private/crt32/dllstuff/crtdll.c b/private/crt32/dllstuff/crtdll.c
new file mode 100644
index 000000000..a03adc428
--- /dev/null
+++ b/private/crt32/dllstuff/crtdll.c
@@ -0,0 +1,376 @@
+#ifdef CRTDLL
+/***
+*crtdll.c - CRT initialization for a DLL using the CRTDLL model of C run-time
+*
+* Copyright (c) 1991-1994, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* This module contains the initialization entry point for the C run-time
+* stub in this DLL. All C run-time code is located in the C Run-Time
+* Library DLL "CRTDLL.DLL", except for a little bit of start-up code in
+* the EXE, and this code in each DLL. This code is necessary to invoke
+* the C++ constructors for the C++ code in this DLL.
+*
+* This entry point should either be specified as the DLL initialization
+* entry point, or else it must be called by the DLL initialization entry
+* point of the DLL with the same arguments that the entry point receives.
+*
+*Revision History:
+* 05-19-92 SKS Initial version
+* 08-01-92 SRW winxcpt.h replaced bu excpt.h which is included by oscalls.h
+* 09-16-92 SKS Prepare for C8 C++ for MIPS by calling C++ constructors
+* 09-29-92 SKS _CRT_DLL must be a WINAPI function!
+* 05-11-93 SKS Add _DllMainCRTStartup as an alternative to _CRT_INIT
+* 06-05-93 SRW Pin CRTDLL.DLL in memory once loaded.
+* 06-07-93 GJF Added __proc_attached flag.
+* 06-07-93 GJF Backed out SteveWo's change of 06-05 and put it into
+* crtlib.c
+* 06-08-93 SKS Clean up failure handling in _CRT_INIT
+* 07-16-93 SRW ALPHA Merge
+* 12-02-93 SKS Add atexit/_onexit support. These routines must be
+* defined here so that DLL's that are linked with
+* CRTDLL.LIB will get these versions (suitable for DLLs),
+* not the versions of atexit/_onexit from CRTDLL.DLL,
+* which are only suitable for an EXE file.
+* 07-18-94 GJF Moved over Win32s support from VC 2.0 tree.
+*
+*******************************************************************************/
+
+/*
+ * SPECIAL BUILD MACRO! Note that crtexe.c (and crtexew.c) is linked in with
+ * the client's code. It does not go into crtdll.dll! Therefore, it must be
+ * built under the _DLL switch (like user code) and CRTDLL must be undefined.
+ */
+#undef CRTDLL
+#define _DLL
+
+#include <cruntime.h>
+#include <oscalls.h>
+#include <internal.h>
+#include <stdlib.h>
+#define _DECL_DLLMAIN /* enable prototypes for DllMain and _CRT_INIT */
+#include <process.h>
+
+/*
+ * routine in DLL to do initialization (in this case, C++ constructors)
+ */
+typedef void (_CALLTYPE1 *PF)(void);
+
+extern void _CALLTYPE4 _initterm(PF *, PF *);
+
+/*
+ * pointers to initialization sections
+ */
+extern PF __xc_a[], __xc_z[]; /* C++ initializers */
+
+/*
+ * Flag identifying the host as Win32s or not-Win32s.
+ */
+int __win32sflag = 0;
+
+static int onexitflag = 0;
+
+/*
+ * flag set iff _CRTDLL_INIT was called with DLL_PROCESS_ATTACH
+ */
+static int __proc_attached = 0;
+
+/*
+ * Pointers to beginning and end of the table of function pointers manipulated
+ * by _onexit()/atexit(). The atexit/_onexit code is shared for both EXE's and
+ * DLL's but different behavior is required. These values are initialized to
+ * 0 by default and will be set to point to a malloc-ed memory block to mark
+ * this module as an DLL.
+ */
+
+PF *__onexitbegin;
+PF *__onexitend;
+
+
+/*
+ * User routine DllMain is called on all notifications
+ */
+
+extern BOOL WINAPI DllMain(
+ HANDLE hDllHandle,
+ DWORD dwReason,
+ LPVOID lpreserved
+ ) ;
+
+/***
+*BOOL WINAPI _CRT_INIT(hDllHandle, dwReason, lpreserved) - C++ DLL initialization.
+*
+*Purpose:
+* This routine does the C runtime initialization for a DLL using CRTDLL.
+* It may be specified as the entry point for the DLL, or it may be
+* called by the routine that is the DLL entry point.
+*
+* On DLL_PROCESS_ATTACH, the C++ constructors for the DLL will be called.
+*
+* On DLL_PROCESS_DETACH, the C++ destructors and _onexit/atexit routines
+* will be called.
+*
+*Entry:
+*
+*Exit:
+*
+*******************************************************************************/
+
+BOOL WINAPI _CRT_INIT(
+ HANDLE hDllHandle,
+ DWORD dwReason,
+ LPVOID lpreserved
+ )
+{
+ unsigned osver;
+
+ /*
+ * First, set the __proc_attached flag
+ */
+ if ( dwReason == DLL_PROCESS_ATTACH )
+ __proc_attached++;
+ else if ( dwReason == DLL_PROCESS_DETACH ) {
+ if ( __proc_attached > 0 )
+ __proc_attached--;
+ else
+ /*
+ * no prior process attach. just return failure.
+ */
+ return FALSE;
+ }
+
+ /*
+ * Get the host version (on first call).
+ */
+ if ( __win32sflag == 0 ) {
+ osver = GetVersion();
+ if ( ((osver & 0x00ff) == 3) && ((osver >> 31) & 1) )
+ __win32sflag++;
+ else
+ __win32sflag--;
+ }
+
+
+ /*
+ * do C++ constructors (initializers) specific to this DLL
+ */
+
+ if ( dwReason == DLL_PROCESS_ATTACH ) {
+
+ /*
+ * If the host is Win32s, create the onexit table and do C++
+ * constructors only for the first connecting process.
+ */
+ if ( (__win32sflag < 0) || (__proc_attached == 1) ) {
+
+ if ( __win32sflag < 0 ) {
+ /*
+ * not Win32s! just malloc the table.
+ */
+ if ( (__onexitbegin = (PF *)malloc(32 *
+ sizeof(PF))) == NULL )
+ /*
+ * cannot allocate minimal required
+ * size. generate failure to load DLL
+ */
+ return FALSE;
+ }
+ else if ( __proc_attached == 1 ) {
+ if ( (__onexitbegin =
+ (PF *)GlobalAlloc( GMEM_FIXED |
+ GMEM_SHARE, 32 * sizeof(PF) )) ==
+ NULL )
+ /*
+ * cannot allocate minimal required
+ * size. generate failure to load DLL
+ */
+ return FALSE;
+ }
+
+ *(__onexitbegin) = (PF) NULL;
+
+ __onexitend = __onexitbegin;
+
+ /*
+ * Invoke C++ constructors
+ */
+ _initterm(__xc_a,__xc_z);
+
+ }
+ }
+ else if ( dwReason == DLL_PROCESS_DETACH ) {
+
+ if ( (__win32sflag < 0) || (__proc_attached == 0) )
+ {
+ /*
+ * Any basic clean-up code that goes here must be
+ * duplicated below in _DllMainCRTStartup for the
+ * case where the user's DllMain() routine fails on a
+ * Process Attach notification. This does not include
+ * calling user C++ destructors, etc.
+ */
+
+ /*
+ * do _onexit/atexit() terminators
+ * (if there are any)
+ *
+ * These terminators MUST be executed in
+ * reverse order (LIFO)!
+ *
+ * NOTE:
+ * This code assumes that __onexitbegin
+ * points to the first valid onexit()
+ * entry and that __onexitend points
+ * past the last valid entry. If
+ * __onexitbegin == __onexitend, the
+ * table is empty and there are no
+ * routines to call.
+ */
+
+ if (__onexitbegin) {
+ PF * pfend = __onexitend;
+
+ while ( -- pfend >= __onexitbegin )
+ /*
+ * if current table entry is not
+ * NULL, call thru it.
+ */
+ if ( *pfend != NULL )
+ (**pfend)();
+
+ /*
+ * just in case Win32s doesn't clean up after
+ * us (any bets?), free the block holding
+ * onexit table
+ */
+ if ( __win32sflag > 0 )
+ GlobalFree( (HGLOBAL)__onexitbegin );
+ else
+ free(__onexitbegin);
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+/***
+*BOOL WINAPI _DllMainCRTStartup(hDllHandle, dwReason, lpreserved) - C++ DLL initialization.
+*
+*Purpose:
+* This is an alternative entry point for DLL's linked with the C run-time
+* libs, rather than using _CRT_INIT. The user should specify this routine
+* as the DLL entry point, and define his/her own routine DllMain to get
+* notifications in his/her code. CRT initialization/termination will be
+* done before or after calling DllMain, as appropriate.
+*
+*Entry:
+*
+*Exit:
+*
+*******************************************************************************/
+BOOL WINAPI _DllMainCRTStartup(
+ HANDLE hDllHandle,
+ DWORD dwReason,
+ LPVOID lpreserved
+ )
+{
+ BOOL retcode = TRUE;
+
+ /*
+ * If this is a process detach notification, check that there has
+ * been a prior process attach notification.
+ */
+ if ( (dwReason == DLL_PROCESS_DETACH) && (__proc_attached == 0) )
+ return FALSE;
+
+ if ( dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH )
+ retcode = _CRT_INIT(hDllHandle, dwReason, lpreserved);
+
+ if ( retcode )
+ retcode = DllMain(hDllHandle, dwReason, lpreserved);
+
+ /*
+ * If _CRT_INIT successfully handles a Process Attach notification
+ * but the user's DllMain routine returns failure, we need to do
+ * clean-up of the C run-time similar to what _CRT_INIT does on a
+ * Process Detach Notification.
+ */
+
+ if ( dwReason == DLL_PROCESS_DETACH || dwReason == DLL_THREAD_DETACH )
+ {
+ if ( _CRT_INIT(hDllHandle, dwReason, lpreserved) == FALSE )
+ retcode = FALSE ;
+ }
+
+ return retcode ;
+}
+
+/***
+*_onexit, atexit - calls to DLL versioons of _onexit & atexit in CRTDLL.DLL
+*
+*Purpose:
+* A DLL linked with CRTDLL.LIB must not call the standard _onexit or
+* atexit exported from CRTDLL.DLL, but an EXE linked with CRTDLL.LIB
+* will call the standard versions of those two routines. Since the
+* names are exported from CRTDLL.DLL, we must define them here for DLLs.
+* All DLLs linked with CRTDLL.LIB must pull in this startup object.
+*
+*Entry:
+* Same as the regular versions of _onexit, atexit.
+*
+*Exit:
+* Same as the regular versions of _onexit, atexit.
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+extern _onexit_t _CALLTYPE1 __dllonexit(_onexit_t, PF **, PF **);
+
+_onexit_t _CALLTYPE1 _onexit (
+ _onexit_t func
+ )
+{
+ unsigned osver;
+ _onexit_t retval;
+
+ /*
+ * Get the host version (on first call).
+ */
+ if ( __win32sflag == 0 ) {
+ osver = GetVersion();
+ if ( ((osver & 0x00ff) == 3) && ((osver >> 31) & 1) )
+ __win32sflag++;
+ else
+ __win32sflag--;
+ }
+
+ /*
+ * If we are running in Win32s, test and set the flag used to
+ * serialize access. Note that we assume no process switch can take
+ * place between a successful test of the flag and the setting of
+ * the flag.
+ */
+ if ( __win32sflag > 0 ) {
+ while ( onexitflag > 0 )
+ Sleep(0);
+ onexitflag++;
+ }
+
+ retval = __dllonexit(func, &__onexitbegin, &__onexitend);
+
+ if ( __win32sflag > 0 )
+ onexitflag--;
+
+ return retval;
+}
+
+int _CALLTYPE1 atexit (
+ PF func
+ )
+{
+ return (_onexit((_onexit_t)func) == NULL) ? -1 : 0;
+}
+
+#endif /* CRTDLL */
diff --git a/private/crt32/dllstuff/crtexe.c b/private/crt32/dllstuff/crtexe.c
new file mode 100644
index 000000000..fbaa86fff
--- /dev/null
+++ b/private/crt32/dllstuff/crtexe.c
@@ -0,0 +1,215 @@
+#ifdef CRTDLL
+/***
+*crtexe.c - Initialization for client EXE using CRT DLL (Win32, Dosx32)
+*
+* Copyright (c) 1991-1993, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* Set up call to client's main() or WinMain().
+*
+*Revision History:
+* 08-12-91 GJF Module created.
+* 01-05-92 GJF Substantially revised
+* 01-17-92 GJF Restored Stevewo's scheme for unhandled exceptions.
+* 01-29-92 GJF Added support for linked-in options (equivalents of
+* binmode.obj, commode.obj and setargv.obj).
+* 04-17-92 SKS Add call to _initterm() to do C++ constructors (I386)
+* 08-01-92 SRW winxcpt.h replaced bu excpt.h which is included by oscalls.h
+* 09-16-92 SKS Prepare for C8 C++ for MIPS by calling C++ constructors
+* 04-26-93 GJF Made lpszCommandLine (unsigned char *) to deal with
+* chars > 127 in the command line.
+* 04-27-93 GJF Removed support for _RT_STACK, _RT_INTDIV,
+* _RT_INVALDISP and _RT_NONCONT.
+* 05-14-93 GJF Added support for quoted program names.
+* 07-16-93 SRW ALPHA Merge
+* 12-07-93 GJF MS C++ front-end now used on Alpha
+* 05-24-94 SRW Fix call to WinMain to match one in ..\startup\crt0.c
+*
+*******************************************************************************/
+
+/*
+ * SPECIAL BUILD MACRO! Note that crtexe.c (and crtexew.c) is linked in with
+ * the client's code. It does not go into crtdll.dll! Therefore, it must be
+ * built under the _DLL switch (like user code) and CRTDLL must be undefined.
+ */
+#undef CRTDLL
+#define _DLL
+
+#include <cruntime.h>
+#include <oscalls.h>
+#include <internal.h>
+#include <rterr.h>
+#include <stdlib.h>
+
+#undef _fmode /* undefine these so that we can reference the */
+#undef _commode /* local version as well as the DLL variables */
+
+extern int _CRTVAR1 _fmode; /* must match the definition in <stdlib.h> */
+extern int _commode; /* must match the definition in <internal.h> */
+
+static int _dowildcard = 0; /* passed to __GetMainArgs() */
+
+/*
+ * routine in DLL to do initialization (in this case, C++ constructors)
+ */
+typedef void (_CALLTYPE1 *PF)(void);
+
+extern void _CALLTYPE4 _initterm(PF *, PF *);
+
+/*
+ * pointers to initialization sections
+ */
+extern PF __xc_a[], __xc_z[]; /* C++ initializers */
+
+/***
+*void mainCRTStartup(void)
+*
+*Purpose:
+* This routine does the C runtime initialization, calls main(), and
+* then exits. It never returns.
+*
+*Entry:
+*
+*Exit:
+*
+*******************************************************************************/
+
+#ifdef _WINMAIN_
+void WinMainCRTStartup(
+#else
+void mainCRTStartup(
+#endif
+ void
+ )
+{
+ int argc; /* three standard arguments to main */
+ char **argv;
+ char **envp;
+
+ int mainret;
+
+#ifdef _WINMAIN_
+ unsigned char *lpszCommandLine;
+ STARTUPINFOA StartupInfo;
+#endif
+
+ /*
+ * Propogate the _fmode and _commode variables to the DLL
+ */
+
+ *_fmode_dll = _fmode;
+ *_commode_dll = _commode;
+
+ /*
+ * Call _setargv(), which will call the __setargv() in this module
+ * if SETARGV.OBJ is linked with the EXE. If SETARGV.OBJ is not
+ * linked with the EXE, a _dummy setargv() will be called.
+ */
+
+ _setargv();
+
+ /*
+ * Get the arguments for the call to main. Note this must be done
+ * explicitly, rather than as part of the dll's initialization, to
+ * implement optional expansion of wild card chars in filename args
+ */
+ __GetMainArgs(&argc, &argv, &envp, _dowildcard);
+
+ /*
+ * do C++ constructors (initializers) specific to this EXE
+ */
+ _initterm( __xc_a, __xc_z );
+
+ try {
+#ifdef _WINMAIN_
+ /*
+ * Skip past program name (first token in command line).
+ * Check for and handle quoted program name.
+ */
+ lpszCommandLine = (unsigned char *)_acmdln;
+
+ if ( *lpszCommandLine == '\"' ) {
+ /*
+ * Scan, and skip over, subsequent characters until
+ * another double-quote or a null is encountered.
+ */
+ while ( *++lpszCommandLine && (*lpszCommandLine
+ != '\"') );
+ /*
+ * If we stopped on a double-quote (usual case), skip
+ * over it.
+ */
+ if ( *lpszCommandLine == '\"' )
+ lpszCommandLine++;
+ }
+ else {
+ while (*lpszCommandLine > ' ')
+ lpszCommandLine++;
+ }
+
+ /*
+ * Skip past any white space preceeding the second token.
+ */
+ while (*lpszCommandLine && (*lpszCommandLine <= ' ')) {
+ lpszCommandLine++;
+ }
+
+ StartupInfo.dwFlags = 0;
+ GetStartupInfoA( &StartupInfo );
+
+ mainret = WinMain( GetModuleHandle(NULL),
+ NULL,
+ lpszCommandLine,
+ StartupInfo.dwFlags & STARTF_USESHOWWINDOW
+ ? StartupInfo.wShowWindow
+ : SW_SHOWDEFAULT
+ );
+#else
+ mainret = main(argc, argv, envp);
+#endif
+ exit(mainret);
+ }
+ except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
+ {
+ /*
+ * Should never reach here
+ */
+ _exit( GetExceptionCode() );
+
+ } /* end of try - except */
+
+}
+
+/***
+*__setargv - dummy version (for wildcard expansion) for CRTDLL.DLL model only
+*
+*Purpose:
+* If the EXE that is linked with CRTDLL.LIB is linked explicitly with
+* SETARGV.OBJ, the call to _setargv() in the C Run-Time start-up code
+* (above) will call this routine, instead of calling a dummy version of
+* _setargv() which will do nothing. This will set to one the static
+* variable which is passed to __GetMainArgs(), thus enabling wildcard
+* expansion of the command line arguments.
+*
+* In the statically-linked C Run-Time models, _setargv() and __setargv()
+* are the actual routines that do the work, but this code exists in
+* CRTDLL.DLL and so some tricks have to be played to make the same
+* SETARGV.OBJ work for EXE's linked with both LIBC.LIB and CRTDLL.LIB.
+*
+*Entry:
+* The static variable _dowildcard is zero (presumably).
+*
+*Exit:
+* The static variable _dowildcard is set to one, meaning that the
+* routine __GetMainArgs() in CRTDLL.DLL *will* do wildcard expansion on
+* the command line arguments. (The default behavior is that it won't.)
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+void _CALLTYPE1 __setargv ( void )
+{
+ _dowildcard = 1;
+}
+#endif /* CRTDLL */
diff --git a/private/crt32/dllstuff/crtexew.c b/private/crt32/dllstuff/crtexew.c
new file mode 100644
index 000000000..276fae13a
--- /dev/null
+++ b/private/crt32/dllstuff/crtexew.c
@@ -0,0 +1,4 @@
+#ifdef CRTDLL
+#define _WINMAIN_
+#include "crtexe.c"
+#endif /* CRTDLL */
diff --git a/private/crt32/dllstuff/crtlib.c b/private/crt32/dllstuff/crtlib.c
new file mode 100644
index 000000000..8a813c580
--- /dev/null
+++ b/private/crt32/dllstuff/crtlib.c
@@ -0,0 +1,258 @@
+#ifdef CRTDLL
+/***
+*crtlib.c - CRT DLL initialization and termination routine (Win32, Dosx32)
+*
+* Copyright (c) 1991-1993, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* This module contains initialization entry point for the CRT DLL in
+* Win32 and Dosx32 environments. It also contains some of the supporting
+* initialization and termination code.
+*
+*Revision History:
+* 08-12-91 GJF Module created. Sort of.
+* 01-17-92 GJF Return exception code value for RTEs corresponding
+* to exceptions.
+* 01-29-92 GJF Support for wildcard expansion in filenames on the
+* command line.
+* 02-14-92 GJF Moved file inheritance stuff to ioinit.c. Call to
+* inherit() is replace by call to _ioinit().
+* 08-26-92 SKS Add _osver, _winver, _winmajor, _winminor
+* 09-04-92 GJF Replaced _CALLTYPE3 with WINAPI.
+* 09-30-92 SRW Call _heap_init before _mtinit
+* 10-19-92 SKS Add "dowildcard" parameter to GetMainArgs()
+* Prepend a second "_" to name since it is internal-only
+* 04-16-93 SKS Change call to _mtdeletelocks to _mtterm. _mtterm
+* calls _mtdeletelocks and also frees up the TLS index.
+* 04-27-93 GJF Removed support for _RT_STACK, _RT_INTDIV,
+* _RT_INVALDISP and _RT_NONCONT.
+* 05-11-93 SKS Change _CRTDLL_INIT to fail loading on failure to
+* initialize/clean up, rather than calling _amsg_exit().
+* 06-03-93 GJF Added __proc_attached flag.
+* 06-07-93 GJF Incorporated SteveWo's code to call LoadLibrary, from
+* crtdll.c.
+* 12-14-93 SKS Add _freeptd(), which frees up the per-thread data
+* maintained by the C run-time library.
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <oscalls.h>
+#include <dos.h>
+#include <internal.h>
+#include <os2dll.h>
+#include <process.h>
+#include <rterr.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * flag set iff _CRTDLL_INIT was called with DLL_PROCESS_ATTACH
+ */
+static int __proc_attached = 0;
+
+/*
+ * command line, environment, and a few other globals
+ */
+char *_acmdln; /* points to command line */
+char *_aenvptr; /* points to environment block */
+
+void (_CALLTYPE1 * _aexit_rtn)(int) = _exit; /* RT message return procedure */
+
+static void _CALLTYPE4 inherit(void); /* local function */
+
+
+/***
+*void __GetMainArgs(pargc, pargv, penvp, dowildcard) - get values for args to main()
+*
+*Purpose:
+* This function invokes the command line parsing and copies the args
+* to main back through the passsed pointers. The reason for doing
+* this here, rather than having _CRTDLL_INIT do the work and exporting
+* the __argc and __argv, is to support the linked-in option to have
+* wildcard characters in filename arguments expanded.
+*
+*Entry:
+* int *pargc - pointer to argc
+* char ***pargv - pointer to argv
+* char ***penvp - pointer to envp
+* int dowildcard - flag (true means expand wildcards in cmd line)
+*
+*Exit:
+* No return value. Values for the arguments to main() are copied through
+* the passed pointers.
+*
+*******************************************************************************/
+
+
+void _CALLTYPE1 __GetMainArgs (
+ int *pargc,
+ char ***pargv,
+ char ***penvp,
+ int dowildcard)
+{
+ if ( dowildcard )
+ __setargv(); /* do wildcard expansion after parsing args */
+ else
+ _setargv(); /* NO wildcard expansion; just parse args */
+
+ *pargc = __argc;
+ *pargv = __argv;
+ *penvp = _environ;
+}
+
+
+/***
+*BOOL _CRTDLL_INIT(hDllHandle, dwReason, lpreserved) - C DLL initialization.
+*
+*Purpose:
+* This routine does the C runtime initialization.
+*
+*Entry:
+*
+*Exit:
+*
+*******************************************************************************/
+
+BOOL WINAPI _CRTDLL_INIT(
+ HANDLE hDllHandle,
+ DWORD dwReason,
+ LPVOID lpreserved
+ )
+{
+ char szDllName[ MAX_PATH ];
+
+ if ( dwReason == DLL_PROCESS_ATTACH ) {
+
+ /*
+ * Increment flag indicating process attach notification
+ * has been received.
+ */
+ __proc_attached++;
+
+ /*
+ * Pin ourselves in memory since we dont clean up if we
+ * unload.
+ */
+ if ( !GetModuleFileName( hDllHandle,
+ szDllName,
+ sizeof(szDllName))
+ )
+ {
+ strcpy(szDllName, "CRTDLL");
+ }
+ LoadLibrary(szDllName);
+ }
+ else if ( dwReason == DLL_PROCESS_DETACH ) {
+ /*
+ * if this is a process detach notification, make sure there
+ * has been a prior process attach notification.
+ */
+ if ( __proc_attached > 0 )
+ __proc_attached--;
+ else
+ /* no prior process attach, just return */
+ return FALSE;
+ }
+ else if ( dwReason == DLL_THREAD_DETACH )
+ {
+ _freeptd(NULL); /* free up per-thread CRT data */
+ }
+
+
+ /*
+ * Only do initialization when a client process attaches to
+ * the DLL.
+ */
+ if ( dwReason != DLL_PROCESS_ATTACH ) {
+ /*
+ * if a client process is detaching, make sure minimal
+ * runtime termination is performed and clean up our
+ * 'locks' (i.e., delete critical sections).
+ */
+ if ( dwReason == DLL_PROCESS_DETACH ) {
+
+ if ( _C_Termination_Done == FALSE )
+ _c_exit();
+#ifdef MTHREAD
+ _mtterm(); /* free TLS index, call _mtdeletelocks() */
+#endif
+ }
+
+ return TRUE;
+ }
+
+ _acmdln = (char *)GetCommandLine();
+ _aenvptr = (char *)GetEnvironmentStrings();
+
+ /*
+ * Get the full Win32 version
+ */
+ _osversion = /* OBSOLETE */
+ _osver = GetVersion();
+
+ _winminor = (_osver >> 8) & 0x00FF ;
+ _winmajor = _osver & 0x00FF ;
+ _winver = (_winmajor << 8) + _winminor;
+ _osver = (_osver >> 16) & 0x00FFFF ;
+
+ /* --------- The following block is OBSOLETE --------- */
+
+ /*
+ * unpack base version info
+ */
+ _baseversion = (_osversion & 0xFFFF0000) >> 16;
+ _baseminor = _baseversion & 0x00FF;
+ _basemajor = (_baseversion & 0xFF00) >> 8;
+
+ /*
+ * unpack top-level version info (Windows version)
+ */
+ _osversion &= 0x0000FFFF;
+ _osmajor = _osversion & 0x00FF;
+ _osminor = (_osversion & 0xFF00) >> 8;
+
+ /* --------- The preceding block is OBSOLETE --------- */
+
+ _heap_init(); /* initialize heap */
+#ifdef MTHREAD
+ if(!_mtinit()) /* initialize multi-thread */
+ return FALSE; /* fail DLL load on failure */
+#endif
+ _ioinit(); /* inherit file info */
+ _setenvp(); /* get environ info */
+
+ _cinit(); /* do C data initialize */
+
+ return TRUE;
+}
+
+/***
+*_amsg_exit(rterrnum) - Fast exit fatal errors
+*
+*Purpose:
+* Exit the program with error code of 255 and appropriate error
+* message.
+*
+*Entry:
+* int rterrnum - error message number (amsg_exit only).
+*
+*Exit:
+* Calls exit() (for integer divide-by-0) or _exit() indirectly
+* through _aexit_rtn [amsg_exit].
+* For multi-thread: calls _exit() function
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+void _CALLTYPE1 _amsg_exit (
+ int rterrnum
+ )
+{
+ _FF_MSGBANNER(); /* write run-time error banner */
+ _NMSG_WRITE(rterrnum); /* write message */
+
+ _aexit_rtn(255); /* normally _exit(255) */
+}
+#endif /* CRTDLL */
diff --git a/private/crt32/dllstuff/dllargv.c b/private/crt32/dllstuff/dllargv.c
new file mode 100644
index 000000000..9b6875a00
--- /dev/null
+++ b/private/crt32/dllstuff/dllargv.c
@@ -0,0 +1,49 @@
+#ifndef _POSIX_
+#ifdef CRTDLL
+/***
+*dllargv.c - Dummy _setargv() routine for use with C Run-Time as a DLL (CRTDLL)
+*
+* Copyright (c) 1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* This object goes into CRTDLL.LIB, which is linked with user programs
+* to use CRTDLL.DLL for C run-time library functions. If the user
+* program links explicitly with SETARGV.OBJ, this object will not be
+* linked in, and the _setargv() that does get called with set the flag
+* that will enable wildcard expansion. If SETARGV.OBJ is not linked
+* into the EXE, this object will get called by the CRT start-up stub
+* and the flag to enable wildcard expansion will not be set.
+*
+*Revision History:
+* 10-19-92 SKS Initial version
+*
+*******************************************************************************/
+
+#include <cruntime.h>
+#include <internal.h>
+
+/***
+*_setargv - dummy version for CRTDLL.DLL model only
+*
+*Purpose:
+* This routine gets called by the C Run-Time start-up code in CRTEXE.C
+* which gets linked into an EXE file linked with CRTDLL.LIB. It does
+* nothing, but if the user links the EXE with SETARGV.OBJ, this routine
+* will not get called but instead __setargv() will be called. (In the
+* CRTDLL model, it will set the variable that is passed to _GetMainArgs
+* and enable wildcard expansion in the command line arguments.)
+*
+*Entry:
+*
+*Exit:
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+void _CALLTYPE1 _setargv ( void )
+{
+ /* NOTHING */
+}
+#endif /* !_POSIX_ */
+#endif /* CRTDLL */
diff --git a/private/crt32/dllstuff/i386/dllsupp.asm b/private/crt32/dllstuff/i386/dllsupp.asm
new file mode 100644
index 000000000..33ae13262
--- /dev/null
+++ b/private/crt32/dllstuff/i386/dllsupp.asm
@@ -0,0 +1,39 @@
+ page ,132
+ title dllsupp - defines some public constants
+;***
+;dllsupp.asm - Definitions of public constants
+;
+; Copyright (c) 1992, Microsoft Corporation. All rights reserved.
+;
+;Purpose:
+; Provides definitions for public constants (absolutes) that are
+; 'normally' defined in objects in the C library, but must be defined
+; here for clients of crtdll.dll. These constants are:
+;
+; _except_list
+; _fltused
+; _ldused
+;
+;Revision History:
+; 01-23-92 GJF Module created.
+;
+;*******************************************************************************
+
+.xlist
+include cruntime.inc
+include except.inc
+.list
+
+; offset, with respect to FS, of pointer to currently active exception handler.
+; referenced by compiler generated code for SEH and by _setjmp().
+
+ public _except_list
+_except_list equ 0
+
+ public _fltused
+_fltused equ 9876h
+
+ public _ldused
+_ldused equ 9876h
+
+ end
diff --git a/private/crt32/dllstuff/makefile b/private/crt32/dllstuff/makefile
new file mode 100644
index 000000000..6ee4f43fa
--- /dev/null
+++ b/private/crt32/dllstuff/makefile
@@ -0,0 +1,6 @@
+#
+# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
+# file to this component. This file merely indirects to the real make file
+# that is shared by all the components of NT OS/2
+#
+!INCLUDE $(NTMAKEENV)\makefile.def
diff --git a/private/crt32/dllstuff/sources b/private/crt32/dllstuff/sources
new file mode 100644
index 000000000..7ea3dcdfa
--- /dev/null
+++ b/private/crt32/dllstuff/sources
@@ -0,0 +1,44 @@
+!IF 0
+
+Copyright (c) 1989 Microsoft Corporation
+
+Module Name:
+
+ sources.
+
+Abstract:
+
+ This file specifies the target component being built and the list of
+ sources files needed to build that component. Also specifies optional
+ compiler switches and libraries that are unique for the component being
+ built.
+
+
+Author:
+
+ Steve Wood (stevewo) 12-Apr-1990
+ jeffrob 29-sep-1990, use crt32.def
+
+NOTE: Commented description of this file is in \nt\bak\bin\sources.tpl
+
+!ENDIF
+
+MAJORCOMP=crt
+MINORCOMP=dllstuff
+
+TARGETNAME=dllstuff
+TARGETPATH=..\obj
+TARGETTYPE=LIBRARY
+386_STDCALL=0
+
+!INCLUDE ..\crt32.def
+
+SOURCES=dllargv.c \
+ cinitexe.c \
+ crtexe.c \
+ crtexew.c \
+ crtdll.c \
+ crtlib.c
+
+i386_SOURCES=i386\dllsupp.asm
+