Api.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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) char16 *dst, size_t sizeInWords, __in_ecount(count) const char16 *src, size_t count);
  9. #if defined(_M_IX86) || defined(_M_X64)
  10. extern void __stdcall js_memset_zero_nontemporal(__bcount(sizeInBytes) void *dst, size_t sizeInBytes);
  11. #endif
  12. // A virtualized thread id. The physical thread on which an instance of the runtime is executed can change but a
  13. // ThreadContextId should be invariant.
  14. // Many parts of the runtime expect to only be called by the execution, or "main", thread. Hosts have the prerogative
  15. // of allocating physical execution threads, thus the physical execution thread is not invariant. Hosts also own the
  16. // virtualization of the thread id and are responsible for making ThreadContextIds invariant.
  17. typedef void * ThreadContextId;
  18. #define NoThreadContextId (ThreadContextId)NULL
  19. // Functions that need to be implemented by user of Common library
  20. namespace Js
  21. {
  22. // Forward declaration
  23. class ScriptContext;
  24. };
  25. namespace JsUtil
  26. {
  27. struct ExternalApi
  28. {
  29. // Returns the current execution ThreadContextId
  30. static ThreadContextId GetCurrentThreadContextId();
  31. static bool RaiseOutOfMemoryIfScriptActive();
  32. static bool RaiseStackOverflowIfScriptActive(Js::ScriptContext * scriptContext, PVOID returnAddress);
  33. static bool RaiseOnIntOverflow();
  34. static void RecoverUnusedMemory();
  35. #if DBG || defined(EXCEPTION_CHECK)
  36. static BOOL IsScriptActiveOnCurrentThreadContext();
  37. #endif
  38. // By default, implemented in Dll\Jscript\ScriptEngine.cpp
  39. // Anyone who statically links with jscript.common.common.lib has to implement this
  40. // This is used to determine which regkey we should read while loading the configuration
  41. static LPCWSTR GetFeatureKeyName();
  42. };
  43. };
  44. // Just an alias to ExternalApi::GetCurrentThreadContextId
  45. inline ThreadContextId GetCurrentThreadContextId()
  46. {
  47. return JsUtil::ExternalApi::GetCurrentThreadContextId();
  48. }