diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-12-01 03:45:48 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-12-08 00:55:20 +0300 |
commit | a9abc17153921294150cda8df84c5d81faae02c4 (patch) | |
tree | 5baf1f1702641d2413cf528ab1c04531a5e500a2 /src/node_wasi.h | |
parent | 0a7c874e9c3cb5da99c88ab46e33a648f0b909d2 (diff) |
wasi: use memory-tracking allocator
This:
- Protects against memory leaks in uvwasi.
- Allows tracking the allocated memory in heap dumps.
PR-URL: https://github.com/nodejs/node/pull/30745
Refs: https://github.com/nodejs/quic/blob/34ee0bc96f804c73cb22b2945a1a78f780938492/src/node_mem.h
Refs: https://github.com/nodejs/quic/pull/126
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_wasi.h')
-rw-r--r-- | src/node_wasi.h | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/node_wasi.h b/src/node_wasi.h index ca726e48a42..7a0be60aa64 100644 --- a/src/node_wasi.h +++ b/src/node_wasi.h @@ -4,24 +4,22 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "base_object.h" -#include "memory_tracker-inl.h" +#include "node_mem.h" #include "uvwasi.h" namespace node { namespace wasi { -class WASI : public BaseObject { +class WASI : public BaseObject, + public mem::NgLibMemoryManager<WASI, uvwasi_mem_t> { public: WASI(Environment* env, v8::Local<v8::Object> object, uvwasi_options_t* options); static void New(const v8::FunctionCallbackInfo<v8::Value>& args); - void MemoryInfo(MemoryTracker* tracker) const override { - /* TODO(cjihrig): Get memory consumption from uvwasi. */ - tracker->TrackField("memory", memory_); - } + void MemoryInfo(MemoryTracker* tracker) const override; SET_MEMORY_INFO_NAME(WASI) SET_SELF_SIZE(WASI) @@ -79,6 +77,11 @@ class WASI : public BaseObject { static void _SetMemory(const v8::FunctionCallbackInfo<v8::Value>& args); + // Implementation for mem::NgLibMemoryManager + void CheckAllocatedSize(size_t previous_size) const; + void IncreaseAllocatedSize(size_t size); + void DecreaseAllocatedSize(size_t size); + private: ~WASI() override; inline void readUInt8(char* memory, uint8_t* value, uint32_t offset); @@ -92,6 +95,8 @@ class WASI : public BaseObject { uvwasi_errno_t backingStore(char** store, size_t* byte_length); uvwasi_t uvw_; v8::Global<v8::Object> memory_; + uvwasi_mem_t alloc_info_; + size_t current_uvwasi_memory_ = 0; }; |