Don't call ReadArgs() if started from WB.
[tangerine.git] / compiler / clib / arosc_init.c
blob8af628c8470855175fc2a3c898931825f1cef64b
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/types.h>
7 #include <exec/resident.h>
8 #include <exec/memory.h>
9 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <aros/libcall.h>
12 #include <aros/asmcall.h>
13 #include <aros/symbolsets.h>
14 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
15 # include "arosc_gcc.h"
16 #endif
18 #include <stddef.h>
19 #include <ctype.h>
20 #include <sys/stat.h>
21 #include <setjmp.h>
23 #define DEBUG 0
24 #include <aros/debug.h>
26 #include "etask.h"
27 #include "__arosc_privdata.h"
28 #include "arosc_init.h"
30 THIS_PROGRAM_HANDLES_SYMBOLSETS
32 extern const char name[];
33 extern const char version[];
34 extern const APTR inittabl[4];
35 extern void *const arosc_functable[];
36 extern const struct inittable datatable;
37 extern struct aroscbase *AROS_SLIB_ENTRY(init,arosc)();
38 AROS_LD1(struct aroscbase *, open, AROS_LDA(ULONG, version, D0), struct aroscbase *, aroscbase, 1, arosc);
39 AROS_LD0(BPTR, close, struct aroscbase *, aroscbase, 2, arosc);
40 AROS_LD0(BPTR, expunge, struct aroscbase *, aroscbase, 3, arosc);
41 AROS_LD0I(int, null, struct aroscbase *, aroscbase, 4, arosc);
42 extern const char arosc_end;
44 struct ExecBase *SysBase;
45 struct aroscbase *aroscbase;
47 extern struct DosLibrary *DOSBase;
50 int entry(void)
52 /* If the library was executed by accident return error code. */
53 return -1;
56 const struct Resident resident=
58 RTC_MATCHWORD,
59 (struct Resident *)&resident,
60 (APTR)&arosc_end,
61 RTF_AUTOINIT,
62 41,
63 NT_LIBRARY,
65 (char *)name,
66 (char *)&version[6],
67 (ULONG *)inittabl
70 const char name[]="arosc.library";
72 const char version[]="$VER: arosc.library 41.1 (" __DATE__ ")\n\015";
74 const APTR inittabl[4]=
76 (APTR)sizeof(struct aroscbase),
77 (APTR)arosc_functable,
78 NULL,
79 &AROS_SLIB_ENTRY(init,arosc)
82 DECLARESET(INIT);
83 DECLARESET(EXIT);
85 AROS_UFH3(struct aroscbase *, AROS_SLIB_ENTRY(init,arosc),
86 AROS_UFHA(struct aroscbase *, __aroscbase, D0),
87 AROS_UFHA(BPTR, segList, A0),
88 AROS_UFHA(struct ExecBase *, __SysBase, A6)
91 AROS_USERFUNC_INIT
93 /* This function is single-threaded by exec by calling Forbid. */
95 /* Store arguments */
96 aroscbase = __aroscbase;
97 SysBase = __SysBase;
99 aroscbase->seglist=segList;
101 if (!set_open_libraries())
103 set_close_libraries();
105 return NULL;
108 /* You would return NULL here if the init failed. */
109 return aroscbase;
110 AROS_USERFUNC_EXIT
114 AROS_LH1(struct aroscbase *, open,
115 AROS_LHA(ULONG, version, D0),
116 struct aroscbase *, aroscbase, 1, arosc)
118 AROS_LIBFUNC_INIT
120 This function is single-threaded by exec by calling Forbid.
121 If you break the Forbid() another task may enter this function
122 at the same time. Take care.
125 /* Keep compiler happy */
126 version=0;
128 if (!arosc_internalinit())
130 arosc_internalexit();
131 return NULL;
134 /* I have one more opener. */
135 aroscbase->library.lib_OpenCnt++;
136 aroscbase->library.lib_Flags &= ~LIBF_DELEXP;
138 /* You would return NULL if the open failed. */
139 return aroscbase;
141 AROS_LIBFUNC_EXIT
144 AROS_LH0(BPTR, close, struct aroscbase *, aroscbase, 2, arosc)
146 AROS_LIBFUNC_INIT
148 This function is single-threaded by exec by calling Forbid.
149 If you break the Forbid() another task may enter this function
150 at the same time. Take care.
153 /* I have one fewer opener. */
154 if(!--aroscbase->library.lib_OpenCnt)
156 /* Delayed expunge pending? */
157 if(aroscbase->library.lib_Flags&LIBF_DELEXP)
158 /* Then expunge the library */
159 return expunge();
162 arosc_internalexit();
164 return 0;
165 AROS_LIBFUNC_EXIT
168 AROS_LH0(BPTR, expunge, struct aroscbase *, aroscbase, 3, arosc)
170 AROS_LIBFUNC_INIT
172 BPTR ret;
174 This function is single-threaded by exec by calling Forbid.
175 Never break the Forbid() or strange things might happen.
178 /* Test for openers. */
179 if(aroscbase->library.lib_OpenCnt)
181 /* Set the delayed expunge flag and return. */
182 aroscbase->library.lib_Flags|=LIBF_DELEXP;
183 return 0;
186 /* Get rid of the library. Remove it from the list. */
187 Remove(&aroscbase->library.lib_Node);
189 /* Get returncode here - FreeMem() will destroy the field. */
190 ret=aroscbase->seglist;
192 set_close_libraries();
194 /* Free the memory. */
195 FreeMem((char *)aroscbase-aroscbase->library.lib_NegSize,
196 aroscbase->library.lib_NegSize+aroscbase->library.lib_PosSize);
198 return ret;
199 AROS_LIBFUNC_EXIT
201 AROS_LH0I(int, null, struct aroscbase *, aroscbase, 4, arosc)
203 AROS_LIBFUNC_INIT
204 return 0;
205 AROS_LIBFUNC_EXIT
208 int arosc_internalinit(void)
210 struct arosc_privdata *oldprivdata, *privdata;
211 struct Process *me = (struct Process *)FindTask(NULL);
212 int res = TRUE;
214 privdata = oldprivdata = GetIntETask(me)->iet_acpd;
216 D(bug("\nEntering arosc_internalinit(): me->name = %s\n", me->pr_Task.tc_Node.ln_Name));
217 D(bug("arosc_internalinit(): oldprivdata = %p\n", oldprivdata));
220 !oldprivdata ||
221 (!oldprivdata->acpd_spawned && oldprivdata->acpd_process_returnaddr != me->pr_ReturnAddr)
224 D(bug("arosc_internalinit(): AllocMem()\n"));
225 privdata = AllocMem(sizeof *privdata, MEMF_CLEAR|MEMF_ANY);
227 if (!privdata)
229 SetIoErr(ERROR_NO_FREE_STORE);
230 return FALSE;
233 D(bug("arosc_internalinit(): newprivdata = %p\n", privdata));
234 privdata->acpd_oldprivdata = oldprivdata;
235 privdata->acpd_process_returnaddr = me->pr_ReturnAddr;
237 GetIntETask(me)->iet_acpd = privdata;
239 res = set_call_funcs(SETNAME(INIT), 1, 1);
242 D(bug("arosc_internalinit(): acpd_usercount++\n"));
243 privdata->acpd_usercount++;
245 return res;
248 int arosc_internalexit(void)
250 struct arosc_privdata *privdata = GetIntETask(FindTask(NULL))->iet_acpd;
252 D(bug("arosc_internalexit(): --acpd_usercount\n"));
254 #warning FIXME: privdata should NEVER be NULL here
255 ASSERT_VALID_PTR(privdata);
256 if (privdata && --privdata->acpd_usercount == 0)
258 set_call_funcs(SETNAME(EXIT), -1, 0);
260 /*restore the old value */
261 GetIntETask(FindTask(NULL))->iet_acpd = privdata->acpd_oldprivdata;
263 D(bug("arosc_internalexit(): FreeMem()\n"));
264 FreeMem(privdata, sizeof(*privdata));
267 D(bug("Exiting arosc_internalexit(): me->name = %s\n\n", FindTask(NULL)->tc_Node.ln_Name));
268 return 0;
271 DEFINESET(INIT);
272 DEFINESET(EXIT);