src/share/demo/jvmti/java_crw_demo/java_crw_demo.h
author duke
Sat Dec 01 00:00:00 2007 +0000 (9 months ago)
changeset 0 37a05a11f281
permissions -rw-r--r--
Initial load
        1 /*
        2  * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
        3  *
        4  * Redistribution and use in source and binary forms, with or without
        5  * modification, are permitted provided that the following conditions
        6  * are met:
        7  *
        8  *   - Redistributions of source code must retain the above copyright
        9  *     notice, this list of conditions and the following disclaimer.
       10  *
       11  *   - Redistributions in binary form must reproduce the above copyright
       12  *     notice, this list of conditions and the following disclaimer in the
       13  *     documentation and/or other materials provided with the distribution.
       14  *
       15  *   - Neither the name of Sun Microsystems nor the names of its
       16  *     contributors may be used to endorse or promote products derived
       17  *     from this software without specific prior written permission.
       18  *
       19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
       20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
       21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
       23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
       27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
       28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
       29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       30  */
       31 
       32 #ifndef JAVA_CRW_DEMO_H
       33 #define JAVA_CRW_DEMO_H
       34 
       35 #include <jni.h>
       36 
       37 #ifdef __cplusplus
       38 extern "C" {
       39 #endif
       40 
       41 /* This callback is used to notify the caller of a fatal error. */
       42 
       43 typedef void (*FatalErrorHandler)(const char*message, const char*file, int line);
       44 
       45 /* This callback is used to return the method information for a class.
       46  *   Since the information was already read here, it was useful to
       47  *   return it here, with no JVMTI phase restrictions.
       48  *   If the class file does represent a "class" and it has methods, then
       49  *   this callback will be called with the class number and pointers to
       50  *   the array of names, array of signatures, and the count of methods.
       51  */
       52 
       53 typedef void (*MethodNumberRegister)(unsigned, const char**, const char**, int);
       54 
       55 /* Class file reader/writer interface. Basic input is a classfile image
       56  *     and details about what to inject. The output is a new classfile image
       57  *     that was allocated with malloc(), and should be freed by the caller.
       58  */
       59 
       60 /* Names of external symbols to look for. These are the names that we
       61  *   try and lookup in the shared library. On Windows 2000, the naming
       62  *   convention is to prefix a "_" and suffix a "@N" where N is 4 times
       63  *   the number or arguments supplied.It has 19 args, so 76 = 19*4.
       64  *   On Windows 2003, Linux, and Solaris, the first name will be
       65  *   found, on Windows 2000 a second try should find the second name.
       66  *
       67  *   WARNING: If You change the JavaCrwDemo typedef, you MUST change
       68  *            multiple things in this file, including this name.
       69  */
       70 
       71 #define JAVA_CRW_DEMO_SYMBOLS { "java_crw_demo", "_java_crw_demo@76" }
       72 
       73 /* Typedef needed for type casting in dynamic access situations. */
       74 
       75 typedef void (JNICALL *JavaCrwDemo)(
       76          unsigned class_number,
       77          const char *name,
       78          const unsigned char *file_image,
       79          long file_len,
       80          int system_class,
       81          char* tclass_name,
       82          char* tclass_sig,
       83          char* call_name,
       84          char* call_sig,
       85          char* return_name,
       86          char* return_sig,
       87          char* obj_init_name,
       88          char* obj_init_sig,
       89          char* newarray_name,
       90          char* newarray_sig,
       91          unsigned char **pnew_file_image,
       92          long *pnew_file_len,
       93          FatalErrorHandler fatal_error_handler,
       94          MethodNumberRegister mnum_callback
       95 );
       96 
       97 /* Function export (should match typedef above) */
       98 
       99 JNIEXPORT void JNICALL java_crw_demo(
      100 
      101          unsigned class_number, /* Caller assigned class number for class */
      102 
      103          const char *name,      /* Internal class name, e.g. java/lang/Object */
      104                                 /*   (Do not use "java.lang.Object" format) */
      105 
      106          const unsigned char
      107            *file_image,         /* Pointer to classfile image for this class */
      108 
      109          long file_len,         /* Length of the classfile in bytes */
      110 
      111          int system_class,      /* Set to 1 if this is a system class */
      112                                 /*   (prevents injections into empty */
      113                                 /*   <clinit>, finalize, and <init> methods) */
      114 
      115          char* tclass_name,     /* Class that has methods we will call at */
      116                                 /*   the injection sites (tclass) */
      117 
      118          char* tclass_sig,      /* Signature of tclass */
      119                                 /*  (Must be "L" + tclass_name + ";") */
      120 
      121          char* call_name,       /* Method name in tclass to call at offset 0 */
      122                                 /*   for every method */
      123 
      124          char* call_sig,        /* Signature of this call_name method */
      125                                 /*  (Must be "(II)V") */
      126 
      127          char* return_name,     /* Method name in tclass to call at all */
      128                                 /*  return opcodes in every method */
      129 
      130          char* return_sig,      /* Signature of this return_name method */
      131                                 /*  (Must be "(II)V") */
      132 
      133          char* obj_init_name,   /* Method name in tclass to call first thing */
      134                                 /*   when injecting java.lang.Object.<init> */
      135 
      136          char* obj_init_sig,    /* Signature of this obj_init_name method */
      137                                 /*  (Must be "(Ljava/lang/Object;)V") */
      138 
      139          char* newarray_name,   /* Method name in tclass to call after every */
      140                                 /*   newarray opcode in every method */
      141 
      142          char* newarray_sig,    /* Signature of this method */
      143                                 /*  (Must be "(Ljava/lang/Object;II)V") */
      144 
      145          unsigned char
      146            **pnew_file_image,   /* Returns a pointer to new classfile image */
      147 
      148          long *pnew_file_len,   /* Returns the length of the new image */
      149 
      150          FatalErrorHandler
      151            fatal_error_handler, /* Pointer to function to call on any */
      152                                 /*  fatal error. NULL sends error to stderr */
      153 
      154          MethodNumberRegister
      155            mnum_callback        /* Pointer to function that gets called */
      156                                 /*   with all details on methods in this */
      157                                 /*   class. NULL means skip this call. */
      158 
      159            );
      160 
      161 
      162 /* External to read the class name out of a class file .
      163  *
      164  *   WARNING: If You change the typedef, you MUST change
      165  *            multiple things in this file, including this name.
      166  */
      167 
      168 #define JAVA_CRW_DEMO_CLASSNAME_SYMBOLS \
      169          { "java_crw_demo_classname", "_java_crw_demo_classname@12" }
      170 
      171 /* Typedef needed for type casting in dynamic access situations. */
      172 
      173 typedef char * (JNICALL *JavaCrwDemoClassname)(
      174          const unsigned char *file_image,
      175          long file_len,
      176          FatalErrorHandler fatal_error_handler);
      177 
      178 JNIEXPORT char * JNICALL java_crw_demo_classname(
      179          const unsigned char *file_image,
      180          long file_len,
      181          FatalErrorHandler fatal_error_handler);
      182 
      183 #ifdef __cplusplus
      184 } /* extern "C" */
      185 #endif /* __cplusplus */
      186 
      187 #endif