Skip to content

Commit 28227a2

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 28227a2

File tree

1 file changed

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

1 file changed

+32
-0
lines changed

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

+32
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,33 @@ 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+
errno = 0;
1329+
quarantine_denominator = strtoul(envstr, &end, 0);
1330+
if (*end != '\0' ||
1331+
(quarantine_denominator == ULONG_MAX &&
1332+
errno == ERANGE)) {
1333+
mrs_puts("invalid "
1334+
MALLOC_QUARANTINE_DENOMINATOR_ENV "\n");
1335+
exit(7);
1336+
}
1337+
}
1338+
if ((envstr = getenv(MALLOC_QUARANTINE_NUMERATOR_ENV)) !=
1339+
NULL) {
1340+
errno = 0;
1341+
quarantine_numerator = strtoul(envstr, &end, 0);
1342+
if (*end != '\0' ||
1343+
(quarantine_numerator == ULONG_MAX &&
1344+
errno == ERANGE)) {
1345+
mrs_puts("invalid "
1346+
MALLOC_QUARANTINE_NUMERATOR_ENV "\n");
1347+
exit(7);
1348+
}
1349+
}
1350+
}
13191351
if (quarantine_denominator == 0) {
13201352
mrs_puts("quarantine_denominator can not be 0\n");
13211353
exit(7);

0 commit comments

Comments
 (0)