GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_wasi.h Lines: 0 2 0.0 %
Date: 2022-12-31 04:22:30 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_NODE_WASI_H_
2
#define SRC_NODE_WASI_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "base_object.h"
7
#include "node_mem.h"
8
#include "uvwasi.h"
9
#include "v8-fast-api-calls.h"
10
11
namespace node {
12
namespace wasi {
13
14
struct WasmMemory {
15
  char* data;
16
  size_t size;
17
};
18
19
class WASI : public BaseObject,
20
             public mem::NgLibMemoryManager<WASI, uvwasi_mem_t> {
21
 public:
22
  WASI(Environment* env,
23
       v8::Local<v8::Object> object,
24
       uvwasi_options_t* options);
25
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
26
27
  void MemoryInfo(MemoryTracker* tracker) const override;
28
  SET_MEMORY_INFO_NAME(WASI)
29
  SET_SELF_SIZE(WASI)
30
31
  static uint32_t ArgsGet(WASI&, WasmMemory, uint32_t, uint32_t);
32
  static uint32_t ArgsSizesGet(WASI&, WasmMemory, uint32_t, uint32_t);
33
  static uint32_t ClockResGet(WASI&, WasmMemory, uint32_t, uint32_t);
34
  static uint32_t ClockTimeGet(WASI&, WasmMemory, uint32_t, uint64_t, uint32_t);
35
  static uint32_t EnvironGet(WASI&, WasmMemory, uint32_t, uint32_t);
36
  static uint32_t EnvironSizesGet(WASI&, WasmMemory, uint32_t, uint32_t);
37
  static uint32_t FdAdvise(
38
      WASI&, WasmMemory, uint32_t, uint64_t, uint64_t, uint32_t);
39
  static uint32_t FdAllocate(WASI&, WasmMemory, uint32_t, uint64_t, uint64_t);
40
  static uint32_t FdClose(WASI&, WasmMemory, uint32_t);
41
  static uint32_t FdDatasync(WASI&, WasmMemory, uint32_t);
42
  static uint32_t FdFdstatGet(WASI&, WasmMemory, uint32_t, uint32_t);
43
  static uint32_t FdFdstatSetFlags(WASI&, WasmMemory, uint32_t, uint32_t);
44
  static uint32_t FdFdstatSetRights(
45
      WASI&, WasmMemory, uint32_t, uint64_t, uint64_t);
46
  static uint32_t FdFilestatGet(WASI&, WasmMemory, uint32_t, uint32_t);
47
  static uint32_t FdFilestatSetSize(WASI&, WasmMemory, uint32_t, uint64_t);
48
  static uint32_t FdFilestatSetTimes(
49
      WASI&, WasmMemory, uint32_t, uint64_t, uint64_t, uint32_t);
50
  static uint32_t FdPread(WASI&,
51
                          WasmMemory memory,
52
                          uint32_t,
53
                          uint32_t,
54
                          uint32_t,
55
                          uint64_t,
56
                          uint32_t);
57
  static uint32_t FdPrestatGet(WASI&, WasmMemory, uint32_t, uint32_t);
58
  static uint32_t FdPrestatDirName(
59
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
60
  static uint32_t FdPwrite(
61
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint64_t, uint32_t);
62
  static uint32_t FdRead(
63
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t);
64
  static uint32_t FdReaddir(
65
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint64_t, uint32_t);
66
  static uint32_t FdRenumber(WASI&, WasmMemory, uint32_t, uint32_t);
67
  static uint32_t FdSeek(
68
      WASI&, WasmMemory, uint32_t, int64_t, uint32_t, uint32_t);
69
  static uint32_t FdSync(WASI&, WasmMemory, uint32_t);
70
  static uint32_t FdTell(WASI&, WasmMemory, uint32_t, uint32_t);
71
  static uint32_t FdWrite(
72
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t);
73
  static uint32_t PathCreateDirectory(
74
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
75
  static uint32_t PathFilestatGet(
76
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
77
  static uint32_t PathFilestatSetTimes(WASI&,
78
                                       WasmMemory,
79
                                       uint32_t,
80
                                       uint32_t,
81
                                       uint32_t,
82
                                       uint32_t,
83
                                       uint64_t,
84
                                       uint64_t,
85
                                       uint32_t);
86
  static uint32_t PathLink(WASI&,
87
                           WasmMemory,
88
                           uint32_t,
89
                           uint32_t,
90
                           uint32_t,
91
                           uint32_t,
92
                           uint32_t,
93
                           uint32_t,
94
                           uint32_t);
95
  static uint32_t PathOpen(WASI&,
96
                           WasmMemory,
97
                           uint32_t,
98
                           uint32_t,
99
                           uint32_t,
100
                           uint32_t,
101
                           uint32_t,
102
                           uint64_t,
103
                           uint64_t,
104
                           uint32_t,
105
                           uint32_t);
106
  static uint32_t PathReadlink(WASI&,
107
                               WasmMemory,
108
                               uint32_t,
109
                               uint32_t,
110
                               uint32_t,
111
                               uint32_t,
112
                               uint32_t,
113
                               uint32_t);
114
  static uint32_t PathRemoveDirectory(
115
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
116
  static uint32_t PathRename(WASI&,
117
                             WasmMemory,
118
                             uint32_t,
119
                             uint32_t,
120
                             uint32_t,
121
                             uint32_t,
122
                             uint32_t,
123
                             uint32_t);
124
  static uint32_t PathSymlink(
125
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
126
  static uint32_t PathUnlinkFile(
127
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
128
  static uint32_t PollOneoff(
129
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t);
130
  static void ProcExit(WASI&, WasmMemory, uint32_t);
131
  static uint32_t ProcRaise(WASI&, WasmMemory, uint32_t);
132
  static uint32_t RandomGet(WASI&, WasmMemory, uint32_t, uint32_t);
133
  static uint32_t SchedYield(WASI&, WasmMemory);
134
  static uint32_t SockRecv(WASI&,
135
                           WasmMemory,
136
                           uint32_t,
137
                           uint32_t,
138
                           uint32_t,
139
                           uint32_t,
140
                           uint32_t,
141
                           uint32_t);
142
  static uint32_t SockSend(
143
      WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
144
  static uint32_t SockShutdown(WASI&, WasmMemory, uint32_t, uint32_t);
145
146
  static void _SetMemory(const v8::FunctionCallbackInfo<v8::Value>& args);
147
148
  // Implementation for mem::NgLibMemoryManager
149
  void CheckAllocatedSize(size_t previous_size) const;
150
  void IncreaseAllocatedSize(size_t size);
151
  void DecreaseAllocatedSize(size_t size);
152
153
  // <typename FT, FT F> as a C++14 desugaring of `<auto F>`
154
  template <typename FT, FT F, typename R, typename... Args>
155
  class WasiFunction {
156
   public:
157
    static void SetFunction(Environment*,
158
                            const char*,
159
                            v8::Local<v8::FunctionTemplate>);
160
161
   private:
162
    static R FastCallback(v8::Local<v8::Object> receiver,
163
                          Args...,
164
                          v8::FastApiCallbackOptions&);
165
166
    static void SlowCallback(const v8::FunctionCallbackInfo<v8::Value>&);
167
  };
168
169
 private:
170
  ~WASI() override;
171
  uvwasi_t uvw_;
172
  v8::Global<v8::WasmMemoryObject> memory_;
173
  uvwasi_mem_t alloc_info_;
174
  size_t current_uvwasi_memory_ = 0;
175
};
176
177
178
}  // namespace wasi
179
}  // namespace node
180
181
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
182
183
#endif  // SRC_NODE_WASI_H_