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 10 namespace node { 11 namespace wasi { 12 13 14 class WASI : public BaseObject, 15 public mem::NgLibMemoryManager<WASI, uvwasi_mem_t> { 16 public: 17 WASI(Environment* env, 18 v8::Local<v8::Object> object, 19 uvwasi_options_t* options); 20 static void New(const v8::FunctionCallbackInfo<v8::Value>& args); 21 22 void MemoryInfo(MemoryTracker* tracker) const override; 23 SET_MEMORY_INFO_NAME(WASI) 24 SET_SELF_SIZE(WASI) 25 26 static void ArgsGet(const v8::FunctionCallbackInfo<v8::Value>& args); 27 static void ArgsSizesGet(const v8::FunctionCallbackInfo<v8::Value>& args); 28 static void ClockResGet(const v8::FunctionCallbackInfo<v8::Value>& args); 29 static void ClockTimeGet(const v8::FunctionCallbackInfo<v8::Value>& args); 30 static void EnvironGet(const v8::FunctionCallbackInfo<v8::Value>& args); 31 static void EnvironSizesGet(const v8::FunctionCallbackInfo<v8::Value>& args); 32 static void FdAdvise(const v8::FunctionCallbackInfo<v8::Value>& args); 33 static void FdAllocate(const v8::FunctionCallbackInfo<v8::Value>& args); 34 static void FdClose(const v8::FunctionCallbackInfo<v8::Value>& args); 35 static void FdDatasync(const v8::FunctionCallbackInfo<v8::Value>& args); 36 static void FdFdstatGet(const v8::FunctionCallbackInfo<v8::Value>& args); 37 static void FdFdstatSetFlags(const v8::FunctionCallbackInfo<v8::Value>& args); 38 static void FdFdstatSetRights( 39 const v8::FunctionCallbackInfo<v8::Value>& args); 40 static void FdFilestatGet(const v8::FunctionCallbackInfo<v8::Value>& args); 41 static void FdFilestatSetSize( 42 const v8::FunctionCallbackInfo<v8::Value>& args); 43 static void FdFilestatSetTimes( 44 const v8::FunctionCallbackInfo<v8::Value>& args); 45 static void FdPread(const v8::FunctionCallbackInfo<v8::Value>& args); 46 static void FdPrestatGet(const v8::FunctionCallbackInfo<v8::Value>& args); 47 static void FdPrestatDirName(const v8::FunctionCallbackInfo<v8::Value>& args); 48 static void FdPwrite(const v8::FunctionCallbackInfo<v8::Value>& args); 49 static void FdRead(const v8::FunctionCallbackInfo<v8::Value>& args); 50 static void FdReaddir(const v8::FunctionCallbackInfo<v8::Value>& args); 51 static void FdRenumber(const v8::FunctionCallbackInfo<v8::Value>& args); 52 static void FdSeek(const v8::FunctionCallbackInfo<v8::Value>& args); 53 static void FdSync(const v8::FunctionCallbackInfo<v8::Value>& args); 54 static void FdTell(const v8::FunctionCallbackInfo<v8::Value>& args); 55 static void FdWrite(const v8::FunctionCallbackInfo<v8::Value>& args); 56 static void PathCreateDirectory( 57 const v8::FunctionCallbackInfo<v8::Value>& args); 58 static void PathFilestatGet(const v8::FunctionCallbackInfo<v8::Value>& args); 59 static void PathFilestatSetTimes( 60 const v8::FunctionCallbackInfo<v8::Value>& args); 61 static void PathLink(const v8::FunctionCallbackInfo<v8::Value>& args); 62 static void PathOpen(const v8::FunctionCallbackInfo<v8::Value>& args); 63 static void PathReadlink(const v8::FunctionCallbackInfo<v8::Value>& args); 64 static void PathRemoveDirectory( 65 const v8::FunctionCallbackInfo<v8::Value>& args); 66 static void PathRename(const v8::FunctionCallbackInfo<v8::Value>& args); 67 static void PathSymlink(const v8::FunctionCallbackInfo<v8::Value>& args); 68 static void PathUnlinkFile(const v8::FunctionCallbackInfo<v8::Value>& args); 69 static void PollOneoff(const v8::FunctionCallbackInfo<v8::Value>& args); 70 static void ProcExit(const v8::FunctionCallbackInfo<v8::Value>& args); 71 static void ProcRaise(const v8::FunctionCallbackInfo<v8::Value>& args); 72 static void RandomGet(const v8::FunctionCallbackInfo<v8::Value>& args); 73 static void SchedYield(const v8::FunctionCallbackInfo<v8::Value>& args); 74 static void SockRecv(const v8::FunctionCallbackInfo<v8::Value>& args); 75 static void SockSend(const v8::FunctionCallbackInfo<v8::Value>& args); 76 static void SockShutdown(const v8::FunctionCallbackInfo<v8::Value>& args); 77 78 static void _SetMemory(const v8::FunctionCallbackInfo<v8::Value>& args); 79 80 // Implementation for mem::NgLibMemoryManager 81 void CheckAllocatedSize(size_t previous_size) const; 82 void IncreaseAllocatedSize(size_t size); 83 void DecreaseAllocatedSize(size_t size); 84 85 private: 86 ~WASI() override; 87 inline void readUInt8(char* memory, uint8_t* value, uint32_t offset); 88 inline void readUInt16(char* memory, uint16_t* value, uint32_t offset); 89 inline void readUInt32(char* memory, uint32_t* value, uint32_t offset); 90 inline void readUInt64(char* memory, uint64_t* value, uint32_t offset); 91 inline void writeUInt8(char* memory, uint8_t value, uint32_t offset); 92 inline void writeUInt16(char* memory, uint16_t value, uint32_t offset); 93 inline void writeUInt32(char* memory, uint32_t value, uint32_t offset); 94 inline void writeUInt64(char* memory, uint64_t value, uint32_t offset); 95 uvwasi_errno_t backingStore(char** store, size_t* byte_length); 96 uvwasi_t uvw_; 97 v8::Global<v8::Object> memory_; 98 uvwasi_mem_t alloc_info_; 99 size_t current_uvwasi_memory_ = 0; 100 }; 101 102 103 } // namespace wasi 104 } // namespace node 105 106 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 107 108 #endif // SRC_NODE_WASI_H_ 109