This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[single-exe] Run from bundle on Windows #26904
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,34 @@ | ||
set(Bundle_Common_SOURCES | ||
${CMAKE_CURRENT_LIST_DIR}/app_bundle.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/file_entry.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/header.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/manifest.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/marker.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/reader.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/runner.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/utils.cpp | ||
) | ||
|
||
set(Bundle_Windows_SOURCES | ||
${Bundle_Common_SOURCES} | ||
${CMAKE_CURRENT_LIST_DIR}/pal_windows.cpp | ||
) | ||
|
||
set(Bundle_Unix_SOURCES | ||
${Bundle_Common_SOURCES} | ||
${CMAKE_CURRENT_LIST_DIR}/pal_unix.cpp | ||
) | ||
|
||
set(Bundle_HEADERS | ||
${CMAKE_CURRENT_LIST_DIR}/app_bundle.h | ||
${CMAKE_CURRENT_LIST_DIR}/error_codes.h | ||
${CMAKE_CURRENT_LIST_DIR}/file_entry.h | ||
${CMAKE_CURRENT_LIST_DIR}/file_type.h | ||
${CMAKE_CURRENT_LIST_DIR}/header.h | ||
${CMAKE_CURRENT_LIST_DIR}/manifest.h | ||
${CMAKE_CURRENT_LIST_DIR}/marker.h | ||
${CMAKE_CURRENT_LIST_DIR}/pal.h | ||
${CMAKE_CURRENT_LIST_DIR}/reader.h | ||
${CMAKE_CURRENT_LIST_DIR}/runner.h | ||
${CMAKE_CURRENT_LIST_DIR}/utils.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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 "app_bundle.h" | ||
#include "marker.h" | ||
#include "runner.h" | ||
|
||
using namespace bundle; | ||
|
||
runner_t* app_bundle_t::s_runner = nullptr; | ||
|
||
bool app_bundle_t::init(const char* exe_path) | ||
{ | ||
if (!bundle::marker_t::is_bundle()) | ||
{ | ||
return false; | ||
} | ||
|
||
pal::string_t self_path; | ||
pal::clr_palstring(exe_path, self_path); | ||
|
||
static runner_t runner(exe_path); | ||
s_runner = &runner; | ||
|
||
StatusCode status = runner.process(); | ||
|
||
return status == StatusCode::Success; | ||
} | ||
|
||
bool app_bundle_t::probe(const char* path, int64_t* size, int64_t* offset) | ||
{ | ||
return s_runner->probe(path, size, offset); | ||
} |
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,28 @@ | ||
// 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. | ||
|
||
// This class represents the bundle for the currently executing application | ||
// It is the bundle-processing module's interface with the outside world. | ||
|
||
#ifndef __APP_BUNDLE_H__ | ||
#define __APP_BUNDLE_H__ | ||
|
||
#include <stdint.h> | ||
|
||
namespace bundle | ||
{ | ||
class runner_t; | ||
|
||
class app_bundle_t | ||
{ | ||
public: | ||
static bool init(const char *path); | ||
static bool probe(const char* path, int64_t* size, int64_t* offset); | ||
|
||
private: | ||
static runner_t *s_runner; | ||
}; | ||
} | ||
|
||
#endif // __APP_BUNDLE_H__ |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,68 @@ | ||
// 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. | ||
|
||
#ifndef PAL_H | ||
#define PAL_H | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <iostream> | ||
#include <cstring> | ||
#include <cstdarg> | ||
#include <cstdint> | ||
#include <cassert> | ||
|
||
#if defined(_WIN32) | ||
#include <windows.h> | ||
#else // defined(_WIN32) | ||
#include <cstdlib> | ||
#include <unistd.h> | ||
#include <libgen.h> | ||
#include <mutex> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <sys/mman.h> | ||
#endif // defined(_WIN32) | ||
|
||
#if defined(_WIN32) | ||
#define DIR_SEPARATOR '\\' | ||
#define PATH_MAX MAX_PATH | ||
|
||
#else // defined(_WIN32) | ||
#define DIR_SEPARATOR '/' | ||
|
||
#if !defined(PATH_MAX) | ||
#define PATH_MAX 4096 | ||
#endif | ||
#endif // defined(_WIN32) | ||
|
||
namespace pal | ||
{ | ||
typedef std::basic_ifstream<char> ifstream_t; | ||
typedef std::istreambuf_iterator<ifstream_t::char_type> istreambuf_iterator_t; | ||
typedef std::basic_istream<char> istream_t; | ||
|
||
typedef char char_t; | ||
typedef std::string string_t; | ||
typedef std::stringstream stringstream_t; | ||
|
||
inline bool clr_palstring(const char* cstr, string_t& out) { out.assign(cstr); return true; } | ||
|
||
#if defined(_WIN32) | ||
typedef HMODULE dll_t; | ||
typedef FARPROC proc_t; | ||
inline int pathcmp(const char_t* path1, const char_t* path2) { return ::_stricmp(path1, path2); } | ||
#else // defined(_WIN32) | ||
typedef void* dll_t; | ||
typedef void* proc_t; | ||
inline int pathcmp(const char_t* path1, const char_t* path2) { return ::strcmp(path1, path2); } | ||
#endif // defined(_WIN32) | ||
|
||
void* map_file_readonly(const string_t& path, size_t& length); | ||
bool unmap_file(void* addr, size_t length); | ||
} | ||
|
||
#endif // PAL_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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 "pal.h" | ||
|
||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <dirent.h> | ||
|
||
void* pal::map_file_readonly(const pal::string_t& path, size_t& length) | ||
{ | ||
int fd = open(path.c_str(), O_RDONLY, (S_IRUSR | S_IRGRP | S_IROTH)); | ||
if (fd == -1) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
struct stat buf; | ||
if (fstat(fd, &buf) != 0) | ||
{ | ||
close(fd); | ||
return nullptr; | ||
} | ||
|
||
length = buf.st_size; | ||
void* address = mmap(nullptr, length, PROT_READ, MAP_SHARED, fd, 0); | ||
|
||
if(address == nullptr) | ||
{ | ||
close(fd); | ||
return nullptr; | ||
} | ||
|
||
close(fd); | ||
return address; | ||
} | ||
|
||
bool pal::unmap_file(void* addr, size_t length) | ||
{ | ||
return munmap(addr, length) == 0; | ||
} |
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. | ||
// See the LICENSE file in the project root for more information. | ||
#include "pal.h" | ||
|
||
void* pal::map_file_readonly(const pal::string_t& path, size_t& length) | ||
{ | ||
HANDLE file = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | ||
|
||
if (file == INVALID_HANDLE_VALUE) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
LARGE_INTEGER fileSize; | ||
if (GetFileSizeEx(file, &fileSize) == 0) | ||
{ | ||
CloseHandle(file); | ||
return nullptr; | ||
} | ||
length = (size_t)fileSize.QuadPart; | ||
|
||
HANDLE map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL); | ||
|
||
if (map == NULL) | ||
{ | ||
CloseHandle(file); | ||
return nullptr; | ||
} | ||
|
||
void* address = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0); | ||
|
||
if (map == NULL) | ||
{ | ||
CloseHandle(file); | ||
return nullptr; | ||
} | ||
|
||
return address; | ||
} | ||
|
||
bool pal::unmap_file(void* addr, size_t length) | ||
{ | ||
return UnmapViewOfFile(addr) != 0; | ||
} | ||
|
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
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we remove this - the error description seems accurate still... and not having any feedback makes it much harder to diagnose issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
trace:error()
routines were no-ops, since the backing functions were not ported. Therefore, I removed the calls from the prototype, because the failure can be easily identified in the debugger (which we needed anyway, since there was no trace output).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - for prototype this is fine.