libctf: hashing
[deliverable/binutils-gdb.git] / libctf / ctf-impl.h
1 /* Implementation header.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3
4 This file is part of libctf.
5
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
9 version.
10
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.
15
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/>. */
19
20 #ifndef _CTF_IMPL_H
21 #define _CTF_IMPL_H
22
23 #include "config.h"
24 #include <sys/errno.h>
25 #include <ctf-api.h>
26 #include <sys/types.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <stdint.h>
31 #include <limits.h>
32 #include <ctype.h>
33 #include <elf.h>
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39
40 /* Compiler attributes. */
41
42 #if defined (__GNUC__)
43
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
47 may be required. */
48
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__. */
52
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__))
58
59 #endif
60
61 /* libctf in-memory state. */
62
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. */
65
66 typedef struct ctf_list
67 {
68 struct ctf_list *l_prev; /* Previous pointer or tail pointer. */
69 struct ctf_list *l_next; /* Next pointer or head pointer. */
70 } ctf_list_t;
71
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);
75
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 *);
79
80 typedef void (*ctf_hash_free_fun) (void *);
81
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 *);
88
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 *);
95
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))
98
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 *);
102
103 extern const char *ctf_strraw (ctf_file_t *, uint32_t);
104 extern const char *ctf_strptr (ctf_file_t *, uint32_t);
105
106 extern void *ctf_set_open_errno (int *, int);
107 extern long ctf_set_errno (ctf_file_t *, int);
108
109 _libctf_malloc_
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);
113
114 _libctf_malloc_
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);
118
119 _libctf_malloc_
120 extern void *ctf_alloc (size_t);
121 extern void ctf_free (void *);
122
123 _libctf_malloc_
124 extern char *ctf_strdup (const char *);
125 extern char *ctf_str_append (char *, const char *);
126 extern const char *ctf_strerror (int);
127
128 _libctf_printflike_ (1, 2)
129 extern void ctf_dprintf (const char *, ...);
130 extern void libctf_init_debug (void);
131
132 extern Elf64_Sym *ctf_sym_to_elf64 (const Elf32_Sym *src, Elf64_Sym *dst);
133
134 extern int _libctf_debug; /* debugging messages enabled */
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif /* _CTF_IMPL_H */
This page took 0.041511 seconds and 5 git commands to generate.