aboutsummaryrefslogtreecommitdiff
path: root/private_include/nw/sections.h
blob: e835c6dea698177e9e378b3a50b7265339e76e70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 <nanowasm/nw.h>
#include <nw/types.h>
#include <stddef.h>
#include <stdio.h>

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_type_push(FILE *f, const struct nw_mod *m, varuint32 idx,
    struct retval *r);
int section_code_push(FILE *f, struct nw_interp *i);
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