1 /*********************************************************************
3 * File : $Source: /cvsroot/ijbswa/current/amiga.c,v $
5 * Purpose : Amiga-specific declarations.
7 * Copyright : Written by and Copyright (C) 2001 members of the
8 * Privoxy team. http://www.privoxy.org/
10 * This program is free software; you can redistribute it
11 * and/or modify it under the terms of the GNU General
12 * Public License as published by the Free Software
13 * Foundation; either version 2 of the License, or (at
14 * your option) any later version.
16 * This program is distributed in the hope that it will
17 * be useful, but WITHOUT ANY WARRANTY; without even the
18 * implied warranty of MERCHANTABILITY or FITNESS FOR A
19 * PARTICULAR PURPOSE. See the GNU General Public
20 * License for more details.
22 * The GNU General Public License should be included with
23 * this file. If not, you can view it at
24 * http://www.gnu.org/copyleft/gpl.html
25 * or write to the Free Software Foundation, Inc., 59
26 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 *********************************************************************/
40 static char *ver USED = "$VER: Privoxy " __AMIGAVERSION__ " (" __AMIGADATE__ ")";
42 static char *stack USED = "$STACK: 524288";
44 unsigned long __stack = 100*1024;
46 struct Task *main_task = NULL;
49 void serve(struct client_state *csp);
51 SAVEDS ULONG server_thread(void)
53 struct client_state *local_csp;
54 struct UserData UserData;
55 struct Task *me=FindTask(NULL);
57 struct Library *SocketBase;
61 local_csp=(struct client_state *)(me->tc_UserData);
62 me->tc_UserData=&UserData;
63 SocketBase=(APTR)OpenLibrary("bsdsocket.library",3);
67 ISocket = (struct SocketIFace *)GetInterface(SocketBase, "main", 1, NULL);
72 SetErrnoPtr(&(UserData.eno),sizeof(int));
73 local_csp->cfd=ObtainSocket(local_csp->cfd, AF_INET, SOCK_STREAM, 0);
74 if (JB_INVALID_SOCKET!=local_csp->cfd)
76 Signal(main_task,SIGF_SINGLE);
77 serve((struct client_state *) local_csp);
79 local_csp->flags &= ~CSP_FLAG_ACTIVE;
80 Signal(main_task,SIGF_SINGLE);
83 DropInterface((struct Interface *)ISocket);
85 CloseLibrary(SocketBase);
88 CloseLibrary(SocketBase);
90 local_csp->flags &= ~CSP_FLAG_ACTIVE;
91 Signal(main_task,SIGF_SINGLE);
108 struct Library *SocketBase = ISocket->Data.LibBase;
109 DropInterface((struct Interface *)ISocket);
111 CloseLibrary(SocketBase);
117 static struct SignalSemaphore memsem;
118 static struct SignalSemaphore *memsemptr = NULL;
120 static struct UserData GlobalUserData;
125 struct Library *SocketBase;
128 main_task = FindTask(NULL);
129 main_task->tc_UserData = &GlobalUserData;
131 if (((struct Library *)SysBase)->lib_Version < 39)
136 signal(SIGINT,SIG_IGN);
137 SocketBase = (APTR)OpenLibrary("bsdsocket.library",3);
141 ISocket = (struct SocketIFace *)GetInterface(SocketBase, "main", 1, NULL);
149 CloseLibrary(SocketBase);
151 fprintf(stderr, "Can't open bsdsocket.library V3+\n");
154 SetErrnoPtr(&(GlobalUserData.eno),sizeof(int));
156 InitSemaphore(&memsem);
160 olddir=CurrentDir(GetProgramDir());
167 /* multithreadingsafe libnix replacements */
168 static void *memPool=NULL;
170 void *malloc (size_t s)
181 if (!(memPool=CreatePool(MEMF_ANY,32*1024,8*1024)))
186 size += sizeof(ULONG) + MEM_BLOCKMASK;
187 size &= ~MEM_BLOCKMASK;
190 ObtainSemaphore(memsemptr);
192 if ((mem=AllocPooled(memPool,size)))
198 ReleaseSemaphore(memsemptr);
213 ObtainSemaphore(memsemptr);
215 FreePooled(memPool,mem,size);
218 ReleaseSemaphore(memsemptr);
223 void *realloc (void *old, size_t ns)
226 LONG osize, *o = old;
231 return malloc(nsize);
233 osize = (*(o-1)) - sizeof(ULONG);
238 if ((new = malloc(nsize)))
252 void __memCleanUp (void)
256 ObtainSemaphore(memsemptr);
264 ReleaseSemaphore(memsemptr);
268 #define ADD2LIST(a,b,c) asm(".stabs \"_" #b "\"," #c ",0,0,_" #a)
269 #define ADD2EXIT(a,pri) ADD2LIST(a,__EXIT_LIST__,22); \
270 asm(".stabs \"___EXIT_LIST__\",20,0,0," #pri "+128")
271 ADD2EXIT(__memCleanUp,-50);
272 #elif !defined(ixemul)
273 #error No libnix and no ixemul!?
276 #error Only GCC is supported, multithreading safe malloc/free required.
277 #endif /* __GNUC__ */
278 #endif /* !__amigaos4__ */
280 #endif /* def AMIGA */