3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEPAWN_VM_TYPES_H
33 #define _INCLUDE_SOURCEPAWN_VM_TYPES_H
37 * @brief Contains all run-time SourcePawn structures.
40 #include "sp_file_headers.h"
42 typedef uint32_t ucell_t; /**< Unsigned 32bit integer */
43 typedef int32_t cell_t; /**< Basic 32bit signed integer type for plugins */
44 typedef uint32_t funcid_t; /**< Function index code */
46 #include "sp_typeutil.h"
48 #define SP_MAX_EXEC_PARAMS 32 /**< Maximum number of parameters in a function */
50 #define SP_JITCONF_DEBUG "debug" /**< Configuration option for debugging. */
51 #define SP_JITCONF_PROFILE "profile" /**< Configuration option for profiling. */
53 #define SP_PROF_NATIVES (1<<0) /**< Profile natives. */
54 #define SP_PROF_CALLBACKS (1<<1) /**< Profile callbacks. */
55 #define SP_PROF_FUNCTIONS (1<<2) /**< Profile functions. */
58 * @brief Error codes for SourcePawn routines.
60 #define SP_ERROR_NONE 0 /**< No error occurred */
61 #define SP_ERROR_FILE_FORMAT 1 /**< File format unrecognized */
62 #define SP_ERROR_DECOMPRESSOR 2 /**< A decompressor was not found */
63 #define SP_ERROR_HEAPLOW 3 /**< Not enough space left on the heap */
64 #define SP_ERROR_PARAM 4 /**< Invalid parameter or parameter type */
65 #define SP_ERROR_INVALID_ADDRESS 5 /**< A memory address was not valid */
66 #define SP_ERROR_NOT_FOUND 6 /**< The object in question was not found */
67 #define SP_ERROR_INDEX 7 /**< Invalid index parameter */
68 #define SP_ERROR_STACKLOW 8 /**< Not enough space left on the stack */
69 #define SP_ERROR_NOTDEBUGGING 9 /**< Debug mode was not on or debug section not found */
70 #define SP_ERROR_INVALID_INSTRUCTION 10 /**< Invalid instruction was encountered */
71 #define SP_ERROR_MEMACCESS 11 /**< Invalid memory access */
72 #define SP_ERROR_STACKMIN 12 /**< Stack went beyond its minimum value */
73 #define SP_ERROR_HEAPMIN 13 /**< Heap went beyond its minimum value */
74 #define SP_ERROR_DIVIDE_BY_ZERO 14 /**< Division by zero */
75 #define SP_ERROR_ARRAY_BOUNDS 15 /**< Array index is out of bounds */
76 #define SP_ERROR_INSTRUCTION_PARAM 16 /**< Instruction had an invalid parameter */
77 #define SP_ERROR_STACKLEAK 17 /**< A native leaked an item on the stack */
78 #define SP_ERROR_HEAPLEAK 18 /**< A native leaked an item on the heap */
79 #define SP_ERROR_ARRAY_TOO_BIG 19 /**< A dynamic array is too big */
80 #define SP_ERROR_TRACKER_BOUNDS 20 /**< Tracker stack is out of bounds */
81 #define SP_ERROR_INVALID_NATIVE 21 /**< Native was pending or invalid */
82 #define SP_ERROR_PARAMS_MAX 22 /**< Maximum number of parameters reached */
83 #define SP_ERROR_NATIVE 23 /**< Error originates from a native */
84 #define SP_ERROR_NOT_RUNNABLE 24 /**< Function or plugin is not runnable */
85 #define SP_ERROR_ABORTED 25 /**< Function call was aborted */
86 #define SP_ERROR_CODE_TOO_OLD 26 /**< Code is too old for this VM */
87 #define SP_ERROR_CODE_TOO_NEW 27 /**< Code is too new for this VM */
88 //Hey you! Update the string table if you add to the end of me! */
90 /**********************************************
91 *** The following structures are reference structures.
92 *** They are not essential to the API, but are used
93 *** to hold the back end database format of the plugin
95 **********************************************/
100 class IVirtualMachine;
107 * @brief Native callback prototype, passed a context and a parameter stack (0=count, 1+=args).
108 * A cell must be returned.
110 typedef cell_t (*SPVM_NATIVE_FUNC)(SourcePawn::IPluginContext *, const cell_t *);
113 * @brief Fake native callback prototype, passed a context, parameter stack, and private data.
114 * A cell must be returned.
116 typedef cell_t (*SPVM_FAKENATIVE_FUNC)(SourcePawn::IPluginContext *, const cell_t *, void *);
118 /**********************************************
119 *** The following structures are bound to the VM/JIT.
120 *** Changing them will result in necessary recompilation.
121 **********************************************/
124 * @brief Offsets and names to a public function.
126 typedef struct sp_public_s
128 funcid_t funcid; /**< Encoded function id */
129 uint32_t code_offs; /**< Relocated code offset */
130 const char *name; /**< Name of function */
134 * @brief Offsets and names to public variables.
136 * The offset is relocated and the name by default points back to the sp_plugin_infotab_t structure.
138 typedef struct sp_pubvar_s
140 cell_t *offs; /**< Pointer to data */
141 const char *name; /**< Name */
144 #define SP_NATIVE_UNBOUND (0) /**< Native is undefined */
145 #define SP_NATIVE_BOUND (1) /**< Native is bound */
147 #define SP_NTVFLAG_OPTIONAL (1<<0) /**< Native is optional */
150 * @brief Native lookup table, by default names point back to the sp_plugin_infotab_t structure.
152 typedef struct sp_native_s
154 SPVM_NATIVE_FUNC pfn; /**< Function pointer */
155 const char * name; /**< Name of function */
156 uint32_t status; /**< Status flags */
157 uint32_t flags; /**< Native flags */
158 void * user; /**< Host-specific data */
162 * @brief Used for setting natives from modules/host apps.
164 typedef struct sp_nativeinfo_s
166 const char *name; /**< Name of the native */
167 SPVM_NATIVE_FUNC func; /**< Address of native implementation */
171 * @brief Run-time debug file table
173 typedef struct sp_debug_file_s
175 uint32_t addr; /**< Address into code */
176 const char * name; /**< Name of file */
180 * @brief Contains run-time debug line table.
182 typedef struct sp_debug_line_s
184 uint32_t addr; /**< Address into code */
185 uint32_t line; /**< Line number */
189 * @brief These structures are equivalent.
191 typedef sp_fdbg_arraydim_t sp_debug_arraydim_t;
194 * @brief The majority of this struct is already located in the parent
195 * block. Thus, only the relocated portions are required.
197 typedef struct sp_debug_symbol_s
199 uint32_t codestart; /**< Relocated code address */
200 uint32_t codeend; /**< Relocated code end address */
201 const char * name; /**< Relocated name */
202 sp_debug_arraydim_t *dims; /**< Relocated dimension struct, if any */
203 sp_fdbg_symbol_t *sym; /**< Pointer to original symbol */
206 #endif //_INCLUDE_SOURCEPAWN_VM_TYPES_H