2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
5 * Copyright (C) 2005 - 2007 The AROS Dev Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 #error <exec/types.h> not included.
30 #ifndef EXEC_LIBRARIES_H
31 #error <exec/libraries.h> not included.
34 #ifndef EXEC_SEMAPHORES_H
35 #error <exec/semaphores.h> not included.
39 #include <exec/tasks.h>
43 #include <sys/cdefs.h>
47 #include <sys/types.h>
51 #include "sys/queue2.h"
55 #include <api/resolv.h>
58 #include <proto/exec.h>
59 #include <kern/amiga_config.h>
62 API_SCRATCH
, /* api not initialized */
63 API_INITIALIZED
, /* librarybase created */
64 API_SHOWN
, /* librarybase made visible */
65 API_HIDDEN
, /* librarybase hidden */
66 API_FUNCTIONPATCHED
/* Api functions set to return -1 */
68 extern enum apistate api_state
;
75 UBYTE byte1
; UBYTE offset1
; UBYTE ln_type
; UBYTE pad0
;
76 UBYTE byte2
; UBYTE offset2
; UBYTE lib_flags
; UBYTE pad1
;
77 UBYTE long3
; UBYTE offset3
; ULONG ln_Name
;
78 UBYTE word4
; UBYTE offset4
; UWORD lib_Version
;
79 UBYTE word5
; UBYTE offset5
; UWORD lib_Revision
;
80 UBYTE long6
; UBYTE offset6
; ULONG lib_IdString
;
88 extern struct LibInitTable Miami_initTable
;
89 extern struct Library
*MasterMiamiBase
;
94 * structure for holding size and address of some dynamically allocated buffers
95 * such as selitems for WaitSelect() and netdatabase entry structures
102 typedef int (* ASM fdCallback_t
)(REG(d0
, int fd
), REG(d1
, int action
));
105 struct Library libNode
;
106 /* -- "Global" Errno -- */
108 BYTE errnoSize
; /* 1, 2 or 4 */
109 /* -- now we are longword aligned -- */
110 UBYTE
* errnoPtr
; /* this points to errno */
112 /* Task pointer of owner task */
113 struct Task
* thisTask
;
114 /* task priority changes (WORDS so we keep structure longword aligned) */
115 BYTE myPri
; /* task's priority just after libcall */
116 BYTE libCallPri
; /* task's priority during library call */
117 /* note: not long word aligned at this point */
118 /* -- descriptor sets -- */
119 WORD dTableSize
; /* long word aligned again */
120 struct socket
** dTable
;
121 fdCallback_t fdCallback
;
122 /* AmiTCP signal masks */
127 /* -- these are used by tsleep()/wakeup() -- */
128 const char * p_wmesg
;
129 queue_chain_t p_sleep_link
;
130 caddr_t p_wchan
; /* event process is awaiting */
131 struct timerequest
* tsleep_timer
;
132 struct MsgPort
* timerPort
;
133 /* -- pointer to select buffer during Select() -- */
134 struct newselbuf
* p_sb
;
135 /* -- per process fields used by various 'library' functions -- */
136 /* buffer for inet_ntoa */
137 char inet_ntoa
[20]; /* xxx.xxx.xxx.xxx\0 */
138 /* -- pointers for data buffers that MAY be used -- */
139 struct DataBuffer selitems
;
140 struct DataBuffer hostents
;
141 struct DataBuffer netents
;
142 struct DataBuffer protoents
;
143 struct DataBuffer servents
;
144 /* -- variables for the syslog (see netinclude:sys/syslog.h) -- */
145 UBYTE LogStat
; /* status */
146 UBYTE LogMask
; /* mask for log events */
147 UWORD LogFacility
; /* facility code */
148 const char * LogTag
; /* tag string for the log events */
149 /* -- resolver variables -- */
152 LONG res_socket
; /* socket used for resolver comm. */
153 struct state res_state
;
154 /* -- socket events -- */
155 struct SignalSemaphore EventLock
;
156 struct MinList EventList
;
157 /* -- buffer for string returns -- */
158 UBYTE result_str
[REPLYBUFLEN
+ 1];
159 /* -- NetDB pointers for getXXXent() and friends -- */
160 struct HostentNode
*HostentNode
;
161 struct ProtoentNode
*ProtoentNode
;
167 #define SBFB_COMPAT43 0L /* compat 43 code (without sockaddr_len) */
169 #define SBFF_COMPAT43 1L
172 * macro for getting error value pointed by the library base. All but
173 * the lowest byte of the errno are assumed to stay zero.
175 int readErrnoValue(struct SocketBase
*);
177 extern struct SignalSemaphore syscall_semaphore
;
178 extern struct List releasedSocketList
;
181 * Functions to put and remove application library to/from exec library list
186 VOID
api_setfunctions(VOID
);
187 VOID
api_sendbreaktotasks(VOID
);
188 VOID
api_deinit(VOID
);
190 /* Function which sets Errno value */
192 VOID
writeErrnoValue(struct SocketBase
*, int);
195 * inline functions which changes (raises) task priority while it is
196 * executing library functions
199 static inline void ObtainSyscallSemaphore(struct SocketBase
*libPtr
)
201 extern struct Task
*AROSTCP_Task
;
203 ObtainSemaphore(&syscall_semaphore
);
204 libPtr
->myPri
= SetTaskPri(libPtr
->thisTask
,
205 libPtr
->libCallPri
= AROSTCP_Task
->tc_Node
.ln_Pri
);
208 static inline void ReleaseSyscallSemaphore(struct SocketBase
*libPtr
)
210 if (libPtr
->libCallPri
!= (libPtr
->myPri
= SetTaskPri(libPtr
->thisTask
,
212 SetTaskPri(libPtr
->thisTask
, libPtr
->myPri
);
213 ReleaseSemaphore(&syscall_semaphore
);
217 * inline function for searching library base when taskpointer is known
220 static inline struct SocketBase
*FindSocketBase(struct Task
*task
)
222 extern struct List socketBaseList
;
223 struct Node
*libNode
;
226 for (libNode
= socketBaseList
.lh_Head
; libNode
->ln_Succ
;
227 libNode
= libNode
->ln_Succ
)
228 if (((struct SocketBase
*)libNode
)->thisTask
== task
) {
230 return (struct SocketBase
*)libNode
;
232 /* here if Task wasn't in socketBaseList */
237 #endif /* !AMIGA_API_H */