diff options
author | Pallavi Taneja <pallavit@microsoft.com> | 2015-11-08 15:34:22 -0800 |
---|---|---|
committer | Pallavi Taneja <pallavit@microsoft.com> | 2015-11-08 15:34:22 -0800 |
commit | ecdc8e02190d826a80a8add2a60e8bf2352c6e5c (patch) | |
tree | 9581a67b3ae27d7efc281970aafe4cc7ca3f94b6 /src/vm/corhost.cpp | |
parent | 19eb062435545d6dbf87d549bee8538cf39bf102 (diff) | |
download | coreclr-ecdc8e02190d826a80a8add2a60e8bf2352c6e5c.tar.gz coreclr-ecdc8e02190d826a80a8add2a60e8bf2352c6e5c.tar.bz2 coreclr-ecdc8e02190d826a80a8add2a60e8bf2352c6e5c.zip |
Expose Environment.GetCommandLineArgs in mscorlib
[tfs-changeset: 1546251]
Diffstat (limited to 'src/vm/corhost.cpp')
-rw-r--r-- | src/vm/corhost.cpp | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/src/vm/corhost.cpp b/src/vm/corhost.cpp index 161b2a1fae..3b559872bd 100644 --- a/src/vm/corhost.cpp +++ b/src/vm/corhost.cpp @@ -1217,6 +1217,58 @@ ErrExit: } #ifdef FEATURE_CORECLR +/* + * This method processes the arguments sent to the host which are then used + * to invoke the main method. + * Note - + * [0] - points to the assemblyName that has been sent by the host. + * The rest are the arguments sent to the assembly. + * Also note, this might not always return the exact same identity as the cmdLine + * used to invoke the method. + * + * For example :- + * ActualCmdLine - Foo arg1 arg2. + * (Host1) - Full_path_to_Foo arg1 arg2 +*/ +void SetCommandLineArgs(LPCWSTR pwzAssemblyPath, int argc, LPCWSTR* argv) +{ + CONTRACTL + { + THROWS; + GC_TRIGGERS; + MODE_COOPERATIVE; + } + CONTRACTL_END; + + struct _gc + { + PTRARRAYREF cmdLineArgs; + } gc; + + ZeroMemory(&gc, sizeof(gc)); + GCPROTECT_BEGIN(gc); + + gc.cmdLineArgs = (PTRARRAYREF)AllocateObjectArray(argc + 1 /* arg[0] should be the exe name*/, g_pStringClass); + OBJECTREF orAssemblyPath = StringObject::NewString(pwzAssemblyPath); + gc.cmdLineArgs->SetAt(0, orAssemblyPath); + + for (int i = 0; i < argc; ++i) + { + OBJECTREF argument = StringObject::NewString(argv[i]); + gc.cmdLineArgs->SetAt(i + 1, argument); + } + + MethodDescCallSite setCmdLineArgs(METHOD__ENVIRONMENT__SET_COMMAND_LINE_ARGS); + + ARG_SLOT args[] = + { + ObjToArgSlot(gc.cmdLineArgs), + }; + setCmdLineArgs.Call(args); + + GCPROTECT_END(); +} + HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId, LPCWSTR pwzAssemblyPath, int argc, @@ -1280,12 +1332,13 @@ HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId, { GCX_COOP(); + // Here we call the managed method that gets the cmdLineArgs array. + SetCommandLineArgs(pwzAssemblyPath, argc, argv); + PTRARRAYREF arguments = NULL; - GCPROTECT_BEGIN(arguments); - + arguments = (PTRARRAYREF)AllocateObjectArray(argc, g_pStringClass); - for (int i = 0; i < argc; ++i) { STRINGREF argument = StringObject::NewString(argv[i]); |