• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/win/resource_exhaustion.h"
6 
7 #include "base/logging.h"
8 
9 namespace base::win {
10 
11 namespace {
12 
13 OnResourceExhaustedFunction g_resource_exhausted_function = nullptr;
14 
15 }  // namespace
16 
SetOnResourceExhaustedFunction(OnResourceExhaustedFunction on_resource_exhausted)17 void SetOnResourceExhaustedFunction(
18     OnResourceExhaustedFunction on_resource_exhausted) {
19   g_resource_exhausted_function = on_resource_exhausted;
20 }
21 
OnResourceExhausted()22 void OnResourceExhausted() {
23   // By default stop execution unless a function has been provided. Code is not
24   // assumed to anticipate or handle resource-exhaustion failures. Note that
25   // this function is currently intentionally not [[noreturn]]. As of writing
26   // chrome/installer/setup/setup_main.cc intentionally continues execution to
27   // attempt to propagate the error outwards.
28   LOG_IF(FATAL, !g_resource_exhausted_function) << "System resource exhausted.";
29 
30   g_resource_exhausted_function();
31 }
32 
33 }  // namespace base::win
34