libctf: library version enforcement
authorNick Alcock <nick.alcock@oracle.com>
Wed, 24 Apr 2019 10:26:42 +0000 (11:26 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Tue, 28 May 2019 16:08:29 +0000 (17:08 +0100)
This old Solaris standard allows callers to specify that they are
expecting one particular API and/or CTF file format from the library.

libctf/
* ctf-impl.h (_libctf_version): New declaration.
* ctf-subr.c (_libctf_version): Define it.
(ctf_version): New.

include/
* ctf-api.h (ctf_version): New.

include/ChangeLog
include/ctf-api.h
libctf/ChangeLog
libctf/ctf-impl.h
libctf/ctf-subr.c

index 4be07a55319bfce7382abe33ca36e1c76a9f9ad1..56922add8a814caa57887c06d6a590ff488d181a 100644 (file)
@@ -1,3 +1,7 @@
+2019-05-28  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-api.h (ctf_version): New.
+
 2019-05-28  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-api.h (ctf_func_info): New.
index 045d8af19054a71cfa1a25e59b231c3fc849aa09..6ab754a1840c09147fe2931705ba826149e194b1 100644 (file)
@@ -269,6 +269,7 @@ extern void *ctf_getspecific (ctf_file_t *);
 
 extern int ctf_errno (ctf_file_t *);
 extern const char *ctf_errmsg (int);
+extern int ctf_version (int);
 
 extern int ctf_func_info (ctf_file_t *, unsigned long, ctf_funcinfo_t *);
 extern int ctf_func_args (ctf_file_t *, unsigned long, uint32_t, ctf_id_t *);
index c0c98d2f43f13828ea27ae4f898e22f91f929935..a6eb11ee3094dc06c7f1a4ec267e61325bc7b5fd 100644 (file)
@@ -1,3 +1,9 @@
+2019-05-28  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-impl.h (_libctf_version): New declaration.
+       * ctf-subr.c (_libctf_version): Define it.
+       (ctf_version): New.
+
 2019-05-28  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-create.c (enumcmp): New.
index ff185049f91fad35da9756614c5de9122f771657..363b62de7dba8426c80a9a26c7646d4a3c97f6fb 100644 (file)
@@ -375,6 +375,7 @@ extern const char *ctf_lookup_symbol_name (ctf_file_t *fp, unsigned long symidx)
 extern const char _CTF_SECTION[];      /* name of CTF ELF section */
 extern const char _CTF_NULLSTR[];      /* empty string */
 
+extern int _libctf_version;    /* library client version */
 extern int _libctf_debug;      /* debugging messages enabled */
 
 #ifdef __cplusplus
index 3103e28a3f3d62c27db4c9f616296713899ea160..09ec2951e5419d7ced577571a5107e6f6302542c 100644 (file)
@@ -27,6 +27,7 @@
 #include <unistd.h>
 
 static size_t _PAGESIZE _libctf_unused_;
+int _libctf_version = CTF_VERSION;           /* Library client version.  */
 int _libctf_debug = 0;                       /* Debugging messages enabled.  */
 
 _libctf_malloc_ void *
@@ -190,6 +191,32 @@ ctf_strerror (int err)
   return (const char *) (strerror (err));
 }
 
+/* Set the CTF library client version to the specified version.  If version is
+   zero, we just return the default library version number.  */
+int
+ctf_version (int version)
+{
+  if (version < 0)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  if (version > 0)
+    {
+      /*  Dynamic version switching is not presently supported. */
+      if (version != CTF_VERSION)
+       {
+         errno = ENOTSUP;
+         return -1;
+       }
+      ctf_dprintf ("ctf_version: client using version %d\n", version);
+      _libctf_version = version;
+    }
+
+  return _libctf_version;
+}
+
 void
 libctf_init_debug (void)
 {
This page took 0.027066 seconds and 4 git commands to generate.