/** * Look up a native libray named "name". Load if not loaded. Name can be a path or a libray name. * The Library will be looked up in a platform-dependant manor. * * @param name short library name, full file name, or path to the library file * @return NativeLibrary */ public static NativeLibrary getInstance(String name) { String nativeName = nativeLibraryName(name); Pointer name0 = Pointer.createStringBuffer(nativeName); if (DEBUG) { VM.print("Calling DLOPEN on "); VM.println(name); } int result = VM.execSyncIO( ChannelConstants.DLOPEN, name0.address().toUWord().toInt(), 0, 0, 0, 0, 0, null, null); Address r = Address.fromPrimitive(result); name0.free(); if (r.isZero()) { throw new RuntimeException("Can't open library " + name + ". OS Error: " + errorStr()); } return new NativeLibrary(name, r); }
/** * getFunction a symbol's address by name (warpper around dlsym) * * @param name * @return Address of symbol */ private Address getSymbolAddress(String name) { if (closed) { throw new IllegalStateException("closed"); } if (DEBUG) { VM.print("Calling DLSYM on "); VM.println(name); } Pointer name0 = Pointer.createStringBuffer(name); int result = VM.execSyncIO( ChannelConstants.DLSYM, ptr.toUWord().toInt(), name0.address().toUWord().toInt(), 0, 0, 0, 0, null, null); name0.free(); return Address.fromPrimitive(result); }