From f25b015e5b668028c34974bbb22faa4105c26690 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 26 Nov 2023 22:43:30 +0100 Subject: First commit --- private_include/nw/sections.h | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 private_include/nw/sections.h (limited to 'private_include/nw/sections.h') diff --git a/private_include/nw/sections.h b/private_include/nw/sections.h new file mode 100644 index 0000000..bef9cd8 --- /dev/null +++ b/private_include/nw/sections.h @@ -0,0 +1,65 @@ +/* + * nanowasm, a tiny WebAssembly/Wasm interpreter + * Copyright (C) 2023-2024 Xavier Del Campo Romero + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#ifndef SECTIONS_H +#define SECTIONS_H + +#include +#include +#include +#include + +struct section +{ + const struct nw_mod_cfg *cfg; + FILE *f; +}; + +int section_custom_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_type_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_import_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_function_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_table_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_memory_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_global_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_export_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_start_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_element_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_code_check(const struct section *s, struct nw_mod *m, unsigned long len); +int section_data_check(const struct section *s, struct nw_mod *m, unsigned long len); + +struct section_function +{ + varuint32 type, index, nreturn; +}; + +struct section_code +{ + long start; +}; + +int section_function(const struct section *s, const struct nw_mod *m, + varuint32 idx, struct section_function *f); +int section_code(const struct section *s, const struct nw_mod *m, + varuint32 idx, struct section_code *c); + +int section_code_push(FILE *f, long pc, struct nw_frame *fr); +int section_type_push(FILE *f, const struct nw_mod *m, varuint32 idx, + struct nw_frame *fr); +int section_global_push(FILE *f, const struct nw_mod *m, struct nw_interp *i); + +struct resizable_limits +{ + bool max_available; + size_t sz, max; +}; + +int check_resizable_limits(FILE *f, struct resizable_limits *r); + +#endif -- cgit v1.2.3