From: Sergei Ognerubov Date: Thu, 14 Dec 2017 22:34:23 +0000 (-0800) Subject: Added new shim for uwp console. Removed the constriction for the number of args.... X-Git-Tag: submit/tizen/20210909.063632~11032^2~936^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=31a585fe3b75b13acd7858fdc13e6014ad1f4d2d;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Added new shim for uwp console. Removed the constriction for the number of args. Replaced all the returns in the main with TerminateProcess. Replaced using the first arg with GetModuleFileName. Commit migrated from https://github.com/dotnet/core-setup/commit/e523a1a355fb8a88f39def321afb40dc6c954893 --- diff --git a/src/installer/uwp/Host/UWPShim/CMakeLists.txt b/src/installer/uwp/Host/UWPShim/CMakeLists.txt index dc5c00e..d499c6d 100644 --- a/src/installer/uwp/Host/UWPShim/CMakeLists.txt +++ b/src/installer/uwp/Host/UWPShim/CMakeLists.txt @@ -1,23 +1,2 @@ -include(../../../settings.cmake) - -add_definitions(-DUNICODE) -add_definitions(-D_UNICODE) -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmain") -set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib") - -include_directories("${CLI_CMAKE_RESOURCE_DIR}/uwpshim") -link_directories(${UWPHOST_LIB_PATH}) -set (PLATFORM STORE) - -add_executable(UWPShim - uwpshim.cpp - native.rc -) - -target_link_libraries(UWPShim - UWPHost - vcruntime -) - -install(TARGETS UWPShim DESTINATION .) +add_subdirectory(Console) +add_subdirectory(Windows) \ No newline at end of file diff --git a/src/installer/uwp/Host/UWPShim/Console/CMakeLists.txt b/src/installer/uwp/Host/UWPShim/Console/CMakeLists.txt new file mode 100644 index 0000000..e070fd3 --- /dev/null +++ b/src/installer/uwp/Host/UWPShim/Console/CMakeLists.txt @@ -0,0 +1,23 @@ +include(../../../../settings.cmake) + +add_definitions(-DUNICODE) +add_definitions(-D_UNICODE) +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmain") +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib") + +include_directories("${CLI_CMAKE_RESOURCE_DIR}/uwpshim") +link_directories(${UWPHOST_LIB_PATH}) +set (PLATFORM STORE) + +add_executable(ConsoleUWPShim + ../uwpshim.cpp + ../native.rc +) + +target_link_libraries(ConsoleUWPShim + UWPHost + vcruntime +) + +install(TARGETS ConsoleUWPShim DESTINATION .) diff --git a/src/installer/uwp/Host/UWPShim/UWPShim.cpp b/src/installer/uwp/Host/UWPShim/UWPShim.cpp index aa479bd..93a7442 100644 --- a/src/installer/uwp/Host/UWPShim/UWPShim.cpp +++ b/src/installer/uwp/Host/UWPShim/UWPShim.cpp @@ -162,25 +162,23 @@ int __cdecl wmain() DWORD exitCode = -1; int argc; LPCWSTR* wszArglist = const_cast(SegmentCommandLine(GetCommandLineW(), &argc)); - - if (argc < 2) - { - // Invalid number of arguments - return exitCode; - } - + // This module is merely a shim to figure out what the actual EntryPoint assembly is and call the Host with // that information. The EntryPoint would be found based on the following assumptions // // 1) Current module lives under the "CoreRuntime" subfolder of the AppX package installation folder. // 2) It has the same name as the EntryPoint assembly that will reside in the parent folder (i.e. the AppX package installation folder). - const wchar_t* pActivationModulePath = wszArglist[0]; + wchar_t pActivationModulePath[MAX_PATH]; + if (!GetModuleFileName(nullptr, pActivationModulePath, MAX_PATH)) + { + return GetLastError(); + } const wchar_t *pLastSlash = wcsrchr(pActivationModulePath, L'\\'); if (pLastSlash == NULL) { - return exitCode; + TerminateProcess(GetCurrentProcess(), exitCode); } wchar_t entryPointAssemblyFileName[MAX_PATH]; @@ -190,6 +188,6 @@ int __cdecl wmain() auto success = ExecuteAssembly(entryPointAssemblyFileName, argc-1, &(wszArglist[1]), &exitCode); - return exitCode; + TerminateProcess(GetCurrentProcess(), exitCode); } diff --git a/src/installer/uwp/Host/UWPShim/Windows/CMakeLists.txt b/src/installer/uwp/Host/UWPShim/Windows/CMakeLists.txt new file mode 100644 index 0000000..16b7003 --- /dev/null +++ b/src/installer/uwp/Host/UWPShim/Windows/CMakeLists.txt @@ -0,0 +1,23 @@ +include(../../../../settings.cmake) + +add_definitions(-DUNICODE) +add_definitions(-D_UNICODE) +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmain") +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib") + +include_directories("${CLI_CMAKE_RESOURCE_DIR}/uwpshim") +link_directories(${UWPHOST_LIB_PATH}) +set (PLATFORM STORE) + +add_executable(UWPShim + ../uwpshim.cpp + ../native.rc +) + +target_link_libraries(UWPShim + UWPHost + vcruntime +) + +install(TARGETS UWPShim DESTINATION .) diff --git a/src/installer/uwp/build.proj b/src/installer/uwp/build.proj index 895e18d..92d3236 100644 --- a/src/installer/uwp/build.proj +++ b/src/installer/uwp/build.proj @@ -26,7 +26,8 @@ - + +