1// Copyright 2017 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#pragma once 6 7#include "generator.h" 8 9// Generates wrappers in the vDSO that add behavior defined by the given 10// CallWrapper list. 11class VdsoWrapperGenerator : public Generator { 12public: 13 VdsoWrapperGenerator(std::string wrapper_prefix, 14 std::string call_prefix, 15 std::vector<CallWrapper*> call_wrappers) 16 : wrapper_prefix_(wrapper_prefix), 17 call_prefix_(call_prefix), wrappers_(call_wrappers) {} 18 19 bool syscall(std::ofstream& os, const Syscall& sc) override; 20 21private: 22 void pre_call(std::ofstream& os, const Syscall& sc) const; 23 void post_call(std::ofstream& os, const Syscall& sc, std::string return_var) const; 24 25 std::string wrapper_prefix_; 26 std::string call_prefix_; 27 std::vector<CallWrapper*> wrappers_; 28}; 29 30// Wrapper for testing that wrappers work correctly. Applied only to syscall_test_wrapper. 31class TestWrapper : public CallWrapper { 32public: 33 bool applies(const Syscall& sc) const override; 34 // Adds a precondition that all args are > 0; 35 void preCall(std::ofstream& os, const Syscall& sc) const override; 36 // Adds a postcondition that the result is < 50; 37 void postCall(std::ofstream& os, const Syscall& sc, std::string return_var) const override; 38}; 39 40// Wraps a syscall with the "blocking" attribute with code that will 41// automatically retry if interrupted. 42class BlockingRetryWrapper : public CallWrapper { 43public: 44 bool applies(const Syscall& sc) const override; 45 void preCall(std::ofstream& os, const Syscall& sc) const override; 46 void postCall(std::ofstream& os, const Syscall& sc, std::string return_var) const override; 47}; 48