GeezerVison is showing github.com — test: specialize OOM check for AIX · nodejs/node@65e9b0f
File tree
Expand file treeCollapse file tree
Open diff view settings
stringbytes-external-exceed-max
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: test/addons/addon.status -14Lines changed: 0 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,17 +3,3 @@ prefix addons |
3 | 3 | [true] # This section applies to all platforms |
4 | 4 |
|
5 | 5 | [$system==aix] |
6 | | -# https://github.com/nodejs/build/issues/1820#issuecomment-505998851 |
7 | | -# https://github.com/nodejs/node/pull/28469 |
8 | | -# https://github.com/nodejs/node/pull/28516 |
9 | | -stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js: SKIP |
10 | | - |
11 | | -# https://github.com/nodejs/node/pull/28516 |
12 | | -stringbytes-external-exceed-max/test-stringbytes-external-at-max: SKIP |
13 | | -stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii: SKIP |
14 | | -stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64: SKIP |
15 | | -stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary: SKIP |
16 | | -stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex: SKIP |
17 | | -stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8: SKIP |
18 | | -stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2: SKIP |
19 | | -stringbytes-external-exceed-max/test-stringbytes-external-exceed-max: SKIP |
Collapse file
Copy file name to clipboardExpand all lines: test/addons/stringbytes-external-exceed-max/binding.cc +31-1Lines changed: 31 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
2 | 2 | #include <node.h> |
3 | 3 | #include <v8.h> |
4 | 4 |
|
| 5 | +#ifdef _AIX |
| 6 | +// AIX allows over-allocation, and will SIGKILL when the allocated pages are |
| 7 | +// used if there is not enough VM. Check for available space until |
| 8 | +// out-of-memory. Don't allow more then some (large) proportion of it to be |
| 9 | +// used for the test strings, so Node & V8 have some space for allocations. |
| 10 | +#include <signal.h> |
| 11 | +#include <sys/vminfo.h> |
| 12 | + |
| 13 | +static void* Allowed(size_t size) { |
| 14 | + blkcnt_t allowedBlocks = psdanger(SIGKILL); |
| 15 | + |
| 16 | + if (allowedBlocks < 1) { |
| 17 | + // Already OOM |
| 18 | + return nullptr; |
| 19 | + } |
| 20 | + const size_t BYTES_PER_BLOCK = 512; |
| 21 | + size_t allowed = (allowedBlocks * BYTES_PER_BLOCK * 4) / 5; |
| 22 | + if (size < allowed) { |
| 23 | + return malloc(size); |
| 24 | + } |
| 25 | + return nullptr; |
| 26 | +} |
| 27 | +#else |
| 28 | +// Other systems also allow over-allocation, but this malloc-and-free approach |
| 29 | +// seems to be working for them. |
| 30 | +static void* Allowed(size_t size) { |
| 31 | + return malloc(size); |
| 32 | +} |
| 33 | +#endif // _AIX |
| 34 | + |
5 | 35 | void EnsureAllocation(const v8::FunctionCallbackInfo<v8::Value> &args) { |
6 | 36 | v8::Isolate* isolate = args.GetIsolate(); |
7 | 37 | uintptr_t size = args[0]->IntegerValue(); |
8 | 38 | v8::Local<v8::Boolean> success; |
9 | 39 |
|
10 | | - void* buffer = malloc(size); |
| 40 | + void* buffer = Allowed(size); |
11 | 41 | if (buffer) { |
12 | 42 | success = v8::Boolean::New(isolate, true); |
13 | 43 | free(buffer); |
|