1474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/*
2474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org *
4474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org *  Use of this source code is governed by a BSD-style license
5474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org *  that can be found in the LICENSE file in the root of the source
6474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org *  tree. An additional intellectual property rights grant can be found
7474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org *  in the file PATENTS.  All contributing project authors may
8474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org *  be found in the AUTHORS file in the root of the source tree.
9474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org */
10474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
11474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
12474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/* This code is in the public domain.
13474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org** Version: 1.1  Author: Walt Karas
14474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org*/
15474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
16474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/* The function in this file performs default actions if self-auditing
17474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org** finds heap corruption.  Don't rely on this code to handle the
18474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org** case where HMM is being used to implement the malloc and free standard
19474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org** library functions.  Rewrite the function if necessary to avoid using
20474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org** I/O and execution termination functions that call malloc or free.
21474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org** In Unix, for example, you would replace the fputs calls with calls
22474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org** to the write system call using file handle number 2.
23474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org*/
24474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "hmm_intrnl.h"
25474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include <stdio.h>
26474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include <stdlib.h>
27474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
28474eb7536515fb785e925cc9375d22817c416851hclam@chromium.orgstatic int entered = 0;
29474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
30474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/* Print abort message, file and line.  Terminate execution.
31474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org*/
326fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.orgvoid hmm_dflt_abort(const char *file, const char *line) {
336fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  /* Avoid use of printf(), which is more likely to use heap. */
34474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
356fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  if (entered)
36474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
376fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org    /* The standard I/O functions called a heap function and caused
386fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org    ** an indirect recursive call to this function.  So we'll have
396fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org    ** to just exit without printing a message.  */
406fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org    while (1);
41474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
426fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  entered = 1;
43474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
446fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  fputs("\n_abort - Heap corruption\n" "File: ", stderr);
456fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  fputs(file, stderr);
466fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  fputs("  Line: ", stderr);
476fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  fputs(line, stderr);
486fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  fputs("\n\n", stderr);
496fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  fputs("hmm_dflt_abort: while(1)!!!\n", stderr);
506fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  fflush(stderr);
51474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
526fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  while (1);
53474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org}
54