9 #include "xmog_localenv.h"
12 #if (XMOG_SUPPORTS_DOTNET==1)
22 typedef void (__stdcall * TRACING_CALLBACK)( int, LPSTR );
34 #define STR_SUCCESS "OK"
35 #define STR_FAILURE "ERROR"
40 #define TYPE_EXCEPTION 1
42 #define TYPE_BOOLEAN 2
45 #define TYPE_DOUBLE 16
49 #define TYPE_SHORT 256
50 #define TYPE_OBJECT 512
51 #define TYPE_VOID 1024
59 #define NETRT_INDIRECT 16384
61 #define JNI_TYPE_MASK (TYPE_BOOLEAN|TYPE_BYTE|TYPE_CHAR|TYPE_DOUBLE|TYPE_FLOAT|TYPE_INT|TYPE_LONG|TYPE_SHORT|TYPE_OBJECT|TYPE_VOID)
62 #define TYPE_MASK (JNI_TYPE_MASK)
64 #define TYPE(x) ((x)&(TYPE_MASK))
65 #define IS_ARRCTOR(x) (((x)&(ARRCTOR))!=0)
66 #define IS_CTOR(x) (((x)&(CTOR))!=0)
67 #define IS_STATIC(x) (((x)&(STATIC))!=0)
68 #define IS_INDIRECT(x) (((x)&(NETRT_INDIRECT))!=0)
69 #define IS_VOID(x) (((x)&(TYPE_VOID))!=0)
72 #define NETRT_SUCCESS (0)
73 #define NETRT_FAILURE (-1)
74 #define NETRT_WARNING (1)
75 #define IS_NETRT_SUCCESS(x) ((x)==NETRT_SUCCESS)
98 global_object( JNIEnv * lenv ) :
102 jobject temp = env->ExceptionOccurred();
107 env->ExceptionDescribe();
109 env->ExceptionClear();
110 jobj = env->NewGlobalRef( temp );
111 env->DeleteLocalRef( temp );
115 global_object( JNIEnv * lenv, jobject gobj ) :
121 global_object(
const global_object & gobj ) :
127 global_object & operator = (
const global_object & gobj )
133 operator jclass()
const
138 operator jobject()
const
171 local_object( JNIEnv * lenv, jobject lobj ) :
177 local_object(
const local_object & lobj ) :
182 jobj = env->NewLocalRef( jobj );
185 local_object & operator = (
const local_object & lobj )
189 env->DeleteLocalRef( jobj );
192 jobj = env->NewLocalRef( jobj );
197 local_object & operator = ( jobject jobj )
200 env->DeleteLocalRef( this->jobj );
206 operator global_object()
const
208 jobject temp = jobj ? env->NewGlobalRef( jobj ) : 0;
210 return global_object( env, temp );
213 operator jobject()
const
226 env->DeleteLocalRef( jobj );
238 static JavaVM * theJVM;
242 static HMODULE hThis;
244 static DWORD dwTLSIndex;
246 static CRITICAL_SECTION initjvm_lock;
248 static CRITICAL_SECTION initccl_lock;
250 static int theJNILevel;
252 static int theJVMLevel;
256 static void * tcb_jvm;
258 static int tl_typesystem;
260 static void * tcb_typesystem;
262 static int tl_callbacks;
264 static void * tcb_callbacks;
266 static int tl_finalization;
268 static void * tcb_finalization;
270 static jclass clsClass;
272 static jclass clsClassLoader;
274 static jclass clsThread;
276 static jclass clsJvalue;
278 static jclass clsRuntimeException;
280 static jclass clsCLRException;
282 static jobject sysClassLoader;
284 static jmethodID midGetName;
286 static jmethodID midLoadClass;
288 static jmethodID midCurrentThread;
290 static jmethodID midGetContextClassLoader;
292 static jmethodID midGetSystemClassLoader;
294 static jmethodID midSetContextClassLoader;
296 static jmethodID midGetImplementedIfcs;
298 static jmethodID midRTEctor;
300 static bool bShuttingDown;
302 static jint (__stdcall *cbVfprintf)( LPSTR msg );
304 static void (__stdcall *cbExit)(jint code);
306 static void (__stdcall *cbAbort)(void);
311 static void calculate_levels();
313 static void init( HMODULE hThis );
315 static void initClass();
317 static void initCCLFix();
319 static void init_jvalue( JNIEnv * env );
321 static void deinit();
323 static JNIEnv * get_env();
325 static void set_env( JNIEnv * env );
327 static int on_load( JavaVM * vm,
void * reserved );
329 static void on_unload( JavaVM * vm,
void * reserved );
333 typedef int (__stdcall JUGGERNET_CALLBACK)(
int & result_type, jvalue & result, jvalue * param );
337 void JNICALL dotnet_abort();
339 void JNICALL dotnet_exit( jint code );
341 jint JNICALL dotnet_vfprintf( FILE * fp,
const char *format, va_list args );
343 jint JNICALL dotnet_callback( JNIEnv * env, jclass clazz, jobject that,
int cbPointer, jobject result, jobject params );
345 __declspec(dllexport)
int __stdcall attach(
int group, LPSTR name, BOOL bAsDaemon );
347 __declspec(dllexport)
int __stdcall bind_jvm( LPSTR name,
int & bWasAlreadyLoaded,
int & bWasAlreadyInitialized );
349 __declspec(dllexport)
int __stdcall call_method(
int methodID,
357 __declspec(dllexport)
int __stdcall define_class( LPWSTR name, LPBYTE code, UINT size,
int & clazz,
int & exc );
359 __declspec(dllexport)
int __stdcall detach();
361 __declspec(dllexport)
int __stdcall equals(
int o1,
int o2, BOOL & result,
int & exc );
363 __declspec(dllexport)
int __stdcall find_class( LPWSTR name,
int & clazz,
int & exc );
365 __declspec(dllexport)
int __stdcall for_name( LPWSTR name,
int & inst,
int & exc );
367 __declspec(dllexport)
int __stdcall free_instance(
int inst );
369 __declspec(dllexport)
int __stdcall get_array_element(
int arr,
int index,
int type, jvalue & val,
int & exc );
371 __declspec(dllexport)
int __stdcall get_array_length(
int arr,
int & result,
int & exc );
373 __declspec(dllexport)
int __stdcall get_class(
int inst );
375 __declspec(dllexport)
int __stdcall get_classname(
int inst, LPWSTR name,
int size,
int & required );
377 __declspec(dllexport)
int __stdcall get_classclassname(
int clazz, LPWSTR name,
int size,
int & required );
379 __declspec(dllexport)
int __stdcall get_duplicate(
int inst );
381 __declspec(dllexport)
int __stdcall get_exception_message(
int exc, LPWSTR msg,
int size,
int & required );
383 __declspec(dllexport)
int __stdcall get_ifcnames(
int inst,
int & strarr );
385 __declspec(dllexport)
int __stdcall get_ifc_name(
int strarr,
int index, LPWSTR msg,
int size,
int & required );
387 __declspec(dllexport)
int __stdcall get_stacktrace(
int exc, LPWSTR msg,
int size,
int & required );
389 __declspec(dllexport)
int __stdcall get_string( jobject str, LPWSTR buffer, int32 size, int32 & required );
391 __declspec(dllexport) jclass __stdcall get_superclass( jclass clazz );
393 __declspec(dllexport)
int __stdcall hashCode( jobject obj, jobject & exc );
395 __declspec(dllexport)
int __stdcall init_field( jclass clazz, LPWSTR wname, LPWSTR wtype, int32 flags, jfieldID & fieldID, jobject & exc );
397 __declspec(dllexport)
int __stdcall init_method( jclass clazz, LPWSTR wname, LPWSTR wtype, int32 flags, jmethodID & methodID, jobject & exc );
399 __declspec(dllexport)
int __stdcall init_tracing_callbacks(
void* pTraceCallbacks,
void* pTraceJvm,
void* pTraveTypeSystem );
401 __declspec(dllexport)
bool __stdcall is_instance_of( jobject inst, jclass clazz );
403 __declspec(dllexport)
bool __stdcall is_same( jobject inst1, jobject inst2 );
405 __declspec(dllexport)
int __stdcall new_instance( LPWSTR classname, jclass clazz, __int64 size, jobject & result, jobject & exc );
407 jint JNICALL java_call( JNIEnv * env, jclass clazz, jobject java_this, jlong dotnet_this, jlong cbPointer, jlong mid, jobject result, jobjectArray params );
409 __declspec(dllexport)
int __stdcall set_array_element( jobject arr, int32 index, int32 type, jvalue val, jobject & exc );
411 __declspec(dllexport)
int __stdcall set_array_byte( jobject arr,
void * narr, int32 start, int32 length, jobject & exc );
413 __declspec(dllexport)
int __stdcall to_string( LPWSTR str, jobject & result, jobject & exc );
415 __declspec(dllexport)
int __stdcall ToString( jlong inst, LPWSTR result, int32 size, int32 & required, jlong & exc );
425 int call_method(
xmog_localenv * env, jmethodID methodID, jobject clazz, jobject inst, int32 flags, jvalue * param, jvalue & result, jobject & exc );
426 int equals(
xmog_localenv * env, jobject o1, jobject o2, BOOL & result, jobject & exc );
427 int find_class(
xmog_localenv * env, LPWSTR name, jobject & clazz, jobject & exc,
bool bIgnoreExc );
429 int get_array_element(
xmog_localenv * env, jobject arr, int32 index, int32 type, jvalue & val, jobject & exc );
430 int get_array_length(
xmog_localenv * env, jobject arr, int32 & result, jobject & exc );
432 int GetClassName(
xmog_localenv * env, jlong inst, LPSTR name, int32 size, int32 & required );
433 int GetClassClassName(
xmog_localenv * env, jlong clazz, LPSTR name, int32 size, int32 & required );
434 int get_exception_message(
xmog_localenv * env, jobject exc, LPWSTR msg, int32 size, int32 & required );
435 int get_stacktrace(
xmog_localenv * env, jobject exc, LPWSTR msg, int32 size, int32 & required );
436 int Get_String(
xmog_localenv * env, jlong str, LPWSTR buffer, int32 size, int32 & required );
438 int new_instance(
xmog_localenv * env, LPWSTR classname, jclass clazz, __int64 size, jobject & result, jobject & exc );
439 int set_array_element(
xmog_localenv * env, jobject arr, int32 index, int32 type, jvalue val, jobject & exc );
440 int to_string(
xmog_localenv * env, LPWSTR str, jobject & result, jobject & exc );
441 int ToString(
xmog_localenv * env, jlong inst, LPWSTR result, int32 size, int32 & required, jlong & exc );
442 LPSTR toUTF( LPWSTR wstr );
443 LPSTR toUTFwithReplace( LPWSTR wstr, WCHAR from, WCHAR to );
444 LPWSTR fromUTF( LPSTR str );