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