X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=libctf%2Fctf-subr.c;h=114df84321211449671543c53ffc8ac5b6d155b1;hb=cf00cd6faf31c208bbfe107140c26895412214bb;hp=3103e28a3f3d62c27db4c9f616296713899ea160;hpb=60da9d955964759b1f52690bff587ad32a198507;p=deliverable%2Fbinutils-gdb.git diff --git a/libctf/ctf-subr.c b/libctf/ctf-subr.c index 3103e28a3f..114df84321 100644 --- a/libctf/ctf-subr.c +++ b/libctf/ctf-subr.c @@ -1,5 +1,5 @@ /* Simple subrs. - Copyright (C) 2019 Free Software Foundation, Inc. + Copyright (C) 2019-2020 Free Software Foundation, Inc. This file is part of libctf. @@ -26,48 +26,9 @@ #include #include -static size_t _PAGESIZE _libctf_unused_; +int _libctf_version = CTF_VERSION; /* Library client version. */ int _libctf_debug = 0; /* Debugging messages enabled. */ -_libctf_malloc_ void * -ctf_data_alloc (size_t size) -{ - void *ret; - -#ifdef HAVE_MMAP - if (_PAGESIZE == 0) - _PAGESIZE = sysconf(_SC_PAGESIZE); - - if (size > _PAGESIZE) - { - ret = mmap (NULL, size, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANON, -1, 0); - if (ret == MAP_FAILED) - ret = NULL; - } - else - ret = calloc (1, size); -#else - ret = calloc (1, size); -#endif - return ret; -} - -void -ctf_data_free (void *buf, size_t size _libctf_unused_) -{ -#ifdef HAVE_MMAP - /* Must be the same as the check in ctf_data_alloc(). */ - - if (size > _PAGESIZE) - (void) munmap (buf, size); - else - free (buf); -#else - free (buf); -#endif -} - /* Private, read-only mmap from a file, with fallback to copying. No handling of page-offset issues at all: the caller must allow for that. */ @@ -104,29 +65,6 @@ ctf_munmap (void *buf, size_t length _libctf_unused_) #endif } -void -ctf_data_protect (void *buf, size_t size) -{ -#ifdef HAVE_MMAP - /* Must be the same as the check in ctf_data_alloc(). */ - - if (size > _PAGESIZE) - (void) mprotect (buf, size, PROT_READ); -#endif -} - -_libctf_malloc_ void * -ctf_alloc (size_t size) -{ - return (malloc (size)); -} - -void -ctf_free (void *buf) -{ - free (buf); -} - ssize_t ctf_pread (int fd, void *buf, ssize_t count, off_t offset) { @@ -190,6 +128,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) {