vfs: check userland buffers before reading them.
[haiku.git] / src / bin / debug / strace / Syscall.h
bloba59904ea76d0c740203b0ab6b508972c693fb424
1 /*
2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef STRACE_SYSCALL_H
6 #define STRACE_SYSCALL_H
8 #include <string>
9 #include <vector>
11 #include <SupportDefs.h>
13 #include "TypeHandler.h"
15 using std::string;
16 using std::vector;
18 // Type
19 class Type {
20 public:
21 Type(string typeName, TypeHandler *handler)
22 : fTypeName(typeName), fHandler(handler) {}
24 const string &TypeName() const { return fTypeName; }
26 void SetHandler(TypeHandler *handler)
28 delete fHandler;
29 fHandler = handler;
32 TypeHandler *Handler() const { return fHandler; }
34 private:
35 string fTypeName;
36 TypeHandler *fHandler;
39 // Parameter
40 class Parameter : public Type {
41 public:
42 Parameter(string name, int32 offset, string typeName, TypeHandler *handler)
43 : Type(typeName, handler),
44 fName(name),
45 fOffset(offset)
49 const string &Name() const { return fName; }
50 int32 Offset() const { return fOffset; }
52 private:
53 string fName;
54 int32 fOffset;
57 // Syscall
58 class Syscall {
59 public:
60 Syscall(string name, string returnTypeName, TypeHandler *returnTypeHandler)
61 : fName(name),
62 fReturnType(new Type(returnTypeName, returnTypeHandler))
66 const string &Name() const
68 return fName;
71 Type *ReturnType() const
73 return fReturnType;
76 void AddParameter(Parameter *parameter)
78 fParameters.push_back(parameter);
81 void AddParameter(string name, int32 offset, string typeName,
82 TypeHandler *handler)
84 AddParameter(new Parameter(name, offset, typeName, handler));
87 int32 CountParameters() const
89 return fParameters.size();
92 Parameter *ParameterAt(int32 index) const
94 return fParameters[index];
97 Parameter *GetParameter(string name) const
99 int32 count = CountParameters();
100 for (int32 i = 0; i < count; i++) {
101 Parameter *parameter = ParameterAt(i);
102 if (parameter->Name() == name)
103 return parameter;
106 return NULL;
109 private:
110 string fName;
111 Type *fReturnType;
112 vector<Parameter*> fParameters;
115 #endif // STRACE_SYSCALL_H