1*ec63e07aSXin Li // Copyright 2019 Google LLC 2*ec63e07aSXin Li // 3*ec63e07aSXin Li // Licensed under the Apache License, Version 2.0 (the "License"); 4*ec63e07aSXin Li // you may not use this file except in compliance with the License. 5*ec63e07aSXin Li // You may obtain a copy of the License at 6*ec63e07aSXin Li // 7*ec63e07aSXin Li // https://www.apache.org/licenses/LICENSE-2.0 8*ec63e07aSXin Li // 9*ec63e07aSXin Li // Unless required by applicable law or agreed to in writing, software 10*ec63e07aSXin Li // distributed under the License is distributed on an "AS IS" BASIS, 11*ec63e07aSXin Li // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*ec63e07aSXin Li // See the License for the specific language governing permissions and 13*ec63e07aSXin Li // limitations under the License. 14*ec63e07aSXin Li 15*ec63e07aSXin Li #ifndef SANDBOXED_API_CALL_H_ 16*ec63e07aSXin Li #define SANDBOXED_API_CALL_H_ 17*ec63e07aSXin Li 18*ec63e07aSXin Li #include <cstddef> 19*ec63e07aSXin Li #include <cstdint> 20*ec63e07aSXin Li 21*ec63e07aSXin Li #include "sandboxed_api/var_type.h" 22*ec63e07aSXin Li 23*ec63e07aSXin Li namespace sapi { 24*ec63e07aSXin Li namespace comms { 25*ec63e07aSXin Li 26*ec63e07aSXin Li struct ReallocRequest { 27*ec63e07aSXin Li uintptr_t old_addr; 28*ec63e07aSXin Li size_t size; 29*ec63e07aSXin Li }; 30*ec63e07aSXin Li 31*ec63e07aSXin Li // Types of TAGs used with Comms channel. 32*ec63e07aSXin Li // Call: 33*ec63e07aSXin Li constexpr uint32_t kMsgCall = 0x101; 34*ec63e07aSXin Li constexpr uint32_t kMsgAllocate = 0x102; 35*ec63e07aSXin Li constexpr uint32_t kMsgFree = 0x103; 36*ec63e07aSXin Li constexpr uint32_t kMsgExit = 0x104; 37*ec63e07aSXin Li constexpr uint32_t kMsgSymbol = 0x105; 38*ec63e07aSXin Li constexpr uint32_t kMsgSendFd = 0x106; 39*ec63e07aSXin Li constexpr uint32_t kMsgRecvFd = 0x107; 40*ec63e07aSXin Li constexpr uint32_t kMsgClose = 0x108; 41*ec63e07aSXin Li constexpr uint32_t kMsgReallocate = 0x109; 42*ec63e07aSXin Li constexpr uint32_t kMsgStrlen = 0x10A; 43*ec63e07aSXin Li // Return: 44*ec63e07aSXin Li constexpr uint32_t kMsgReturn = 0x201; 45*ec63e07aSXin Li 46*ec63e07aSXin Li } // namespace comms 47*ec63e07aSXin Li 48*ec63e07aSXin Li struct FuncCall { 49*ec63e07aSXin Li // Used with HandleCallMsg: 50*ec63e07aSXin Li enum { 51*ec63e07aSXin Li kFuncNameMax = 128, 52*ec63e07aSXin Li kArgsMax = 12, 53*ec63e07aSXin Li }; 54*ec63e07aSXin Li 55*ec63e07aSXin Li // Function to be called. 56*ec63e07aSXin Li char func[kFuncNameMax]; 57*ec63e07aSXin Li // Return type. 58*ec63e07aSXin Li v::Type ret_type; 59*ec63e07aSXin Li // Size of the return value (in bytes). 60*ec63e07aSXin Li size_t ret_size; 61*ec63e07aSXin Li // Number of input arguments. 62*ec63e07aSXin Li size_t argc; 63*ec63e07aSXin Li // Types of the input arguments. 64*ec63e07aSXin Li v::Type arg_type[kArgsMax]; 65*ec63e07aSXin Li // Size (in bytes) of input arguments. 66*ec63e07aSXin Li size_t arg_size[kArgsMax]; 67*ec63e07aSXin Li // Arguments to the call. 68*ec63e07aSXin Li union { 69*ec63e07aSXin Li uintptr_t arg_int; 70*ec63e07aSXin Li long double arg_float; 71*ec63e07aSXin Li } args[kArgsMax]; 72*ec63e07aSXin Li // Auxiliary type: 73*ec63e07aSXin Li // For pointers: type of the data it points to, 74*ec63e07aSXin Li // For others: unspecified. 75*ec63e07aSXin Li v::Type aux_type[kArgsMax]; 76*ec63e07aSXin Li // Size of the auxiliary data (e.g. a structure the pointer points to). 77*ec63e07aSXin Li size_t aux_size[kArgsMax]; 78*ec63e07aSXin Li }; 79*ec63e07aSXin Li 80*ec63e07aSXin Li struct FuncRet { 81*ec63e07aSXin Li // Return type: 82*ec63e07aSXin Li v::Type ret_type; 83*ec63e07aSXin Li // Return value. 84*ec63e07aSXin Li union { 85*ec63e07aSXin Li uintptr_t int_val; 86*ec63e07aSXin Li long double float_val; 87*ec63e07aSXin Li }; 88*ec63e07aSXin Li // Status of the operation: success/failure. 89*ec63e07aSXin Li bool success; 90*ec63e07aSXin Li }; 91*ec63e07aSXin Li 92*ec63e07aSXin Li } // namespace sapi 93*ec63e07aSXin Li 94*ec63e07aSXin Li #endif // SANDBOXED_API_CALL_H_ 95