Domain.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "il2cpp-config.h"
  2. #include "vm/Class.h"
  3. #include "vm/Domain.h"
  4. #include "vm/Object.h"
  5. #include "vm/Runtime.h"
  6. #include "vm/Thread.h"
  7. #include "gc/GarbageCollector.h"
  8. #include "gc/WriteBarrier.h"
  9. #include "il2cpp-class-internals.h"
  10. #include "il2cpp-object-internals.h"
  11. namespace il2cpp
  12. {
  13. namespace vm
  14. {
  15. Il2CppDomain* Domain::S_domain = NULL;
  16. Il2CppDomain* Domain::GetCurrent()
  17. {
  18. if (S_domain)
  19. return S_domain;
  20. // allocate using gc memory since we hold onto object references
  21. S_domain = (Il2CppDomain*)il2cpp::gc::GarbageCollector::AllocateFixed(sizeof(Il2CppDomain), NULL);
  22. gc::WriteBarrier::GenericStore(&S_domain->ephemeron_tombstone, Object::New(il2cpp_defaults.object_class));
  23. return S_domain;
  24. }
  25. Il2CppDomain* Domain::GetRoot()
  26. {
  27. // just one domain for now
  28. return GetCurrent();
  29. }
  30. void Domain::ContextInit(Il2CppDomain *domain)
  31. {
  32. Il2CppClass* klass = Class::FromName(il2cpp_defaults.corlib, "System.Runtime.Remoting.Contexts", "Context");
  33. Il2CppAppContext* context = (Il2CppAppContext*)Object::New(klass);
  34. // To match Mono's implementation we do not call the constructor here. If we do, context_id will be 1, which
  35. // is not correct.
  36. context->domain_id = domain->domain_id;
  37. context->context_id = 0;
  38. gc::WriteBarrier::GenericStore(&domain->default_context, context);
  39. }
  40. void Domain::ContextSet(Il2CppAppContext* context)
  41. {
  42. IL2CPP_OBJECT_SETREF(il2cpp::vm::Thread::Current()->GetInternalThread(), current_appcontext, (Il2CppObject*)context);
  43. }
  44. Il2CppAppContext* Domain::ContextGet()
  45. {
  46. return (Il2CppAppContext*)il2cpp::vm::Thread::Current()->GetInternalThread()->current_appcontext;
  47. }
  48. } /* namespace vm */
  49. } /* namespace il2cpp */