2010-03-03 21:02:56 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: sw=4 ts=4 et :
|
|
|
|
*/
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-03 21:02:56 -08:00
|
|
|
|
2010-11-09 02:13:03 -08:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
2010-04-08 11:05:02 -07:00
|
|
|
# define MOZALLOC_EXPORT __declspec(dllexport)
|
|
|
|
#endif
|
|
|
|
|
2010-04-20 13:12:02 -07:00
|
|
|
#include "mozilla/mozalloc_abort.h"
|
2010-03-03 21:02:56 -08:00
|
|
|
#include "mozilla/mozalloc_oom.h"
|
|
|
|
|
2012-01-24 08:08:51 -08:00
|
|
|
static mozalloc_oom_abort_handler gAbortHandler;
|
|
|
|
|
2010-03-03 21:02:56 -08:00
|
|
|
void
|
2012-01-24 08:08:51 -08:00
|
|
|
mozalloc_handle_oom(size_t size)
|
2010-03-03 21:02:56 -08:00
|
|
|
{
|
|
|
|
// NB: this is handle_oom() stage 1, which simply aborts on OOM.
|
|
|
|
// we might proceed to a stage 2 in which an attempt is made to
|
|
|
|
// reclaim memory
|
2012-01-24 08:08:51 -08:00
|
|
|
|
|
|
|
if (gAbortHandler)
|
|
|
|
gAbortHandler(size);
|
|
|
|
|
2010-04-20 13:12:02 -07:00
|
|
|
mozalloc_abort("out of memory");
|
2010-03-03 21:02:56 -08:00
|
|
|
}
|
2012-01-24 08:08:51 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
mozalloc_set_oom_abort_handler(mozalloc_oom_abort_handler handler)
|
|
|
|
{
|
|
|
|
gAbortHandler = handler;
|
|
|
|
}
|