1 const char amiga_rcs[] = "$Id: amiga.c,v 1.9 2002/03/26 22:29:54 swa Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/Attic/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.
31 * Revision 1.9 2002/03/26 22:29:54 swa
32 * we have a new homepage!
34 * Revision 1.8 2002/03/25 19:32:15 joergs
35 * Name in version string changed from junkbuster to Privoxy.
37 * Revision 1.7 2002/03/24 13:25:43 swa
38 * name change related issues
40 * Revision 1.6 2002/03/09 20:03:52 jongfoster
41 * - Making various functions return int rather than size_t.
42 * (Undoing a recent change). Since size_t is unsigned on
43 * Windows, functions like read_socket that return -1 on
44 * error cannot return a size_t.
46 * THIS WAS A MAJOR BUG - it caused frequent, unpredictable
47 * crashes, and also frequently caused JB to jump to 100%
48 * CPU and stay there. (Because it thought it had just
49 * read ((unsigned)-1) == 4Gb of data...)
51 * - The signature of write_socket has changed, it now simply
52 * returns success=0/failure=nonzero.
54 * - Trying to get rid of a few warnings --with-debug on
55 * Windows, I've introduced a new type "jb_socket". This is
56 * used for the socket file descriptors. On Windows, this
57 * is SOCKET (a typedef for unsigned). Everywhere else, it's
58 * an int. The error value can't be -1 any more, so it's
59 * now JB_INVALID_SOCKET (which is -1 on UNIX, and in
60 * Windows it maps to the #define INVALID_SOCKET.)
62 * - The signature of bind_port has changed.
64 * Revision 1.5 2002/03/03 09:18:03 joergs
65 * Made jumbjuster work on AmigaOS again.
67 * Revision 1.4 2001/10/07 15:35:13 oes
68 * Replaced 6 boolean members of csp with one bitmap (csp->flags)
70 * Revision 1.3 2001/09/12 22:54:51 joergs
71 * Stacksize of main thread increased.
73 * Revision 1.2 2001/05/23 00:13:58 joergs
74 * AmigaOS support fixed.
76 * Revision 1.1.1.1 2001/05/15 13:58:46 oes
77 * Initial import of version 2.9.3 source tree
80 *********************************************************************/
92 const char amiga_h_rcs[] = AMIGA_H_VERSION;
94 unsigned long __stack = 100*1024;
95 static char ver[] = "$VER: Privoxy " __AMIGAVERSION__ " (" __AMIGADATE__ ")";
96 struct Task *main_task = NULL;
99 void serve(struct client_state *csp);
101 __saveds ULONG server_thread(void)
103 struct client_state *local_csp;
104 struct UserData UserData;
105 struct Task *me=FindTask(NULL);
108 local_csp=(struct client_state *)(me->tc_UserData);
109 me->tc_UserData=&UserData;
110 SocketBase=(APTR)OpenLibrary("bsdsocket.library",3);
113 SetErrnoPtr(&(UserData.eno),sizeof(int));
114 local_csp->cfd=ObtainSocket(local_csp->cfd, AF_INET, SOCK_STREAM, 0);
115 if(JB_INVALID_SOCKET!=local_csp->cfd)
117 Signal(main_task,SIGF_SINGLE);
118 serve((struct client_state *) local_csp);
120 local_csp->flags &= ~CSP_FLAG_ACTIVE;
121 Signal(main_task,SIGF_SINGLE);
123 CloseLibrary(SocketBase);
125 local_csp->flags &= ~CSP_FLAG_ACTIVE;
126 Signal(main_task,SIGF_SINGLE);
134 void amiga_exit(void)
138 CloseLibrary(SocketBase);
143 static struct SignalSemaphore memsem;
144 static struct SignalSemaphore *memsemptr = NULL;
145 static struct UserData GlobalUserData;
149 main_task = FindTask(NULL);
150 main_task->tc_UserData = &GlobalUserData;
152 if (((struct Library *)SysBase)->lib_Version < 39)
157 signal(SIGINT,SIG_IGN);
158 SocketBase = (APTR)OpenLibrary("bsdsocket.library",3);
161 fprintf(stderr, "Can't open bsdsocket.library V3+\n");
164 SetErrnoPtr(&(GlobalUserData.eno),sizeof(int));
165 InitSemaphore(&memsem);
168 olddir=CurrentDir(GetProgramDir());
174 /* multithreadingsafe libnix replacements */
175 static void *memPool=NULL;
177 void *malloc (size_t s)
188 if (!(memPool=CreatePool(MEMF_ANY,32*1024,8*1024)))
193 size += sizeof(ULONG) + MEM_BLOCKMASK;
194 size &= ~MEM_BLOCKMASK;
197 ObtainSemaphore(memsemptr);
199 if ((mem=AllocPooled(memPool,size)))
205 ReleaseSemaphore(memsemptr);
220 ObtainSemaphore(memsemptr);
222 FreePooled(memPool,mem,size);
225 ReleaseSemaphore(memsemptr);
230 void *realloc (void *old, size_t ns)
233 LONG osize, *o = old;
238 return malloc(nsize);
240 osize = (*(o-1)) - sizeof(ULONG);
245 if ((new = malloc(nsize)))
259 void __memCleanUp (void)
263 ObtainSemaphore(memsemptr);
271 ReleaseSemaphore(memsemptr);
275 #define ADD2LIST(a,b,c) asm(".stabs \"_" #b "\"," #c ",0,0,_" #a )
276 #define ADD2EXIT(a,pri) ADD2LIST(a,__EXIT_LIST__,22); \
277 asm(".stabs \"___EXIT_LIST__\",20,0,0," #pri "+128")
278 ADD2EXIT(__memCleanUp,-50);
279 #elif !defined(ixemul)
280 #error No libnix and no ixemul!?
283 #error Only GCC is supported, multithreading safe malloc/free required.
284 #endif /* __GNUC__ */
286 #endif /* def AMIGA */