[ THIS IS A WIP AND MAY CHANGE AT ANY TIME! ]
Let's talk about shared objects and my "namespace" idea.
Let's say we have
void *dlnewns(void);
void *dlcopyns(void *namespace);
void *dlthisns(void);
void *dlnsopen(void *namespace, const char *filename, int flag);
void *dlnssym(void *namespace, const char *symbol);
int dlnsclose(void *namespace, void *handle);
int dldelns(void *namespace);
(If you notice, I didn't include a dlnserror()
, we can just use dlerror()
for that)
dlnewns() creates a new empty namespace and returns it. This is a completely isolated namespace.
dlcopyns() makes a copy of a namespace and returns that copy. This technically reopens all the handles inside the namespace, so the copy is isolated from the original namespace. (This lets libdl tweak all the handles/libs to work with the new namespace)
dlthisns() returns the namespace of the caller. This is mainly for use with dlcopyns()?
dlnsopen() is the namespaced variant of dlopen(). Returns a handle. RTLD_LOCAL only opens the lib with the namespace, without injecting the names into it. RTLD_GLOBAL injects names into the namespace.
dlnssym() is basically how you get things in to and out of namespaces. This does a lookup directly on the namespace, not on a handle.
dlnsclose() is the namespaced variant of dlclose(). Returns 0 on success and nonzero on error. (is this needed? can't we just use dlclose() instead?)
dldelns() is like dlclose(), but for namespaces. Because namespaces are local to the running application, not a shared resource, this actually destroys them. (Altho I guess if you pass a namespace into a namespace this would be a footgun... Meh, no worse than the dlopen() without dlclose() footgun)