aboutsummaryrefslogtreecommitdiff
path: root/winsup/mingw/dllcrt1.c
blob: a0055d8b0af7c3cdb5a4f057a74fa065a778d3d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * dllcrt1.c
 *
 * Initialization code for DLLs.
 *
 * This file is part of the Mingw32 package.
 *
 * Contributors:
 *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
 *  DLL support adapted from Gunther Ebert <gunther.ebert@ixos-leipzig.de>
 *  Maintained by Mumit Khan <khan@xraylith.wisc.EDU>
 *
 *  THIS SOFTWARE IS NOT COPYRIGHTED
 *
 *  This source code is offered for use in the public domain. You may
 *  use, modify or distribute it freely.
 *
 *  This code is distributed in the hope that it will be useful but
 *  WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
 *  DISCLAMED. This includes but is not limited to warrenties of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * $Revision$
 * $Author$
 * $Date$
 * 
 */

#include <stdio.h>
#include <io.h>
#include <process.h>
#include <windows.h>

/* Unlike normal crt1, I don't initialize the FPU, because the process
 * should have done that already. I also don't set the file handle modes,
 * because that would be rude. */

#ifdef	__GNUC__
extern void __main ();
extern void __do_global_dtors ();
#endif

extern BOOL WINAPI DllMain (HANDLE, DWORD, LPVOID);

BOOL WINAPI
DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
{
  BOOL bRet;

  if (dwReason == DLL_PROCESS_ATTACH)
    {
#ifdef	__GNUC__
      /* From libgcc.a, calls global class constructors. */
      __main ();
#endif
    }

  /*
   * Call the user-supplied DllMain subroutine
   * NOTE: DllMain is optional, so libmingw32.a includes a stub
   *       which will be used if the user does not supply one.
   */
  bRet = DllMain (hDll, dwReason, lpReserved);

#ifdef	__GNUC__
  if (dwReason == DLL_PROCESS_DETACH)
    {
      /* From libgcc.a, calls global class destructors. */
      __do_global_dtors ();
    }
#endif

  return bRet;
}

/*
 * For the moment a dummy atexit. Atexit causes problems in DLLs, especially
 * if they are dynamically loaded. For now atexit inside a DLL does nothing.
 * NOTE: We need this even if the DLL author never calls atexit because
 *       the global constructor function __do_global_ctors called from __main
 *       will attempt to register __do_global_dtors using atexit.
 *       Thanks to Andrey A. Smirnov for pointing this one out.
 */
int
atexit (void (*pfn) ())
{
  return 0;
}