1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5#ifndef __CORJITHOST_H__
6#define __CORJITHOST_H__
7
8// ICorJitHost
9//
10// ICorJitHost provides the interface that the JIT uses to access some functionality that
11// would normally be provided by the operating system. This is intended to allow for
12// host-specific policies re: memory allocation, configuration value access, etc. It is
13// expected that the `ICorJitHost` value provided to `jitStartup` lives at least as
14// long as the JIT itself.
15class ICorJitHost
16{
17public:
18 // Allocate memory of the given size in bytes.
19 virtual void* allocateMemory(size_t size) = 0;
20
21 // Frees memory previous obtained by a call to `ICorJitHost::allocateMemory`.
22 virtual void freeMemory(void* block) = 0;
23
24 // Return an integer config value for the given key, if any exists.
25 virtual int getIntConfigValue(
26 const wchar_t* name,
27 int defaultValue
28 ) = 0;
29
30 // Return a string config value for the given key, if any exists.
31 virtual const wchar_t* getStringConfigValue(
32 const wchar_t* name
33 ) = 0;
34
35 // Free a string ConfigValue returned by the runtime.
36 // JITs using the getStringConfigValue query are required
37 // to return the string values to the runtime for deletion.
38 // This avoids leaking the memory in the JIT.
39 virtual void freeStringConfigValue(
40 const wchar_t* value
41 ) = 0;
42
43 // Allocate memory slab of the given size in bytes. The host is expected to pool
44 // these for a good performance.
45 virtual void* allocateSlab(size_t size, size_t* pActualSize)
46 {
47 *pActualSize = size;
48 return allocateMemory(size);
49 }
50
51 // Free memory slab of the given size in bytes.
52 virtual void freeSlab(void* slab, size_t actualSize)
53 {
54 freeMemory(slab);
55 }
56};
57
58#endif
59