Skip to content

Commit b3f3df4

Browse files
committed
mrs: make quarantine size tuneable
The environmental variables _RUNTIME_QUARANTINE_NUMERATOR and _RUNTIME_QUARANTINE_DENOMINATOR can now override compiled defaults for QUARANTINE_NUMERATOR and QUARANTINE_DENOMINATOR.
1 parent 7395a7b commit b3f3df4

File tree

1 file changed

+26
-0
lines changed
  • lib/libc/stdlib/malloc/mrs

1 file changed

+26
-0
lines changed

lib/libc/stdlib/malloc/mrs/mrs.c

+26
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ extern void snmalloc_flush_message_queue(void);
139139
#define MALLOC_NOBOUND_CHERI_POINTERS \
140140
"_RUNTIME_NOBOUND_CHERI_POINTERS"
141141

142+
#define MALLOC_QUARANTINE_DENOMINATOR_ENV \
143+
"_RUNTIME_QUARANTINE_DENOMINATOR"
144+
#define MALLOC_QUARANTINE_NUMERATOR_ENV \
145+
"_RUNTIME_QUARANTINE_NUMERATOR"
146+
142147
/*
143148
* Different allocators give their strong symbols different names. Hide
144149
* this implementation detail being the REAL() macro.
@@ -1316,6 +1321,27 @@ mrs_init_impl_locked(void)
13161321
exit(7);
13171322
}
13181323

1324+
if (!issetugid()) {
1325+
char *envstr, *end;
1326+
if ((envstr = getenv(MALLOC_QUARANTINE_DENOMINATOR_ENV)) !=
1327+
NULL) {
1328+
quarantine_denominator = strtoul(envstr, &end, 0);
1329+
if (*end != '\0') {
1330+
mrs_puts("invalid "
1331+
MALLOC_QUARANTINE_DENOMINATOR_ENV "\n");
1332+
exit(7);
1333+
}
1334+
}
1335+
if ((envstr = getenv(MALLOC_QUARANTINE_NUMERATOR_ENV)) !=
1336+
NULL) {
1337+
quarantine_numerator = strtoul(envstr, &end, 0);
1338+
if (*end != '\0') {
1339+
mrs_puts("invalid "
1340+
MALLOC_QUARANTINE_NUMERATOR_ENV "\n");
1341+
exit(7);
1342+
}
1343+
}
1344+
}
13191345
if (quarantine_denominator == 0) {
13201346
mrs_puts("quarantine_denominator can not be 0\n");
13211347
exit(7);

0 commit comments

Comments
 (0)