ATLAS Offline Software
Loading...
Searching...
No Matches
ubsan_suppress.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
10
11
13#include <unistd.h>
14#include <fcntl.h>
15#include <dlfcn.h>
16
17
18namespace CxxUtils {
19
20
22{
23public:
26 RedirStderr (const RedirStderr&) = delete;
28
29private:
32};
33
34
35// Redirect stderr to /dev/null, remembering the original FD.
37{
38 m_nullfd = open ("/dev/null", O_WRONLY);
39 m_stderr = dup (2);
40 if (m_nullfd >= 0) {
41 dup2 (m_nullfd, 2);
42 }
43}
44
45
46// Restore stderr to its original FD.
48{
49 dup2 (m_stderr, 2);
50 close (m_nullfd);
51 close (m_stderr);
52}
53
54
69void ubsan_suppress (void (*func)())
70{
71 if (dlsym (RTLD_DEFAULT, "__ubsan_handle_add_overflow") != NULL)
72 {
73 RedirStderr redir;
74 func();
75 }
76 else {
77 func();
78 }
79}
80
81
82} // namespace CxxUtils
RedirStderr(const RedirStderr &)=delete
RedirStderr & operator=(const RedirStderr &)=delete
void ubsan_suppress(void(*func)())
Helper for suppressing ubsan warnings.
Helper for suppressing ubsan warnings.