Failed to get void ponter as function arguments while calling function from application to Dynamic Loaded Library in Linux

I have created one dynamic library in Linux OS. There is one function called test which has one argument as void *buffer.

I have used mmap call inside that function which maps memory successfully without any issue.

I have mapped that memory into one global char *buffer inside dynamic loaded library.

void *buffer;

int test(void *buffer_app)
   buffer = (char *)mmap(0, buffer_size, PROT_READ | PROT_WRITE, MAP_SHARED,  
   fd, 0);

   buffer_app = (char *)buffer;
   return 0;

Than, I have created one command line test application which will open that dynamic library using dlopen function.

All, above things works fine as per requirement.

After that, I have kept one void *buffer as global inside command line test application and passed it as argument of test function to map memory from dll.

void *buffer;

int main()
    void *handle;
    int status = 0;
    handle = dlopen("", RTLD_NOW  | RTLD_GLOBAL);

    dlerror();    /* Clear any existing error */

    giPtr = dlsym(handle, "GI_Funcs");

    status = giPtr->test(buffer);


So, I am getting address of buffer as 0x0 instead of address which points memory called by mmap in dynamic library.

Does anyone has idea about this issue?

Source: dll

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.