190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/* 2f71323e297a928af368937089d3ed71239786f86Andreas Huber * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber * 4f71323e297a928af368937089d3ed71239786f86Andreas Huber * Use of this source code is governed by a BSD-style license 5f71323e297a928af368937089d3ed71239786f86Andreas Huber * that can be found in the LICENSE file in the root of the source 6f71323e297a928af368937089d3ed71239786f86Andreas Huber * tree. An additional intellectual property rights grant can be found 7f71323e297a928af368937089d3ed71239786f86Andreas Huber * in the file PATENTS. All contributing project authors may 8f71323e297a928af368937089d3ed71239786f86Andreas Huber * be found in the AUTHORS file in the root of the source tree. 990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber */ 1090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 1190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 1290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/* This code is in the public domain. 1390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber** Version: 1.1 Author: Walt Karas 1490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber*/ 1590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 1690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/* The function in this file performs default actions if self-auditing 1790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber** finds heap corruption. Don't rely on this code to handle the 1890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber** case where HMM is being used to implement the malloc and free standard 1990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber** library functions. Rewrite the function if necessary to avoid using 2090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber** I/O and execution termination functions that call malloc or free. 2190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber** In Unix, for example, you would replace the fputs calls with calls 2290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber** to the write system call using file handle number 2. 2390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber*/ 2490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "hmm_intrnl.h" 2590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include <stdio.h> 2690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include <stdlib.h> 2790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 2890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huberstatic int entered = 0; 2990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 3090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/* Print abort message, file and line. Terminate execution. 3190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber*/ 32ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangvoid hmm_dflt_abort(const char *file, const char *line) { 33ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang /* Avoid use of printf(), which is more likely to use heap. */ 3490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 35ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (entered) 3690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 37ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang /* The standard I/O functions called a heap function and caused 38ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ** an indirect recursive call to this function. So we'll have 39ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ** to just exit without printing a message. */ 40ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang while (1); 4190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 42ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang entered = 1; 4390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 44ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang fputs("\n_abort - Heap corruption\n" "File: ", stderr); 45ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang fputs(file, stderr); 46ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang fputs(" Line: ", stderr); 47ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang fputs(line, stderr); 48ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang fputs("\n\n", stderr); 49ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang fputs("hmm_dflt_abort: while(1)!!!\n", stderr); 50ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang fflush(stderr); 5190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 52ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang while (1); 5390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} 54