1 const char amiga_rcs[] = "$Id: amiga.c,v 1.2 2001/05/23 00:13:58 joergs Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/amiga.c,v $
6 * Purpose : Amiga-specific declarations.
8 * Copyright : Written by and Copyright (C) 2001 the SourceForge
9 * IJBSWA team. http://ijbswa.sourceforge.net
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software
14 * Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will
18 * be useful, but WITHOUT ANY WARRANTY; without even the
19 * implied warranty of MERCHANTABILITY or FITNESS FOR A
20 * PARTICULAR PURPOSE. See the GNU General Public
21 * License for more details.
23 * The GNU General Public License should be included with
24 * this file. If not, you can view it at
25 * http://www.gnu.org/copyleft/gpl.html
26 * or write to the Free Software Foundation, Inc., 59
27 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 * Revision 1.2 2001/05/23 00:13:58 joergs
32 * AmigaOS support fixed.
34 * Revision 1.1.1.1 2001/05/15 13:58:46 oes
35 * Initial import of version 2.9.3 source tree
38 *********************************************************************/
50 const char amiga_h_rcs[] = AMIGA_H_VERSION;
52 unsigned long __stack = 100*1024;
53 static char ver[] = "$VER: junkbuster " __AMIGAVERSION__ " (" __AMIGADATE__ ")";
54 struct Task *main_task = NULL;
57 void serve(struct client_state *csp);
59 __saveds ULONG server_thread(void)
61 struct client_state *local_csp;
62 struct UserData UserData;
63 struct Task *me=FindTask(NULL);
66 local_csp=(struct client_state *)(me->tc_UserData);
67 me->tc_UserData=&UserData;
68 SocketBase=(APTR)OpenLibrary("bsdsocket.library",3);
71 SetErrnoPtr(&(UserData.eno),sizeof(int));
72 local_csp->cfd=ObtainSocket(local_csp->cfd, AF_INET, SOCK_STREAM, 0);
73 if(-1!=local_csp->cfd)
75 Signal(main_task,SIGF_SINGLE);
76 serve((struct client_state *) local_csp);
78 local_csp->active = 0;
79 Signal(main_task,SIGF_SINGLE);
81 CloseLibrary(SocketBase);
83 local_csp->active = 0;
84 Signal(main_task,SIGF_SINGLE);
94 CloseLibrary(SocketBase);
98 static struct SignalSemaphore memsem;
99 static struct SignalSemaphore *memsemptr = NULL;
100 static struct UserData GlobalUserData;
104 main_task = FindTask(NULL);
105 main_task->tc_UserData = &GlobalUserData;
107 if (((struct Library *)SysBase)->lib_Version < 39)
112 signal(SIGINT,SIG_IGN);
113 SocketBase = (APTR)OpenLibrary("bsdsocket.library",3);
116 fprintf(stderr, "Can't open bsdsocket.library V3+\n");
119 SetErrnoPtr(&(GlobalUserData.eno),sizeof(int));
120 InitSemaphore(&memsem);
128 /* multitaskingsafe libnix replacements */
129 static void *memPool=NULL;
131 void *malloc (size_t s)
142 if (!(memPool=CreatePool(MEMF_ANY,32*1024,8*1024)))
147 size += sizeof(ULONG) + MEM_BLOCKMASK;
148 size &= ~MEM_BLOCKMASK;
151 ObtainSemaphore(memsemptr);
153 if ((mem=AllocPooled(memPool,size)))
159 ReleaseSemaphore(memsemptr);
174 ObtainSemaphore(memsemptr);
176 FreePooled(memPool,mem,size);
179 ReleaseSemaphore(memsemptr);
184 void *realloc (void *old, size_t ns)
187 LONG osize, *o = old;
192 return malloc(nsize);
194 osize = (*(o-1)) - sizeof(ULONG);
199 if ((new = malloc(nsize)))
213 void __memCleanUp (void)
217 ObtainSemaphore(memsemptr);
225 ReleaseSemaphore(memsemptr);
229 #define ADD2LIST(a,b,c) asm(".stabs \"_" #b "\"," #c ",0,0,_" #a )
230 #define ADD2EXIT(a,pri) ADD2LIST(a,__EXIT_LIST__,22); \
231 asm(".stabs \"___EXIT_LIST__\",20,0,0," #pri "+128")
232 ADD2EXIT(__memCleanUp,-50);
233 #elif !defined(ixemul)
234 #error No libnix and no ixemul!?
237 #error Only GCC is supported, multitasking safe malloc/free required.
238 #endif /* __GNUC__ */
240 #endif /* def AMIGA */