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