1 /* Implementation header.
2 Copyright (C) 2019 Free Software Foundation, Inc.
4 This file is part of libctf.
6 libctf is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING. If not see
18 <http://www.gnu.org/licenses/>. */
24 #include <sys/errno.h>
26 #include <sys/types.h>
40 /* Compiler attributes. */
42 #if defined (__GNUC__)
44 /* GCC. We assume that all compilers claiming to be GCC support sufficiently
45 many GCC attributes that the code below works. If some non-GCC compilers
46 masquerading as GCC in fact do not implement these attributes, version checks
49 /* We use the _libctf_*_ pattern to avoid clashes with any future attribute
50 macros glibc may introduce, which have names of the pattern
51 __attribute_blah__. */
53 #define _libctf_printflike_(string_index,first_to_check) \
54 __attribute__ ((__format__ (__printf__, (string_index), (first_to_check))))
55 #define _libctf_unlikely_(x) __builtin_expect ((x), 0)
56 #define _libctf_unused_ __attribute__ ((__unused__))
57 #define _libctf_malloc_ __attribute__((__malloc__))
61 /* libctf in-memory state. */
63 typedef struct ctf_fixed_hash ctf_hash_t
; /* Private to ctf-hash.c. */
64 typedef struct ctf_dynhash ctf_dynhash_t
; /* Private to ctf-hash.c. */
66 typedef struct ctf_list
68 struct ctf_list
*l_prev
; /* Previous pointer or tail pointer. */
69 struct ctf_list
*l_next
; /* Next pointer or head pointer. */
72 typedef unsigned int (*ctf_hash_fun
) (const void *ptr
);
73 extern unsigned int ctf_hash_integer (const void *ptr
);
74 extern unsigned int ctf_hash_string (const void *ptr
);
76 typedef int (*ctf_hash_eq_fun
) (const void *, const void *);
77 extern int ctf_hash_eq_integer (const void *, const void *);
78 extern int ctf_hash_eq_string (const void *, const void *);
80 typedef void (*ctf_hash_free_fun
) (void *);
82 extern ctf_hash_t
*ctf_hash_create (unsigned long, ctf_hash_fun
, ctf_hash_eq_fun
);
83 extern int ctf_hash_insert_type (ctf_hash_t
*, ctf_file_t
*, uint32_t, uint32_t);
84 extern int ctf_hash_define_type (ctf_hash_t
*, ctf_file_t
*, uint32_t, uint32_t);
85 extern ctf_id_t
ctf_hash_lookup_type (ctf_hash_t
*, ctf_file_t
*, const char *);
86 extern uint32_t ctf_hash_size (const ctf_hash_t
*);
87 extern void ctf_hash_destroy (ctf_hash_t
*);
89 extern ctf_dynhash_t
*ctf_dynhash_create (ctf_hash_fun
, ctf_hash_eq_fun
,
90 ctf_hash_free_fun
, ctf_hash_free_fun
);
91 extern int ctf_dynhash_insert (ctf_dynhash_t
*, void *, void *);
92 extern void ctf_dynhash_remove (ctf_dynhash_t
*, const void *);
93 extern void *ctf_dynhash_lookup (ctf_dynhash_t
*, const void *);
94 extern void ctf_dynhash_destroy (ctf_dynhash_t
*);
96 #define ctf_list_prev(elem) ((void *)(((ctf_list_t *)(elem))->l_prev))
97 #define ctf_list_next(elem) ((void *)(((ctf_list_t *)(elem))->l_next))
99 extern void ctf_list_append (ctf_list_t
*, void *);
100 extern void ctf_list_prepend (ctf_list_t
*, void *);
101 extern void ctf_list_delete (ctf_list_t
*, void *);
103 extern const char *ctf_strraw (ctf_file_t
*, uint32_t);
104 extern const char *ctf_strptr (ctf_file_t
*, uint32_t);
106 extern void *ctf_set_open_errno (int *, int);
107 extern long ctf_set_errno (ctf_file_t
*, int);
110 extern void *ctf_data_alloc (size_t);
111 extern void ctf_data_free (void *, size_t);
112 extern void ctf_data_protect (void *, size_t);
115 extern void *ctf_mmap (size_t length
, size_t offset
, int fd
);
116 extern void ctf_munmap (void *, size_t);
117 extern ssize_t
ctf_pread (int fd
, void *buf
, ssize_t count
, off_t offset
);
120 extern void *ctf_alloc (size_t);
121 extern void ctf_free (void *);
124 extern char *ctf_strdup (const char *);
125 extern char *ctf_str_append (char *, const char *);
126 extern const char *ctf_strerror (int);
128 _libctf_printflike_ (1, 2)
129 extern void ctf_dprintf (const char *, ...);
130 extern void libctf_init_debug (void);
132 extern Elf64_Sym
*ctf_sym_to_elf64 (const Elf32_Sym
*src
, Elf64_Sym
*dst
);
134 extern int _libctf_debug
; /* debugging messages enabled */
140 #endif /* _CTF_IMPL_H */