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 <[email protected]> 6 Based on original work by Bjorn Ekwall <[email protected]> 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 <stdbool.h> 16 #include <stdio.h> 17 18 #include <list_types.h> 19 20 enum symbol_type { 21 SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION, 22 SYM_ENUM_CONST 23 }; 24 25 enum symbol_status { 26 STATUS_UNCHANGED, STATUS_DEFINED, STATUS_MODIFIED 27 }; 28 29 struct string_list { 30 struct string_list *next; 31 enum symbol_type tag; 32 int in_source_file; 33 char *string; 34 }; 35 36 struct symbol { 37 struct hlist_node hnode; 38 char *name; 39 enum symbol_type type; 40 struct string_list *defn; 41 struct symbol *expansion_trail; 42 struct symbol *visited; 43 int is_extern; 44 int is_declared; 45 enum symbol_status status; 46 int is_override; 47 }; 48 49 typedef struct string_list **yystype; 50 #define YYSTYPE yystype 51 52 extern int cur_line; 53 extern char *cur_filename; 54 extern int in_source_file; 55 56 struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact); 57 struct symbol *add_symbol(const char *name, enum symbol_type type, 58 struct string_list *defn, int is_extern); 59 void export_symbol(const char *); 60 61 void free_node(struct string_list *list); 62 void free_list(struct string_list *s, struct string_list *e); 63 struct string_list *copy_node(struct string_list *); 64 struct string_list *copy_list_range(struct string_list *start, 65 struct string_list *end); 66 67 int yylex(void); 68 int yyparse(void); 69 70 extern bool dont_want_type_specifier; 71 72 void error_with_pos(const char *, ...) __attribute__ ((format(printf, 1, 2))); 73 74 /*----------------------------------------------------------------------*/ 75 #define xmalloc(size) ({ void *__ptr = malloc(size); \ 76 if(!__ptr && size != 0) { \ 77 fprintf(stderr, "out of memory\n"); \ 78 exit(1); \ 79 } \ 80 __ptr; }) 81 #define xstrdup(str) ({ char *__str = strdup(str); \ 82 if (!__str) { \ 83 fprintf(stderr, "out of memory\n"); \ 84 exit(1); \ 85 } \ 86 __str; }) 87 88 #endif /* genksyms.h */ 89