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