• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium 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 #ifndef SANDBOX_WIN_SRC_INTERNAL_TYPES_H_
6 #define SANDBOX_WIN_SRC_INTERNAL_TYPES_H_
7 
8 #include <stdint.h>
9 
10 namespace sandbox {
11 
12 const wchar_t kNtdllName[] = L"ntdll.dll";
13 const wchar_t kKerneldllName[] = L"kernel32.dll";
14 const wchar_t kKernelBasedllName[] = L"kernelbase.dll";
15 
16 // Defines the supported C++ types encoding to numeric id. Like a poor's man
17 // RTTI. Note that true C++ RTTI will not work because the types are not
18 // polymorphic anyway.
19 enum ArgType {
20   INVALID_TYPE = 0,
21   WCHAR_TYPE,
22   UINT32_TYPE,
23   UNISTR_TYPE,
24   VOIDPTR_TYPE,
25   INPTR_TYPE,
26   INOUTPTR_TYPE,
27   LAST_TYPE
28 };
29 
30 // Encapsulates a pointer to a buffer and the size of the buffer.
31 class CountedBuffer {
32  public:
CountedBuffer(void * buffer,uint32_t size)33   CountedBuffer(void* buffer, uint32_t size) : size_(size), buffer_(buffer) {}
34 
Size()35   uint32_t Size() const { return size_; }
36 
Buffer()37   void* Buffer() const {
38     return buffer_;
39   }
40 
41  private:
42   uint32_t size_;
43   void* buffer_;
44 };
45 
46 // Helper class to convert void-pointer packed ints for both
47 // 32 and 64 bit builds. This construct is non-portable.
48 class IPCInt {
49  public:
IPCInt(void * buffer)50   explicit IPCInt(void* buffer) {
51     buffer_.vp = buffer;
52   }
53 
IPCInt(unsigned __int32 i32)54   explicit IPCInt(unsigned __int32 i32) {
55     buffer_.vp = NULL;
56     buffer_.i32 = i32;
57   }
58 
As32Bit()59   unsigned __int32 As32Bit() const {
60     return buffer_.i32;
61   }
62 
AsVoidPtr()63   void* AsVoidPtr() const {
64     return buffer_.vp;
65   }
66 
67  private:
68   union U {
69     void* vp;
70     unsigned __int32 i32;
71   } buffer_;
72 };
73 
74 }  // namespace sandbox
75 
76 #endif  // SANDBOX_WIN_SRC_INTERNAL_TYPES_H_
77