| 1 | /* |
| 2 | * Copyright 2011 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: |
| 20 | * Daniel Kopecek <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 24 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 25 | #endif |
| 26 | |
| 27 | #include <stddef.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <pthread.h> |
| 31 | #include <sexp.h>cxx . . $ `<file>/src/OVAL/probes/SEAP/public/sexp.h`/ |
| 32 | |
| 33 | #include "common/bfind.h"cxx . . $ `<file>/src/common/bfind.h`/ |
| 34 | |
| 35 | #include "ncache.h"cxx . . $ `<file>/src/OVAL/probes/probe/ncache.h`/ |
| 36 | |
| 37 | /** |
| 38 | * Lock cache for reading. |
| 39 | * @param c element name cache |
| 40 | * @param r return value on failure |
| 41 | */ |
| 42 | #define PROBE_NCACHE_RLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:42:9`!(c,r) \ |
| 43 | do { \ |
| 44 | if (pthread_rwlock_rdlock (&(c)->lock) != 0) \ |
| 45 | return (r); \ |
| 46 | } while (0) |
| 47 | |
| 48 | /** |
| 49 | * Unlock cache which was previously locked for reading. |
| 50 | * @param c element name cache |
| 51 | * @return this function calls abort(3) if it is unable to |
| 52 | * unlock the cache so as to prevent a deadlock. |
| 53 | */ |
| 54 | #define PROBE_NCACHE_RUNLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:54:9`!(c) \ |
| 55 | do { \ |
| 56 | if (pthread_rwlock_unlock (&(c)->lock) != 0) \ |
| 57 | abort (); \ |
| 58 | } while (0) |
| 59 | |
| 60 | /** |
| 61 | * Lock cache for writing. |
| 62 | * @param c element name cache |
| 63 | * @param r return value on failure |
| 64 | */ |
| 65 | #define PROBE_NCACHE_WLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:65:9`!(c,r) \ |
| 66 | do { \ |
| 67 | if (pthread_rwlock_wrlock (&(c)->lock) != 0) \ |
| 68 | return (r); \ |
| 69 | } while (0) |
| 70 | |
| 71 | /** |
| 72 | * Unlock cache which was previously locked for writing. |
| 73 | * @param c element name cache |
| 74 | * @return this function calls abort(3) if it is unable to |
| 75 | * unlock the cache so as to prevent a deadlock. |
| 76 | */ |
| 77 | #define PROBE_NCACHE_WUNLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:77:9`!(c) PROBE_NCACHE_RUNLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:54:9`!(c) |
| 78 | |
| 79 | probe_ncache_tcxx . . $ probe_ncache_t# *probe_ncache_newcxx . . $ probe_ncache_new(e2066d1f01a5893b). (void) |
| 80 | { |
| 81 | probe_ncache_tcxx . . $ probe_ncache_t# *cache = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(probe_ncache_tcxx . . $ probe_ncache_t#)); |
| 82 | |
| 83 | if (pthread_rwlock_initcxx . . $ pthread_rwlock_init(fc6013e2b28f9555). (&cache->lockcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#lock., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) != 0) { |
| 84 | freecxx . . $ free(5d22bdacc48458e8). (cache); |
| 85 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 86 | } |
| 87 | |
| 88 | cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name. = calloccxx . . $ calloc(63a7bf2941bfcd7a). (PROBE_NCACHE_INIT_SIZEcxx . . $ `src/OVAL/probes/probe/ncache.h:29:9`!, sizeof (SEXP_tcxx . . $ SEXP_t# *)); |
| 89 | cache->sizecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#size. = PROBE_NCACHE_INIT_SIZEcxx . . $ `src/OVAL/probes/probe/ncache.h:29:9`!; |
| 90 | cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real. = 0; |
| 91 | |
| 92 | return (cache); |
| 93 | } |
| 94 | |
| 95 | void probe_ncache_freecxx . . $ probe_ncache_free(c0ad2c06e7dc4d8f). (probe_ncache_tcxx . . $ probe_ncache_t# *cache) |
| 96 | { |
| 97 | size_t i; |
| 98 | |
| 99 | if (cache == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | for (i = 0; i < cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real.; ++i) |
| 104 | if (cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name.[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 105 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name.[i]); |
| 106 | |
| 107 | freecxx . . $ free(5d22bdacc48458e8). (cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name.); |
| 108 | pthread_rwlock_destroycxx . . $ pthread_rwlock_destroy(e530de6d038c3578). (&cache->lockcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#lock.); |
| 109 | freecxx . . $ free(5d22bdacc48458e8). (cache); |
| 110 | |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | void probe_ncache_clearcxx . . $ probe_ncache_clear(c0ad2c06e7dc4d8f). (probe_ncache_tcxx . . $ probe_ncache_t# *cache) |
| 115 | { |
| 116 | size_t i; |
| 117 | |
| 118 | if (cache == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 119 | return; |
| 120 | |
| 121 | if (pthread_rwlock_wrlockcxx . . $ pthread_rwlock_wrlock(e530de6d038c3578).(&(cache)->lockcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#lock.)) |
| 122 | return; |
| 123 | for (i = 0; i < cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real.; ++i) |
| 124 | if (cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name.[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 125 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name.[i]); |
| 126 | cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real. = 0; |
| 127 | if (pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&(cache)->lockcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#lock.)) |
| 128 | abortcxx . . $ abort(8df32a62017fbbf6).(); |
| 129 | } |
| 130 | |
| 131 | static int probe_ncache_cmp1cxx . . $ probe_ncache_cmp1(12e0941ff31e22b). (const char *name, const SEXP_tcxx . . $ SEXP_t# **sexp) |
| 132 | { |
| 133 | return ((-1) * SEXP_strcmpcxx . . $ SEXP_strcmp(3ef1a37bcb3c2a). (*sexp, name)); |
| 134 | } |
| 135 | |
| 136 | static int probe_ncache_cmp2cxx . . $ probe_ncache_cmp2(30a029ab7499ce09). (const SEXP_tcxx . . $ SEXP_t# **a, const SEXP_tcxx . . $ SEXP_t# **b) |
| 137 | { |
| 138 | return SEXP_string_cmpcxx . . $ SEXP_string_cmp(40f0d25f01d6dc5f). (*a, *b); |
| 139 | } |
| 140 | |
| 141 | SEXP_tcxx . . $ SEXP_t# *probe_ncache_addcxx . . $ probe_ncache_add(be2a40239769fba4). (probe_ncache_tcxx . . $ probe_ncache_t# *cache, const char *name) |
| 142 | { |
| 143 | SEXP_tcxx . . $ SEXP_t# *ref; |
| 144 | |
| 145 | if (cache == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 146 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 147 | } |
| 148 | |
| 149 | ref = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2). (name, strlencxx . . $ strlen(751346f8406fd082). (name)); |
| 150 | |
| 151 | if (ref == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 152 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 153 | |
| 154 | PROBE_NCACHE_WLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:65:9`!(cache, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 155 | |
| 156 | if (cache->sizecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#size. <= cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real.) { |
| 157 | void *new_name = realloccxx . . $ realloc(417ab160f6baadc6). (cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name., sizeof (SEXP_tcxx . . $ SEXP_t# *) * (cache->sizecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#size. + PROBE_NCACHE_ADD_SIZEcxx . . $ `src/OVAL/probes/probe/ncache.h:30:9`!)); |
| 158 | if (new_name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 159 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(ref); |
| 160 | PROBE_NCACHE_WUNLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:77:9`!(cache); |
| 161 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 162 | } |
| 163 | cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name. = new_name; |
| 164 | cache->sizecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#size. += PROBE_NCACHE_ADD_SIZEcxx . . $ `src/OVAL/probes/probe/ncache.h:30:9`!; |
| 165 | } |
| 166 | |
| 167 | cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name.[cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real.] = ref; |
| 168 | ++cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real.; |
| 169 | |
| 170 | ref = SEXP_refcxx . . $ SEXP_ref(2f7f980afaaae0f0). (ref); |
| 171 | qsortcxx . . $ qsort(ebb60b13a65e77d7). (cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name., cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real., sizeof (SEXP_tcxx . . $ SEXP_t# *), (int (*)(const void *, const void *)) &probe_ncache_cmp2cxx . . $ probe_ncache_cmp2(30a029ab7499ce09).); |
| 172 | |
| 173 | PROBE_NCACHE_WUNLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:77:9`!(cache); |
| 174 | |
| 175 | return (ref); |
| 176 | } |
| 177 | |
| 178 | SEXP_tcxx . . $ SEXP_t# *probe_ncache_getcxx . . $ probe_ncache_get(be2a40239769fba4). (probe_ncache_tcxx . . $ probe_ncache_t# *cache, const char *name) |
| 179 | { |
| 180 | SEXP_tcxx . . $ SEXP_t# **ref = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 181 | |
| 182 | if (cache == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 183 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 184 | } |
| 185 | |
| 186 | PROBE_NCACHE_RLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:42:9`!(cache, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 187 | |
| 188 | if (cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real. > 0) { |
| 189 | ref = (SEXP_tcxx . . $ SEXP_t# **)oscap_bfindcxx . . $ oscap_bfind(55e9dbee426f048c). (cache->namecxx . . $ $anonymous_type_d167a6ed189dc5d9_0#name., cache->realcxx . . $ $anonymous_type_d167a6ed189dc5d9_0#real., sizeof (SEXP_tcxx . . $ SEXP_t# *), |
| 190 | (void *)name, (int (*)(void *, void *))&probe_ncache_cmp1cxx . . $ probe_ncache_cmp1(12e0941ff31e22b).); |
| 191 | |
| 192 | if (ref != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 193 | ref = (SEXP_tcxx . . $ SEXP_t# **)SEXP_refcxx . . $ SEXP_ref(2f7f980afaaae0f0). (*ref); |
| 194 | } |
| 195 | |
| 196 | PROBE_NCACHE_RUNLOCKcxx . . $ `src/OVAL/probes/probe/ncache.c:54:9`!(cache); |
| 197 | |
| 198 | return ((SEXP_tcxx . . $ SEXP_t# *)(ref)); |
| 199 | } |
| 200 | |
| 201 | SEXP_tcxx . . $ SEXP_t# *probe_ncache_refcxx . . $ probe_ncache_ref(be2a40239769fba4). (probe_ncache_tcxx . . $ probe_ncache_t# *cache, const char *name) |
| 202 | { |
| 203 | SEXP_tcxx . . $ SEXP_t# *ref; |
| 204 | |
| 205 | if (name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 206 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 207 | } |
| 208 | |
| 209 | if (cache == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 210 | return SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2). (name, strlencxx . . $ strlen(751346f8406fd082). (name)); |
| 211 | |
| 212 | ref = probe_ncache_getcxx . . $ probe_ncache_get(be2a40239769fba4). (cache, name); |
| 213 | |
| 214 | if (ref == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 215 | ref = probe_ncache_addcxx . . $ probe_ncache_add(be2a40239769fba4). (cache, name); |
| 216 | |
| 217 | return (ref); |
| 218 | } |