-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mechanism for runtime to query host for information
- Loading branch information
1 parent
78b3f9d
commit 5d744ee
Showing
9 changed files
with
199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#ifndef _HOSTINFORMATION_H_ | ||
#define _HOSTINFORMATION_H_ | ||
|
||
#include <corehost/host_runtime_contract.h> | ||
|
||
class HostInformation | ||
{ | ||
public: | ||
static void SetContract(_In_ host_runtime_contract* hostContract); | ||
static bool GetProperty(_In_z_ const char* name, SString& value); | ||
}; | ||
|
||
#endif // _HOSTINFORMATION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#include "common.h" | ||
#include "hostinformation.h" | ||
#include "pinvokeoverride.h" | ||
|
||
namespace | ||
{ | ||
host_runtime_contract* s_hostContract = nullptr; | ||
} | ||
|
||
void HostInformation::SetContract(_In_ host_runtime_contract* hostContract) | ||
{ | ||
_ASSERTE(s_hostContract == nullptr); | ||
s_hostContract = hostContract; | ||
|
||
if (s_hostContract->pinvoke_override != nullptr) | ||
PInvokeOverride::SetPInvokeOverride(s_hostContract->pinvoke_override, PInvokeOverride::Source::RuntimeConfiguration); | ||
} | ||
|
||
bool HostInformation::GetProperty(_In_z_ const char* name, SString& value) | ||
{ | ||
if (s_hostContract == nullptr || s_hostContract->get_runtime_property == nullptr) | ||
return false; | ||
|
||
size_t len = MAX_PATH + 1; | ||
char* dest = value.OpenUTF8Buffer(static_cast<COUNT_T>(len)); | ||
size_t lenActual = s_hostContract->get_runtime_property(name, dest, len, s_hostContract->context); | ||
value.CloseBuffer(); | ||
|
||
// Doesn't exist or failed to get property | ||
if (lenActual == (size_t)-1 || lenActual == 0) | ||
return false; | ||
|
||
if (lenActual <= len) | ||
return true; | ||
|
||
// Buffer was not large enough | ||
len = lenActual; | ||
dest = value.OpenUTF8Buffer(static_cast<COUNT_T>(len)); | ||
lenActual = s_hostContract->get_runtime_property(name, dest, len, s_hostContract->context); | ||
value.CloseBuffer(); | ||
|
||
return lenActual > 0 && lenActual <= len; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#ifndef __HOST_RUNTIME_CONTRACT_H__ | ||
#define __HOST_RUNTIME_CONTRACT_H__ | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
#if defined(_WIN32) | ||
#define HOST_CONTRACT_CALLTYPE __stdcall | ||
#else | ||
#define HOST_CONTRACT_CALLTYPE | ||
#endif | ||
|
||
// Known host property names | ||
#define HOST_PROPERTY_RUNTIME_CONTRACT "HOST_RUNTIME_CONTRACT" | ||
#define HOST_PROPERTY_ENTRY_ASSEMBLY_NAME "ENTRY_ASSEMBLY_NAME" | ||
|
||
struct host_runtime_contract | ||
{ | ||
void* context; | ||
|
||
bool(HOST_CONTRACT_CALLTYPE* bundle_probe)( | ||
const char* path, | ||
int64_t* offset, | ||
int64_t* size, | ||
int64_t* compressedSize); | ||
|
||
const void* (HOST_CONTRACT_CALLTYPE* pinvoke_override)( | ||
const char* library_name, | ||
const char* entry_point_name); | ||
|
||
size_t(HOST_CONTRACT_CALLTYPE* get_runtime_property)( | ||
const char* key, | ||
char* value_buffer, | ||
size_t value_buffer_size, | ||
void* contract_context); | ||
}; | ||
|
||
#endif // __HOST_RUNTIME_CONTRACT_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters