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