2016-05-03 19:31:07 +00:00
|
|
|
// Functions for performing sanity checks on the program state.
|
2016-05-18 22:30:21 +00:00
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
2019-10-13 22:50:48 +00:00
|
|
|
#include "sanity.h"
|
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include <unistd.h>
|
2006-02-28 13:17:16 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
#include "common.h"
|
2016-05-03 19:31:07 +00:00
|
|
|
#include "fallback.h" // IWYU pragma: keep
|
2019-05-27 22:56:53 +00:00
|
|
|
#include "flog.h"
|
2019-04-29 01:13:55 +00:00
|
|
|
#include "global_safety.h"
|
2005-09-20 13:26:39 +00:00
|
|
|
#include "history.h"
|
|
|
|
#include "kill.h"
|
2016-05-03 19:31:07 +00:00
|
|
|
#include "proc.h"
|
|
|
|
#include "reader.h"
|
2006-07-19 22:55:49 +00:00
|
|
|
|
2016-05-03 19:31:07 +00:00
|
|
|
/// Status from earlier sanity checks.
|
2019-04-29 01:13:55 +00:00
|
|
|
static relaxed_atomic_bool_t insane{false};
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2016-05-03 19:31:07 +00:00
|
|
|
void sanity_lose() {
|
2019-05-27 22:56:53 +00:00
|
|
|
FLOG(error, _(L"Errors detected, shutting down. Break on sanity_lose() to debug."));
|
2017-01-24 23:14:56 +00:00
|
|
|
insane = true;
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 19:31:07 +00:00
|
|
|
void validate_pointer(const void *ptr, const wchar_t *err, int null_ok) {
|
|
|
|
// Test if the pointer data crosses a segment boundary.
|
2020-04-08 23:56:59 +00:00
|
|
|
if ((0x00000003L & reinterpret_cast<intptr_t>(ptr)) != 0) {
|
2019-05-30 09:54:09 +00:00
|
|
|
FLOGF(error, _(L"The pointer '%ls' is invalid"), err);
|
2012-11-19 00:30:30 +00:00
|
|
|
sanity_lose();
|
|
|
|
}
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2019-11-19 02:34:50 +00:00
|
|
|
if ((!null_ok) && (ptr == nullptr)) {
|
2019-05-30 09:54:09 +00:00
|
|
|
FLOGF(error, _(L"The pointer '%ls' is null"), err);
|
2012-11-19 00:30:30 +00:00
|
|
|
sanity_lose();
|
|
|
|
}
|
2005-09-20 13:26:39 +00:00
|
|
|
}
|