github.com/moontrade/wavm-go@v0.3.2-0.20220316110326-d229dd66ad65/worker/worker.h (about)

     1  #ifndef __MOONTRADE_WORKER_H
     2  #define __MOONTRADE_WORKER_H
     3  
     4  #include <assert.h>
     5  #include <stdbool.h>
     6  #include <stddef.h>
     7  #include <stdint.h>
     8  #include <stdio.h>
     9  #include <stdlib.h>
    10  #include <time.h>
    11  #include "wavm-c.h"
    12  
    13  #ifdef __cplusplus
    14  extern "C" {
    15  #endif
    16  
    17  typedef wasm_trap_t* (*wasm_func_call_t)(wasm_store_t*, const wasm_func_t*, const wasm_val_t[], wasm_val_t[]);
    18  
    19  typedef struct moontrade_worker_t
    20  {
    21  	int64_t id;
    22  	struct moontrade_worker_t* next;
    23  	struct moontrade_worker_t* prev;
    24  	wasm_engine_t* engine;
    25  	wasm_compartment_t* compartment;
    26  	wasm_store_t* store;
    27  	wasm_memory_t* memory;
    28  	wasm_func_t* start;
    29  	wasm_func_t* resume;
    30  	wasm_func_t* alloc;
    31  	wasm_func_t* realloc;
    32  	wasm_func_t* free;
    33  	wasm_func_t* stub;
    34  	void* funcCall;
    35  	const char* log;
    36  	int64_t logLen;
    37  	int64_t logCap;
    38  	int64_t begin;
    39  	int64_t end;
    40  	int64_t started;
    41  	int64_t resumeAt;
    42  	int64_t* resumeAtStack;
    43  	int64_t resumeAtStackLen;
    44  	int64_t resumeAtStackCap;
    45  } moontrade_worker_t;
    46  
    47  typedef struct moontrade_call_t
    48  {
    49  	moontrade_worker_t* worker;
    50  	wasm_func_t* thunk;
    51  	wasm_func_t* func;
    52  	wasm_trap_t* trap;
    53  	wasm_val_t** args;
    54  	wasm_val_t* results[];
    55  } moontrade_call_t;
    56  
    57  void moontrade_stub();
    58  
    59  void moontrade_benchmark_stub(moontrade_worker_t* worker, int64_t n);
    60  void moontrade_benchmark_stub_fn(moontrade_worker_t* worker, void* fn, int64_t n);
    61  
    62  uint64_t moontrade_now();
    63  
    64  wasm_trap_t* moontrade_start(moontrade_worker_t* worker);
    65  
    66  wasm_trap_t* moontrade_resume(moontrade_worker_t* worker);
    67  
    68  void moontrade_call(uintptr_t arg0, uintptr_t arg1);
    69  
    70  //wasm_trap_t* moontrade_call(moontrade_worker_t* worker,
    71  //							const wasm_func_t* func,
    72  //							const wasm_val_t args[],
    73  //							wasm_val_t results[]);
    74  
    75  wasm_trap_t* moontrade_fd_write(const wasm_val_t args[], wasm_val_t results[]);
    76  
    77  wasm_trap_t* moontrade_clock_time_get(const wasm_val_t args[], wasm_val_t results[]);
    78  
    79  wasm_trap_t* moontrade_args_sizes_get(const wasm_val_t args[], wasm_val_t results[]);
    80  
    81  wasm_trap_t* moontrade_args_get(const wasm_val_t args[], wasm_val_t results[]);
    82  
    83  wasm_trap_t* moontrade_set_timeout(const wasm_val_t args[], wasm_val_t results[]);
    84  
    85  #ifdef __cplusplus
    86  } // extern "C"
    87  #endif
    88  
    89  #endif // #ifdef __MOONTRADE_WORKER_H