From fd5089b471e12d327d7ab12c3de6069d9e1a9573 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Fri, 31 Mar 2017 00:01:16 +0300 Subject: [PATCH] [sgen] Add debug option for valloc limit This allows us to stress test OOM inside sgen (and potentially other areas). --- mono/sgen/sgen-gc.c | 11 +++++++++++ mono/utils/mono-mmap-internals.h | 6 ++++++ mono/utils/mono-mmap-windows.c | 6 ++++++ mono/utils/mono-mmap.c | 24 +++++++++++++++++++++++- mono/utils/mono-mmap.h | 2 +- 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/mono/sgen/sgen-gc.c b/mono/sgen/sgen-gc.c index fb6082ab6ab..f6aad7eeb37 100644 --- a/mono/sgen/sgen-gc.c +++ b/mono/sgen/sgen-gc.c @@ -193,6 +193,7 @@ #include "mono/utils/hazard-pointer.h" #include +#include #undef pthread_create #undef pthread_join @@ -3215,6 +3216,15 @@ sgen_gc_init (void) } else if (!strcmp (opt, "verify-before-allocs")) { verify_before_allocs = 1; has_per_allocation_action = TRUE; + } else if (g_str_has_prefix (opt, "max-valloc-size=")) { + size_t max_valloc_size; + char *arg = strchr (opt, '=') + 1; + if (*opt && mono_gc_parse_environment_string_extract_number (arg, &max_valloc_size)) { + mono_valloc_set_limit (max_valloc_size); + } else { + sgen_env_var_error (MONO_GC_DEBUG_NAME, NULL, "`max-valloc-size` must be an integer."); + } + continue; } else if (g_str_has_prefix (opt, "verify-before-allocs=")) { char *arg = strchr (opt, '=') + 1; verify_before_allocs = atoi (arg); @@ -3295,6 +3305,7 @@ sgen_gc_init (void) fprintf (stderr, "Valid