Skip to content

Commit c7fb7e0

Browse files
committed
capi: add POLKAVM_IMPORT_WITH_INDEX
1 parent cf23d34 commit c7fb7e0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

capi/polkavm_guest.h

+26
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ struct PolkaVM_Metadata {
120120
unsigned char output_regs;
121121
} __attribute__ ((packed));
122122

123+
struct PolkaVM_Metadata_V2 {
124+
unsigned char version;
125+
unsigned int flags;
126+
unsigned int symbol_length;
127+
const char * symbol;
128+
unsigned char input_regs;
129+
unsigned char output_regs;
130+
unsigned char has_index;
131+
unsigned int index;
132+
} __attribute__ ((packed));
133+
123134
#ifdef _LP64
124135
#define POLKAVM_EXPORT_DEF() \
125136
".quad %[metadata]\n" \
@@ -173,6 +184,21 @@ static arg_return_ty __attribute__ ((naked)) fn_name(POLKAVM_IMPORT_ARGS_IMPL(__
173184
); \
174185
}
175186

187+
#define POLKAVM_IMPORT_WITH_INDEX(index, arg_return_ty, fn_name, ...) \
188+
static struct PolkaVM_Metadata_V2 POLKAVM_JOIN(fn_name, __IMPORT_METADATA) __attribute__ ((section(".polkavm_metadata"))) = { \
189+
2, 0, sizeof(#fn_name) - 1, #fn_name, POLKAVM_COUNT_REGS(__VA_ARGS__), POLKAVM_COUNT_REGS(arg_return_ty), 1, index \
190+
}; \
191+
static arg_return_ty __attribute__ ((naked)) fn_name(POLKAVM_IMPORT_ARGS_IMPL(__VA_ARGS__)) { \
192+
__asm__( \
193+
POLKAVM_IMPORT_DEF() \
194+
"ret\n" \
195+
: \
196+
: \
197+
[metadata] "i" (&POLKAVM_JOIN(fn_name, __IMPORT_METADATA)) \
198+
: "memory" \
199+
); \
200+
}
201+
176202
#define POLKAVM_MIN_STACK_SIZE(size) \
177203
static void __attribute__ ((naked, used)) POLKAVM_UNIQUE(polkavm_stack_size)() { \
178204
__asm__( \

0 commit comments

Comments
 (0)