1 #ifndef GENSYSCALLS_H 2 #define GENSYSCALLS_H 3 4 // TODO: <syscalls.h> is pre-processed with the cross-compiler, but the 5 // pre-processed header is compiled with the native compiler. Unfortunately 6 // <stdarg.h> is included indirectly, which results in a missing typedef when 7 // the host compiler is gcc 2 and the native compiler gcc 4. The type is never 8 // really used, so this doesn't really matter what it is defined to. The better 9 // solution would be to remove the <stdarg.h> dependency, though. 10 #if __GNUC__ == 2 11 typedef void *__builtin_va_list; 12 #endif 13 14 // Type 15 class Type { 16 public: 17 Type(const char* name, int size, 18 int usedSize, 19 const char* alignmentTypeName); 20 ~Type() {} 21 22 const char* TypeName() const { return fName; } 23 int Size() const { return fSize; } 24 int UsedSize() const { return fUsedSize; } 25 const char* AlignmentTypeName() const 26 { return fAlignmentType; } 27 28 private: 29 const char* fName; 30 int fSize; 31 int fUsedSize; 32 const char* fAlignmentType; 33 }; 34 35 // Parameter 36 class Parameter : public Type { 37 public: 38 Parameter(const char* typeName, 39 const char* parameterName, int size, 40 int usedSize, int offset, 41 const char* alignmentTypeName); 42 ~Parameter() {} 43 44 const char* ParameterName() const { return fParameterName; } 45 int Offset() const { return fOffset; } 46 47 private: 48 const char* fParameterName; 49 int fOffset; 50 }; 51 52 // Syscall 53 class Syscall { 54 public: 55 Syscall(const char* name, 56 const char* kernelName); 57 ~Syscall(); 58 59 const char* Name() const { return fName; } 60 const char* KernelName() const { return fKernelName; } 61 Type* ReturnType() const { return fReturnType; } 62 63 int CountParameters() const; 64 Parameter* ParameterAt(int index) const; 65 Parameter* LastParameter() const; 66 67 template<typename T> void SetReturnType(const char* name); 68 template<typename T> void AddParameter(const char* typeName, 69 const char* parameterName); 70 71 Type* SetReturnType(const char* name, int size, 72 int usedSize, 73 const char* alignmentTypeName); 74 Parameter* AddParameter(const char* typeName, 75 const char* parameterName, int size, 76 int usedSize, int offset, 77 const char* alignmentTypeName); 78 79 private: 80 struct ParameterVector; 81 82 const char* fName; 83 const char* fKernelName; 84 Type* fReturnType; 85 ParameterVector* fParameters; 86 }; 87 88 // SyscallVector 89 class SyscallVector { 90 public: 91 SyscallVector(); 92 ~SyscallVector(); 93 94 static SyscallVector* Create(); 95 96 int CountSyscalls() const; 97 Syscall* SyscallAt(int index) const; 98 99 Syscall* CreateSyscall(const char* name, 100 const char* kernelName); 101 102 private: 103 struct _SyscallVector; 104 105 _SyscallVector* fSyscalls; 106 }; 107 108 extern SyscallVector* create_syscall_vector(); 109 110 111 #ifndef DONT_INCLUDE_ARCH_GENSYSCALLS_H 112 113 // align_to_type 114 template<typename T> 115 int 116 align_to_type(int size) 117 { 118 return (size + sizeof(T) - 1) / sizeof(T) * sizeof(T); 119 } 120 121 #include "arch_gensyscalls.h" 122 123 // SetReturnType 124 template<typename T> 125 void 126 Syscall::SetReturnType(const char* name) 127 { 128 ReturnTypeCreator<T>::Create(this, name); 129 } 130 131 // AddParameter 132 template<typename T> 133 void 134 Syscall::AddParameter(const char* typeName, const char* parameterName) 135 { 136 ParameterCreator<T>::Create(this, typeName, parameterName); 137 } 138 139 #endif // !DONT_INCLUDE_ARCH_GENSYSCALLS_H 140 141 #endif // GENSYSCALLS_H 142