mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 01:04:57 +08:00
Change-Id: I34eb993b562c77f56d8fbd51a02ee266c1f76678 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
42 lines
985 B
C++
42 lines
985 B
C++
/*
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
#include "shared/source/helpers/abort.h"
|
|
|
|
#include "offline_compiler/utilities/windows/seh_exception.h"
|
|
|
|
#include <setjmp.h>
|
|
|
|
static jmp_buf jmpbuf;
|
|
|
|
class SafetyGuardWindows {
|
|
public:
|
|
template <typename T, typename Object, typename Method>
|
|
T call(Object *object, Method method, T retValueOnCrash) {
|
|
int jump = 0;
|
|
jump = setjmp(jmpbuf);
|
|
|
|
if (jump == 0) {
|
|
__try {
|
|
return (object->*method)();
|
|
} __except (SehException::filter(GetExceptionCode(), GetExceptionInformation())) {
|
|
if (onExcept) {
|
|
onExcept();
|
|
} else {
|
|
NEO::abortExecution();
|
|
}
|
|
longjmp(jmpbuf, 1);
|
|
}
|
|
}
|
|
return retValueOnCrash;
|
|
}
|
|
|
|
typedef void (*callbackFunction)();
|
|
callbackFunction onExcept = nullptr;
|
|
};
|