63543f411d6268332da1d38f896af3a614697199
[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    $Id: suck.h 8295 2007-08-11 17:57:24Z michi $
26
27 */
28
29
30 #ifndef _SUCK_H
31 #define _SUCK_H
32
33 #include "config.h"
34 #include "vm/types.h"
35
36 #include "toolbox/hashtable.h"
37 #include "toolbox/list.h"
38
39 #include "vm/global.h"
40
41 #include "vmcore/class.h"
42 #include "vmcore/loader.h"
43
44
45 /* list_classpath_entry *******************************************************/
46
47 enum {
48         CLASSPATH_PATH,
49         CLASSPATH_ARCHIVE
50 };
51
52 typedef struct list_classpath_entry list_classpath_entry;
53
54 struct list_classpath_entry {
55 #if defined(ENABLE_THREADS)
56         java_object_t      header;              /* monitor locking on zip/jar files   */
57 #endif
58         s4                 type;
59         char              *path;
60         s4                 pathlen;
61 #if defined(ENABLE_ZLIB)
62         hashtable         *htclasses;
63 #endif
64         listnode_t         linkage;
65 };
66
67
68 /* macros to read LE and BE types from a buffer ********************************
69
70    BE macros are for Java class file loading.
71    LE macros are for ZIP file loading.
72
73 *******************************************************************************/
74
75 /* LE macros (for ZIP files ) *************************************************/
76
77 #if defined(__I386__) || defined(__X86_64__)
78
79 /* we can optimize the LE access on little endian machines without alignment */
80
81 #define SUCK_LE_U1(p)    *((u1 *) (p))
82 #define SUCK_LE_U2(p)    *((u2 *) (p))
83 #define SUCK_LE_U4(p)    *((u4 *) (p))
84
85 #if U8_AVAILABLE == 1
86 #define SUCK_LE_U8(p)    *((u8 *) (p))
87 #endif
88
89 #else /* defined(__I386__) || defined(__X86_64__) */
90
91 #define SUCK_LE_U1(p) \
92       ((u1) (p)[0])
93
94 #define SUCK_LE_U2(p) \
95     ((((u2) (p)[1]) << 8) + \
96       ((u2) (p)[0]))
97
98 #define SUCK_LE_U4(p) \
99     ((((u4) (p)[3]) << 24) + \
100      (((u4) (p)[2]) << 16) + \
101      (((u4) (p)[1]) << 8) + \
102       ((u4) (p)[0]))
103
104 #if U8_AVAILABLE == 1
105 #define SUCK_LE_U8(p) \
106     ((((u8) (p)[7]) << 56) + \
107      (((u8) (p)[6]) << 48) + \
108      (((u8) (p)[5]) << 40) + \
109      (((u8) (p)[4]) << 32) + \
110      (((u8) (p)[3]) << 24) + \
111      (((u8) (p)[2]) << 16) + \
112      (((u8) (p)[1]) << 8) + \
113       ((u8) (p)[0]))
114 #endif
115
116 #endif /* defined(__I386__) || defined(__X86_64__) */
117
118
119 /* BE macros (for Java class files ) ******************************************/
120
121 #define SUCK_BE_U1(p) \
122       ((u1) (p)[0])
123
124 #define SUCK_BE_U2(p) \
125     ((((u2) (p)[0]) << 8) + \
126       ((u2) (p)[1]))
127
128 #define SUCK_BE_U4(p) \
129     ((((u4) (p)[0]) << 24) + \
130      (((u4) (p)[1]) << 16) + \
131      (((u4) (p)[2]) << 8) + \
132       ((u4) (p)[3]))
133
134 #if U8_AVAILABLE == 1
135 #define SUCK_BE_U8(p) \
136     ((((u8) (p)[0]) << 56) + \
137      (((u8) (p)[1]) << 48) + \
138      (((u8) (p)[2]) << 40) + \
139      (((u8) (p)[3]) << 32) + \
140      (((u8) (p)[4]) << 24) + \
141      (((u8) (p)[5]) << 16) + \
142      (((u8) (p)[6]) << 8) + \
143       ((u8) (p)[7]))
144 #endif
145
146
147 #define SUCK_BE_S1(p)    (s1) SUCK_BE_U1(p)
148 #define SUCK_BE_S2(p)    (s2) SUCK_BE_U2(p)
149 #define SUCK_BE_S4(p)    (s4) SUCK_BE_U4(p)
150 #define SUCK_BE_S8(p)    (s8) SUCK_BE_U8(p)
151
152
153 /* signed suck defines ********************************************************/
154
155 #define suck_s1(a)    (s1) suck_u1((a))
156 #define suck_s2(a)    (s2) suck_u2((a))
157 #define suck_s4(a)    (s4) suck_u4((a))
158 #define suck_s8(a)    (s8) suck_u8((a))
159
160
161 /* export variables ***********************************************************/
162
163 extern list_t *list_classpath_entries;
164
165
166 /* function prototypes ********************************************************/
167
168 bool suck_init(void);
169
170 void suck_add(char *classpath);
171 void suck_add_from_property(char *key);
172
173 bool suck_check_classbuffer_size(classbuffer *cb, s4 len);
174
175 u1 suck_u1(classbuffer *cb);
176 u2 suck_u2(classbuffer *cb);
177 u4 suck_u4(classbuffer *cb);
178 u8 suck_u8(classbuffer *cb);
179
180 float suck_float(classbuffer *cb);
181 double suck_double(classbuffer *cb);
182
183 void suck_nbytes(u1 *buffer, classbuffer *cb, s4 len);
184 void suck_skip_nbytes(classbuffer *cb, s4 len);
185
186 classbuffer *suck_start(classinfo *c);
187
188 void suck_stop(classbuffer *cb);
189
190 #endif /* _SUCK_H */
191
192 /*
193  * These are local overrides for various environment variables in Emacs.
194  * Please do not remove this and leave it at the end of the file, where
195  * Emacs will automagically detect them.
196  * ---------------------------------------------------------------------
197  * Local variables:
198  * mode: c
199  * indent-tabs-mode: t
200  * c-basic-offset: 4
201  * tab-width: 4
202  * End:
203  */