1ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* 2ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * This file is part of ltrace. 3f70812ec281a829ca7a758337aacec58eca41550Petr Machata * Copyright (C) 2012, 2013 Petr Machata, Red Hat Inc. 4ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * 5ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * This program is free software; you can redistribute it and/or 6ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * modify it under the terms of the GNU General Public License as 7ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * published by the Free Software Foundation; either version 2 of the 8ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * License, or (at your option) any later version. 9ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * 10ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * This program is distributed in the hope that it will be useful, but 11ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * WITHOUT ANY WARRANTY; without even the implied warranty of 12ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * General Public License for more details. 14ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * 15ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * You should have received a copy of the GNU General Public License 16ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * along with this program; if not, write to the Free Software 17ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * 02110-1301 USA 19ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata */ 20ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 21ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata#ifndef _PROTOTYPE_H_ 22ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata#define _PROTOTYPE_H_ 23ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 2482f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata#include <stdbool.h> 2582f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata 26ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata#include "forward.h" 27ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata#include "dict.h" 28ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata#include "vect.h" 29ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 30ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Function prototype. */ 31ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatastruct prototype { 32ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata /* Vector of struct param. */ 33ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata struct vect params; 34ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 35ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata struct arg_type_info *return_info; 36ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata int own_return_info : 1; 37ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata}; 38ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 39ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Initialize a prototype PROTO. The name will be NAME, and the 40ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * corresponding string will be owned and freed on destroy if 41ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * OWN_NAME. */ 42ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatavoid prototype_init(struct prototype *proto); 43ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 44ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Destroy PROTO (but don't free the memory block pointed-to by 45ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * PROTO). */ 46ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatavoid prototype_destroy(struct prototype *proto); 47ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 48ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Add new parameter PARAM to PROTO. The structure contents are 49ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * copied and PARAM pointer itself is not owned by PROTO. */ 50ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machataint prototype_push_param(struct prototype *proto, struct param *param); 51ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 52ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Return number of parameters of prototype. */ 53ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatasize_t prototype_num_params(struct prototype *proto); 54ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 55ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Destroy N-th parameter from PROTO. N shall be smaller than the 56ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * number of parameters. */ 57ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatavoid prototype_destroy_nth_param(struct prototype *proto, size_t n); 58ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 59ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Get N-th parameter of PROTO. N shall be smaller than the number of 60ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * parameters. */ 61ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatastruct param *prototype_get_nth_param(struct prototype *proto, size_t n); 62ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 63ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Iterate through the parameters of PROTO. See callback.h for notes 64ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * on iteration interfaces. */ 65ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatastruct param *prototype_each_param 66ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata (struct prototype *proto, struct param *start_after, 67ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata enum callback_status (*cb)(struct prototype *, struct param *, void *), 68ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata void *data); 69ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 70ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* For storing type aliases. */ 71ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatastruct named_type { 72ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata struct arg_type_info *info; 73ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata int forward : 1; 743ac9b91974678878889776221c390f39f5c2ffcfPetr Machata int own_type : 1; 75ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata}; 76ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 773ac9b91974678878889776221c390f39f5c2ffcfPetr Machata/* Initialize a named type INFO, which, if OWN_TYPE, is destroyed when 783ac9b91974678878889776221c390f39f5c2ffcfPetr Machata * named_type_destroy is called. */ 793ac9b91974678878889776221c390f39f5c2ffcfPetr Machatavoid named_type_init(struct named_type *named, 803ac9b91974678878889776221c390f39f5c2ffcfPetr Machata struct arg_type_info *info, int own_type); 813ac9b91974678878889776221c390f39f5c2ffcfPetr Machata 82ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatavoid named_type_destroy(struct named_type *named); 83ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 84ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* One prototype library. */ 85ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatastruct protolib { 86ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata /* Other libraries to look through if the definition is not 87ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * found here. Note that due to the way imports are stored, 88ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * there is no way to distinguish where exactly (at which 89ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * place of the config file) the import was made. */ 90ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata struct vect imports; 91ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 92ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata /* Dictionary of name->struct prototype. */ 93f7650d1e1c09e360a0cd27ee99b051cc9b127091Petr Machata struct dict prototypes; 94ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 95ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata /* Dictionary of name->struct named_type. */ 96f7650d1e1c09e360a0cd27ee99b051cc9b127091Petr Machata struct dict named_types; 977f1d856ea4882a23461886d0f589244cc11f0b2fPetr Machata 987f1d856ea4882a23461886d0f589244cc11f0b2fPetr Machata /* Reference count. */ 997f1d856ea4882a23461886d0f589244cc11f0b2fPetr Machata unsigned refs; 100ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata}; 101ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 102f7650d1e1c09e360a0cd27ee99b051cc9b127091Petr Machata/* Initialize PLIB. */ 103f7650d1e1c09e360a0cd27ee99b051cc9b127091Petr Machatavoid protolib_init(struct protolib *plib); 104ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 105ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Destroy PLIB. */ 106ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatavoid protolib_destroy(struct protolib *plib); 107ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 108ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Push IMPORT to PLIB. Returns 0 on success or a negative value on 109ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * failure. In particular, -2 is returned if mutual import is 110ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * detected. */ 111ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machataint protolib_add_import(struct protolib *plib, struct protolib *import); 112ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 113ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Add a prototype PROTO to PLIB. Returns 0 on success or a negative 114ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * value on failure. NAME is owned and released on PLIB destruction 115ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * if OWN_NAME. */ 116ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machataint protolib_add_prototype(struct protolib *plib, 117ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata const char *name, int own_name, 118ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata struct prototype *proto); 119ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 120ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Add a named type NAMED to PLIB. Returns 0 on success or a negative 121ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * value on failure. NAME is owned and released on PLIB destruction 1223ac9b91974678878889776221c390f39f5c2ffcfPetr Machata * if OWN_NAME. NAMED _pointer_ is copied to PLIB. */ 123ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machataint protolib_add_named_type(struct protolib *plib, 124ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata const char *name, int own_name, 125ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata struct named_type *named); 126ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 12782f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata/* Lookup prototype named NAME in PLIB. If none is found and IMPORTS 12882f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata * is true, look recursively in each of the imports. Returns the 12982f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata * corresponding prototype, or NULL if none was found. */ 130ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatastruct prototype *protolib_lookup_prototype(struct protolib *plib, 13182f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata const char *name, bool imports); 132ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 133ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* Add a named type NAMED to PLIB. Returns 0 on success or a negative 134ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * value on failure. */ 135ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machataint protolib_add_type(struct protolib *plib, struct named_type *named); 136ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 13782f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata/* Lookup type named NAME in PLIB. If none is found and IMPORTS is 13882f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata * true, look recursively in each of the imports. Returns the 13982f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata * corresponding type, or NULL if none was found. */ 140ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatastruct named_type *protolib_lookup_type(struct protolib *plib, 14182f748d1bc2b95d594327ad15f3a6908070dd5c3Petr Machata const char *name, bool imports); 142ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 143ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata/* A cache of prototype libraries. Can load prototype libraries on 144ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * demand. 145ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * 146ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * XXX ltrace should open one config per ABI, which maps long, int, 147ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * etc. to uint32_t etc. It would also map char to either of 148ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * {u,}int8_t. Other protolibs would have this as implicit import. 149ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * That would mean that the cache needs ABI tagging--each ABI should 150ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * have a separate prototype cache, because the types will potentially 151ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * differ between the ABI's. protolib cache would then naturally be 152ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata * stored in the ABI object, when this is introduced. */ 153ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machatastruct protolib_cache { 15482ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata /* Dictionary of filename->protolib*. */ 15582ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata struct dict protolibs; 15682ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata 15782ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata /* Fake module for implicit imports. This is populated by all 15882ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * files coming from -F. When -F is empty, it also contains 15982ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * either $HOME/.ltrace.conf, or /etc/ltrace.conf (whichever 16082ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * comes first). */ 16182ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata struct protolib imports; 16282ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata 16382ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata /* For tracking uses of cache during cache's own 16482ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * initialization. */ 16582ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata int bootstrap : 1; 166ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata}; 167ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 16882ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata/* Initialize CACHE. Returns 0 on success or a negative value on 16982ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * failure. */ 17082ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machataint protolib_cache_init(struct protolib_cache *cache, 17182ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata struct protolib *import); 17282ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata 17382ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata/* Destroy CACHE. */ 17482ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machatavoid protolib_cache_destroy(struct protolib_cache *cache); 17582ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata 17682ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata/* Get protolib corresponding to KEY from CACHE. KEY would typically 17782ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * be the soname of a library for which a protolib should be obtained. 17882ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * If none has been loaded yet, load a new protolib, cache and return 17982ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * it. Returns NULL for failures. 18082ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * 18182ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * Protolibs are loaded from a config directory. If -F contains 18282ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * directory names, those are checked first. Next, os_get_config_dirs 18382ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * callback is used to get a list of directories to look into. In the 18482ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * first round, if ALLOW_PRIVATE, ltrace looks in user's private 18582ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * directories. If the config file wasn't found, the second round is 18698a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * made through system directories. In each directory, ltrace looks 18798a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * and reads the file named KEY.conf. 18882ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * 18998a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * If the config file still wasn't found, an empty (but non-NULL) 19098a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * protolib is provided instead. That is augmented with the following 19198a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * imports: 19282ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * 19382ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * - Legacy typedefs 19498a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * - The IMPORT argument passed to protolib_cache_init, if non-NULL 19598a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * - $HOME/.ltrace.conf if available 19698a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * - @sysconfdir@/ltrace.conf if available 19782ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * - Any configure _files_ passed in -F 19882ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * 19982ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * This function returns either the loaded protolib, or NULL when 20082ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * there was an error. */ 20198a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machatastruct protolib *protolib_cache_load(struct protolib_cache *cache, 20298a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata const char *key, int own_key, 20398a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata bool allow_private); 20482ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata 20598a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata/* This is similar to protolib_cache_load, except that if a protolib 20698a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * is not found NULL is returned instead of a default module. 20798a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * 20898a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * It returns 0 for success and a negative value for failure, and the 20998a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * actual return value is passed via *RET.*/ 21098a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machataint protolib_cache_maybe_load(struct protolib_cache *cache, 21198a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata const char *key, int own_key, 21298a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata bool allow_private, 21398a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata struct protolib **ret); 21498a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata 21598a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata/* This is similar to protolib_cache_load, but instead of looking for 21698a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * the file to load in directories, the filename is given. */ 21782ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machatastruct protolib *protolib_cache_file(struct protolib_cache *cache, 218a5e983bd5555c496a209f3e3a48e2826940b09f5Petr Machata const char *filename, int own_filename); 21982ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata 22098a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata/* This caches a default module. This is what protolib_cache_load 22198a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * calls if it fails to find the actual protolib. Returns default 22298a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata * protolib or NULL if there was an error. */ 22398a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machatastruct protolib *protolib_cache_default(struct protolib_cache *cache, 22498a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata const char *key, int own_key); 22598a7dce70986f2394d22ee5dd8ed355ceb2104b4Petr Machata 22682ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata/* This is similar to protolib_cache_file, but the library to cache is 22782ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * given in argument. Returns 0 on success or a negative value on 22882ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata * failure. PLIB is thereafter owned by CACHE. */ 22982ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machataint protolib_cache_protolib(struct protolib_cache *cache, 230a5e983bd5555c496a209f3e3a48e2826940b09f5Petr Machata const char *filename, int own_filename, 23182ce0f8e3aefc3f833e7059f3cedeacedca0cad2Petr Machata struct protolib *plib); 232ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 23308cdf328add7b723b94b151866e5d0173662f6c6Petr Machata/* Single global prototype cache. 23408cdf328add7b723b94b151866e5d0173662f6c6Petr Machata * 23508cdf328add7b723b94b151866e5d0173662f6c6Petr Machata * XXX Eventually each ABI should have its own cache. The idea is 23608cdf328add7b723b94b151866e5d0173662f6c6Petr Machata * that there's one per-ABI config file that all others use for 23708cdf328add7b723b94b151866e5d0173662f6c6Petr Machata * elementary typedefs (long, char, size_t). Ltrace then only deals 23808cdf328add7b723b94b151866e5d0173662f6c6Petr Machata * in fixed-width integral types (and pointers etc.). */ 23908cdf328add7b723b94b151866e5d0173662f6c6Petr Machataextern struct protolib_cache g_protocache; 24008cdf328add7b723b94b151866e5d0173662f6c6Petr Machata 24108cdf328add7b723b94b151866e5d0173662f6c6Petr Machatavoid init_global_config(void); 242ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata 243ebc56a70e20ca0b3fc49c0eb5fc83e56c5e1fa5bPetr Machata#endif /* _PROTOTYPE_H_ */ 244