Skip to main content
Corrected spelling, fixed grammar
Source Link
karel
  • 2k
  • 2
  • 19
  • 30

I made a simple memory mangermanager, and I'm trying to compile it using a shared library in the driver.

The shared library files itself compiles fine. However, however when I compiled the driver by calling the functions in the shared library with my memory manager, it shows me the screenshot below:error messages

error messages

Here areis my code for the shared.c:

I made a simple memory manger and I'm trying to compile it using shared library in the driver.

The shared library files itself compiles fine. However, when I compiled the driver by calling the functions in the shared library with my memory manager, it shows me the screenshot below:error messages

Here are my code for the shared.c

I made a simple memory manager, and I'm trying to compile it using a shared library in the driver.

The shared library files itself compiles fine, however when I compiled the driver by calling the functions in the shared library with my memory manager, it shows me the screenshot below:

error messages

Here is my code for the shared.c:

added 122 characters in body
Source Link
TommyLan
  • 35
  • 1
  • 5

edit: So I managed to run the exe file but I failed on "get_functions". Are there any problems with my get_functions?

edit: So I managed to run the exe file but I failed on "get_functions". Are there any problems with my get_functions?

added 817 characters in body
Source Link
TommyLan
  • 35
  • 1
  • 5
/* conveniences for casting and declarations */
typedef block_info* (*MM_CREATE)(size_t, MMPolicy);
typedef void* (*MM_ALLOCATE)(block_info *, size_t, char *);
typedef int (*MM_DEALLOCATE)(block_info *, void *);
typedef void (*MM_DESTROY)(block_info *);

/* Function pointers retrieved from the shared library */
typedef struct LibraryFunctions
{
   MM_CREATE create;
   MM_DESTROY destroy;
   MM_ALLOCATE allocate;
   MM_DEALLOCATE deallocate;
}LibraryFunctions;

/* Loads a shared library and returns a pointer to it in libhandle */

/* Returns SUCCESS, if it successful, otherwise, FAILURE           */
int load_library(const char *libname, void **libhandle)
{

*libhandle = dlopen(*libhandle, RTLD_LAZY);

if(!(*libhandle))
{
    return FAILURE;
}
else
{
    return SUCCESS;
}

return *libname;
}
int get_functions(void *libhandle, 
               LibraryFunctions *functions, 
               const char **fn_names)
{
functions->create = (MM_CREATE)(intptr_t)dlsym(libhandle, *fn_names);

if(!functions->create)
{
    return FAILURE;
}
                 
functions->destroy = (MM_DESTROY)(intptr_t)dlsym(libhandle, *fn_names);

if(!functions->destroy)
{
    return FAILURE;
}

functions->allocate = (MM_ALLOCATE)(intptr_t)dlsym(libhandle, *fn_names);

if(!functions->allocate)
{
    return FAILURE;
}

functions->deallocate = (MM_DEALLOCATE)(intptr_t)dlsym(libhandle, *fn_names);

if(!functions->deallocate)
{
    return FAILURE;
}

return SUCCESS;

Here} Here is part of the driver code to call the shared library:

/* conveniences for casting and declarations */
typedef block_info* (*MM_CREATE)(size_t, MMPolicy);
typedef void* (*MM_ALLOCATE)(block_info *, size_t, char *);
typedef int (*MM_DEALLOCATE)(block_info *, void *);
typedef void (*MM_DESTROY)(block_info *);

/* Function pointers retrieved from the shared library */
typedef struct LibraryFunctions
{
   MM_CREATE create;
   MM_DESTROY destroy;
   MM_ALLOCATE allocate;
   MM_DEALLOCATE deallocate;
}LibraryFunctions;

/* Loads a shared library and returns a pointer to it in libhandle */

/* Returns SUCCESS, if it successful, otherwise, FAILURE           */
int load_library(const char *libname, void **libhandle)
{

*libhandle = dlopen(*libhandle, RTLD_LAZY);

if(!(*libhandle))
{
    return FAILURE;
}
else
{
    return SUCCESS;
}

return *libname;
}

Here is part of the driver code to call the shared library:

/* conveniences for casting and declarations */
typedef block_info* (*MM_CREATE)(size_t, MMPolicy);
typedef void* (*MM_ALLOCATE)(block_info *, size_t, char *);
typedef int (*MM_DEALLOCATE)(block_info *, void *);
typedef void (*MM_DESTROY)(block_info *);

/* Function pointers retrieved from the shared library */
typedef struct LibraryFunctions
{
   MM_CREATE create;
   MM_DESTROY destroy;
   MM_ALLOCATE allocate;
   MM_DEALLOCATE deallocate;
}LibraryFunctions;

/* Loads a shared library and returns a pointer to it in libhandle */

/* Returns SUCCESS, if it successful, otherwise, FAILURE           */
int load_library(const char *libname, void **libhandle)
{

*libhandle = dlopen(*libhandle, RTLD_LAZY);

if(!(*libhandle))
{
    return FAILURE;
}
else
{
    return SUCCESS;
}

return *libname;
}
int get_functions(void *libhandle, 
               LibraryFunctions *functions, 
               const char **fn_names)
{
functions->create = (MM_CREATE)(intptr_t)dlsym(libhandle, *fn_names);

if(!functions->create)
{
    return FAILURE;
}
                 
functions->destroy = (MM_DESTROY)(intptr_t)dlsym(libhandle, *fn_names);

if(!functions->destroy)
{
    return FAILURE;
}

functions->allocate = (MM_ALLOCATE)(intptr_t)dlsym(libhandle, *fn_names);

if(!functions->allocate)
{
    return FAILURE;
}

functions->deallocate = (MM_DEALLOCATE)(intptr_t)dlsym(libhandle, *fn_names);

if(!functions->deallocate)
{
    return FAILURE;
}

return SUCCESS;

} Here is part of the driver code to call the shared library:

added 44 characters in body
Source Link
TommyLan
  • 35
  • 1
  • 5
Loading
Source Link
TommyLan
  • 35
  • 1
  • 5
Loading