This repository was archived by the owner on May 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvdso_wrapper_generator.cpp
More file actions
92 lines (74 loc) · 2.78 KB
/
Copy pathvdso_wrapper_generator.cpp
File metadata and controls
92 lines (74 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "vdso_wrapper_generator.h"
#include <algorithm>
using std::ofstream;
using std::string;
using std::vector;
static const string in = " ";
static const string inin = in + in;
static bool none_apply(const Syscall& sc, const std::vector<CallWrapper*> wrappers) {
for (const CallWrapper* wrapper : wrappers) {
if (wrapper->applies(sc)) {
return false;
}
}
return true;
}
bool VdsoWrapperGenerator::syscall(ofstream& os, const Syscall& sc) {
if (sc.is_vdso() || none_apply(sc, wrappers_)) {
// Skip all calls implemented in the VDSO. They're on their own.
return os.good();
}
// Writing the wrapper.
write_syscall_signature_line(os, sc, wrapper_prefix_, "", " ", false, "");
os << " {\n"
<< in;
std::string return_var = write_syscall_return_var(os, sc);
pre_call(os, sc);
os << inin;
// Invoke the actuall syscall.
write_syscall_invocation(os, sc, return_var, call_prefix_);
post_call(os, sc, return_var);
if (!return_var.empty()) {
os << in << "return " << return_var << ";\n";
}
os << "}\n\n";
// Now put the wrapper into the public interface.
os << "VDSO_INTERFACE_FUNCTION(zx_" << sc.name << ");\n\n";
return os.good();
}
void VdsoWrapperGenerator::pre_call(ofstream& os, const Syscall& sc) const {
std::for_each(wrappers_.begin(), wrappers_.end(), [&os, &sc](const CallWrapper* wrapper) {
if (wrapper->applies(sc)) {
wrapper->preCall(os, sc);
}
});
}
void VdsoWrapperGenerator::post_call(ofstream& os, const Syscall& sc, string return_var) const {
std::for_each(wrappers_.rbegin(), wrappers_.rend(), [&os, &sc, &return_var](const CallWrapper* wrapper) {
if (wrapper->applies(sc)) {
wrapper->postCall(os, sc, return_var);
}
});
}
bool TestWrapper::applies(const Syscall& sc) const {
return sc.name == "syscall_test_wrapper";
}
void TestWrapper::preCall(ofstream& os, const Syscall& sc) const {
os << in << "if (a < 0 || b < 0 || c < 0) return ZX_ERR_INVALID_ARGS;\n";
}
void TestWrapper::postCall(ofstream& os, const Syscall& sc, string return_var) const {
os << in << "if (" << return_var << " > 50) return ZX_ERR_OUT_OF_RANGE;\n";
}
bool BlockingRetryWrapper::applies(const Syscall& sc) const {
return sc.is_blocking();
}
void BlockingRetryWrapper::preCall(ofstream& os, const Syscall& sc) const {
os << in << "do {\n";
}
void BlockingRetryWrapper::postCall(
ofstream& os, const Syscall& sc, string return_var) const {
os << in << "} while (unlikely(" << return_var << " == ZX_ERR_INTERNAL_INTR_RETRY));\n";
}