11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_HEAP_CPPGC_PLATFORM_H_
61cb0ef41Sopenharmony_ci#define V8_HEAP_CPPGC_PLATFORM_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <string>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "include/cppgc/source-location.h"
111cb0ef41Sopenharmony_ci#include "src/base/macros.h"
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cinamespace cppgc {
141cb0ef41Sopenharmony_cinamespace internal {
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciclass HeapBase;
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE FatalOutOfMemoryHandler final {
191cb0ef41Sopenharmony_ci public:
201cb0ef41Sopenharmony_ci  using Callback = void(const std::string&, const SourceLocation&, HeapBase*);
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  FatalOutOfMemoryHandler() = default;
231cb0ef41Sopenharmony_ci  explicit FatalOutOfMemoryHandler(HeapBase* heap) : heap_(heap) {}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  [[noreturn]] void operator()(
261cb0ef41Sopenharmony_ci      const std::string& reason = std::string(),
271cb0ef41Sopenharmony_ci      const SourceLocation& = SourceLocation::Current()) const;
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  void SetCustomHandler(Callback*);
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  // Disallow copy/move.
321cb0ef41Sopenharmony_ci  FatalOutOfMemoryHandler(const FatalOutOfMemoryHandler&) = delete;
331cb0ef41Sopenharmony_ci  FatalOutOfMemoryHandler& operator=(const FatalOutOfMemoryHandler&) = delete;
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci private:
361cb0ef41Sopenharmony_ci  HeapBase* heap_ = nullptr;
371cb0ef41Sopenharmony_ci  Callback* custom_handler_ = nullptr;
381cb0ef41Sopenharmony_ci};
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci}  // namespace internal
411cb0ef41Sopenharmony_ci}  // namespace cppgc
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci#endif  // V8_HEAP_CPPGC_PLATFORM_H_
44