* Removed all Id tags.
[cacao.git] / src / vmcore / suck.h
1 /* src/vmcore/suck.h - functions to read LE ordered types from a buffer
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _SUCK_H
29 #define _SUCK_H
30
31 #include "config.h"
32 #include "vm/types.h"
33
34 #include "toolbox/hashtable.h"
35 #include "toolbox/list.h"
36
37 #include "vm/global.h"
38
39 #include "vmcore/class.h"
40 #include "vmcore/loader.h"
41
42
43 /* list_classpath_entry *******************************************************/
44
45 enum {
46         CLASSPATH_PATH,
47         CLASSPATH_ARCHIVE
48 };
49
50 typedef struct list_classpath_entry list_classpath_entry;
51
52 struct list_classpath_entry {
53 #if defined(ENABLE_THREADS)
54         java_object_t      header;              /* monitor locking on zip/jar files   */
55 #endif
56         s4                 type;
57         char              *path;
58         s4                 pathlen;
59 #if defined(ENABLE_ZLIB)
60         hashtable         *htclasses;
61 #endif
62         listnode_t         linkage;
63 };
64
65
66 /* macros to read LE and BE types from a buffer ********************************
67
68    BE macros are for Java class file loading.
69    LE macros are for ZIP file loading.
70
71 *******************************************************************************/
72
73 /* LE macros (for ZIP files ) *************************************************/
74
75 #if defined(__I386__) || defined(__X86_64__)
76
77 /* we can optimize the LE access on little endian machines without alignment */
78
79 #define SUCK_LE_U1(p)    *((u1 *) (p))
80 #define SUCK_LE_U2(p)    *((u2 *) (p))
81 #define SUCK_LE_U4(p)    *((u4 *) (p))
82
83 #if U8_AVAILABLE == 1
84 #define SUCK_LE_U8(p)    *((u8 *) (p))
85 #endif
86
87 #else /* defined(__I386__) || defined(__X86_64__) */
88
89 #define SUCK_LE_U1(p) \
90       ((u1) (p)[0])
91
92 #define SUCK_LE_U2(p) \
93     ((((u2) (p)[1]) << 8) + \
94       ((u2) (p)[0]))
95
96 #define SUCK_LE_U4(p) \
97     ((((u4) (p)[3]) << 24) + \
98      (((u4) (p)[2]) << 16) + \
99      (((u4) (p)[1]) << 8) + \
100       ((u4) (p)[0]))
101
102 #if U8_AVAILABLE == 1
103 #define SUCK_LE_U8(p) \
104     ((((u8) (p)[7]) << 56) + \
105      (((u8) (p)[6]) << 48) + \
106      (((u8) (p)[5]) << 40) + \
107      (((u8) (p)[4]) << 32) + \
108      (((u8) (p)[3]) << 24) + \
109      (((u8) (p)[2]) << 16) + \
110      (((u8) (p)[1]) << 8) + \
111       ((u8) (p)[0]))
112 #endif
113
114 #endif /* defined(__I386__) || defined(__X86_64__) */
115
116
117 /* BE macros (for Java class files ) ******************************************/
118
119 #define SUCK_BE_U1(p) \
120       ((u1) (p)[0])
121
122 #define SUCK_BE_U2(p) \
123     ((((u2) (p)[0]) << 8) + \
124       ((u2) (p)[1]))
125
126 #define SUCK_BE_U4(p) \
127     ((((u4) (p)[0]) << 24) + \
128      (((u4) (p)[1]) << 16) + \
129      (((u4) (p)[2]) << 8) + \
130       ((u4) (p)[3]))
131
132 #if U8_AVAILABLE == 1
133 #define SUCK_BE_U8(p) \
134     ((((u8) (p)[0]) << 56) + \
135      (((u8) (p)[1]) << 48) + \
136      (((u8) (p)[2]) << 40) + \
137      (((u8) (p)[3]) << 32) + \
138      (((u8) (p)[4]) << 24) + \
139      (((u8) (p)[5]) << 16) + \
140      (((u8) (p)[6]) << 8) + \
141       ((u8) (p)[7]))
142 #endif
143
144
145 #define SUCK_BE_S1(p)    (s1) SUCK_BE_U1(p)
146 #define SUCK_BE_S2(p)    (s2) SUCK_BE_U2(p)
147 #define SUCK_BE_S4(p)    (s4) SUCK_BE_U4(p)
148 #define SUCK_BE_S8(p)    (s8) SUCK_BE_U8(p)
149
150
151 /* signed suck defines ********************************************************/
152
153 #define suck_s1(a)    (s1) suck_u1((a))
154 #define suck_s2(a)    (s2) suck_u2((a))
155 #define suck_s4(a)    (s4) suck_u4((a))
156 #define suck_s8(a)    (s8) suck_u8((a))
157
158
159 /* export variables ***********************************************************/
160
161 extern list_t *list_classpath_entries;
162
163
164 /* function prototypes ********************************************************/
165
166 bool suck_init(void);
167
168 void suck_add(char *classpath);
169 void suck_add_from_property(char *key);
170
171 bool suck_check_classbuffer_size(classbuffer *cb, s4 len);
172
173 u1 suck_u1(classbuffer *cb);
174 u2 suck_u2(classbuffer *cb);
175 u4 suck_u4(classbuffer *cb);
176 u8 suck_u8(classbuffer *cb);
177
178 float suck_float(classbuffer *cb);
179 double suck_double(classbuffer *cb);
180
181 void suck_nbytes(u1 *buffer, classbuffer *cb, s4 len);
182 void suck_skip_nbytes(classbuffer *cb, s4 len);
183
184 classbuffer *suck_start(classinfo *c);
185
186 void suck_stop(classbuffer *cb);
187
188 #endif /* _SUCK_H */
189
190 /*
191  * These are local overrides for various environment variables in Emacs.
192  * Please do not remove this and leave it at the end of the file, where
193  * Emacs will automagically detect them.
194  * ---------------------------------------------------------------------
195  * Local variables:
196  * mode: c
197  * indent-tabs-mode: t
198  * c-basic-offset: 4
199  * tab-width: 4
200  * End:
201  */