PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dfmgr.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * dfmgr.c
4  * Dynamic function manager code.
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/utils/fmgr/dfmgr.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include <sys/stat.h>
18 
19 #include "dynloader.h"
20 #include "lib/stringinfo.h"
21 #include "miscadmin.h"
22 #include "storage/shmem.h"
23 #include "utils/dynamic_loader.h"
24 #include "utils/hsearch.h"
25 
26 
27 /* signatures for PostgreSQL-specific library init/fini functions */
28 typedef void (*PG_init_t) (void);
29 typedef void (*PG_fini_t) (void);
30 
31 /* hashtable entry for rendezvous variables */
32 typedef struct
33 {
34  char varName[NAMEDATALEN]; /* hash key (must be first) */
35  void *varValue;
37 
38 /*
39  * List of dynamically loaded files (kept in malloc'd memory).
40  */
41 
42 typedef struct df_files
43 {
44  struct df_files *next; /* List link */
45  dev_t device; /* Device file is on */
46 #ifndef WIN32 /* ensures we never again depend on this under
47  * win32 */
48  ino_t inode; /* Inode number of file */
49 #endif
50  void *handle; /* a handle for pg_dl* functions */
51  char filename[FLEXIBLE_ARRAY_MEMBER]; /* Full pathname of file */
53 
56 
57 /* stat() call under Win32 returns an st_ino field, but it has no meaning */
58 #ifndef WIN32
59 #define SAME_INODE(A,B) ((A).st_ino == (B).inode && (A).st_dev == (B).device)
60 #else
61 #define SAME_INODE(A,B) false
62 #endif
63 
65 
66 static void *internal_load_library(const char *libname);
67 static void incompatible_module_error(const char *libname,
68  const Pg_magic_struct *module_magic_data) pg_attribute_noreturn();
69 static void internal_unload_library(const char *libname);
70 static bool file_exists(const char *name);
71 static char *expand_dynamic_library_name(const char *name);
72 static void check_restricted_library_name(const char *name);
73 static char *substitute_libpath_macro(const char *name);
74 static char *find_in_dynamic_libpath(const char *basename);
75 
76 /* Magic structure that module needs to match to be accepted */
78 
79 
80 /*
81  * Load the specified dynamic-link library file, and look for a function
82  * named funcname in it.
83  *
84  * If the function is not found, we raise an error if signalNotFound is true,
85  * else return (PGFunction) NULL. Note that errors in loading the library
86  * will provoke ereport() regardless of signalNotFound.
87  *
88  * If filehandle is not NULL, then *filehandle will be set to a handle
89  * identifying the library file. The filehandle can be used with
90  * lookup_external_function to lookup additional functions in the same file
91  * at less cost than repeating load_external_function.
92  */
94 load_external_function(char *filename, char *funcname,
95  bool signalNotFound, void **filehandle)
96 {
97  char *fullname;
98  void *lib_handle;
99  PGFunction retval;
100 
101  /* Expand the possibly-abbreviated filename to an exact path name */
102  fullname = expand_dynamic_library_name(filename);
103 
104  /* Load the shared library, unless we already did */
105  lib_handle = internal_load_library(fullname);
106 
107  /* Return handle if caller wants it */
108  if (filehandle)
109  *filehandle = lib_handle;
110 
111  /* Look up the function within the library */
112  retval = (PGFunction) pg_dlsym(lib_handle, funcname);
113 
114  if (retval == NULL && signalNotFound)
115  ereport(ERROR,
116  (errcode(ERRCODE_UNDEFINED_FUNCTION),
117  errmsg("could not find function \"%s\" in file \"%s\"",
118  funcname, fullname)));
119 
120  pfree(fullname);
121  return retval;
122 }
123 
124 /*
125  * This function loads a shlib file without looking up any particular
126  * function in it. If the same shlib has previously been loaded,
127  * unload and reload it.
128  *
129  * When 'restricted' is true, only libraries in the presumed-secure
130  * directory $libdir/plugins may be referenced.
131  */
132 void
133 load_file(const char *filename, bool restricted)
134 {
135  char *fullname;
136 
137  /* Apply security restriction if requested */
138  if (restricted)
140 
141  /* Expand the possibly-abbreviated filename to an exact path name */
142  fullname = expand_dynamic_library_name(filename);
143 
144  /* Unload the library if currently loaded */
145  internal_unload_library(fullname);
146 
147  /* Load the shared library */
148  (void) internal_load_library(fullname);
149 
150  pfree(fullname);
151 }
152 
153 /*
154  * Lookup a function whose library file is already loaded.
155  * Return (PGFunction) NULL if not found.
156  */
158 lookup_external_function(void *filehandle, char *funcname)
159 {
160  return (PGFunction) pg_dlsym(filehandle, funcname);
161 }
162 
163 
164 /*
165  * Load the specified dynamic-link library file, unless it already is
166  * loaded. Return the pg_dl* handle for the file.
167  *
168  * Note: libname is expected to be an exact name for the library file.
169  */
170 static void *
171 internal_load_library(const char *libname)
172 {
173  DynamicFileList *file_scanner;
174  PGModuleMagicFunction magic_func;
175  char *load_error;
176  struct stat stat_buf;
177  PG_init_t PG_init;
178 
179  /*
180  * Scan the list of loaded FILES to see if the file has been loaded.
181  */
182  for (file_scanner = file_list;
183  file_scanner != NULL &&
184  strcmp(libname, file_scanner->filename) != 0;
185  file_scanner = file_scanner->next)
186  ;
187 
188  if (file_scanner == NULL)
189  {
190  /*
191  * Check for same files - different paths (ie, symlink or link)
192  */
193  if (stat(libname, &stat_buf) == -1)
194  ereport(ERROR,
196  errmsg("could not access file \"%s\": %m",
197  libname)));
198 
199  for (file_scanner = file_list;
200  file_scanner != NULL &&
201  !SAME_INODE(stat_buf, *file_scanner);
202  file_scanner = file_scanner->next)
203  ;
204  }
205 
206  if (file_scanner == NULL)
207  {
208  /*
209  * File not loaded yet.
210  */
211  file_scanner = (DynamicFileList *)
212  malloc(offsetof(DynamicFileList, filename) +strlen(libname) + 1);
213  if (file_scanner == NULL)
214  ereport(ERROR,
215  (errcode(ERRCODE_OUT_OF_MEMORY),
216  errmsg("out of memory")));
217 
218  MemSet(file_scanner, 0, offsetof(DynamicFileList, filename));
219  strcpy(file_scanner->filename, libname);
220  file_scanner->device = stat_buf.st_dev;
221 #ifndef WIN32
222  file_scanner->inode = stat_buf.st_ino;
223 #endif
224  file_scanner->next = NULL;
225 
226  file_scanner->handle = pg_dlopen(file_scanner->filename);
227  if (file_scanner->handle == NULL)
228  {
229  load_error = (char *) pg_dlerror();
230  free((char *) file_scanner);
231  /* errcode_for_file_access might not be appropriate here? */
232  ereport(ERROR,
234  errmsg("could not load library \"%s\": %s",
235  libname, load_error)));
236  }
237 
238  /* Check the magic function to determine compatibility */
239  magic_func = (PGModuleMagicFunction)
241  if (magic_func)
242  {
243  const Pg_magic_struct *magic_data_ptr = (*magic_func) ();
244 
245  if (magic_data_ptr->len != magic_data.len ||
246  memcmp(magic_data_ptr, &magic_data, magic_data.len) != 0)
247  {
248  /* copy data block before unlinking library */
249  Pg_magic_struct module_magic_data = *magic_data_ptr;
250 
251  /* try to unlink library */
252  pg_dlclose(file_scanner->handle);
253  free((char *) file_scanner);
254 
255  /* issue suitable complaint */
256  incompatible_module_error(libname, &module_magic_data);
257  }
258  }
259  else
260  {
261  /* try to unlink library */
262  pg_dlclose(file_scanner->handle);
263  free((char *) file_scanner);
264  /* complain */
265  ereport(ERROR,
266  (errmsg("incompatible library \"%s\": missing magic block",
267  libname),
268  errhint("Extension libraries are required to use the PG_MODULE_MAGIC macro.")));
269  }
270 
271  /*
272  * If the library has a _PG_init() function, call it.
273  */
274  PG_init = (PG_init_t) pg_dlsym(file_scanner->handle, "_PG_init");
275  if (PG_init)
276  (*PG_init) ();
277 
278  /* OK to link it into list */
279  if (file_list == NULL)
280  file_list = file_scanner;
281  else
282  file_tail->next = file_scanner;
283  file_tail = file_scanner;
284  }
285 
286  return file_scanner->handle;
287 }
288 
289 /*
290  * Report a suitable error for an incompatible magic block.
291  */
292 static void
293 incompatible_module_error(const char *libname,
294  const Pg_magic_struct *module_magic_data)
295 {
296  StringInfoData details;
297 
298  /*
299  * If the version doesn't match, just report that, because the rest of the
300  * block might not even have the fields we expect.
301  */
302  if (magic_data.version != module_magic_data->version)
303  {
304  char library_version[32];
305 
306  if (module_magic_data->version >= 1000)
307  snprintf(library_version, sizeof(library_version), "%d",
308  module_magic_data->version / 100);
309  else
310  snprintf(library_version, sizeof(library_version), "%d.%d",
311  module_magic_data->version / 100,
312  module_magic_data->version % 100);
313  ereport(ERROR,
314  (errmsg("incompatible library \"%s\": version mismatch",
315  libname),
316  errdetail("Server is version %d, library is version %s.",
317  magic_data.version / 100, library_version)));
318  }
319 
320  /*
321  * Otherwise, spell out which fields don't agree.
322  *
323  * XXX this code has to be adjusted any time the set of fields in a magic
324  * block change!
325  */
326  initStringInfo(&details);
327 
328  if (module_magic_data->funcmaxargs != magic_data.funcmaxargs)
329  {
330  if (details.len)
331  appendStringInfoChar(&details, '\n');
332  appendStringInfo(&details,
333  _("Server has FUNC_MAX_ARGS = %d, library has %d."),
334  magic_data.funcmaxargs,
335  module_magic_data->funcmaxargs);
336  }
337  if (module_magic_data->indexmaxkeys != magic_data.indexmaxkeys)
338  {
339  if (details.len)
340  appendStringInfoChar(&details, '\n');
341  appendStringInfo(&details,
342  _("Server has INDEX_MAX_KEYS = %d, library has %d."),
343  magic_data.indexmaxkeys,
344  module_magic_data->indexmaxkeys);
345  }
346  if (module_magic_data->namedatalen != magic_data.namedatalen)
347  {
348  if (details.len)
349  appendStringInfoChar(&details, '\n');
350  appendStringInfo(&details,
351  _("Server has NAMEDATALEN = %d, library has %d."),
352  magic_data.namedatalen,
353  module_magic_data->namedatalen);
354  }
355  if (module_magic_data->float4byval != magic_data.float4byval)
356  {
357  if (details.len)
358  appendStringInfoChar(&details, '\n');
359  appendStringInfo(&details,
360  _("Server has FLOAT4PASSBYVAL = %s, library has %s."),
361  magic_data.float4byval ? "true" : "false",
362  module_magic_data->float4byval ? "true" : "false");
363  }
364  if (module_magic_data->float8byval != magic_data.float8byval)
365  {
366  if (details.len)
367  appendStringInfoChar(&details, '\n');
368  appendStringInfo(&details,
369  _("Server has FLOAT8PASSBYVAL = %s, library has %s."),
370  magic_data.float8byval ? "true" : "false",
371  module_magic_data->float8byval ? "true" : "false");
372  }
373 
374  if (details.len == 0)
375  appendStringInfoString(&details,
376  _("Magic block has unexpected length or padding difference."));
377 
378  ereport(ERROR,
379  (errmsg("incompatible library \"%s\": magic block mismatch",
380  libname),
381  errdetail_internal("%s", details.data)));
382 }
383 
384 /*
385  * Unload the specified dynamic-link library file, if it is loaded.
386  *
387  * Note: libname is expected to be an exact name for the library file.
388  *
389  * XXX for the moment, this is disabled, resulting in LOAD of an already-loaded
390  * library always being a no-op. We might re-enable it someday if we can
391  * convince ourselves we have safe protocols for un-hooking from hook function
392  * pointers, releasing custom GUC variables, and perhaps other things that
393  * are definitely unsafe currently.
394  */
395 static void
396 internal_unload_library(const char *libname)
397 {
398 #ifdef NOT_USED
399  DynamicFileList *file_scanner,
400  *prv,
401  *nxt;
402  struct stat stat_buf;
403  PG_fini_t PG_fini;
404 
405  /*
406  * We need to do stat() in order to determine whether this is the same
407  * file as a previously loaded file; it's also handy so as to give a good
408  * error message if bogus file name given.
409  */
410  if (stat(libname, &stat_buf) == -1)
411  ereport(ERROR,
413  errmsg("could not access file \"%s\": %m", libname)));
414 
415  /*
416  * We have to zap all entries in the list that match on either filename or
417  * inode, else internal_load_library() will still think it's present.
418  */
419  prv = NULL;
420  for (file_scanner = file_list; file_scanner != NULL; file_scanner = nxt)
421  {
422  nxt = file_scanner->next;
423  if (strcmp(libname, file_scanner->filename) == 0 ||
424  SAME_INODE(stat_buf, *file_scanner))
425  {
426  if (prv)
427  prv->next = nxt;
428  else
429  file_list = nxt;
430 
431  /*
432  * If the library has a _PG_fini() function, call it.
433  */
434  PG_fini = (PG_fini_t) pg_dlsym(file_scanner->handle, "_PG_fini");
435  if (PG_fini)
436  (*PG_fini) ();
437 
438  clear_external_function_hash(file_scanner->handle);
439  pg_dlclose(file_scanner->handle);
440  free((char *) file_scanner);
441  /* prv does not change */
442  }
443  else
444  prv = file_scanner;
445  }
446 #endif /* NOT_USED */
447 }
448 
449 static bool
450 file_exists(const char *name)
451 {
452  struct stat st;
453 
454  AssertArg(name != NULL);
455 
456  if (stat(name, &st) == 0)
457  return S_ISDIR(st.st_mode) ? false : true;
458  else if (!(errno == ENOENT || errno == ENOTDIR || errno == EACCES))
459  ereport(ERROR,
461  errmsg("could not access file \"%s\": %m", name)));
462 
463  return false;
464 }
465 
466 
467 /* Example format: ".so" */
468 #ifndef DLSUFFIX
469 #error "DLSUFFIX must be defined to compile this file."
470 #endif
471 
472 /*
473  * If name contains a slash, check if the file exists, if so return
474  * the name. Else (no slash) try to expand using search path (see
475  * find_in_dynamic_libpath below); if that works, return the fully
476  * expanded file name. If the previous failed, append DLSUFFIX and
477  * try again. If all fails, just return the original name.
478  *
479  * The result will always be freshly palloc'd.
480  */
481 static char *
483 {
484  bool have_slash;
485  char *new;
486  char *full;
487 
488  AssertArg(name);
489 
490  have_slash = (first_dir_separator(name) != NULL);
491 
492  if (!have_slash)
493  {
494  full = find_in_dynamic_libpath(name);
495  if (full)
496  return full;
497  }
498  else
499  {
500  full = substitute_libpath_macro(name);
501  if (file_exists(full))
502  return full;
503  pfree(full);
504  }
505 
506  new = psprintf("%s%s", name, DLSUFFIX);
507 
508  if (!have_slash)
509  {
510  full = find_in_dynamic_libpath(new);
511  pfree(new);
512  if (full)
513  return full;
514  }
515  else
516  {
517  full = substitute_libpath_macro(new);
518  pfree(new);
519  if (file_exists(full))
520  return full;
521  pfree(full);
522  }
523 
524  /*
525  * If we can't find the file, just return the string as-is. The ensuing
526  * load attempt will fail and report a suitable message.
527  */
528  return pstrdup(name);
529 }
530 
531 /*
532  * Check a restricted library name. It must begin with "$libdir/plugins/"
533  * and there must not be any directory separators after that (this is
534  * sufficient to prevent ".." style attacks).
535  */
536 static void
538 {
539  if (strncmp(name, "$libdir/plugins/", 16) != 0 ||
540  first_dir_separator(name + 16) != NULL)
541  ereport(ERROR,
542  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
543  errmsg("access to library \"%s\" is not allowed",
544  name)));
545 }
546 
547 /*
548  * Substitute for any macros appearing in the given string.
549  * Result is always freshly palloc'd.
550  */
551 static char *
553 {
554  const char *sep_ptr;
555 
556  AssertArg(name != NULL);
557 
558  /* Currently, we only recognize $libdir at the start of the string */
559  if (name[0] != '$')
560  return pstrdup(name);
561 
562  if ((sep_ptr = first_dir_separator(name)) == NULL)
563  sep_ptr = name + strlen(name);
564 
565  if (strlen("$libdir") != sep_ptr - name ||
566  strncmp(name, "$libdir", strlen("$libdir")) != 0)
567  ereport(ERROR,
568  (errcode(ERRCODE_INVALID_NAME),
569  errmsg("invalid macro name in dynamic library path: %s",
570  name)));
571 
572  return psprintf("%s%s", pkglib_path, sep_ptr);
573 }
574 
575 
576 /*
577  * Search for a file called 'basename' in the colon-separated search
578  * path Dynamic_library_path. If the file is found, the full file name
579  * is returned in freshly palloc'd memory. If the file is not found,
580  * return NULL.
581  */
582 static char *
583 find_in_dynamic_libpath(const char *basename)
584 {
585  const char *p;
586  size_t baselen;
587 
588  AssertArg(basename != NULL);
589  AssertArg(first_dir_separator(basename) == NULL);
591 
593  if (strlen(p) == 0)
594  return NULL;
595 
596  baselen = strlen(basename);
597 
598  for (;;)
599  {
600  size_t len;
601  char *piece;
602  char *mangled;
603  char *full;
604 
605  piece = first_path_var_separator(p);
606  if (piece == p)
607  ereport(ERROR,
608  (errcode(ERRCODE_INVALID_NAME),
609  errmsg("zero-length component in parameter \"dynamic_library_path\"")));
610 
611  if (piece == NULL)
612  len = strlen(p);
613  else
614  len = piece - p;
615 
616  piece = palloc(len + 1);
617  strlcpy(piece, p, len + 1);
618 
619  mangled = substitute_libpath_macro(piece);
620  pfree(piece);
621 
622  canonicalize_path(mangled);
623 
624  /* only absolute paths */
625  if (!is_absolute_path(mangled))
626  ereport(ERROR,
627  (errcode(ERRCODE_INVALID_NAME),
628  errmsg("component in parameter \"dynamic_library_path\" is not an absolute path")));
629 
630  full = palloc(strlen(mangled) + 1 + baselen + 1);
631  sprintf(full, "%s/%s", mangled, basename);
632  pfree(mangled);
633 
634  elog(DEBUG3, "find_in_dynamic_libpath: trying \"%s\"", full);
635 
636  if (file_exists(full))
637  return full;
638 
639  pfree(full);
640 
641  if (p[len] == '\0')
642  break;
643  else
644  p += len + 1;
645  }
646 
647  return NULL;
648 }
649 
650 
651 /*
652  * Find (or create) a rendezvous variable that one dynamically
653  * loaded library can use to meet up with another.
654  *
655  * On the first call of this function for a particular varName,
656  * a "rendezvous variable" is created with the given name.
657  * The value of the variable is a void pointer (initially set to NULL).
658  * Subsequent calls with the same varName just return the address of
659  * the existing variable. Once created, a rendezvous variable lasts
660  * for the life of the process.
661  *
662  * Dynamically loaded libraries can use rendezvous variables
663  * to find each other and share information: they just need to agree
664  * on the variable name and the data it will point to.
665  */
666 void **
667 find_rendezvous_variable(const char *varName)
668 {
669  static HTAB *rendezvousHash = NULL;
670 
671  rendezvousHashEntry *hentry;
672  bool found;
673 
674  /* Create a hashtable if we haven't already done so in this process */
675  if (rendezvousHash == NULL)
676  {
677  HASHCTL ctl;
678 
679  MemSet(&ctl, 0, sizeof(ctl));
680  ctl.keysize = NAMEDATALEN;
681  ctl.entrysize = sizeof(rendezvousHashEntry);
682  rendezvousHash = hash_create("Rendezvous variable hash",
683  16,
684  &ctl,
685  HASH_ELEM);
686  }
687 
688  /* Find or create the hashtable entry for this varName */
689  hentry = (rendezvousHashEntry *) hash_search(rendezvousHash,
690  varName,
691  HASH_ENTER,
692  &found);
693 
694  /* Initialize to NULL if first time */
695  if (!found)
696  hentry->varValue = NULL;
697 
698  return &hentry->varValue;
699 }
700 
701 /*
702  * Estimate the amount of space needed to serialize the list of libraries
703  * we have loaded.
704  */
705 Size
707 {
708  DynamicFileList *file_scanner;
709  Size size = 1;
710 
711  for (file_scanner = file_list;
712  file_scanner != NULL;
713  file_scanner = file_scanner->next)
714  size = add_size(size, strlen(file_scanner->filename) + 1);
715 
716  return size;
717 }
718 
719 /*
720  * Serialize the list of libraries we have loaded to a chunk of memory.
721  */
722 void
723 SerializeLibraryState(Size maxsize, char *start_address)
724 {
725  DynamicFileList *file_scanner;
726 
727  for (file_scanner = file_list;
728  file_scanner != NULL;
729  file_scanner = file_scanner->next)
730  {
731  Size len;
732 
733  len = strlcpy(start_address, file_scanner->filename, maxsize) + 1;
734  Assert(len < maxsize);
735  maxsize -= len;
736  start_address += len;
737  }
738  start_address[0] = '\0';
739 }
740 
741 /*
742  * Load every library the serializing backend had loaded.
743  */
744 void
745 RestoreLibraryState(char *start_address)
746 {
747  while (*start_address != '\0')
748  {
749  internal_load_library(start_address);
750  start_address += strlen(start_address) + 1;
751  }
752 }
char filename[FLEXIBLE_ARRAY_MEMBER]
Definition: dfmgr.c:51
void * varValue
Definition: dfmgr.c:35
#define SAME_INODE(A, B)
Definition: dfmgr.c:59
int errhint(const char *fmt,...)
Definition: elog.c:987
#define AssertState(condition)
Definition: c.h:674
int indexmaxkeys
Definition: fmgr.h:400
#define HASH_ELEM
Definition: hsearch.h:87
#define DEBUG3
Definition: elog.h:23
static void incompatible_module_error(const char *libname, const Pg_magic_struct *module_magic_data) pg_attribute_noreturn()
Definition: dfmgr.c:293
static char * substitute_libpath_macro(const char *name)
Definition: dfmgr.c:552
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition: fmgr.h:40
char * pstrdup(const char *in)
Definition: mcxt.c:1165
PGFunction lookup_external_function(void *filehandle, char *funcname)
Definition: dfmgr.c:158
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
int namedatalen
Definition: fmgr.h:401
Size entrysize
Definition: hsearch.h:73
void canonicalize_path(char *path)
Definition: path.c:254
static DynamicFileList * file_list
Definition: dfmgr.c:54
int errcode(int sqlerrcode)
Definition: elog.c:575
struct df_files DynamicFileList
#define MemSet(start, val, len)
Definition: c.h:853
#define pg_dlclose(h)
Definition: aix.h:36
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static char * expand_dynamic_library_name(const char *name)
Definition: dfmgr.c:482
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
#define pg_attribute_noreturn()
Definition: c.h:649
static void internal_unload_library(const char *libname)
Definition: dfmgr.c:396
void ** find_rendezvous_variable(const char *varName)
Definition: dfmgr.c:667
static const Pg_magic_struct magic_data
Definition: dfmgr.c:77
#define pg_dlopen(f)
Definition: aix.h:34
int errdetail_internal(const char *fmt,...)
Definition: elog.c:900
#define malloc(a)
Definition: header.h:45
#define NAMEDATALEN
Definition: dynahash.c:193
void pfree(void *pointer)
Definition: mcxt.c:992
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
void SerializeLibraryState(Size maxsize, char *start_address)
Definition: dfmgr.c:723
#define ERROR
Definition: elog.h:43
static bool file_exists(const char *name)
Definition: dfmgr.c:450
char * Dynamic_library_path
Definition: dfmgr.c:64
void * handle
Definition: dfmgr.c:50
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:189
int funcmaxargs
Definition: fmgr.h:399
int errdetail(const char *fmt,...)
Definition: elog.c:873
int errcode_for_file_access(void)
Definition: elog.c:598
#define is_absolute_path(filename)
Definition: port.h:77
static void * internal_load_library(const char *libname)
Definition: dfmgr.c:171
void clear_external_function_hash(void *filehandle)
Definition: fmgr.c:567
#define ereport(elevel, rest)
Definition: elog.h:122
#define AssertArg(condition)
Definition: c.h:673
#define pg_dlerror()
Definition: aix.h:37
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:201
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
PGFunction load_external_function(char *filename, char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:94
Definition: dfmgr.c:42
int float8byval
Definition: fmgr.h:403
#define PG_MAGIC_FUNCTION_NAME_STRING
Definition: fmgr.h:425
void RestoreLibraryState(char *start_address)
Definition: dfmgr.c:745
struct df_files * next
Definition: dfmgr.c:44
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:301
char * first_dir_separator(const char *filename)
Definition: path.c:103
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
Size EstimateLibraryStateSpace(void)
Definition: dfmgr.c:706
Size keysize
Definition: hsearch.h:72
dev_t device
Definition: dfmgr.c:45
#define free(a)
Definition: header.h:60
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
static void check_restricted_library_name(const char *name)
Definition: dfmgr.c:537
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:133
#define pg_dlsym(h, f)
Definition: aix.h:35
size_t Size
Definition: c.h:353
void(* PG_init_t)(void)
Definition: dfmgr.c:28
const char * name
Definition: encode.c:521
int float4byval
Definition: fmgr.h:402
#define PG_MODULE_MAGIC_DATA
Definition: fmgr.h:407
static DynamicFileList * file_tail
Definition: dfmgr.c:55
ino_t inode
Definition: dfmgr.c:48
static char * filename
Definition: pg_dumpall.c:80
void * palloc(Size size)
Definition: mcxt.c:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
const Pg_magic_struct *(* PGModuleMagicFunction)(void)
Definition: fmgr.h:422
#define _(x)
Definition: elog.c:84
char pkglib_path[MAXPGPATH]
Definition: globals.c:64
static char * find_in_dynamic_libpath(const char *basename)
Definition: dfmgr.c:583
char * first_path_var_separator(const char *pathlist)
Definition: path.c:120
#define offsetof(type, field)
Definition: c.h:551
int version
Definition: fmgr.h:398
void(* PG_fini_t)(void)
Definition: dfmgr.c:29