Example #1
0
 /**
  * look up this dynamic library for a symbol
  *
  * @param symbolName symbol name
  * @return The <code>Address</code> of the symbol system handler (actually an address to an
  *     AixLinkage triplet). (-1: not found or couldn't be created)
  */
 public Address getSymbol(String symbolName) {
   // Convert file name from unicode to filesystem character set
   // (assume file name is ascii, for now).
   //
   byte[] asciiName = VM_StringUtilities.stringToBytesNullTerminated(symbolName);
   return VM_SysCall.sysCall.sysDlsym(libHandler, asciiName);
 }
Example #2
0
  /**
   * Load a dynamic library and maintain it in this object.
   *
   * @param libraryName library name
   */
  private VM_DynamicLibrary(String libraryName) {
    // Convert file name from unicode to filesystem character set.
    // (Assume file name is ASCII, for now).
    //
    byte[] asciiName = VM_StringUtilities.stringToBytesNullTerminated(libraryName);

    // make sure we have enough stack to load the library.
    // This operation has been known to require more than 20K of stack.
    VM_Thread myThread = VM_Scheduler.getCurrentThread();
    Offset remaining = VM_Magic.getFramePointer().diff(myThread.stackLimit);
    int stackNeededInBytes = VM_StackframeLayoutConstants.STACK_SIZE_DLOPEN - remaining.toInt();
    if (stackNeededInBytes > 0) {
      if (myThread.hasNativeStackFrame()) {
        throw new java.lang.StackOverflowError("dlopen");
      } else {
        VM_Thread.resizeCurrentStack(myThread.getStackLength() + stackNeededInBytes, null);
      }
    }

    libHandler = VM_SysCall.sysCall.sysDlopen(asciiName);

    if (libHandler.isZero()) {
      VM.sysWriteln("error loading library: " + libraryName);
      throw new UnsatisfiedLinkError();
    }

    libName = libraryName;
    try {
      callOnLoad();
    } catch (UnsatisfiedLinkError e) {
      unload();
      throw e;
    }

    if (VM.verboseJNI) {
      VM.sysWriteln("[Loaded native library: " + libName + "]");
    }
  }