1 const char amiga_rcs[] = "$Id: amiga.c,v 1.15 2012/03/09 16:23:50 fabiankeil 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 * Privoxy team. http://www.privoxy.org/
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.
29 *********************************************************************/
41 const char amiga_h_rcs[] = AMIGA_H_VERSION;
43 static char *ver USED = "$VER: Privoxy " __AMIGAVERSION__ " (" __AMIGADATE__ ")";
45 static char *stack USED = "$STACK: 524288";
47 unsigned long __stack = 100*1024;
49 struct Task *main_task = NULL;
52 void serve(struct client_state *csp);
54 SAVEDS ULONG server_thread(void)
56 struct client_state *local_csp;
57 struct UserData UserData;
58 struct Task *me=FindTask(NULL);
60 struct Library *SocketBase;
64 local_csp=(struct client_state *)(me->tc_UserData);
65 me->tc_UserData=&UserData;
66 SocketBase=(APTR)OpenLibrary("bsdsocket.library",3);
70 ISocket = (struct SocketIFace *)GetInterface(SocketBase, "main", 1, NULL);
75 SetErrnoPtr(&(UserData.eno),sizeof(int));
76 local_csp->cfd=ObtainSocket(local_csp->cfd, AF_INET, SOCK_STREAM, 0);
77 if (JB_INVALID_SOCKET!=local_csp->cfd)
79 Signal(main_task,SIGF_SINGLE);
80 serve((struct client_state *) local_csp);
82 local_csp->flags &= ~CSP_FLAG_ACTIVE;
83 Signal(main_task,SIGF_SINGLE);
86 DropInterface((struct Interface *)ISocket);
88 CloseLibrary(SocketBase);
91 CloseLibrary(SocketBase);
93 local_csp->flags &= ~CSP_FLAG_ACTIVE;
94 Signal(main_task,SIGF_SINGLE);
102 void amiga_exit(void)
111 struct Library *SocketBase = ISocket->Data.LibBase;
112 DropInterface((struct Interface *)ISocket);
114 CloseLibrary(SocketBase);
120 static struct SignalSemaphore memsem;
121 static struct SignalSemaphore *memsemptr = NULL;
123 static struct UserData GlobalUserData;
128 struct Library *SocketBase;
131 main_task = FindTask(NULL);
132 main_task->tc_UserData = &GlobalUserData;
134 if (((struct Library *)SysBase)->lib_Version < 39)
139 signal(SIGINT,SIG_IGN);
140 SocketBase = (APTR)OpenLibrary("bsdsocket.library",3);
144 ISocket = (struct SocketIFace *)GetInterface(SocketBase, "main", 1, NULL);
152 CloseLibrary(SocketBase);
154 fprintf(stderr, "Can't open bsdsocket.library V3+\n");
157 SetErrnoPtr(&(GlobalUserData.eno),sizeof(int));
159 InitSemaphore(&memsem);
163 olddir=CurrentDir(GetProgramDir());
170 /* multithreadingsafe libnix replacements */
171 static void *memPool=NULL;
173 void *malloc (size_t s)
184 if (!(memPool=CreatePool(MEMF_ANY,32*1024,8*1024)))
189 size += sizeof(ULONG) + MEM_BLOCKMASK;
190 size &= ~MEM_BLOCKMASK;
193 ObtainSemaphore(memsemptr);
195 if ((mem=AllocPooled(memPool,size)))
201 ReleaseSemaphore(memsemptr);
216 ObtainSemaphore(memsemptr);
218 FreePooled(memPool,mem,size);
221 ReleaseSemaphore(memsemptr);
226 void *realloc (void *old, size_t ns)
229 LONG osize, *o = old;
234 return malloc(nsize);
236 osize = (*(o-1)) - sizeof(ULONG);
241 if ((new = malloc(nsize)))
255 void __memCleanUp (void)
259 ObtainSemaphore(memsemptr);
267 ReleaseSemaphore(memsemptr);
271 #define ADD2LIST(a,b,c) asm(".stabs \"_" #b "\"," #c ",0,0,_" #a)
272 #define ADD2EXIT(a,pri) ADD2LIST(a,__EXIT_LIST__,22); \
273 asm(".stabs \"___EXIT_LIST__\",20,0,0," #pri "+128")
274 ADD2EXIT(__memCleanUp,-50);
275 #elif !defined(ixemul)
276 #error No libnix and no ixemul!?
279 #error Only GCC is supported, multithreading safe malloc/free required.
280 #endif /* __GNUC__ */
281 #endif /* !__amigaos4__ */
283 #endif /* def AMIGA */