summaryrefslogtreecommitdiff
path: root/test/addons/stringbytes-external-exceed-max
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2019-07-24 14:07:55 -0700
committerRich Trott <rtrott@gmail.com>2019-07-27 16:03:43 -0700
commit41fa5536d179e86540756c78f7794bbd697c8697 (patch)
tree38bc329342b3c206fbdd219d766028bdf8cc1fe7 /test/addons/stringbytes-external-exceed-max
parent4e2d1a1433d17a3b327b76aebdb3e56e90c060b1 (diff)
downloadandroid-node-v8-41fa5536d179e86540756c78f7794bbd697c8697.tar.gz
android-node-v8-41fa5536d179e86540756c78f7794bbd697c8697.tar.bz2
android-node-v8-41fa5536d179e86540756c78f7794bbd697c8697.zip
test: specialize OOM check for AIX
Assumption that if memory can be malloc()ed it can be used is not true on AIX. Later access of the allocated pages can trigger SIGKILL if there are insufficient VM pages. Use psdanger() to better estimate available memory. Fixes: https://github.com/nodejs/build/issues/1849 More info: - https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/generalprogramming/sys_mem_alloc.html - https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/p_bostechref/psdanger.html Related to: - https://github.com/nodejs/build/issues/1820#issuecomment-505998851 - https://github.com/nodejs/node/pull/28469 - https://github.com/nodejs/node/pull/28516 PR-URL: https://github.com/nodejs/node/pull/28857 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/addons/stringbytes-external-exceed-max')
-rw-r--r--test/addons/stringbytes-external-exceed-max/binding.cc32
1 files changed, 31 insertions, 1 deletions
diff --git a/test/addons/stringbytes-external-exceed-max/binding.cc b/test/addons/stringbytes-external-exceed-max/binding.cc
index 573b505bde..0e3cd3f4d0 100644
--- a/test/addons/stringbytes-external-exceed-max/binding.cc
+++ b/test/addons/stringbytes-external-exceed-max/binding.cc
@@ -2,12 +2,42 @@
#include <node.h>
#include <v8.h>
+#ifdef _AIX
+// AIX allows over-allocation, and will SIGKILL when the allocated pages are
+// used if there is not enough VM. Check for available space until
+// out-of-memory. Don't allow more then some (large) proportion of it to be
+// used for the test strings, so Node & V8 have some space for allocations.
+#include <signal.h>
+#include <sys/vminfo.h>
+
+static void* Allowed(size_t size) {
+ blkcnt_t allowedBlocks = psdanger(SIGKILL);
+
+ if (allowedBlocks < 1) {
+ // Already OOM
+ return nullptr;
+ }
+ const size_t BYTES_PER_BLOCK = 512;
+ size_t allowed = (allowedBlocks * BYTES_PER_BLOCK * 4) / 5;
+ if (size < allowed) {
+ return malloc(size);
+ }
+ return nullptr;
+}
+#else
+// Other systems also allow over-allocation, but this malloc-and-free approach
+// seems to be working for them.
+static void* Allowed(size_t size) {
+ return malloc(size);
+}
+#endif // _AIX
+
void EnsureAllocation(const v8::FunctionCallbackInfo<v8::Value> &args) {
v8::Isolate* isolate = args.GetIsolate();
uintptr_t size = args[0].As<v8::Integer>()->Value();
v8::Local<v8::Boolean> success;
- void* buffer = malloc(size);
+ void* buffer = Allowed(size);
if (buffer) {
success = v8::Boolean::New(isolate, true);
free(buffer);