Skip to content

Commit e38eb67

Browse files
Sandboxed API Teamcopybara-github
authored andcommitted
Skip processing UNSUPPORTED functions in the generator
SANDBOX_UNSUPPORTED("reason") is used to skip functions that are currently not supported by the code generator. Skip processing them. PiperOrigin-RevId: 889277347 Change-Id: I4cd19909b1d401bebd711b712528163db69b9230
1 parent fc0e86a commit e38eb67

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

sandboxed_api/annotations_unimplemented.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@
5151
#define SANDBOX_LIFETIME_BOUND(opaque_other) \
5252
[[clang::annotate("sandbox", "lifetime_bound", #opaque_other)]]
5353

54+
// This annotation is only used for testing purposes. Please do not use it.
55+
#define SANDBOX_UNIMPLEMENTED_TEST \
56+
[[clang::annotate("sandbox", "unimplemented_test")]]
57+
5458
#endif // SANDBOXED_API_ANNOTATIONS_UNIMPLEMENTED_H_

sandboxed_api/tests/testcases/lwbox_sandbox.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
// same file, we need a separate annotation file for SANDBOX_FUNCS.
55
SANDBOX_FUNCS(mylib_is_sandboxed, mylib_scalar_types, mylib_add, mylib_copy,
66
mylib_copy_raw, mylib_expected_syscall1, mylib_expected_syscall2,
7-
mylib_unexpected_syscall1, mylib_unexpected_syscall2);
7+
mylib_unexpected_syscall1, mylib_unexpected_syscall2,
8+
mylib_func_with_todo);

sandboxed_api/tests/testcases/replaced_library.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "absl/strings/string_view.h"
2828
#include "sandboxed_api/annotations.h"
29+
#include "sandboxed_api/annotations_unimplemented.h"
2930

3031
bool mylib_is_sandboxed();
3132

@@ -47,4 +48,10 @@ void mylib_unexpected_syscall2();
4748
// SANDBOX_FUNCS/SANDBOX_IGNORE_FUNCS annotations.
4849
void mylib_func_with_unsupported_arg(union mylib_union* arg);
4950

51+
// This function has a SANDBOX_UNSUPPORTED annotation and should be ignored
52+
// without causing errors.
53+
SANDBOX_UNSUPPORTED("This function is not supported for testing purposes.")
54+
void mylib_func_with_todo(
55+
const char* arg SANDBOX_UNIMPLEMENTED_TEST SANDBOX_IN_PTR);
56+
5057
#endif // SANDBOXED_API_SANDBOX2_TESTCASES_REPLACED_LIBRARY_H_

sandboxed_api/tools/clang_generator/sandboxed_library_emitter.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,13 @@ absl::Status SandboxedLibraryEmitter::AddFunction(clang::FunctionDecl* decl) {
776776
// Also check that they are consistent with the other annotations.
777777
// If it is a HOST thunk, it needs to be attached to the original function.
778778

779+
bool has_unsupported_annotation = false;
779780
auto annotations_status = GetSandboxAnnotations(decl);
780781
if (annotations_status.ok()) {
781782
for (const auto& ann : *annotations_status) {
782-
if (ann.name == "host_thunk") {
783+
if (ann.name == "unsupported") {
784+
has_unsupported_annotation = true;
785+
} else if (ann.name == "host_thunk") {
783786
if (ann.args.empty()) {
784787
return absl::NotFoundError(
785788
"Host thunk doesn't not specify the function name.");
@@ -856,6 +859,10 @@ absl::Status SandboxedLibraryEmitter::AddFunction(clang::FunctionDecl* decl) {
856859
}
857860
}
858861

862+
if (has_unsupported_annotation) {
863+
return absl::OkStatus();
864+
}
865+
859866
if (ignore_funcs_.contains(decl->getNameAsString()) ||
860867
(!sandbox_funcs_.empty() &&
861868
!sandbox_funcs_.contains(decl->getNameAsString()))) {

0 commit comments

Comments
 (0)