1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* Generate kernel symbol version hashes. 3 Copyright 1996, 1997 Linux International. 4 5 New implementation contributed by Richard Henderson <rth@tamu.edu> 6 Based on original work by Bjorn Ekwall <bj0rn@blox.se> 7 8 This file is part of the Linux modutils. 9 10 */ 11 12 #ifndef MODUTILS_GENKSYMS_H 13 #define MODUTILS_GENKSYMS_H 1 14 15 #include <stdio.h> 16 17 #include <list_types.h> 18 19 enum symbol_type { 20 SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION, 21 SYM_ENUM_CONST 22 }; 23 24 enum symbol_status { 25 STATUS_UNCHANGED, STATUS_DEFINED, STATUS_MODIFIED 26 }; 27 28 struct string_list { 29 struct string_list *next; 30 enum symbol_type tag; 31 int in_source_file; 32 char *string; 33 }; 34 35 struct symbol { 36 struct hlist_node hnode; 37 char *name; 38 enum symbol_type type; 39 struct string_list *defn; 40 struct symbol *expansion_trail; 41 struct symbol *visited; 42 int is_extern; 43 int is_declared; 44 enum symbol_status status; 45 int is_override; 46 }; 47 48 typedef struct string_list **yystype; 49 #define YYSTYPE yystype 50 51 extern int cur_line; 52 extern char *cur_filename; 53 extern int in_source_file; 54 55 struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact); 56 struct symbol *add_symbol(const char *name, enum symbol_type type, 57 struct string_list *defn, int is_extern); 58 void export_symbol(const char *); 59 60 void free_node(struct string_list *list); 61 void free_list(struct string_list *s, struct string_list *e); 62 struct string_list *copy_node(struct string_list *); 63 struct string_list *copy_list_range(struct string_list *start, 64 struct string_list *end); 65 66 int yylex(void); 67 int yyparse(void); 68 69 void error_with_pos(const char *, ...) __attribute__ ((format(printf, 1, 2))); 70 71 /*----------------------------------------------------------------------*/ 72 #define xmalloc(size) ({ void *__ptr = malloc(size); \ 73 if(!__ptr && size != 0) { \ 74 fprintf(stderr, "out of memory\n"); \ 75 exit(1); \ 76 } \ 77 __ptr; }) 78 #define xstrdup(str) ({ char *__str = strdup(str); \ 79 if (!__str) { \ 80 fprintf(stderr, "out of memory\n"); \ 81 exit(1); \ 82 } \ 83 __str; }) 84 85 #endif /* genksyms.h */ 86