1 | // RUN: %clang_msan -fsanitize-memory-track-origins=0 -O0 %s -o %t && MSAN_OPTIONS=soft_rss_limit_mb=18:verbosity=1:allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s -implicit-check-not="soft rss limit" -check-prefixes=CHECK,NOORIG |
2 | // RUN: %clang_msan -fsanitize-memory-track-origins=2 -O0 %s -o %t && MSAN_OPTIONS=soft_rss_limit_mb=36:verbosity=1:allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s -implicit-check-not="soft rss limit" -check-prefixes=CHECK,ORIGIN |
3 | |
4 | #include <assert.h> |
5 | #include <sanitizer/allocator_interface.h> |
6 | #include <stdio.h> |
7 | #include <stdlib.h> |
8 | #include <string.h> |
9 | #include <unistd.h> |
10 | |
11 | void *p; |
12 | |
13 | int main(int argc, char **argv) { |
14 | int s = 20 * 1024 * 1024; |
15 | fprintf(stderr, format: "malloc\n" ); |
16 | p = malloc(size: s); |
17 | sleep(seconds: 1); |
18 | fprintf(stderr, format: "memset\n" ); |
19 | memset(s: p, c: 1, n: s); |
20 | sleep(seconds: 1); |
21 | fprintf(stderr, format: "free\n" ); |
22 | free(ptr: p); |
23 | sleep(seconds: 1); |
24 | return 0; |
25 | } |
26 | |
27 | // CHECK-LABEL: malloc |
28 | |
29 | // Non origin mode allocate ~20M for shadow. |
30 | // Origin mode allocate ~20M for shadow and ~20M for origin. |
31 | // CHECK: soft rss limit exhausted |
32 | |
33 | // CHECK-LABEL: memset |
34 | |
35 | // Memset reserve modified pages, frees ~20M for shadow. So not change in RSS for non-origin mode. |
36 | // Origin mode also frees ~20M of origins, so 'unexhausted'. |
37 | // ORIGIN: soft rss limit unexhausted |
38 | |
39 | // CHECK-LABEL: free |
40 | |
41 | // Now non-origin release all everything. |
42 | // NOORIG: soft rss limit unexhausted |