00001 #ifndef _cfmacros_h_included_ 00002 #define _cfmacros_h_included_ 00003 00004 /*! 00005 * @file cfmacros.h 00006 * 00007 * @brief Macros for navigating class file structures in a ClassFile. 00008 * 00009 * 00010 * @section Control 00011 * 00012 * \$URL: https://svn.apache.org/path/name/cfmacros.h $ \$Id: cfmacros.h 0 09/28/2005 dlydick $ 00013 * 00014 * Copyright 2005 The Apache Software Foundation 00015 * or its licensors, as applicable. 00016 * 00017 * Licensed under the Apache License, Version 2.0 ("the License"); 00018 * you may not use this file except in compliance with the License. 00019 * You may obtain a copy of the License at 00020 * 00021 * http://www.apache.org/licenses/LICENSE-2.0 00022 * 00023 * Unless required by applicable law or agreed to in writing, 00024 * software distributed under the License is distributed on an 00025 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 00026 * either express or implied. 00027 * 00028 * See the License for the specific language governing permissions 00029 * and limitations under the License. 00030 * 00031 * @version \$LastChangedRevision: 0 $ 00032 * 00033 * @date \$LastChangedDate: 09/28/2005 $ 00034 * 00035 * @author \$LastChangedBy: dlydick $ 00036 * Original code contributed by Daniel Lydick on 09/28/2005. 00037 * 00038 * @section Reference 00039 * 00040 */ 00041 00042 ARCH_COPYRIGHT_APACHE(cfmacros, h, "$URL: https://svn.apache.org/path/name/cfmacros.h $ $Id: cfmacros.h 0 09/28/2005 dlydick $"); 00043 00044 #include "heap.h" 00045 00046 /*! 00047 * @name Typed constant_pool pointers 00048 * 00049 * @brief Convert generic constant_pool[] entry into a 00050 * @link #CONSTANT_Class_info CONSTANT_xxxxx_info@endlink typed pointer, 00051 * stripping off the generic prefix bytes. 00052 * 00053 * Adjust a generic constant_pool entry (cp_info_dup *) 00054 * into its corresponding 00055 * @link #CONSTANT_Class_info CONSTANT_xxxxx_info@endlink typed pointer 00056 * by changing the pointer to point not to the beginning of the 00057 * (cp_info_dup) structure, but to its @p @b cp member, which is where 00058 * the data actually begins. This is useful for argument passing 00059 * when the whole (cp_info_dup *) is available. The original 00060 * adjustment was made in the first place to support native member 00061 * accesses on real machine architectures that are picky about 00062 * multi-byte accesses that are not aligned to addresses of the 00063 * same size. 00064 * 00065 * @see ARCH_ODD4_ADDRESS_SIGSEGV 00066 * 00067 * @see ARCH_ODD2_ADDRESS_SIGSEGV 00068 * 00069 * 00070 * @param pcpinfodup Pointer to a constant_pool entry, typically 00071 * @c @b &pcfs->constant_pool[n] 00072 * 00073 * 00074 * @returns Pointer to the @c @b ->cp member, typed as 00075 * @link #CONSTANT_Class_info CONSTANT_xxxxx_info@endlink 00076 * 00077 */ 00078 00079 /*@{ */ /* Begin grouped definitions */ 00080 00081 #define PTR_THIS_CP_Class(pcpinfodup) \ 00082 ((CONSTANT_Class_info *) &(pcpinfodup)->cp) 00083 00084 #define PTR_THIS_CP_Fieldref(pcpinfodup) \ 00085 ((CONSTANT_Fieldref_info *) &(pcpinfodup)->cp) 00086 00087 #define PTR_THIS_CP_Methodref(pcpinfodup) \ 00088 ((CONSTANT_Methodref_info *) &(pcpinfodup)->cp) 00089 00090 #define PTR_THIS_CP_InterfaceMethodref(pcpinfodup) \ 00091 ((CONSTANT_InterfaceMethodref_info *) &(pcpinfodup)->cp) 00092 00093 #define PTR_THIS_CP_String(pcpinfodup) \ 00094 ((CONSTANT_String_info *) &(pcpinfodup)->cp) 00095 00096 #define PTR_THIS_CP_Integer(pcpinfodup) \ 00097 ((CONSTANT_Integer_info *) &(pcpinfodup)->cp) 00098 00099 #define PTR_THIS_CP_Float(pcpinfodup) \ 00100 ((CONSTANT_Float_info *) &(pcpinfodup)->cp) 00101 00102 #define PTR_THIS_CP_Long(pcpinfodup) \ 00103 ((CONSTANT_Long_info *) &(pcpinfodup)->cp) 00104 00105 #define PTR_THIS_CP_Double(pcpinfodup) \ 00106 ((CONSTANT_Double_info *) &(pcpinfodup)->cp) 00107 00108 #define PTR_THIS_CP_NameAndType(pcpinfodup) \ 00109 ((CONSTANT_NameAndType_info *) &(pcpinfodup)->cp) 00110 00111 #define PTR_THIS_CP_Utf8(pcpinfodup) \ 00112 ((CONSTANT_Utf8_info *) &(pcpinfodup)->cp) 00113 00114 /*@} */ /* End of grouped definitions */ 00115 00116 00117 /*! 00118 * @name General navigation and parsing macros. 00119 * 00120 * @param pcfs ClassFile pointer to a fully parsed class data area 00121 * @param cpidx Index into its constant_pool[] array. 00122 * 00123 */ 00124 00125 /*@{ */ /* Begin grouped definitions */ 00126 00127 /*! 00128 * @brief Report the (cp_info *) of the address of the 00129 * class file @p @b pcfs constant_pool entry at this 00130 * index @p @b cpidx. 00131 * 00132 * 00133 * @returns(cp_info *) to a constant_pool[cpidx] 00134 * 00135 */ 00136 #define PTR_CP_ENTRY(pcfs, cpidx) (&(pcfs->constant_pool[cpidx])->cp) 00137 00138 00139 /*! 00140 * @brief Report the (u1) tag value of the class file @p @b pcf 00141 * constant_pool entry at this index @p @b cpidx. 00142 * 00143 * 00144 * @returns (u1) tag value of entry at constant_pool[cpidx] 00145 * 00146 */ 00147 #define CP_TAG(pcfs, cpidx) ((PTR_CP_ENTRY(pcfs, cpidx))->tag) 00148 00149 00150 /*! 00151 * @brief Point into a (cp_info) data structure and return 00152 * start of @link cp_info#info info@endlink field as a (u1 *). 00153 * 00154 * 00155 * @returns address or contents of something in a constant_pool[] entry, 00156 * see above description. 00157 */ 00158 #define PTR_CP_INFO(pcfs, cpidx) \ 00159 ((u1 *) (&PTR_CP_ENTRY(pcfs, cpidx)->info)) 00160 00161 /*@} */ /* End of grouped definitions */ 00162 00163 00164 /*! 00165 * @name Pointer casting for very common constructions. 00166 * 00167 * @brief Report the (cp_info *) of a PTR_CP_ENTRY(), 00168 * but cast as a pointer to one of the following 00169 * data types. 00170 * 00171 * The PTR_CP_ENTRY_TYPE() macro may used to choose any 00172 * arbitrary type at all. 00173 * 00174 * If @p @b type is a 00175 * (@link #CONSTANT_Class_info CONSTANT_xxxxx_info@endlink *), the 00176 * result may be referenced DIRECTLY BY THE VM 00177 * SPEC. These types are: 00178 * 00179 * 00180 * <ul> 00181 * <li> 00182 * PTR_CP_ENTRY_TYPE() (any_desired_type *) 00183 * </li> 00184 * 00185 * <li> 00186 * PTR_CP_ENTRY_CLASS() (CONSTANT_Class_info *) 00187 * </li> 00188 * 00189 * <li> 00190 * PTR_CP_ENTRY_UTF8() (CONSTANT_Utf8_info *) 00191 * </li> 00192 * </ul> 00193 * 00194 * 00195 * @param type typedef definition for pointer cast of result 00196 * 00197 * @param pcfs ClassFile pointer to a fully parsed class data area 00198 * 00199 * @param cpidx Index into its constant_pool[] array. 00200 * 00201 * @returns Pointer to a constant_pool[cpidx], variously typed as above. 00202 * 00203 */ 00204 00205 /*@{ */ /* Begin grouped definitions */ 00206 00207 #define PTR_CP_ENTRY_TYPE(type, pcfs, cpidx) \ 00208 ((type *) PTR_CP_ENTRY(pcfs, cpidx)) 00209 00210 #define PTR_CP_ENTRY_CLASS(pcfs, cpidx) \ 00211 ((CONSTANT_Class_info *) PTR_CP_ENTRY(pcfs, cpidx)) 00212 00213 #define PTR_CP_ENTRY_UTF8(pcfs, cpidx) \ 00214 ((CONSTANT_Utf8_info *) PTR_CP_ENTRY(pcfs, cpidx)) 00215 00216 /*@} */ /* End of grouped definitions */ 00217 00218 00219 /*******************************************************************/ 00220 /*! 00221 * @name UTF string manipulation macros. 00222 * 00223 * @brief Probe CONSTANT_Utf8_info constant_pool entries for 00224 * field data and addresses. 00225 * 00226 * Return information about (CONSTANT_Utf8_info) entry, namely: 00227 * 00228 * <ul> 00229 * 00230 * <li> 00231 * Pointing to constant_pool entry of THIS @p @b pcfs and @p @b cpidx, 00232 * being a (CONSTANT_Utf8_info) string: 00233 * <ul> 00234 * <li> 00235 * PTR_CP_THIS() Pointer to whole (CONSTANT_Utf8_info) 00236 * CP entry cast as (CONSTANT_Utf8_info *), 00237 * namely to the beginning of the 00238 * structure. 00239 * </li> 00240 * 00241 * <li> 00242 * CP_THIS_STRLEN() @p @b length field of 00243 * (CONSTANT_Utf8_info) CP entry, as (u2). 00244 * </li> 00245 * 00246 * <li> 00247 * PTR_CP_THIS_STRNAME() Pointer to @p @b bytes area of 00248 * (CONSTANT_Utf8_info) CP entry, cast 00249 * as (rchar *). 00250 * </li></ul></li> 00251 * 00252 * 00253 * <li> 00254 * ONE level of indirection, namely, point to UTF string info 00255 * AT THE ENTRY POINTED TO by this @p @b pcfs and 00256 * @p @b cpidx AS FOUND IN @p @b strname_idx FIELD: 00257 * <ul> 00258 * 00259 * <li> 00260 * PTR_CP1_NAME() Pointer to whole (CONSTANT_Utf8_info) 00261 * CP entry referenced by index in 00262 * @p @b strname_idx field, cast as 00263 * (CONSTANT_Utf8_info *) and pointing 00264 * to the beginning of that structure. 00265 * </li> 00266 * 00267 * <li> 00268 * CP1_NAME_STRLEN() @p @b length field of 00269 * (CONSTANT_Utf8_info) field as 00270 * indirectly referenced by 00271 * PTR_CP1_NAME() macro, as (u2). 00272 * </li> 00273 * 00274 * <li> 00275 * PTR_CP1_NAME_STRNAME() Pointer to @p @b bytes area of 00276 * (CONSTANT_Utf8_info) entry as 00277 * indirectly referenced by 00278 * PTR_CP1_NAME() macro, as (u1 *). 00279 * </li></ul></li> 00280 * 00281 * 00282 * <li> 00283 * ONE level of indirection, specifically using type 00284 * (CONSTANT_Class_info) as the constant_pool entry type. 00285 * 00286 * <ul> 00287 * 00288 * <li> 00289 * PTR_CP1_CLASS_NAME() Pointer to whole (CONSTANT_Utf8_info) 00290 * CP entry referenced by index that 00291 * represents a (CONSTANT_Class_info) 00292 * slot entry. Cast as type 00293 * (CONSTANT_Utf8_info *) and pointing 00294 * to the beginning of that structure. 00295 * </li> 00296 * 00297 * <li> 00298 * CP1_CLASS_NAME_STRLEN() @p @b length field of string name of this 00299 * (CONSTANT_Class_info) entry's UTF 00300 * name string, as (u2). 00301 * </li> 00302 * 00303 * <li> 00304 * PTR_CP1_CLASS_NAME_STRNAME() Pointer to @p @b bytes area of this 00305 * (CONSTANT_Class_info) entry's UTF 00306 * name string, as (u1 *). 00307 * </li></ul></li> 00308 * 00309 * <li> 00310 * TWO levels of indirection, namely, this @p @b pcfs and @p @b cpidx 00311 * point to a (type) constant_pool entry whose 00312 * @p @b strname_idx field contains a constant_pool 00313 * index to a (CONSTANT_Class_info) entry. 00314 * Obtain info about the (CONSTANT_Utf8_info) 00315 * entry which is named by that (CONSTANT_Class_info) 00316 * entry's @p @b name_index field, that is, the name 00317 * of the class: 00318 * <ul> 00319 * 00320 * <li> 00321 * PTR_CP2_CLASS_NAME() Pointer to whole 00322 * (CONSTANT_Utf8_info) CP entry 00323 * referenced by index in 00324 * @p @b strname_idx field of @b type 00325 * CP entry (that is, 00326 @link #CONSTANT_Class_info 00327 CONSTANT_xxxxx_info@endlink), 00328 * which references the class name 00329 * of that CP entry, as referenced by 00330 * the @p @b strname_idx CP entry of 00331 * @p @b cpidx case as 00332 * (CONSTANT_Utf8_info *) and 00333 * pointing to the beginning of 00334 * that structure. 00335 * </li> 00336 * 00337 * <li> 00338 * CP2_CLASS_NAME_STRLEN() @p @b length field of 00339 * (CONSTANT_Utf8_info) field as 00340 * indirectly referenced by 00341 * PTR_CP2_CLASS_NAME() macro, 00342 * as (u2). 00343 * </li> 00344 * 00345 * <li> 00346 * PTR_CP2_CLASS_NAME_STRNAME() Pointer to @p @b bytes area of 00347 * (CONSTANT_Utf8_info) entry as 00348 * indirectly referenced by 00349 * PTR_CP2_CLASS_NAME() macro, 00350 * as (u1 *). 00351 * </li></ul></li></ul> 00352 * 00353 * 00354 * 00355 * @param type typedef definition for pointer cast of result 00356 * 00357 * @param pcfs ClassFile pointer to a fully parsed class 00358 * data area 00359 * 00360 * @param cpidx Index into its constant_pool[] array. 00361 * 00362 * @param strname_idx Field name of indirect constant_pool pointed 00363 * to by @p @b pcfs and @p @b cpidx. The index 00364 * found here is the index containing the UTF 00365 * string. (@b CP1_xxx and @b CP2_xxx macros only) 00366 * 00367 * @returns (cp_info *) to a constant_pool[cpidx] 00368 * 00369 */ 00370 00371 /*@{ */ /* Begin grouped definitions */ 00372 00373 /******************************************************************* 00374 * 00375 * Pointing to constant_pool entry of THIS @p @b pcfs and @p @b cpidx, 00376 * being a (CONSTANT_Utf8_info) string. 00377 * 00378 */ 00379 #define PTR_CP_THIS(pcfs, cpidx) \ 00380 PTR_CP_ENTRY_TYPE(CONSTANT_Utf8_info, pcfs, cpidx) 00381 00382 #define CP_THIS_STRLEN(pcfs, cpidx) \ 00383 PTR_CP_ENTRY_TYPE(CONSTANT_Utf8_info, pcfs, cpidx)->length 00384 00385 #define PTR_CP_THIS_STRNAME(pcfs, cpidx) \ 00386 ((rchar *) &PTR_CP_ENTRY_TYPE(CONSTANT_Utf8_info, pcfs, cpidx) \ 00387 ->bytes[0]) 00388 00389 00390 /******************************************************************* 00391 * 00392 * --- ONE level of indirection, namely, point to UTF string info 00393 * AT THE ENTRY POINTED TO by this @p @b pcfs and 00394 * @p @b cpidx AS FOUND IN FIELD @p @b strname_idx: 00395 */ 00396 #define PTR_CP1_NAME(type, pcfs, cpidx, strname_idx) \ 00397 PTR_CP_THIS(pcfs, (PTR_CP_ENTRY_TYPE(type, pcfs,cpidx)->strname_idx)) 00398 00399 #define CP1_NAME_STRLEN(type, pcfs, cpidx, strname_idx) \ 00400 CP_THIS_STRLEN(pcfs, (PTR_CP_ENTRY_TYPE(type,pcfs,cpidx)->strname_idx)) 00401 00402 #define PTR_CP1_NAME_STRNAME(type, pcfs, cpidx, strname_idx) \ 00403 PTR_CP_THIS_STRNAME(pcfs, (PTR_CP_ENTRY_TYPE(type, pcfs, cpidx) \ 00404 ->strname_idx)) 00405 00406 /******************************************************************* 00407 * 00408 * --- ONE level of indirection, but specifically for manipulating 00409 * (CONSTANT_Class_info) slot in constant_pool. 00410 * @p @b pcfs and @b cpidx refer to such a class info 00411 * slot. 00412 */ 00413 #define PTR_CP1_CLASS_NAME(pcfs, cpidx) \ 00414 PTR_CP1_NAME(CONSTANT_Class_info, pcfs, cpidx, name_index) 00415 00416 00417 #define CP1_CLASS_NAME_STRLEN(pcfs, cpidx) \ 00418 CP1_NAME_STRLEN(CONSTANT_Class_info, pcfs, cpidx, name_index) 00419 00420 #define PTR_CP1_CLASS_NAME_STRNAME(pcfs, cpidx) \ 00421 PTR_CP1_NAME_STRNAME(CONSTANT_Class_info, pcfs, cpidx, name_index) 00422 00423 /******************************************************************* 00424 * 00425 * --- TWO levels of indirection, namely, point to UTF string info 00426 * AT THE ENTRY POINTED TO by this @p @b pcfs and 00427 * @p @b cpidx AS FOUND IN FIELD @p @b strname_idx: 00428 */ 00429 00430 #define PTR_CP2_CLASS_NAME(type, pcfs, cpidx, strname_idx) \ 00431 PTR_CP_THIS(pcfs, \ 00432 (PTR_CP_ENTRY_TYPE(CONSTANT_Class_info, \ 00433 pcfs, \ 00434 (PTR_CP_ENTRY_TYPE(type, pcfs, cpidx) \ 00435 ->strname_idx)) \ 00436 ->name_index)) 00437 00438 #define CP2_CLASS_NAME_STRLEN(type, pcfs, cpidx, strname_idx) \ 00439 CP_THIS_STRLEN(pcfs, \ 00440 (PTR_CP_ENTRY_TYPE(CONSTANT_Class_info, \ 00441 pcfs, \ 00442 (PTR_CP_ENTRY_TYPE(type, pcfs, cpidx) \ 00443 ->strname_idx)) \ 00444 ->name_index)) 00445 00446 #define PTR_CP2_CLASS_NAME_STRNAME(type, pcfs, cpidx, strname_idx) \ 00447 PTR_CP_THIS_STRNAME(pcfs, \ 00448 (PTR_CP_ENTRY_TYPE(CONSTANT_Class_info, \ 00449 pcfs, \ 00450 (PTR_CP_ENTRY_TYPE(type, pcfs, cpidx) \ 00451 ->strname_idx)) \ 00452 ->name_index)) 00453 00454 /*@} */ /* End of grouped definitions */ 00455 00456 /*******************************************************************/ 00457 00458 /*! 00459 * @name Non-aligned multi-byte field access 00460 * 00461 * @brief Cast arbitrary pointers to type (u2 *) and (u4 *) for 00462 * referencing items in class file data image. These pointers 00463 * DO NOT need to be 2- or 4-byte aligned. 00464 * 00465 * 00466 * @param ptr Name of pointer variable to receive (cast) value 00467 * 00468 * @param loc Name of pointer variable to be (recast) as either 00469 * (u2 *) or (u4 *). 00470 * 00471 * 00472 * @returns @p @b loc receives new value from (recast *) @p @b loc 00473 * 00474 */ 00475 00476 /*@{ */ /* Begin grouped definitions */ 00477 00478 #define MAKE_PU2(ptr, loc) ptr = (u2 *) (loc) 00479 #define MAKE_PU4(ptr, loc) ptr = (u4 *) (loc) 00480 00481 /*@} */ /* End of grouped definitions */ 00482 00483 00484 /*******************************************************************/ 00485 /*! 00486 * @name Responses to generic failure types 00487 * 00488 * @brief Generic return type for error test, including either return 00489 * value of a typed @link #rnull rnull@endlink pointer 00490 * (@b GENERIC_FAILUREx_PTR() only), a generic value 00491 * (@b GENERIC_FAILUREx_VALUE() only), or throw an error 00492 * (@b GENERIC_FAILUREx_THROWERROR() only), plus a error message. 00493 * If @p @b expr is @link #rtrue rtrue@endlink, return the return value 00494 * or throw the error (depending on the specific macro), else 00495 * continue with inline code. 00496 * 00497 * The versions @b GENERAL_FAILURE1_xxx() and @b GENERAL_FAILURE2_xxx() 00498 * also may pass a formatting parameter for @p @b msg to format into the 00499 * output string. 00500 * 00501 * The following is a grand union of the parameters for @e all of these 00502 * macros. A given macro may or may not use some of them: 00503 * 00504 * 00505 * @param expr Any logical expression that returns 00506 * @link #rtrue rtrue@endlink or 00507 * @link #rfalse rfalse@endlink. 00508 * 00509 * @param dml Debug message level for amount of output verbosity 00510 * 00511 * @param fn Name of function invoking this macro 00512 * 00513 * @param msg Any text message to display to stderr if @p @b expr 00514 * is @link #rtrue rtrue@endlink. 00515 * For @b GENERIC_FAILURE{1|2}(), this 00516 * should also contain 1 or 2 formatting items also. 00517 * 00518 * @param parm1 (for @b GENERIC_FAILURE{1|2}_xxx() only) First 00519 * parameter to format into @p @b msg. 00520 * 00521 * @param parm2 (for @b GENERIC_FAILURE2_xxx() only) Second 00522 * parameter to format into @p @b msg. 00523 * 00524 * @param rettype Function return TYPE (not including '*' modifier) 00525 * to be used instead of (rvoid *). Used by 00526 * @b GENERIC_FAILUREx_PTR() only. 00527 * 00528 * @param retval Function return VALUE, used by 00529 * @b GENERIC_FAILUREx_VALUE() and 00530 * @b GENERIC_FAILUREx_THROWERROR() . 00531 * 00532 * @param retclass Function error class to throw, used by 00533 * GENERIC_FAILUREx_THROWERROR() only. 00534 * 00535 * @param heap1ptr Data heap block to free, or 00536 * @link #rnull rnull@endlink if not needed. 00537 * 00538 * @param heap2ptr Data heap block to free, or 00539 * @link #rnull rnull@endlink if not needed. 00540 * 00541 * 00542 * @returns If @p @b expr is @link #rtrue rtrue@endlink, 00543 * return a typed @link #rnull rnull@endlink pointer to the 00544 * calling function, cast as <b><code>(rettype *)</code></b>, 00545 * else continue with inline code. 00546 * 00547 */ 00548 00549 /*@{ */ /* Begin grouped definitions */ 00550 00551 #define GENERIC_FAILURE_PTR(expr, dml, fn, msg, rettype, \ 00552 heap1ptr, heap2ptr) \ 00553 if (expr) \ 00554 { \ 00555 HEAP_FREE_DATA((rvoid *) heap1ptr); /* Ignored if rnull */ \ 00556 HEAP_FREE_DATA((rvoid *) heap2ptr); /* Ignored if rnull */ \ 00557 sysDbgMsg(dml, fn, msg); \ 00558 return((rettype *) rnull); \ 00559 } 00560 00561 #define GENERIC_FAILURE1_PTR(expr, dml, fn, msg, parm1, rettype, \ 00562 heap1ptr, heap2ptr) \ 00563 if (expr) \ 00564 { \ 00565 HEAP_FREE_DATA((rvoid *) heap1ptr); /* Ignored if rnull */ \ 00566 HEAP_FREE_DATA((rvoid *) heap2ptr); /* Ignored if rnull */ \ 00567 sysDbgMsg(dml, fn, msg, parm1); \ 00568 return((rettype *) rnull); \ 00569 } 00570 00571 #define GENERIC_FAILURE2_PTR(expr, dml, fn, msg, parm1, parm2, rettype,\ 00572 heap1ptr, heap2ptr) \ 00573 if (expr) \ 00574 { \ 00575 HEAP_FREE_DATA((rvoid *) heap1ptr); /* Ignored if rnull */ \ 00576 HEAP_FREE_DATA((rvoid *) heap2ptr); /* Ignored if rnull */ \ 00577 sysDbgMsg(dml, fn, msg, parm1, parm2); \ 00578 return((rettype *) rnull); \ 00579 } 00580 00581 #define GENERIC_FAILURE_VALUE(expr, dml, fn, msg, retval, heap1ptr, \ 00582 heap2ptr) \ 00583 if (expr) \ 00584 { \ 00585 HEAP_FREE_DATA((rvoid *) heap1ptr); /* Ignored if rnull */ \ 00586 HEAP_FREE_DATA((rvoid *) heap2ptr); /* Ignored if rnull */ \ 00587 sysDbgMsg(dml, fn, msg); \ 00588 return(retval); \ 00589 } 00590 00591 #define GENERIC_FAILURE1_VALUE(expr, dml, fn, msg, parm1, retval, \ 00592 heap1ptr, heap2ptr) \ 00593 if (expr) \ 00594 { \ 00595 HEAP_FREE_DATA((rvoid *) heap1ptr); /* Ignored if rnull */ \ 00596 HEAP_FREE_DATA((rvoid *) heap2ptr); /* Ignored if rnull */ \ 00597 sysDbgMsg(dml, fn, msg, parm1); \ 00598 return(retval); \ 00599 } 00600 00601 #define GENERIC_FAILURE2_VALUE(expr, dml, fn, msg, parm1, parm2,retval,\ 00602 heap1ptr, heap2ptr) \ 00603 if (expr) \ 00604 { \ 00605 HEAP_FREE_DATA((rvoid *) heap1ptr); /* Ignored if rnull */ \ 00606 HEAP_FREE_DATA((rvoid *) heap2ptr); /* Ignored if rnull */ \ 00607 sysDbgMsg(dml, fn, msg, parm1, parm2); \ 00608 return(retval); \ 00609 } 00610 00611 #define GENERIC_FAILURE_THROWERROR(expr, dml, fn, msg, retval,retclass,\ 00612 heap1ptr, heap2ptr) \ 00613 if (expr) \ 00614 { \ 00615 HEAP_FREE_DATA((rvoid *) heap1ptr); /* Ignored if rnull */ \ 00616 HEAP_FREE_DATA((rvoid *) heap2ptr); /* Ignored if rnull */ \ 00617 sysDbgMsg(dml, fn, msg); \ 00618 exit_throw_exception(retval, retclass); \ 00619 /*NOTREACHED*/ \ 00620 } 00621 00622 #define GENERIC_FAILURE1_THROWERROR(expr, dml, fn, msg, parm1, retval, \ 00623 retclass, heap1ptr, heap2ptr) \ 00624 if (expr) \ 00625 { \ 00626 HEAP_FREE_DATA((rvoid *) heap1ptr); /* Ignored if rnull */ \ 00627 HEAP_FREE_DATA((rvoid *) heap2ptr); /* Ignored if rnull */ \ 00628 sysDbgMsg(dml, fn, msg, parm1); \ 00629 exit_throw_exception(retval, retclass); \ 00630 /*NOTREACHED*/ \ 00631 } 00632 00633 #define GENERIC_FAILURE2_THROWERROR(expr, dml, fn, msg, parm1, parm2, \ 00634 retval, retclass, heap1ptr, heap2ptr) \ 00635 if (expr) \ 00636 { \ 00637 HEAP_FREE_DATA((rvoid *) heap1ptr); /* Ignored if rnull */ \ 00638 HEAP_FREE_DATA((rvoid *) heap2ptr); /* Ignored if rnull */ \ 00639 sysDbgMsg(dml, fn, msg, parm1, parm2); \ 00640 exit_throw_exception(retval, retclass); \ 00641 /*NOTREACHED*/ \ 00642 } 00643 00644 /*@} */ /* End of grouped definitions */ 00645 00646 /*******************************************************************/ 00647 /*! 00648 * @name Support for failed system calls 00649 * 00650 * @brief Recover from error when loading and parsing class file 00651 * by returning an @link #rnull rnull@endlink pointer, properly cast. 00652 * 00653 * <ul> 00654 * <li> 00655 * LOAD_SYSCALL_FAILURE() @link #rnull rnull@endlink pointer 00656 * as (ClassFile *) 00657 * </li> 00658 * 00659 * <li> 00660 * LOAD_SYSCALL_FAILURE_ATTRIB() @link #rnull rnull@endlink pointer 00661 * as (u1 *) 00662 * </li> 00663 * </ul> 00664 * 00665 * 00666 * @param expr Any logical expression that returns 00667 * @link #rtrue rtrue@endlink or 00668 * @link #rfalse rfalse@endlink. 00669 * 00670 * @param msg Any text message to display to stderr if @p @b expr 00671 * is @link #rtrue rtrue@endlink. 00672 * 00673 * @param heap1ptr Method heap block to free, or 00674 * @link #rnull rnull@endlink if not needed. 00675 * 00676 * @param heap2ptr Method heap block to free, or 00677 * @link #rnull rnull@endlink if not needed. 00678 * 00679 * 00680 * @returns If @p @b expr is @link #rtrue rtrue@endlink, return 00681 * an @link #rnull rnull@endlink pointer to the 00682 * calling function, cast as shown above, else continue 00683 * with inline code. 00684 * 00685 */ 00686 00687 /*@{ */ /* Begin grouped definitions */ 00688 00689 #define LOAD_SYSCALL_FAILURE(expr, msg, heap1ptr, heap2ptr) \ 00690 if (expr) \ 00691 { \ 00692 HEAP_FREE_METHOD((rvoid *) heap1ptr); \ 00693 HEAP_FREE_METHOD((rvoid *) heap2ptr); \ 00694 } \ 00695 GENERIC_FAILURE_PTR(expr, \ 00696 DMLMIN, \ 00697 "classfile_loadclassdata", \ 00698 msg, \ 00699 ClassFile, \ 00700 rnull, \ 00701 rnull); /* Extra ; */ 00702 00703 #define LOAD_SYSCALL_FAILURE_ATTRIB(expr, msg, heap1ptr, heap2ptr) \ 00704 if (expr) \ 00705 { \ 00706 HEAP_FREE_METHOD((rvoid *) heap1ptr); \ 00707 HEAP_FREE_METHOD((rvoid *) heap2ptr); \ 00708 } \ 00709 GENERIC_FAILURE_PTR(expr, \ 00710 DMLMIN, \ 00711 "cfattrib_loadattribute", \ 00712 msg, \ 00713 u1, \ 00714 rnull, \ 00715 rnull); /* Extra ; */ 00716 00717 /*@} */ /* End of grouped definitions */ 00718 00719 00720 /*******************************************************************/ 00721 /*! 00722 * 00723 * @name Architecture-dependent byte swapping macros. 00724 * 00725 * @brief Inline the logic to swap bytes on multi-byte elements. 00726 * 00727 * This is only meaningful on CONFIG_LITTLE_ENDIAN architectures. 00728 * (Notice that if @p @b member does not match the pointer's 00729 * type, there @e will be a compile warning or error.) 00730 * 00731 * 00732 * @param type Which constant_pool type, CONSTANT_xxx_info, 00733 * that will be used as (type *) to reference members. 00734 * @param member Member of (CONSTANT_xxx_info *) to be manipulated. 00735 * 00736 * 00737 * @returns @link #rvoid rvoid@endlink 00738 * 00739 * 00740 * @attention The following variables area must be defined for the 00741 * CP_ITEM_SWAP_U2() and CP_ITEM_SWAP_U2 macros to work: 00742 * @verbatim 00743 u2 *pcpu2; 00744 u4 *pcpu4; 00745 @endverbatim 00746 * 00747 * 00748 * @todo There needs to be logic implemented that can determine 00749 * whether or not a particular field has been byte swapped 00750 * in case a constant pool reference is made to an entry 00751 * that was previously byte swapped. This has NOT been 00752 * done for this ioriginal implementation because it is 00753 * on a Solaris 9 machine, which is big endian. 00754 * 00755 */ 00756 00757 /*@{ */ /* Begin grouped definitions */ 00758 00759 #ifdef CONFIG_LITTLE_ENDIAN 00760 #define CP_ITEM_SWAP_U2(type, member) \ 00761 pcpu2 = &(((type *) &pcpd->cp)->member); \ 00762 MACHINE_JSHORT_SWAP_PTR(pcpu2) 00763 00764 #define CP_ITEM_SWAP_U4(type, member) \ 00765 pcpu4 = &(((type *) &pcpd->cp)->member); \ 00766 MACHINE_JINT_SWAP_PTR(pcpu4) 00767 00768 #else 00769 /* CONFIG_BIG_ENDIAN: big endian architectures have nothing to do */ 00770 00771 #define CP_ITEM_SWAP_U2(type, member) 00772 #define CP_ITEM_SWAP_U4(type, member) 00773 00774 #endif 00775 /*@} */ /* End of grouped definitions */ 00776 00777 /*******************************************************************/ 00778 /*! 00779 * @name Generic prefix bytes. 00780 * 00781 * @brief Fill in empty area at start of selected structures for 00782 * address alignment purposes. 00783 * 00784 * Fill pattern bytes are provided for (cp_info) and (attribute_info) 00785 * structure alignment within (cp_info_dup) and (attribute_info_dup) 00786 * structures. This assures that 2- and 4-byte alignments needed 00787 * for the beginning of those structures is followed (after the first 00788 * element, the @p @b tag and @p @b attribute_name_index elements, 00789 * respectively). 00790 * 00791 * Real machine architectures that have issues with non-aligned 00792 * multi-byte accesses do @e not like the fact that ClassFile 00793 * structures such as cp_info begin with a single byte field followed 00794 * by multi-byte fields. In like manner, structures like attribute_info 00795 * have only 2- and 4-byte fields, yet may contain an odd number of 00796 * bytes in their @link #attribute_info info@endlink fields. 00797 * Due to the streaming nature of Java class files, subsequent 00798 * attributes may thus be misaligned, even though they may only contain 00799 * fields with an even number of bytes. Thus the cp_info_dup and 00800 * attribute_info_dup structures were devised to suppress problems like 00801 * this. When the class file is read, all structure accesses are 00802 * performed on blocks of allocated memory that start on 4- or 8-byte 00803 * address boundaries and pad the first few bytes so that all 2- and 00804 * 4-byte accesses are on 2- or 4-byte boundaries. 00805 * 00806 * There are three @b FILL_INFO_DUPx fill fields for padding and 00807 * three @b FILL_INFO_NOTUSED_Ux fill fields for assigning values 00808 * to @b notusedXX fields. 00809 * 00810 * @see cp_info_dup 00811 * @see attribute_info_dup 00812 * @see ARCH_ODD4_ADDRESS_SIGSEGV 00813 * @see ARCH_ODD2_ADDRESS_SIGSEGV 00814 * 00815 * @todo WATCH OUT! When changing CP_INFO_NUM_EMPTIES or 00816 * ATTRIBUTE_INFO_NUM_EMPTIES, beware of not having 00817 * he right number of @c @b struct->empty[x]=FILL 00818 * lines in the cp_info_dup and attribute_info_dup assignments! 00819 * Could eliminate these, but they are useful for 00820 * debugging. 00821 * 00822 * @todo 4-byte unused fields are meaningful only for 64-bit 00823 * implementations. 00824 * 00825 * @todo For 64-bit compilations, these fill patterns may need 00826 * to be expanded to support 8-byte alignments for some 00827 * architectures. For 32-bit compilations, nothing needs 00828 * to be done. (Verify if this is so.) Remember that the 00829 * @b WORDSIZE64 configuration macro is used to 00830 * distinguish this mode of compilation. (See 00831 * @link ./config.sh config.sh@endlink for details.) 00832 * 00833 */ 00834 /*@{*/ 00835 #define FILL_INFO_DUP0 0xbe 00836 #define FILL_INFO_DUP1 0xef 00837 #define FILL_INFO_DUP2 0x99 00838 00839 /* 00840 * Same for 1-, 2- and 4-byte @b notusedX fields. 00841 */ 00842 #define FILL_INFO_NOTUSED_U1 0x9a 00843 #define FILL_INFO_NOTUSED_U2 0x9ace 00844 #define FILL_INFO_NOTUSED_U4 0x9aceface 00845 /*@}*/ 00846 00847 #endif /* _cfmacros_h_included_ */ 00848 00849 /* EOF */ 00850