blob: 21ed2ec2d98ca8cdc6fe7bf28000d5d5fc7bf528 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* 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 Gleixner1a59d1b82019-05-27 08:55:05 +020010 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#ifndef MODUTILS_GENKSYMS_H
13#define MODUTILS_GENKSYMS_H 1
14
15#include <stdio.h>
16
Sam Ravnborgce560682006-03-12 23:26:29 +010017enum symbol_type {
Michal Mareke37ddb82011-02-03 23:57:09 +010018 SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION,
19 SYM_ENUM_CONST
Linus Torvalds1da177e2005-04-16 15:20:36 -070020};
21
Andreas Gruenbacher64e6c1e2008-12-01 14:21:01 -080022enum symbol_status {
23 STATUS_UNCHANGED, STATUS_DEFINED, STATUS_MODIFIED
24};
25
Sam Ravnborgce560682006-03-12 23:26:29 +010026struct string_list {
27 struct string_list *next;
28 enum symbol_type tag;
Michal Marek2c5925d2011-10-08 01:18:35 +020029 int in_source_file;
Sam Ravnborgce560682006-03-12 23:26:29 +010030 char *string;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031};
32
Sam Ravnborgce560682006-03-12 23:26:29 +010033struct 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 Gruenbacher15fde672006-05-09 20:37:30 +020039 struct symbol *visited;
Sam Ravnborgce560682006-03-12 23:26:29 +010040 int is_extern;
Andreas Gruenbacher64e6c1e2008-12-01 14:21:01 -080041 int is_declared;
42 enum symbol_status status;
Andreas Gruenbacher5dae9a52008-12-01 14:21:03 -080043 int is_override;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044};
45
46typedef struct string_list **yystype;
47#define YYSTYPE yystype
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049extern int cur_line;
Masahiro Yamadaab37d5a2021-01-16 08:43:02 +090050extern char *cur_filename;
Michal Marek2c5925d2011-10-08 01:18:35 +020051extern int in_source_file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Michal Marek01762c42011-02-15 15:11:36 +010053struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054struct symbol *add_symbol(const char *name, enum symbol_type type,
Sam Ravnborgce560682006-03-12 23:26:29 +010055 struct string_list *defn, int is_extern);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056void export_symbol(const char *);
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058void free_node(struct string_list *list);
Sam Ravnborgce560682006-03-12 23:26:29 +010059void free_list(struct string_list *s, struct string_list *e);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060struct string_list *copy_node(struct string_list *);
Michal Mareke37ddb82011-02-03 23:57:09 +010061struct string_list *copy_list_range(struct string_list *start,
62 struct string_list *end);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64int yylex(void);
65int yyparse(void);
66
Nicolas Iooss3def0342017-05-20 13:27:00 +020067void error_with_pos(const char *, ...) __attribute__ ((format(printf, 1, 2)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/*----------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#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 Ravnborgce560682006-03-12 23:26:29 +010083#endif /* genksyms.h */