-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler #106736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fc1aad5
[compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler
cjappl bed7e12
Add rtsan_enabled define
cjappl 5f91c56
Tweaked name of macro
cjappl 218b520
[PR] david - get rid of scoped enabler, macro, simplify interface
cjappl ec20696
Improve docs of rtsan enable/disable
cjappl 50f3672
[PR] vitalybuka - nested disabler test
cjappl aac11a1
[PR] vitalybuka - adjusted interface, deleted constructors and remove…
cjappl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//===-- sanitizer/rtsan_interface.h -----------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file is a part of RealtimeSanitizer. | ||
// | ||
// Public interface header. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SANITIZER_RTSAN_INTERFACE_H | ||
#define SANITIZER_RTSAN_INTERFACE_H | ||
|
||
#include <sanitizer/common_interface_defs.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
// Disable all RTSan error reporting. | ||
// Must be paired with a call to `__rtsan_enable` | ||
void SANITIZER_CDECL __rtsan_disable(void); | ||
|
||
// Re-enable all RTSan error reporting. | ||
// Must follow a call to `__rtsan_disable`. | ||
void SANITIZER_CDECL __rtsan_enable(void); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
|
||
namespace __rtsan { | ||
#if defined(__has_feature) && __has_feature(realtime_sanitizer) | ||
|
||
class ScopedDisabler { | ||
public: | ||
ScopedDisabler() { __rtsan_disable(); } | ||
~ScopedDisabler() { __rtsan_enable(); } | ||
|
||
#if __cplusplus >= 201103L | ||
cjappl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ScopedDisabler(const ScopedDisabler &) = delete; | ||
ScopedDisabler &operator=(const ScopedDisabler &) = delete; | ||
ScopedDisabler(ScopedDisabler &&) = delete; | ||
ScopedDisabler &operator=(ScopedDisabler &&) = delete; | ||
#else | ||
private: | ||
ScopedDisabler(const ScopedDisabler &); | ||
ScopedDisabler &operator=(const ScopedDisabler &); | ||
#endif // __cplusplus >= 201103L | ||
}; | ||
|
||
#else | ||
|
||
class ScopedDisabler { | ||
public: | ||
ScopedDisabler() {} | ||
#if __cplusplus >= 201103L | ||
ScopedDisabler(const ScopedDisabler &) = delete; | ||
ScopedDisabler &operator=(const ScopedDisabler &) = delete; | ||
ScopedDisabler(ScopedDisabler &&) = delete; | ||
ScopedDisabler &operator=(ScopedDisabler &&) = delete; | ||
#else | ||
private: | ||
ScopedDisabler(const ScopedDisabler &); | ||
ScopedDisabler &operator=(const ScopedDisabler &); | ||
#endif // __cplusplus >= 201103L | ||
}; | ||
|
||
#endif // defined(__has_feature) && __has_feature(realtime_sanitizer) | ||
} // namespace __rtsan | ||
#endif // __cplusplus | ||
|
||
#endif // SANITIZER_RTSAN_INTERFACE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// RUN: %clangxx -fsanitize=realtime %s -o %t | ||
// RUN: not %run %t 2>&1 | FileCheck %s | ||
// RUN: %clangxx %s -fsanitize=realtime -o - -S -emit-llvm | FileCheck %s --check-prefix=CHECK-ENABLED-IR | ||
// RUN: %clangxx %s -o - -S -emit-llvm | FileCheck %s --check-prefix=CHECK-DISABLED-IR | ||
// UNSUPPORTED: ios | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "sanitizer/rtsan_interface.h" | ||
|
||
void violation() [[clang::nonblocking]] { | ||
void *ptr; | ||
{ | ||
__rtsan::ScopedDisabler disabler{}; | ||
cjappl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ptr = malloc(2); | ||
fprintf(stderr, "Allocated pointer %p in disabled context\n", ptr); | ||
} | ||
|
||
// ensure nested disablers don't interfere with one another | ||
{ | ||
void *ptr2; | ||
__rtsan::ScopedDisabler disabler{}; | ||
{ | ||
__rtsan::ScopedDisabler disabler2{}; | ||
ptr2 = malloc(2); | ||
fprintf(stderr, "Allocated second pointer %p in disabled context\n", | ||
ptr2); | ||
} | ||
|
||
free(ptr2); | ||
fprintf(stderr, "Free'd second pointer in disabled context\n"); | ||
} | ||
|
||
free(ptr); | ||
} | ||
|
||
int main() { | ||
violation(); | ||
return 0; | ||
// CHECK: Allocated pointer {{.*}} in disabled context | ||
// CHECK: Allocated second pointer {{.*}} in disabled context | ||
// CHECK: Free'd second pointer in disabled context | ||
// CHECK: {{.*Real-time violation.*}} | ||
// CHECK-NOT: {{.*malloc*}} | ||
// CHECK-NEXT: {{.*free.*}} | ||
} | ||
|
||
// CHECK-ENABLED-IR: {{.*@__rtsan_disable.*}} | ||
// CHECK-ENABLED-IR: {{.*@__rtsan_enable.*}} | ||
|
||
// CHECK-DISABLED-IR-NOT: {{.*__rtsan_disable.*}} | ||
// CHECK-DISABLED-IR-NOT: {{.*__rtsan_enable.*}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.