Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #ifndef MODUTILS_GENKSYMS_H |
| 13 | #define MODUTILS_GENKSYMS_H 1 |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | |
Sam Ravnborg | ce56068 | 2006-03-12 23:26:29 +0100 | [diff] [blame] | 17 | enum symbol_type { |
Michal Marek | e37ddb8 | 2011-02-03 23:57:09 +0100 | [diff] [blame] | 18 | SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION, |
| 19 | SYM_ENUM_CONST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | }; |
| 21 | |
Andreas Gruenbacher | 64e6c1e | 2008-12-01 14:21:01 -0800 | [diff] [blame] | 22 | enum symbol_status { |
| 23 | STATUS_UNCHANGED, STATUS_DEFINED, STATUS_MODIFIED |
| 24 | }; |
| 25 | |
Sam Ravnborg | ce56068 | 2006-03-12 23:26:29 +0100 | [diff] [blame] | 26 | struct string_list { |
| 27 | struct string_list *next; |
| 28 | enum symbol_type tag; |
Michal Marek | 2c5925d | 2011-10-08 01:18:35 +0200 | [diff] [blame] | 29 | int in_source_file; |
Sam Ravnborg | ce56068 | 2006-03-12 23:26:29 +0100 | [diff] [blame] | 30 | char *string; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
Sam Ravnborg | ce56068 | 2006-03-12 23:26:29 +0100 | [diff] [blame] | 33 | struct symbol { |
| 34 | struct symbol *hash_next; |
| 35 | const char *name; |
| 36 | enum symbol_type type; |
| 37 | struct string_list *defn; |
| 38 | struct symbol *expansion_trail; |
Andreas Gruenbacher | 15fde67 | 2006-05-09 20:37:30 +0200 | [diff] [blame] | 39 | struct symbol *visited; |
Sam Ravnborg | ce56068 | 2006-03-12 23:26:29 +0100 | [diff] [blame] | 40 | int is_extern; |
Andreas Gruenbacher | 64e6c1e | 2008-12-01 14:21:01 -0800 | [diff] [blame] | 41 | int is_declared; |
| 42 | enum symbol_status status; |
Andreas Gruenbacher | 5dae9a5 | 2008-12-01 14:21:03 -0800 | [diff] [blame] | 43 | int is_override; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | typedef struct string_list **yystype; |
| 47 | #define YYSTYPE yystype |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | extern int cur_line; |
Masahiro Yamada | ab37d5a | 2021-01-16 08:43:02 +0900 | [diff] [blame] | 50 | extern char *cur_filename; |
Michal Marek | 2c5925d | 2011-10-08 01:18:35 +0200 | [diff] [blame] | 51 | extern int in_source_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Michal Marek | 01762c4 | 2011-02-15 15:11:36 +0100 | [diff] [blame] | 53 | struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | struct symbol *add_symbol(const char *name, enum symbol_type type, |
Sam Ravnborg | ce56068 | 2006-03-12 23:26:29 +0100 | [diff] [blame] | 55 | struct string_list *defn, int is_extern); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | void export_symbol(const char *); |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | void free_node(struct string_list *list); |
Sam Ravnborg | ce56068 | 2006-03-12 23:26:29 +0100 | [diff] [blame] | 59 | void free_list(struct string_list *s, struct string_list *e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct string_list *copy_node(struct string_list *); |
Michal Marek | e37ddb8 | 2011-02-03 23:57:09 +0100 | [diff] [blame] | 61 | struct string_list *copy_list_range(struct string_list *start, |
| 62 | struct string_list *end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | int yylex(void); |
| 65 | int yyparse(void); |
| 66 | |
Nicolas Iooss | 3def034 | 2017-05-20 13:27:00 +0200 | [diff] [blame] | 67 | void error_with_pos(const char *, ...) __attribute__ ((format(printf, 1, 2))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | /*----------------------------------------------------------------------*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #define xmalloc(size) ({ void *__ptr = malloc(size); \ |
| 71 | if(!__ptr && size != 0) { \ |
| 72 | fprintf(stderr, "out of memory\n"); \ |
| 73 | exit(1); \ |
| 74 | } \ |
| 75 | __ptr; }) |
| 76 | #define xstrdup(str) ({ char *__str = strdup(str); \ |
| 77 | if (!__str) { \ |
| 78 | fprintf(stderr, "out of memory\n"); \ |
| 79 | exit(1); \ |
| 80 | } \ |
| 81 | __str; }) |
| 82 | |
Sam Ravnborg | ce56068 | 2006-03-12 23:26:29 +0100 | [diff] [blame] | 83 | #endif /* genksyms.h */ |