internal_types.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifndef SANDBOX_WIN_SRC_INTERNAL_TYPES_H_
  5. #define SANDBOX_WIN_SRC_INTERNAL_TYPES_H_
  6. #include <stdint.h>
  7. namespace sandbox {
  8. const wchar_t kNtdllName[] = L"ntdll.dll";
  9. const wchar_t kKerneldllName[] = L"kernel32.dll";
  10. const wchar_t kKernelBasedllName[] = L"kernelbase.dll";
  11. // Defines the supported C++ types encoding to numeric id. Like a simplified
  12. // RTTI. Note that true C++ RTTI will not work because the types are not
  13. // polymorphic anyway.
  14. enum ArgType {
  15. INVALID_TYPE = 0,
  16. WCHAR_TYPE,
  17. UINT32_TYPE,
  18. UNISTR_TYPE,
  19. VOIDPTR_TYPE,
  20. INPTR_TYPE,
  21. INOUTPTR_TYPE,
  22. LAST_TYPE
  23. };
  24. // Encapsulates a pointer to a buffer and the size of the buffer.
  25. class CountedBuffer {
  26. public:
  27. CountedBuffer(void* buffer, uint32_t size) : size_(size), buffer_(buffer) {}
  28. uint32_t Size() const { return size_; }
  29. void* Buffer() const { return buffer_; }
  30. private:
  31. uint32_t size_;
  32. void* buffer_;
  33. };
  34. // Helper class to convert void-pointer packed ints for both
  35. // 32 and 64 bit builds. This construct is non-portable.
  36. class IPCInt {
  37. public:
  38. explicit IPCInt(void* buffer) { buffer_.vp = buffer; }
  39. explicit IPCInt(uint32_t i32) {
  40. buffer_.vp = nullptr;
  41. buffer_.i32 = i32;
  42. }
  43. uint32_t As32Bit() const { return buffer_.i32; }
  44. void* AsVoidPtr() const { return buffer_.vp; }
  45. private:
  46. union U {
  47. void* vp;
  48. uint32_t i32;
  49. } buffer_;
  50. };
  51. } // namespace sandbox
  52. #endif // SANDBOX_WIN_SRC_INTERNAL_TYPES_H_