Imported Upstream version 6.8.0.73

Former-commit-id: d18deab1b47cfd3ad8cba82b3f37d00eec2170af
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-12-10 18:00:56 +00:00
parent bceda29824
commit 73ee7591e8
1043 changed files with 16271 additions and 22080 deletions

View File

@ -0,0 +1,7 @@
# Files copied from coreclr/src/coreclr/hosts/unixcorerun repo
AM_CPPFLAGS = $(SHARED_CFLAGS)
bin_PROGRAMS = corerun
corerun_SOURCES = corerun.cpp coreruncommon.cpp coreruncommon.h coreclrhost.h

816
netcore/corerun/Makefile.in Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,125 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// APIs for hosting CoreCLR
//
#ifndef __CORECLR_HOST_H__
#define __CORECLR_HOST_H__
#if defined(_WIN32) && defined(_M_IX86)
#define CORECLR_CALLING_CONVENTION __stdcall
#else
#define CORECLR_CALLING_CONVENTION
#endif
// For each hosting API, we define a function prototype and a function pointer
// The prototype is useful for implicit linking against the dynamic coreclr
// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
#define CORECLR_HOSTING_API(function, ...) \
extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \
typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__)
//
// Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain
//
// Parameters:
// exePath - Absolute path of the executable that invoked the ExecuteAssembly (the native host application)
// appDomainFriendlyName - Friendly name of the app domain that will be created to execute the assembly
// propertyCount - Number of properties (elements of the following two arguments)
// propertyKeys - Keys of properties of the app domain
// propertyValues - Values of properties of the app domain
// hostHandle - Output parameter, handle of the created host
// domainId - Output parameter, id of the created app domain
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_initialize,
const char* exePath,
const char* appDomainFriendlyName,
int propertyCount,
const char** propertyKeys,
const char** propertyValues,
void** hostHandle,
unsigned int* domainId);
//
// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host.
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_shutdown,
void* hostHandle,
unsigned int domainId);
//
// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host.
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
// latchedExitCode - Latched exit code after domain unloaded
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_shutdown_2,
void* hostHandle,
unsigned int domainId,
int* latchedExitCode);
//
// Create a native callable function pointer for a managed method.
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
// entryPointAssemblyName - Name of the assembly which holds the custom entry point
// entryPointTypeName - Name of the type which holds the custom entry point
// entryPointMethodName - Name of the method which is the custom entry point
// delegate - Output parameter, the function stores a native callable function pointer to the delegate at the specified address
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_create_delegate,
void* hostHandle,
unsigned int domainId,
const char* entryPointAssemblyName,
const char* entryPointTypeName,
const char* entryPointMethodName,
void** delegate);
//
// Execute a managed assembly with given arguments
//
// Parameters:
// hostHandle - Handle of the host
// domainId - Id of the domain
// argc - Number of arguments passed to the executed assembly
// argv - Array of arguments passed to the executed assembly
// managedAssemblyPath - Path of the managed assembly to execute (or NULL if using a custom entrypoint).
// exitCode - Exit code returned by the executed assembly
//
// Returns:
// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed
//
CORECLR_HOSTING_API(coreclr_execute_assembly,
void* hostHandle,
unsigned int domainId,
int argc,
const char** argv,
const char* managedAssemblyPath,
unsigned int* exitCode);
#undef CORECLR_HOSTING_API
#endif // __CORECLR_HOST_H__

162
netcore/corerun/corerun.cpp Normal file
View File

@ -0,0 +1,162 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#include <coreruncommon.h>
#include <string>
#include <string.h>
#include <sys/stat.h>
// Display the command line options
void DisplayUsage()
{
fprintf(
stderr,
"Usage: corerun [OPTIONS] assembly [ARGUMENTS]\n"
"Execute the specified managed assembly with the passed in arguments\n\n"
"Options:\n"
"-c, --clr-path path to the libcoreclr.so and the managed CLR assemblies\n");
}
// Parse the command line arguments
bool ParseArguments(
const int argc,
const char* argv[],
const char** clrFilesPath,
const char** managedAssemblyPath,
int* managedAssemblyArgc,
const char*** managedAssemblyArgv)
{
bool success = false;
*clrFilesPath = nullptr;
*managedAssemblyPath = nullptr;
*managedAssemblyArgv = nullptr;
*managedAssemblyArgc = 0;
// The command line must contain at least the current exe name and the managed assembly path
if (argc >= 2)
{
for (int i = 1; i < argc; i++)
{
// Check for an option
if (argv[i][0] == '-')
{
// Path to the libcoreclr.so and the managed CLR assemblies
if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--clr-path") == 0)
{
i++;
if (i < argc)
{
*clrFilesPath = argv[i];
}
else
{
fprintf(stderr, "Option %s: missing path\n", argv[i - 1]);
break;
}
}
else if (strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
DisplayUsage();
break;
}
else
{
fprintf(stderr, "Unknown option %s\n", argv[i]);
break;
}
}
else
{
// First argument that is not an option is the managed assembly to execute
*managedAssemblyPath = argv[i];
int managedArgvOffset = (i + 1);
*managedAssemblyArgc = argc - managedArgvOffset;
if (*managedAssemblyArgc != 0)
{
*managedAssemblyArgv = &argv[managedArgvOffset];
}
success = true;
break;
}
}
}
else
{
DisplayUsage();
}
return success;
}
int corerun(const int argc, const char* argv[])
{
const char* clrFilesPath;
const char* managedAssemblyPath;
const char** managedAssemblyArgv;
int managedAssemblyArgc;
if (!ParseArguments(
argc,
argv,
&clrFilesPath,
&managedAssemblyPath,
&managedAssemblyArgc,
&managedAssemblyArgv))
{
// Invalid command line
return -1;
}
// Check if the specified managed assembly file exists
struct stat sb;
if (stat(managedAssemblyPath, &sb) == -1)
{
perror("Managed assembly not found");
return -1;
}
// Verify that the managed assembly path points to a file
if (!S_ISREG(sb.st_mode))
{
fprintf(stderr, "The specified managed assembly is not a file\n");
return -1;
}
// Make sure we have a full path for argv[0].
std::string argv0AbsolutePath;
if (!GetEntrypointExecutableAbsolutePath(argv0AbsolutePath))
{
perror("Could not get full path");
return -1;
}
std::string clrFilesAbsolutePath;
if(!GetClrFilesAbsolutePath(argv0AbsolutePath.c_str(), clrFilesPath, clrFilesAbsolutePath))
{
return -1;
}
std::string managedAssemblyAbsolutePath;
if (!GetAbsolutePath(managedAssemblyPath, managedAssemblyAbsolutePath))
{
perror("Failed to convert managed assembly path to absolute path");
return -1;
}
int exitCode = ExecuteManagedAssembly(
argv0AbsolutePath.c_str(),
clrFilesAbsolutePath.c_str(),
managedAssemblyAbsolutePath.c_str(),
managedAssemblyArgc,
managedAssemblyArgv);
return exitCode;
}
int main(const int argc, const char* argv[])
{
return corerun(argc, argv);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#include <string>
// Get the path to entrypoint executable
bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable);
// Get absolute path from the specified path.
// Return true in case of a success, false otherwise.
bool GetAbsolutePath(const char* path, std::string& absolutePath);
// Get directory of the specified path.
// Return true in case of a success, false otherwise.
bool GetDirectory(const char* absolutePath, std::string& directory);
//
// Get the absolute path to use to locate libcoreclr.so and the CLR assemblies are stored. If clrFilesPath is provided,
// this function will return the absolute path to it. Otherwise, the directory of the current executable is used.
//
// Return true in case of a success, false otherwise.
//
bool GetClrFilesAbsolutePath(const char* currentExePath, const char* clrFilesPath, std::string& clrFilesAbsolutePath);
// Add all *.dll, *.ni.dll, *.exe, and *.ni.exe files from the specified directory to the tpaList string.
void AddFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList);
//
// Execute the specified managed assembly.
//
// Parameters:
// currentExePath - Path to the current executable
// clrFilesAbsolutePath - Absolute path to the folder where the libcoreclr.so and CLR managed assemblies are stored
// managedAssemblyPath - Path to the managed assembly to execute
// managedAssemblyArgc - Number of arguments passed to the executed assembly
// managedAssemblyArgv - Array of arguments passed to the executed assembly
//
// Returns:
// ExitCode of the assembly
//
int ExecuteManagedAssembly(
const char* currentExeAbsolutePath,
const char* clrFilesAbsolutePath,
const char* managedAssemblyAbsolutePath,
int managedAssemblyArgc,
const char** managedAssemblyArgv);
#if defined(__APPLE__)
#include <mach-o/dyld.h>
static const char * const coreClrDll = "libcoreclr.dylib";
#else
static const char * const coreClrDll = "libcoreclr.so";
#endif