예제 #1
0
//---------------------------------------------------------------------------
// LoadLibrary() - loads the converter DLL and retrieves the entry points; if
// unable to load and initialize the library or if required entry points are
// not exported, throws an exception
// hwnd - handle to the parent window
// libpath - full path to DLL to load
//
void TRtfConverter::LoadLibrary(HWND hwnd, AnsiString libpath)
{
  // attempt to load library
  HINSTANCE hinst = ::LoadLibrary(libpath.c_str());
  if (!hinst) throw Exception("Unable to load library");

  // library loaded ok
  FLibrary = hinst;

  // get entry points for calls
  pInitConverter32 = (InitConverter32*) ::GetProcAddress(FLibrary, "InitConverter32");
  pUninitConverter = (UninitConverter*) ::GetProcAddress(FLibrary, "UninitConverter");
  pIsFormatCorrect32 = (IsFormatCorrect32*) ::GetProcAddress(FLibrary, "IsFormatCorrect32");
  pForeignToRtf32 = (ForeignToRtf32*) ::GetProcAddress(FLibrary, "ForeignToRtf32");
  pRtfToForeign32 = (RtfToForeign32*) ::GetProcAddress(FLibrary, "RtfToForeign32");
  pRegisterApp = (RegisterApp*) ::GetProcAddress(FLibrary, "RegisterApp");
  pCchFetchLpszError = (CchFetchLpszError*) ::GetProcAddress(FLibrary, "CchFetchLpszError");
  pGetReadNames = (GetReadNames*) ::GetProcAddress(FLibrary, "GetReadNames");
  pGetWriteNames = (GetWriteNames*) ::GetProcAddress(FLibrary, "GetWriteNames");
  pFRegisterConverter = (FRegisterConverter*) ::GetProcAddress(FLibrary, "FRegisterConverter");

  // verify that required entry points are available
  if (!pInitConverter32 || !pIsFormatCorrect32 || !pForeignToRtf32) {
    UnloadLibrary();
    throw Exception("Unable to initialize library (required entry points missing)");
    }

  // initialize converter - if cannot, unload and return failure
  if (!pInitConverter32(hwnd, Application->ExeName.c_str())) {
    UnloadLibrary();
    throw Exception("Unable to initialize library (initialization failed)");
    }
}
예제 #2
0
bool
Library::Close(JSContext* cx, unsigned argc, Value* vp)
{
  CallArgs args = CallArgsFromVp(argc, vp);

  RootedObject obj(cx);
  if (args.thisv().isObject())
    obj = &args.thisv().toObject();
  if (!obj || !IsLibrary(obj)) {
    JS_ReportErrorASCII(cx, "not a library");
    return false;
  }

  if (args.length() != 0) {
    JS_ReportErrorASCII(cx, "close doesn't take any arguments");
    return false;
  }

  // delete our internal objects
  UnloadLibrary(obj);
  JS_SetReservedSlot(obj, SLOT_LIBRARY, PrivateValue(nullptr));

  args.rval().setUndefined();
  return true;
}
예제 #3
0
 void CDynamicLoading::UnloadAllLibraries() {
    for(TDLHandleMap::iterator it = m_tOpenLibs.begin();
        it != m_tOpenLibs.end();
        ++it) {
       UnloadLibrary(it->second);
    }
 }
예제 #4
0
void OMCFactory::UnloadAllLibs(void)
{
    map<string,shared_library>::iterator iter;
    for(iter = _modules.begin();iter!=_modules.end();++iter)
    {
        UnloadLibrary(iter->second);
    }
}
예제 #5
0
 void CDynamicLoading::UnloadLibrary(const std::string& str_lib) {
    TDLHandleMap::iterator it = m_tOpenLibs.find(str_lib);
    if(it != m_tOpenLibs.end()) {
       UnloadLibrary(it->second);
    }
    else {
       THROW_ARGOSEXCEPTION("Can't unload library \""
                            << str_lib
                            << "\": library does not appear to have been loaded.");
    }
 }
예제 #6
0
void LibraryList::UnloadLibrary(LibraryView* wrap) {
  // Sanity check.
  LOG("%s: for %s (ref_count=%d)\n",
      __FUNCTION__,
      wrap->GetName(),
      wrap->ref_count());

  if (!wrap->IsSystem() && !wrap->IsCrazy())
    return;

  if (!wrap->SafeDecrementRef())
    return;

  // If this is a crazy library, perform manual cleanup first.
  if (wrap->IsCrazy()) {
    SharedLibrary* lib = wrap->GetCrazy();

    // Remove from internal list of crazy libraries.
    if (lib->list_next_)
      lib->list_next_->list_prev_ = lib->list_prev_;
    if (lib->list_prev_)
      lib->list_prev_->list_next_ = lib->list_next_;
    if (lib == head_)
      head_ = lib->list_next_;

    // Call JNI_OnUnload, if necessary, then the destructors.
    lib->CallJniOnUnload();
    lib->CallDestructors();

    // Unload the dependencies recursively.
    SharedLibrary::DependencyIterator iter(lib);
    while (iter.GetNext()) {
      LibraryView* dependency = FindKnownLibrary(iter.GetName());
      if (dependency)
        UnloadLibrary(dependency);
    }

    // Tell GDB of this removal.
    Globals::GetRDebug()->DelEntry(&lib->link_map_);
  }

  known_libraries_.Remove(wrap);

  // Delete the wrapper, which will delete the crazy library, or
  // dlclose() the system one.
  delete wrap;
}
예제 #7
0
JSBool
Library::Close(JSContext* cx, unsigned argc, jsval* vp)
{
  JSObject* obj = JS_THIS_OBJECT(cx, vp);
  if (!obj)
    return JS_FALSE;
  if (!IsLibrary(obj)) {
    JS_ReportError(cx, "not a library");
    return JS_FALSE;
  }

  if (argc != 0) {
    JS_ReportError(cx, "close doesn't take any arguments");
    return JS_FALSE;
  }

  // delete our internal objects
  UnloadLibrary(obj);
  JS_SetReservedSlot(obj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL));

  JS_SET_RVAL(cx, vp, JSVAL_VOID);
  return JS_TRUE;
}
예제 #8
0
bool
Library::Close(JSContext* cx, unsigned argc, Value* vp)
{
    CallArgs args = CallArgsFromVp(argc, vp);
    JSObject* obj = JS_THIS_OBJECT(cx, vp);
    if (!obj)
        return false;
    if (!IsLibrary(obj)) {
        JS_ReportError(cx, "not a library");
        return false;
    }

    if (args.length() != 0) {
        JS_ReportError(cx, "close doesn't take any arguments");
        return false;
    }

    // delete our internal objects
    UnloadLibrary(obj);
    JS_SetReservedSlot(obj, SLOT_LIBRARY, PrivateValue(nullptr));

    args.rval().setUndefined();
    return true;
}
예제 #9
0
void
Library::Finalize(JSFreeOp* fop, JSObject* obj)
{
  UnloadLibrary(obj);
}
예제 #10
0
DLL_LOCAL bool MyoWrapper::LoadLibrary(void)
{
#ifndef TARGET_WINNT
    const char *lib_name = "libmyo-client.so";
#else // TARGET_WINNT
    const char *lib_name = "myo-client.dll";
#endif // TARGET_WINNT

    OFFLOAD_DEBUG_TRACE(2, "Loading MYO library %s ...\n", lib_name);

    m_lib_handle = DL_open(lib_name);
    if (m_lib_handle == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to load the library. errno = %d\n",
                            errno);
        return false;
    }

    m_lib_init = (MyoError (*)(void*, void*))
        DL_sym(m_lib_handle, "myoiLibInit", MYO_VERSION1);
    if (m_lib_init == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoiLibInit");
        UnloadLibrary();
        return false;
    }

    m_lib_fini = (void (*)(void))
        DL_sym(m_lib_handle, "myoiLibFini", MYO_VERSION1);
    if (m_lib_fini == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoiLibFini");
        UnloadLibrary();
        return false;
    }

    m_shared_malloc = (void* (*)(size_t))
        DL_sym(m_lib_handle, "myoSharedMalloc", MYO_VERSION1);
    if (m_shared_malloc == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoSharedMalloc");
        UnloadLibrary();
        return false;
    }

    m_shared_free = (void (*)(void*))
        DL_sym(m_lib_handle, "myoSharedFree", MYO_VERSION1);
    if (m_shared_free == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoSharedFree");
        UnloadLibrary();
        return false;
    }

    m_shared_aligned_malloc = (void* (*)(size_t, size_t))
        DL_sym(m_lib_handle, "myoSharedAlignedMalloc", MYO_VERSION1);
    if (m_shared_aligned_malloc == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoSharedAlignedMalloc");
        UnloadLibrary();
        return false;
    }

    m_shared_aligned_free = (void (*)(void*))
        DL_sym(m_lib_handle, "myoSharedAlignedFree", MYO_VERSION1);
    if (m_shared_aligned_free == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoSharedAlignedFree");
        UnloadLibrary();
        return false;
    }

    m_acquire = (MyoError (*)(void))
        DL_sym(m_lib_handle, "myoAcquire", MYO_VERSION1);
    if (m_acquire == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoAcquire");
        UnloadLibrary();
        return false;
    }

    m_release = (MyoError (*)(void))
        DL_sym(m_lib_handle, "myoRelease", MYO_VERSION1);
    if (m_release == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoRelease");
        UnloadLibrary();
        return false;
    }

    m_host_var_table_propagate = (MyoError (*)(void*, int))
        DL_sym(m_lib_handle, "myoiHostVarTablePropagate", MYO_VERSION1);
    if (m_host_var_table_propagate == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoiHostVarTablePropagate");
        UnloadLibrary();
        return false;
    }

    m_host_fptr_table_register = (MyoError (*)(void*, int, int))
        DL_sym(m_lib_handle, "myoiHostFptrTableRegister", MYO_VERSION1);
    if (m_host_fptr_table_register == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoiHostFptrTableRegister");
        UnloadLibrary();
        return false;
    }

    m_remote_thunk_call = (MyoError (*)(void*, void*, int))
        DL_sym(m_lib_handle, "myoiRemoteThunkCall", MYO_VERSION1);
    if (m_remote_thunk_call == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoiRemoteThunkCall");
        UnloadLibrary();
        return false;
    }

    m_remote_call = (MyoiRFuncCallHandle (*)(const char*, void*, int))
        DL_sym(m_lib_handle, "myoiRemoteCall", MYO_VERSION1);
    if (m_remote_call == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoiRemoteCall");
        UnloadLibrary();
        return false;
    }

    m_get_result = (MyoError (*)(MyoiRFuncCallHandle))
        DL_sym(m_lib_handle, "myoiGetResult", MYO_VERSION1);
    if (m_get_result == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoiGetResult");
        UnloadLibrary();
        return false;
    }

    m_arena_create = (MyoError (*)(MyoOwnershipType, int, MyoArena*))
        DL_sym(m_lib_handle, "myoArenaCreate", MYO_VERSION1);
    if (m_arena_create == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoArenaCreate");
        UnloadLibrary();
        return false;
    }

    m_arena_aligned_malloc = (void* (*)(MyoArena, size_t, size_t))
        DL_sym(m_lib_handle, "myoArenaAlignedMalloc", MYO_VERSION1);
    if (m_arena_aligned_malloc == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoArenaAlignedMalloc");
        UnloadLibrary();
        return false;
    }

    m_arena_aligned_free = (void* (*)(MyoArena, void*))
        DL_sym(m_lib_handle, "myoArenaAlignedFree", MYO_VERSION1);
    if (m_arena_aligned_free == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoArenaAlignedFree");
        UnloadLibrary();
        return false;
    }

    m_arena_acquire = (MyoError (*)(MyoArena))
        DL_sym(m_lib_handle, "myoArenaAcquire", MYO_VERSION1);
    if (m_acquire == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoArenaAcquire");
        UnloadLibrary();
        return false;
    }

    m_arena_release = (MyoError (*)(MyoArena))
        DL_sym(m_lib_handle, "myoArenaRelease", MYO_VERSION1);
    if (m_release == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoArenaRelease");
        UnloadLibrary();
        return false;
    }

    // Check for "feature-available" API added in MPSS 3.3.
    // Not finding it is not an error.
    m_feature_available = (MyoError (*)(int))
        DL_sym(m_lib_handle, "myoiSupportsFeature", MYO_VERSION1);
    if (m_feature_available == 0) {
        OFFLOAD_DEBUG_TRACE(2, "Failed to find %s in MYO library\n",
                            "myoiSupportsFeature");
    }    

    OFFLOAD_DEBUG_TRACE(2, "The library was successfully loaded\n");

    // Create arena if supported
    CreateVtableArena();
    OFFLOAD_DEBUG_TRACE(3, "Vtable arena created\n");

    m_is_available = true;

    return true;
}
예제 #11
0
//---------------------------------------------------------------------------
// ~TRtfConverter() - dtor
// unload the library
//
TRtfConverter::~TRtfConverter()
{
  UnloadLibrary();
  FSemaphore = false;
}