Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: specialize OOM check for AIX #28857

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions test/addons/addon.status
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ prefix addons
[true] # This section applies to all platforms

[$system==aix]
# https://github.com/nodejs/build/issues/1820#issuecomment-505998851
# https://github.com/nodejs/node/pull/28469
# https://github.com/nodejs/node/pull/28516
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js: SKIP

# https://github.com/nodejs/node/pull/28516
stringbytes-external-exceed-max/test-stringbytes-external-at-max: SKIP
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii: SKIP
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64: SKIP
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary: SKIP
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex: SKIP
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8: SKIP
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2: SKIP
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max: SKIP
32 changes: 31 additions & 1 deletion test/addons/stringbytes-external-exceed-max/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down