1 /*
2  *  ClamAV bytecode internal API
3  *
4  *  Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
5  *  Copyright (C) 2009-2013 Sourcefire, Inc.
6  *
7  *  Authors: Török Edvin
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License version 2 as
11  *  published by the Free Software Foundation.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  *  MA 02110-1301, USA.
22  */
23 #ifndef TYPE_DESC_H
24 #define TYPE_DESC_H
25 
26 #include "clambc.h"
27 struct cli_bc_ctx;
28 
29 enum derived_t {
30     DFunctionType,
31     DPointerType,
32     DStructType,
33     DPackedStructType,
34     DArrayType
35 };
36 
37 struct cli_bc_type {
38     enum derived_t kind;
39     uint16_t *containedTypes;
40     unsigned numElements;
41     uint32_t size;
42     unsigned align;
43 };
44 
45 typedef uint32_t (*cli_apicall_int2)(struct cli_bc_ctx *, uint32_t, uint32_t);
46 typedef uint32_t (*cli_apicall_pointer)(struct cli_bc_ctx *, void *, uint32_t);
47 typedef uint32_t (*cli_apicall_int1)(struct cli_bc_ctx *, uint32_t);
48 typedef void *(*cli_apicall_malloclike)(struct cli_bc_ctx *, uint32_t);
49 typedef int32_t (*cli_apicall_ptrbuffdata)(struct cli_bc_ctx *, void *, uint32_t, uint32_t, uint32_t, uint32_t);
50 typedef int32_t (*cli_apicall_allocobj)(struct cli_bc_ctx *);
51 typedef void *(*cli_apicall_bufget)(struct cli_bc_ctx *, int32_t, uint32_t);
52 typedef int32_t (*cli_apicall_int3)(struct cli_bc_ctx *, int32_t, int32_t, int32_t);
53 typedef int32_t (*cli_apicall_2bufs)(struct cli_bc_ctx *, void *, int32_t, void *, int32_t);
54 typedef int32_t (*cli_apicall_ptrbufid)(struct cli_bc_ctx *, void *, int32_t, int32_t);
55 
56 struct cli_apicall {
57     const char *name;
58     uint16_t type; /* type id in cli_apicall_types array */
59     uint16_t idx;
60     uint8_t kind;
61 };
62 
63 struct cli_apiglobal {
64     const char *name;
65     enum bc_global globalid;
66     uint16_t type;
67     unsigned offset;
68 };
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 extern const struct cli_bc_type cli_apicall_types[];
74 extern const unsigned cli_apicall_maxtypes;
75 
76 extern const struct cli_apiglobal cli_globals[];
77 
78 extern const struct cli_apicall cli_apicalls[];
79 extern const cli_apicall_int2 cli_apicalls0[];
80 extern const cli_apicall_pointer cli_apicalls1[];
81 extern const cli_apicall_int1 cli_apicalls2[];
82 extern const cli_apicall_malloclike cli_apicalls3[];
83 extern const cli_apicall_ptrbuffdata cli_apicalls4[];
84 extern const cli_apicall_allocobj cli_apicalls5[];
85 extern const cli_apicall_bufget cli_apicalls6[];
86 extern const cli_apicall_int3 cli_apicalls7[];
87 extern const cli_apicall_2bufs cli_apicalls8[];
88 extern const cli_apicall_ptrbufid cli_apicalls9[];
89 extern const unsigned cli_apicall_maxapi;
90 extern const unsigned cli_apicall_maxglobal;
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 #endif
96