2014-02-27 18:55:04 +08:00
|
|
|
/** \file sanity.cpp
|
2012-11-18 18:23:22 +08:00
|
|
|
Functions for performing sanity checks on the program state
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
2006-08-11 09:18:35 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
|
2006-02-28 21:17:16 +08:00
|
|
|
#include "fallback.h"
|
2005-09-20 21:26:39 +08:00
|
|
|
#include "util.h"
|
2006-02-28 21:17:16 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
#include "common.h"
|
|
|
|
#include "sanity.h"
|
|
|
|
#include "proc.h"
|
|
|
|
#include "history.h"
|
|
|
|
#include "reader.h"
|
|
|
|
#include "kill.h"
|
|
|
|
#include "wutil.h"
|
2006-07-20 06:55:49 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Status from earlier sanity checks
|
|
|
|
*/
|
|
|
|
static int insane;
|
|
|
|
|
|
|
|
void sanity_lose()
|
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
debug(0, _(L"Errors detected, shutting down. Break on sanity_lose() to debug."));
|
|
|
|
insane = 1;
|
2005-09-20 21:26:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int sanity_check()
|
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
if (!insane)
|
|
|
|
if (get_is_interactive())
|
|
|
|
history_sanity_check();
|
|
|
|
if (!insane)
|
|
|
|
reader_sanity_check();
|
|
|
|
if (!insane)
|
|
|
|
kill_sanity_check();
|
|
|
|
if (!insane)
|
|
|
|
proc_sanity_check();
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
return insane;
|
2005-09-20 21:26:39 +08:00
|
|
|
}
|
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
void validate_pointer(const void *ptr, const wchar_t *err, int null_ok)
|
2005-09-20 21:26:39 +08:00
|
|
|
{
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
/*
|
|
|
|
Test if the pointer data crosses a segment boundary.
|
|
|
|
*/
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
if ((0x00000003l & (intptr_t)ptr) != 0)
|
|
|
|
{
|
|
|
|
debug(0, _(L"The pointer '%ls' is invalid"), err);
|
|
|
|
sanity_lose();
|
|
|
|
}
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
if ((!null_ok) && (ptr==0))
|
|
|
|
{
|
|
|
|
debug(0, _(L"The pointer '%ls' is null"), err);
|
|
|
|
sanity_lose();
|
|
|
|
}
|
2005-09-20 21:26:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|