Api.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #pragma intrinsic(memcpy)
  7. extern void __stdcall js_memcpy_s(__bcount(sizeInBytes) void *dst, size_t sizeInBytes, __in_bcount(count) const void *src, size_t count);
  8. extern void __stdcall js_wmemcpy_s(__ecount(sizeInWords) wchar16 *dst, size_t sizeInWords, __in_ecount(count) const wchar16 *src, size_t count);
  9. // A virtualized thread id. The physical thread on which an instance of the runtime is executed can change but a
  10. // ThreadContextId should be invariant.
  11. // Many parts of the runtime expect to only be called by the execution, or "main", thread. Hosts have the prerogative
  12. // of allocating physical execution threads, thus the physical execution thread is not invariant. Hosts also own the
  13. // virtualization of the thread id and are responsible for making ThreadContextIds invariant.
  14. typedef void * ThreadContextId;
  15. #define NoThreadContextId (ThreadContextId)NULL
  16. // Functions that need to be implemented by user of Common library
  17. namespace Js
  18. {
  19. // Forward declaration
  20. class ScriptContext;
  21. };
  22. namespace JsUtil
  23. {
  24. struct ExternalApi
  25. {
  26. // Returns the current execution ThreadContextId
  27. static ThreadContextId GetCurrentThreadContextId();
  28. static bool RaiseOutOfMemoryIfScriptActive();
  29. static bool RaiseStackOverflowIfScriptActive(Js::ScriptContext * scriptContext, PVOID returnAddress);
  30. static bool RaiseOnIntOverflow();
  31. static void RecoverUnusedMemory();
  32. #if DBG || defined(EXCEPTION_CHECK)
  33. static BOOL IsScriptActiveOnCurrentThreadContext();
  34. #endif
  35. // By default, implemented in Dll\Jscript\ScriptEngine.cpp
  36. // Anyone who statically links with jscript.common.common.lib has to implement this
  37. // This is used to determine which regkey we should read while loading the configuration
  38. static LPCWSTR GetFeatureKeyName();
  39. };
  40. };
  41. // Just an alias to ExternalApi::GetCurrentThreadContextId
  42. inline ThreadContextId GetCurrentThreadContextId()
  43. {
  44. return JsUtil::ExternalApi::GetCurrentThreadContextId();
  45. }