26 #ifndef PG_USE_STDBOOL
72 #define SAME_INODE(A,B) ((A).st_ino == (B).inode && (A).st_dev == (B).device)
74 #define SAME_INODE(A,B) false
106 bool signalNotFound,
void **filehandle)
120 *filehandle = lib_handle;
125 if (retval == NULL && signalNotFound)
127 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
128 errmsg(
"could not find function \"%s\" in file \"%s\"",
189 struct stat stat_buf;
196 file_scanner != NULL &&
197 strcmp(libname, file_scanner->
filename) != 0;
198 file_scanner = file_scanner->
next)
201 if (file_scanner == NULL)
206 if (
stat(libname, &stat_buf) == -1)
209 errmsg(
"could not access file \"%s\": %m",
213 file_scanner != NULL &&
215 file_scanner = file_scanner->
next)
219 if (file_scanner == NULL)
226 if (file_scanner == NULL)
228 (
errcode(ERRCODE_OUT_OF_MEMORY),
229 errmsg(
"out of memory")));
232 strcpy(file_scanner->
filename, libname);
237 file_scanner->
next = NULL;
240 if (file_scanner->
handle == NULL)
247 errmsg(
"could not load library \"%s\": %s",
248 libname, load_error)));
279 (
errmsg(
"incompatible library \"%s\": missing magic block",
281 errhint(
"Extension libraries are required to use the PG_MODULE_MAGIC macro.")));
299 return file_scanner->
handle;
317 char library_version[32];
319 if (module_magic_data->
version >= 1000)
320 snprintf(library_version,
sizeof(library_version),
"%d",
321 module_magic_data->
version / 100);
323 snprintf(library_version,
sizeof(library_version),
"%d.%d",
324 module_magic_data->
version / 100,
325 module_magic_data->
version % 100);
327 (
errmsg(
"incompatible library \"%s\": version mismatch",
329 errdetail(
"Server is version %d, library is version %s.",
341 (
errmsg(
"incompatible library \"%s\": ABI mismatch",
343 errdetail(
"Server has ABI \"%s\", library has \"%s\".",
362 _(
"Server has %s = %d, library has %d."),
372 _(
"Server has %s = %d, library has %d."),
382 _(
"Server has %s = %d, library has %d."),
392 _(
"Server has %s = %s, library has %s."),
394 module_magic_data->
float8byval ?
"true" :
"false");
397 if (details.
len == 0)
399 _(
"Magic block has unexpected length or padding difference."));
402 (
errmsg(
"incompatible library \"%s\": magic block mismatch",
475 if (strncmp(
name,
"$libdir/plugins/", 16) != 0 ||
478 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
479 errmsg(
"access to library \"%s\" is not allowed",
501 if (strlen(
"$libdir") != sep_ptr -
name ||
502 strncmp(
name,
"$libdir", strlen(
"$libdir")) != 0)
504 (
errcode(ERRCODE_INVALID_NAME),
505 errmsg(
"invalid macro name in dynamic library path: %s",
532 baselen = strlen(basename);
544 (
errcode(ERRCODE_INVALID_NAME),
545 errmsg(
"zero-length component in parameter \"dynamic_library_path\"")));
563 (
errcode(ERRCODE_INVALID_NAME),
564 errmsg(
"component in parameter \"dynamic_library_path\" is not an absolute path")));
566 full =
palloc(strlen(mangled) + 1 + baselen + 1);
567 sprintf(full,
"%s/%s", mangled, basename);
570 elog(
DEBUG3,
"find_in_dynamic_libpath: trying \"%s\"", full);
605 static HTAB *rendezvousHash = NULL;
611 if (rendezvousHash == NULL)
617 rendezvousHash =
hash_create(
"Rendezvous variable hash",
647 file_scanner != NULL;
648 file_scanner = file_scanner->
next)
663 file_scanner != NULL;
664 file_scanner = file_scanner->
next)
671 start_address +=
len;
673 start_address[0] =
'\0';
682 while (*start_address !=
'\0')
685 start_address += strlen(start_address) + 1;
#define Assert(condition)
#define pg_attribute_noreturn()
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
static char * expand_dynamic_library_name(const char *name)
static DynamicFileList * file_tail
static char * find_in_dynamic_libpath(const char *basename)
void RestoreLibraryState(char *start_address)
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
char * Dynamic_library_path
static char * substitute_libpath_macro(const char *name)
static void incompatible_module_error(const char *libname, const Pg_magic_struct *module_magic_data) pg_attribute_noreturn()
static void * internal_load_library(const char *libname)
void SerializeLibraryState(Size maxsize, char *start_address)
void load_file(const char *filename, bool restricted)
static const Pg_magic_struct magic_data
Size EstimateLibraryStateSpace(void)
void ** find_rendezvous_variable(const char *varName)
static DynamicFileList * file_list
struct df_files DynamicFileList
static void check_restricted_library_name(const char *name)
void * lookup_external_function(void *filehandle, const char *funcname)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int errdetail_internal(const char *fmt,...)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool pg_file_exists(const char *name)
#define PG_MAGIC_FUNCTION_NAME_STRING
const Pg_magic_struct *(* PGModuleMagicFunction)(void)
#define PG_MODULE_MAGIC_DATA
char pkglib_path[MAXPGPATH]
char * pstrdup(const char *in)
void pfree(void *pointer)
#define is_absolute_path(filename)
char * first_dir_separator(const char *filename)
void canonicalize_path(char *path)
char * first_path_var_separator(const char *pathlist)
size_t strlcpy(char *dst, const char *src, size_t siz)
char * psprintf(const char *fmt,...)
Size add_size(Size s1, Size s2)
static pg_noinline void Size size
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
char filename[FLEXIBLE_ARRAY_MEMBER]
void * dlsym(void *handle, const char *symbol)
void * dlopen(const char *file, int mode)
int dlclose(void *handle)