src/solaris/native/sun/awt/awt_LoadLibrary.c

Print this page




  88     int xt_before_xm = 0;
  89     int XAWT = 0;
  90     jstring toolkit = NULL;
  91     jstring propname = NULL;
  92 
  93     if (awtHandle != NULL) {
  94         /* Avoid several loading attempts */
  95         return JNI_VERSION_1_2;
  96     }
  97 
  98     jvm = vm;
  99 
 100     /* Get address of this library and the directory containing it. */
 101     dladdr((void *)JNI_OnLoad, &dlinfo);
 102     realpath((char *)dlinfo.dli_fname, buf);
 103     len = strlen(buf);
 104     p = strrchr(buf, '/');
 105 
 106     /*
 107      * The code below is responsible for:
 108      * 1. Loading appropriate awt library, i.e. xawt/libmawt or headless/libwawt
 109      * 2. Setting "awt.toolkit" system property to use the appropriate Java toolkit class,
 110      *    (if user has specified the toolkit in env varialble)
 111      */
 112 
 113     propname = (*env)->NewStringUTF(env, "awt.toolkit");
 114     /* Check if toolkit is specified in env variable */
 115     envvar = getenv("AWT_TOOLKIT");
 116     if (envvar) {
 117         if (strstr(envvar, "XToolkit")) {
 118             toolkit = (*env)->NewStringUTF(env, "sun.awt.X11.XToolkit");
 119         }
 120         /* If user specified toolkit then set java system property */
 121         if (toolkit && propname) {
 122             JNU_CallStaticMethodByName (env,
 123                                         NULL,
 124                                         "java/lang/System",
 125                                         "setProperty",
 126                                         "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
 127                                         propname,toolkit);
 128         }
 129     }
 130 
 131     /* Calculate library name to load */
 132     if (AWTIsHeadless()) {
 133         strncpy(p, "/headless/libmawt.so", MAXPATHLEN-len-1);
 134     } else {
 135         /* Default AWT Toolkit on Linux and Solaris is XAWT. */
 136         strncpy(p, "/xawt/libmawt.so", MAXPATHLEN-len-1);
 137     }
 138 
 139     if (toolkit) {
 140         (*env)->DeleteLocalRef(env, toolkit);
 141     }
 142     if (propname) {
 143         (*env)->DeleteLocalRef(env, propname);
 144     }
 145 
 146     JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
 147                                "(Ljava/lang/String;)V",
 148                                JNU_NewStringPlatform(env, buf));
 149 
 150     awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
 151 
 152     return JNI_VERSION_1_2;
 153 }
 154 
 155 JNIEXPORT jint JNICALL
 156 JNI_OnLoad(JavaVM *vm, void *reserved)
 157 {
 158     return AWT_OnLoad(vm, reserved);
 159 }
 160 
 161 /*
 162  * This entry point must remain in libawt.so as part of a contract
 163  * with the CDE variant of Java Media Framework. (sdtjmplay)
 164  * Reflect this call over to the correct libmawt.so.
 165  */
 166 JNIEXPORT void JNICALL
 167 Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
 168                                      jobject frame, jstring jcommand)
 169 {
 170     /* type of the old backdoor function */
 171     typedef JNIEXPORT void JNICALL
 172         XsessionWMcommand_type(JNIEnv *env, jobject this,
 173                                jobject frame, jstring jcommand);
 174 
 175     static XsessionWMcommand_type *XsessionWMcommand = NULL;
 176 
 177     if (XsessionWMcommand == NULL && awtHandle == NULL) {
 178         return;
 179     }
 180 
 181     XsessionWMcommand = (XsessionWMcommand_type *)
 182         dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand");
 183 
 184     if (XsessionWMcommand == NULL)
 185         return;
 186 
 187     (*XsessionWMcommand)(env, this, frame, jcommand);
 188 }
 189 
 190 
 191 /*
 192  * This entry point must remain in libawt.so as part of a contract
 193  * with the CDE variant of Java Media Framework. (sdtjmplay)
 194  * Reflect this call over to the correct libmawt.so.
 195  */
 196 JNIEXPORT void JNICALL
 197 Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jargv)
 198 {
 199     typedef JNIEXPORT void JNICALL
 200         XsessionWMcommand_New_type(JNIEnv *env, jobjectArray jargv);
 201 
 202     static XsessionWMcommand_New_type *XsessionWMcommand = NULL;
 203 
 204     if (XsessionWMcommand == NULL && awtHandle == NULL) {
 205         return;
 206     }
 207 
 208     XsessionWMcommand = (XsessionWMcommand_New_type *)
 209         dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand_New");
 210 
 211     if (XsessionWMcommand == NULL)
 212         return;
 213 
 214     (*XsessionWMcommand)(env, jargv);


 233 
 234 #define REFLECT_FUNCTION(return_type, name, arglist, paramlist)         \
 235 typedef return_type name##_type arglist;                                \
 236 return_type name arglist                                                \
 237 {                                                                       \
 238     static name##_type *name##_ptr = NULL;                              \
 239     if (name##_ptr == NULL && awtHandle == NULL) {                      \
 240         return NULL;                                                    \
 241     }                                                                   \
 242     name##_ptr = (name##_type *)                                        \
 243         dlsym(awtHandle, #name);                                        \
 244     if (name##_ptr == NULL) {                                           \
 245         return NULL;                                                    \
 246     }                                                                   \
 247     return (*name##_ptr)paramlist;                                      \
 248 }
 249 
 250 
 251 /*
 252  * These entry point must remain in libawt.so ***for Java Plugin ONLY***
 253  * Reflect this call over to the correct libmawt.so.
 254  */
 255 
 256 REFLECT_VOID_FUNCTION(getAwtLockFunctions,
 257                       (void (**AwtLock)(JNIEnv *), void (**AwtUnlock)(JNIEnv *),
 258                        void (**AwtNoFlushUnlock)(JNIEnv *), void *reserved),
 259                       (AwtLock, AwtUnlock, AwtNoFlushUnlock, reserved))
 260 
 261 REFLECT_VOID_FUNCTION(getAwtData,
 262                       (int32_t *awt_depth, Colormap *awt_cmap, Visual **awt_visual,
 263                        int32_t *awt_num_colors, void *pReserved),
 264                       (awt_depth, awt_cmap, awt_visual,
 265                        awt_num_colors, pReserved))
 266 
 267 REFLECT_FUNCTION(Display *, getAwtDisplay, (void), ())


  88     int xt_before_xm = 0;
  89     int XAWT = 0;
  90     jstring toolkit = NULL;
  91     jstring propname = NULL;
  92 
  93     if (awtHandle != NULL) {
  94         /* Avoid several loading attempts */
  95         return JNI_VERSION_1_2;
  96     }
  97 
  98     jvm = vm;
  99 
 100     /* Get address of this library and the directory containing it. */
 101     dladdr((void *)JNI_OnLoad, &dlinfo);
 102     realpath((char *)dlinfo.dli_fname, buf);
 103     len = strlen(buf);
 104     p = strrchr(buf, '/');
 105 
 106     /*
 107      * The code below is responsible for:
 108      * 1. Loading appropriate awt library, i.e. libawt_xawt or libawt_headless
 109      * 2. Setting "awt.toolkit" system property to use the appropriate Java toolkit class,
 110      *    (if user has specified the toolkit in env varialble)
 111      */
 112 
 113     propname = (*env)->NewStringUTF(env, "awt.toolkit");
 114     /* Check if toolkit is specified in env variable */
 115     envvar = getenv("AWT_TOOLKIT");
 116     if (envvar) {
 117         if (strstr(envvar, "XToolkit")) {
 118             toolkit = (*env)->NewStringUTF(env, "sun.awt.X11.XToolkit");
 119         }
 120         /* If user specified toolkit then set java system property */
 121         if (toolkit && propname) {
 122             JNU_CallStaticMethodByName (env,
 123                                         NULL,
 124                                         "java/lang/System",
 125                                         "setProperty",
 126                                         "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
 127                                         propname,toolkit);
 128         }
 129     }
 130 
 131     /* Calculate library name to load */
 132     if (AWTIsHeadless()) {
 133         strncpy(p, "/libawt_headless.so", MAXPATHLEN-len-1);
 134     } else {
 135         /* Default AWT Toolkit on Linux and Solaris is XAWT. */
 136         strncpy(p, "/libawt_xawt.so", MAXPATHLEN-len-1);
 137     }
 138 
 139     if (toolkit) {
 140         (*env)->DeleteLocalRef(env, toolkit);
 141     }
 142     if (propname) {
 143         (*env)->DeleteLocalRef(env, propname);
 144     }
 145 
 146     JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
 147                                "(Ljava/lang/String;)V",
 148                                JNU_NewStringPlatform(env, buf));
 149 
 150     awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
 151 
 152     return JNI_VERSION_1_2;
 153 }
 154 
 155 JNIEXPORT jint JNICALL
 156 JNI_OnLoad(JavaVM *vm, void *reserved)
 157 {
 158     return AWT_OnLoad(vm, reserved);
 159 }
 160 
 161 /*
 162  * This entry point must remain in libawt.so as part of a contract
 163  * with the CDE variant of Java Media Framework. (sdtjmplay)
 164  * Reflect this call over to the correct libawt_<toolkit>.so.
 165  */
 166 JNIEXPORT void JNICALL
 167 Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
 168                                      jobject frame, jstring jcommand)
 169 {
 170     /* type of the old backdoor function */
 171     typedef JNIEXPORT void JNICALL
 172         XsessionWMcommand_type(JNIEnv *env, jobject this,
 173                                jobject frame, jstring jcommand);
 174 
 175     static XsessionWMcommand_type *XsessionWMcommand = NULL;
 176 
 177     if (XsessionWMcommand == NULL && awtHandle == NULL) {
 178         return;
 179     }
 180 
 181     XsessionWMcommand = (XsessionWMcommand_type *)
 182         dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand");
 183 
 184     if (XsessionWMcommand == NULL)
 185         return;
 186 
 187     (*XsessionWMcommand)(env, this, frame, jcommand);
 188 }
 189 
 190 
 191 /*
 192  * This entry point must remain in libawt.so as part of a contract
 193  * with the CDE variant of Java Media Framework. (sdtjmplay)
 194  * Reflect this call over to the correct libawt_<toolkit>.so.
 195  */
 196 JNIEXPORT void JNICALL
 197 Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jargv)
 198 {
 199     typedef JNIEXPORT void JNICALL
 200         XsessionWMcommand_New_type(JNIEnv *env, jobjectArray jargv);
 201 
 202     static XsessionWMcommand_New_type *XsessionWMcommand = NULL;
 203 
 204     if (XsessionWMcommand == NULL && awtHandle == NULL) {
 205         return;
 206     }
 207 
 208     XsessionWMcommand = (XsessionWMcommand_New_type *)
 209         dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand_New");
 210 
 211     if (XsessionWMcommand == NULL)
 212         return;
 213 
 214     (*XsessionWMcommand)(env, jargv);


 233 
 234 #define REFLECT_FUNCTION(return_type, name, arglist, paramlist)         \
 235 typedef return_type name##_type arglist;                                \
 236 return_type name arglist                                                \
 237 {                                                                       \
 238     static name##_type *name##_ptr = NULL;                              \
 239     if (name##_ptr == NULL && awtHandle == NULL) {                      \
 240         return NULL;                                                    \
 241     }                                                                   \
 242     name##_ptr = (name##_type *)                                        \
 243         dlsym(awtHandle, #name);                                        \
 244     if (name##_ptr == NULL) {                                           \
 245         return NULL;                                                    \
 246     }                                                                   \
 247     return (*name##_ptr)paramlist;                                      \
 248 }
 249 
 250 
 251 /*
 252  * These entry point must remain in libawt.so ***for Java Plugin ONLY***
 253  * Reflect this call over to the correct libawt_<toolkit>.so.
 254  */
 255 
 256 REFLECT_VOID_FUNCTION(getAwtLockFunctions,
 257                       (void (**AwtLock)(JNIEnv *), void (**AwtUnlock)(JNIEnv *),
 258                        void (**AwtNoFlushUnlock)(JNIEnv *), void *reserved),
 259                       (AwtLock, AwtUnlock, AwtNoFlushUnlock, reserved))
 260 
 261 REFLECT_VOID_FUNCTION(getAwtData,
 262                       (int32_t *awt_depth, Colormap *awt_cmap, Visual **awt_visual,
 263                        int32_t *awt_num_colors, void *pReserved),
 264                       (awt_depth, awt_cmap, awt_visual,
 265                        awt_num_colors, pReserved))
 266 
 267 REFLECT_FUNCTION(Display *, getAwtDisplay, (void), ())