@@ -235,6 +235,8 @@ struct Allocator {
235
235
AllocatorCache fallback_allocator_cache;
236
236
QuarantineCache fallback_quarantine_cache;
237
237
238
+ atomic_uint8_t rss_limit_exceeded;
239
+
238
240
// ------------------- Options --------------------------
239
241
atomic_uint16_t min_redzone;
240
242
atomic_uint16_t max_redzone;
@@ -268,6 +270,14 @@ struct Allocator {
268
270
SharedInitCode (options);
269
271
}
270
272
273
+ bool RssLimitExceeded () {
274
+ return atomic_load (&rss_limit_exceeded, memory_order_relaxed);
275
+ }
276
+
277
+ void SetRssLimitExceeded (bool limit_exceeded) {
278
+ atomic_store (&rss_limit_exceeded, limit_exceeded, memory_order_relaxed);
279
+ }
280
+
271
281
void RePoisonChunk (uptr chunk) {
272
282
// This could be a user-facing chunk (with redzones), or some internal
273
283
// housekeeping chunk, like TransferBatch. Start by assuming the former.
@@ -363,6 +373,8 @@ struct Allocator {
363
373
AllocType alloc_type, bool can_fill) {
364
374
if (UNLIKELY (!asan_inited))
365
375
AsanInitFromRtl ();
376
+ if (RssLimitExceeded ())
377
+ return allocator.ReturnNullOrDieOnOOM ();
366
378
Flags &fl = *flags ();
367
379
CHECK (stack);
368
380
const uptr min_alignment = SHADOW_GRANULARITY;
@@ -400,16 +412,15 @@ struct Allocator {
400
412
401
413
AsanThread *t = GetCurrentThread ();
402
414
void *allocated;
403
- bool check_rss_limit = true ;
404
415
if (t) {
405
416
AllocatorCache *cache = GetAllocatorCache (&t->malloc_storage ());
406
417
allocated =
407
- allocator.Allocate (cache, needed_size, 8 , false , check_rss_limit );
418
+ allocator.Allocate (cache, needed_size, 8 , false );
408
419
} else {
409
420
SpinMutexLock l (&fallback_mutex);
410
421
AllocatorCache *cache = &fallback_allocator_cache;
411
422
allocated =
412
- allocator.Allocate (cache, needed_size, 8 , false , check_rss_limit );
423
+ allocator.Allocate (cache, needed_size, 8 , false );
413
424
}
414
425
415
426
if (!allocated) return allocator.ReturnNullOrDieOnOOM ();
@@ -866,8 +877,8 @@ void asan_mz_force_unlock() {
866
877
instance.ForceUnlock ();
867
878
}
868
879
869
- void AsanSoftRssLimitExceededCallback (bool exceeded ) {
870
- instance.allocator . SetRssLimitIsExceeded (exceeded );
880
+ void AsanSoftRssLimitExceededCallback (bool limit_exceeded ) {
881
+ instance.SetRssLimitExceeded (limit_exceeded );
871
882
}
872
883
873
884
} // namespace __asan
0 commit comments