LastError.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "LastError.h"
  2. #include "Thread.h"
  3. #include "os/LastError.h"
  4. namespace il2cpp
  5. {
  6. namespace vm
  7. {
  8. int32_t LastError::s_LastErrorThreadLocalStorageOffset = -1;
  9. uint32_t LastError::GetLastError()
  10. {
  11. if (s_LastErrorThreadLocalStorageOffset == -1)
  12. return 0;
  13. return *(uint32_t*)Thread::GetThreadStaticData(s_LastErrorThreadLocalStorageOffset);
  14. }
  15. void LastError::SetLastError(uint32_t error)
  16. {
  17. IL2CPP_ASSERT(s_LastErrorThreadLocalStorageOffset != -1);
  18. uint32_t* lastErrorTls = (uint32_t*)Thread::GetThreadStaticData(s_LastErrorThreadLocalStorageOffset);
  19. *lastErrorTls = error;
  20. }
  21. void LastError::StoreLastError()
  22. {
  23. SetLastError(os::LastError::GetLastError());
  24. }
  25. void LastError::InitializeLastErrorThreadStatic()
  26. {
  27. if (s_LastErrorThreadLocalStorageOffset == -1)
  28. s_LastErrorThreadLocalStorageOffset = Thread::AllocThreadStaticData(sizeof(uint32_t));
  29. }
  30. } /* namespace vm */
  31. } /* namespace il2cpp */