RemotePointerWrapper.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2012 Sony Computer Entertainment Inc.
  2. // All Rights Reserved.
  3. #ifndef RemotePointerWrapper_h
  4. #define RemotePointerWrapper_h
  5. #if ENABLE(DETACHED_JIT)
  6. #include "jit/JITStubTypes.h"
  7. #include "jit_detached/JSCBridge.h"
  8. #include "runtime/JSCJSValue.h"
  9. #include <assert.h>
  10. namespace JSC {
  11. struct ClassInfo;
  12. class JSObject;
  13. class RemotePointerWrapper {
  14. public:
  15. static uintptr_t const s_invalidAddress = 0x0;
  16. public:
  17. operator void *() { assert(m_pointer != (void*)s_invalidAddress); return m_pointer; }
  18. operator void *() const { assert(m_pointer != (void*)s_invalidAddress); return m_pointer; }
  19. void * operator&() { assert(m_pointer != (void*)s_invalidAddress); return m_pointer; }
  20. void const * operator&() const { assert(m_pointer != (void*)s_invalidAddress); return m_pointer; }
  21. RemotePointerWrapper & operator=(uintptr_t value) { m_pointer = reinterpret_cast<void *>(value); return *this; }
  22. protected:
  23. void * m_pointer;
  24. };
  25. template <class FunctionPtrSignature>
  26. class RemoteFunctionWrapper {
  27. public:
  28. operator void *() { assert(m_function != 0); return reinterpret_cast<void*>(m_function); }
  29. operator void *() const { assert(m_function != 0); return reinterpret_cast<void*>(m_function); }
  30. operator FunctionPtrSignature() { assert(m_function != 0); return m_function; }
  31. operator FunctionPtrSignature() const { assert(m_function != 0); return m_function; }
  32. private:
  33. friend void JSCBridge::initializeCompilerSharedData();
  34. RemoteFunctionWrapper & operator=(uintptr_t func) { m_function = reinterpret_cast<FunctionPtrSignature>(func); return *this; } // TODO remove reinterpret_cast here because it defeats the purpose of having this class templetized for type safety
  35. private:
  36. FunctionPtrSignature m_function;
  37. };
  38. // provided for type safety. each one corresponds to the enum values defined in JITStubCall's m_returnType (see JITStubCall.h)
  39. typedef RemotePointerWrapper RemoteFunctionReturningVoid;
  40. typedef RemotePointerWrapper RemoteFunctionReturningVoidPtr;
  41. typedef RemotePointerWrapper RemoteFunctionReturningInt;
  42. typedef RemotePointerWrapper RemoteFunctionReturningValue;
  43. typedef RemotePointerWrapper RemoteFunctionReturningCell;
  44. typedef RemoteFunctionWrapper<int (*)(STUB_ARGS_DECLARATION)> RemoteCtiFunctionReturningInt;
  45. typedef RemoteFunctionWrapper<JSObject * (*)(STUB_ARGS_DECLARATION)> RemoteCtiFunctionReturningObject;
  46. typedef RemoteFunctionWrapper<EncodedJSValue (*)(STUB_ARGS_DECLARATION)> RemoteCtiFunctionReturningValue;
  47. typedef RemoteFunctionWrapper<void (*)(STUB_ARGS_DECLARATION)> RemoteCtiFunctionReturningVoid;
  48. typedef RemoteFunctionWrapper<void * (*)(STUB_ARGS_DECLARATION)> RemoteCtiFunctionReturningVoidPtr;
  49. class RemoteClassInfoPtr : public RemotePointerWrapper {
  50. public:
  51. operator ClassInfo * () { return reinterpret_cast<ClassInfo *>(m_pointer); }
  52. operator ClassInfo * () const { return reinterpret_cast<ClassInfo *>(m_pointer); }
  53. ClassInfo & operator *() { return *(reinterpret_cast<ClassInfo *>(m_pointer)); }
  54. RemoteClassInfoPtr & operator=(uintptr_t value) { m_pointer = reinterpret_cast<void *>(value); return *this; }
  55. };
  56. } // namespace JSC
  57. #endif // #if ENABLE(DETACHED_JIT)
  58. #endif // #ifndef RemotePointerWrapper_h