1*404b540aSrobert /* Startup code for libgcc_s.nlm, necessary because we can't allow
2*404b540aSrobert libgcc_s to use libc's malloc & Co., which associate allocations
3*404b540aSrobert with the NLM owning the current (application) thread.
4*404b540aSrobert Contributed by Jan Beulich (jbeulich@novell.com)
5*404b540aSrobert Copyright (C) 2004 Free Software Foundation, Inc.
6*404b540aSrobert
7*404b540aSrobert This file is part of GCC.
8*404b540aSrobert
9*404b540aSrobert GCC is free software; you can redistribute it and/or modify
10*404b540aSrobert it under the terms of the GNU General Public License as published by
11*404b540aSrobert the Free Software Foundation; either version 2, or (at your option)
12*404b540aSrobert any later version.
13*404b540aSrobert
14*404b540aSrobert GCC is distributed in the hope that it will be useful,
15*404b540aSrobert but WITHOUT ANY WARRANTY; without even the implied warranty of
16*404b540aSrobert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17*404b540aSrobert GNU General Public License for more details.
18*404b540aSrobert
19*404b540aSrobert You should have received a copy of the GNU General Public License
20*404b540aSrobert along with GCC; see the file COPYING. If not, write to
21*404b540aSrobert the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22*404b540aSrobert Boston, MA 02110-1301, USA. */
23*404b540aSrobert
24*404b540aSrobert #include <netware.h>
25*404b540aSrobert #include <stddef.h>
26*404b540aSrobert #include <stdlib.h>
27*404b540aSrobert #include <windows.h>
28*404b540aSrobert
29*404b540aSrobert static rtag_t allocRTag;
30*404b540aSrobert
31*404b540aSrobert BOOL
DllMain(HINSTANCE libraryId,DWORD reason,void * hModule)32*404b540aSrobert DllMain (HINSTANCE libraryId __attribute__ ((__unused__)),
33*404b540aSrobert DWORD reason, void *hModule)
34*404b540aSrobert {
35*404b540aSrobert switch (reason)
36*404b540aSrobert {
37*404b540aSrobert case DLL_NLM_STARTUP:
38*404b540aSrobert allocRTag = AllocateResourceTag (hModule,
39*404b540aSrobert "libgcc memory", AllocSignature);
40*404b540aSrobert return allocRTag != NULL;
41*404b540aSrobert case DLL_NLM_SHUTDOWN:
42*404b540aSrobert /* This does not recover resources associated with the tag...
43*404b540aSrobert ReturnResourceTag (allocRTag, 0); */
44*404b540aSrobert break;
45*404b540aSrobert }
46*404b540aSrobert return 1;
47*404b540aSrobert }
48*404b540aSrobert
49*404b540aSrobert void *
malloc(size_t size)50*404b540aSrobert malloc (size_t size)
51*404b540aSrobert {
52*404b540aSrobert return AllocSleepOK (size, allocRTag, NULL);
53*404b540aSrobert }
54*404b540aSrobert
55*404b540aSrobert void
free(void * ptr)56*404b540aSrobert free (void *ptr)
57*404b540aSrobert {
58*404b540aSrobert Free (ptr);
59*404b540aSrobert }
60