Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:54:45+00:00 2026-05-27T22:54:45+00:00

I am trying to understand few things about using dylib and still studying, so

  • 0

I am trying to understand few things about using dylib and still studying, so please excuse me if I ask stupid question.

  1. Is it possible for lib loaded via dlopen() to unload itself?

Ex. In code below, can we just execute the hello() code then at the end unload it.

 __attribute__((constructor))
 static void hello()
{
   // get handle to this dylib some how ???
   // some how unload itself ????
}

I have seen on few links, that it is possible to unload a libray from itself. But it is for windows. Lib unload itself.

2 . Can another process unload the library injected in some xyz process?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:54:45+00:00Added an answer on May 27, 2026 at 10:54 pm

    It may be possible for a DLL to unload itself but it may cause the process that legitimately loaded the DLL to crash if that proces later calls a function in the DLL.

    The link you refer to describes DLL injection which is where the code of a DLL is loaded as part of the address space of a process with a view to intercepting calls the process makes to functions in other “legitimate” DLLs . It is usually done in a “secretive” manner. i.e. the process whose calls are intercepted and rerouted is unaware of the DLL injection.

    So the link refers to advanced stuff which is used in rare circumstances.

    You are also wondering what to do if a DLL you load throws an exception. You should be able to catch it, but it might not be necessary to unload the DLL. There are OS specific calls on all platforms to unload a shared library. So, yes, you can do it. However it would be unusual to unload a DLL just because it threw an exception. It normally works fine but would cause a problem if another thread in your process is still using code in that DLL (this you would have to be aware of obviously).

    The short answer is, yes, you can unload the DLL if you explicitly loaded it. Just think carefully about when is the best time to unload it.

    Windows:

    LoadLibrary()
    FreeLibrary()
    GetProcAddress()
    

    Unix/Linux:

    dlopen()
    dlclose()
    dlsym()
    

    PS:I use the one term, DLL in my answer to refer to shared libraries on Windows and Linux.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Windbg and trying to understand a few things about value
Trying to understand an fft (Fast Fourier Transform) routine I'm using (stealing)(recycling) Input is
Learning java server technologies, trying to clarify some things. There are few technologies that
So I'm trying to implement things mentioned in Spring's 3.1 blog post about From
I've got a question about a PixelShader I am trying to implement, and what
I'm new to C and trying to learn a few things. What I'm trying
I'm trying to understand the basics of practical programming around character encodings. A few
I am trying to learn a few things from http://code.google.com/p/iosched/source/checkout . I wanted to
this is really stupid, but I been trying dozens of different things and I
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.