Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/installer/corehost/cli/hostmisc')
-rw-r--r--src/installer/corehost/cli/hostmisc/pal.h8
-rw-r--r--src/installer/corehost/cli/hostmisc/pal.unix.cpp30
-rw-r--r--src/installer/corehost/cli/hostmisc/pal.windows.cpp31
-rw-r--r--src/installer/corehost/cli/hostmisc/utils.cpp19
-rw-r--r--src/installer/corehost/cli/hostmisc/utils.h2
5 files changed, 24 insertions, 66 deletions
diff --git a/src/installer/corehost/cli/hostmisc/pal.h b/src/installer/corehost/cli/hostmisc/pal.h
index 10cb0e2c302..432756a3f37 100644
--- a/src/installer/corehost/cli/hostmisc/pal.h
+++ b/src/installer/corehost/cli/hostmisc/pal.h
@@ -165,7 +165,7 @@ namespace pal
inline bool rmdir (const char_t* path) { return RemoveDirectoryW(path) != 0; }
inline int rename(const char_t* old_name, const char_t* new_name) { return ::_wrename(old_name, new_name); }
inline int remove(const char_t* path) { return ::_wremove(path); }
- inline bool munmap(void* addr, size_t length) { return UnmapViewOfFile(addr) != 0; }
+ inline bool unmap_file(void* addr, size_t length) { return UnmapViewOfFile(addr) != 0; }
inline int get_pid() { return GetCurrentProcessId(); }
inline void sleep(uint32_t milliseconds) { Sleep(milliseconds); }
#else
@@ -222,7 +222,7 @@ namespace pal
inline bool rmdir(const char_t* path) { return ::rmdir(path) == 0; }
inline int rename(const char_t* old_name, const char_t* new_name) { return ::rename(old_name, new_name); }
inline int remove(const char_t* path) { return ::remove(path); }
- inline bool munmap(void* addr, size_t length) { return ::munmap(addr, length) == 0; }
+ inline bool unmap_file(void* addr, size_t length) { return munmap(addr, length) == 0; }
inline int get_pid() { return getpid(); }
inline void sleep(uint32_t milliseconds) { usleep(milliseconds * 1000); }
@@ -257,9 +257,7 @@ namespace pal
return fallbackRid;
}
- const void* mmap_read(const string_t& path, size_t* length = nullptr);
- void* mmap_copy_on_write(const string_t& path, size_t* length = nullptr);
-
+ void* map_file_readonly(const string_t& path, size_t& length);
bool touch_file(const string_t& path);
bool realpath(string_t* path, bool skip_error_logging = false);
bool file_exists(const string_t& path);
diff --git a/src/installer/corehost/cli/hostmisc/pal.unix.cpp b/src/installer/corehost/cli/hostmisc/pal.unix.cpp
index 3626761b0ec..2ca39c3793a 100644
--- a/src/installer/corehost/cli/hostmisc/pal.unix.cpp
+++ b/src/installer/corehost/cli/hostmisc/pal.unix.cpp
@@ -70,7 +70,7 @@ bool pal::touch_file(const pal::string_t& path)
return true;
}
-static void* map_file(const pal::string_t& path, size_t* length, int prot, int flags)
+void* pal::map_file_readonly(const pal::string_t& path, size_t& length)
{
int fd = open(path.c_str(), O_RDONLY);
if (fd == -1)
@@ -86,35 +86,21 @@ static void* map_file(const pal::string_t& path, size_t* length, int prot, int f
close(fd);
return nullptr;
}
- size_t size = buf.st_size;
- if (length != nullptr)
- {
- *length = size;
- }
-
- void* address = mmap(nullptr, size, prot, flags, fd, 0);
+ length = buf.st_size;
+ void* address = mmap(nullptr, length, PROT_READ, MAP_SHARED, fd, 0);
- if (address == MAP_FAILED)
+ if(address == nullptr)
{
trace::error(_X("Failed to map file. mmap(%s) failed with error %d"), path.c_str(), errno);
- address = nullptr;
+ close(fd);
+ return nullptr;
}
close(fd);
return address;
}
-const void* pal::mmap_read(const string_t& path, size_t* length)
-{
- return map_file(path, length, PROT_READ, MAP_SHARED);
-}
-
-void* pal::mmap_copy_on_write(const string_t& path, size_t* length)
-{
- return map_file(path, length, PROT_READ | PROT_WRITE, MAP_PRIVATE);
-}
-
bool pal::getcwd(pal::string_t* recv)
{
recv->clear();
@@ -504,10 +490,10 @@ bool pal::get_default_installation_dir(pal::string_t* recv)
pal::string_t trim_quotes(pal::string_t stringToCleanup)
{
pal::char_t quote_array[2] = {'\"', '\''};
- for (size_t index = 0; index < sizeof(quote_array)/sizeof(quote_array[0]); index++)
+ for(size_t index = 0; index < sizeof(quote_array)/sizeof(quote_array[0]); index++)
{
size_t pos = stringToCleanup.find(quote_array[index]);
- while (pos != std::string::npos)
+ while(pos != std::string::npos)
{
stringToCleanup = stringToCleanup.erase(pos, 1);
pos = stringToCleanup.find(quote_array[index]);
diff --git a/src/installer/corehost/cli/hostmisc/pal.windows.cpp b/src/installer/corehost/cli/hostmisc/pal.windows.cpp
index f8348a05d16..0cb6d2f91d9 100644
--- a/src/installer/corehost/cli/hostmisc/pal.windows.cpp
+++ b/src/installer/corehost/cli/hostmisc/pal.windows.cpp
@@ -76,7 +76,7 @@ bool pal::touch_file(const pal::string_t& path)
return true;
}
-static void* map_file(const pal::string_t& path, size_t *length, DWORD mapping_protect, DWORD view_desired_access)
+void* pal::map_file_readonly(const pal::string_t& path, size_t &length)
{
HANDLE file = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
@@ -86,19 +86,16 @@ static void* map_file(const pal::string_t& path, size_t *length, DWORD mapping_p
return nullptr;
}
- if (length != nullptr)
+ LARGE_INTEGER fileSize;
+ if (GetFileSizeEx(file, &fileSize) == 0)
{
- LARGE_INTEGER fileSize;
- if (GetFileSizeEx(file, &fileSize) == 0)
- {
- trace::error(_X("Failed to map file. GetFileSizeEx(%s) failed with error %d"), path.c_str(), GetLastError());
- CloseHandle(file);
- return nullptr;
- }
- *length = (size_t)fileSize.QuadPart;
+ trace::error(_X("Failed to map file. GetFileSizeEx(%s) failed with error %d"), path.c_str(), GetLastError());
+ CloseHandle(file);
+ return nullptr;
}
+ length = (size_t)fileSize.QuadPart;
- HANDLE map = CreateFileMappingW(file, NULL, mapping_protect, 0, 0, NULL);
+ HANDLE map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
if (map == NULL)
{
@@ -107,7 +104,7 @@ static void* map_file(const pal::string_t& path, size_t *length, DWORD mapping_p
return nullptr;
}
- void *address = MapViewOfFile(map, view_desired_access, 0, 0, 0);
+ void *address = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
if (address == NULL)
{
@@ -123,16 +120,6 @@ static void* map_file(const pal::string_t& path, size_t *length, DWORD mapping_p
return address;
}
-const void* pal::mmap_read(const string_t& path, size_t* length)
-{
- return map_file(path, length, PAGE_READONLY, FILE_MAP_READ);
-}
-
-void* pal::mmap_copy_on_write(const string_t& path, size_t* length)
-{
- return map_file(path, length, PAGE_WRITECOPY, FILE_MAP_READ | FILE_MAP_COPY);
-}
-
bool pal::getcwd(pal::string_t* recv)
{
recv->clear();
diff --git a/src/installer/corehost/cli/hostmisc/utils.cpp b/src/installer/corehost/cli/hostmisc/utils.cpp
index 4a3208af237..4e0d8ab3170 100644
--- a/src/installer/corehost/cli/hostmisc/utils.cpp
+++ b/src/installer/corehost/cli/hostmisc/utils.cpp
@@ -4,7 +4,6 @@
#include "utils.h"
#include "trace.h"
-#include "bundle/info.h"
bool library_exists_in_dir(const pal::string_t& lib_dir, const pal::string_t& lib_name, pal::string_t* p_lib_path)
{
@@ -366,7 +365,6 @@ pal::string_t get_deps_from_app_binary(const pal::string_t& app_base, const pal:
{
pal::string_t deps_file;
auto app_name = get_filename(app);
-
deps_file.reserve(app_base.length() + 1 + app_name.length() + 5);
deps_file.append(app_base);
@@ -379,28 +377,19 @@ pal::string_t get_deps_from_app_binary(const pal::string_t& app_base, const pal:
return deps_file;
}
-pal::string_t get_runtime_config_path(const pal::string_t& path, const pal::string_t& name)
+void get_runtime_config_paths(const pal::string_t& path, const pal::string_t& name, pal::string_t* cfg, pal::string_t* dev_cfg)
{
auto json_path = path;
auto json_name = name + _X(".runtimeconfig.json");
append_path(&json_path, json_name.c_str());
- return json_path;
-}
+ cfg->assign(json_path);
-pal::string_t get_runtime_config_dev_path(const pal::string_t& path, const pal::string_t& name)
-{
auto dev_json_path = path;
auto dev_json_name = name + _X(".runtimeconfig.dev.json");
append_path(&dev_json_path, dev_json_name.c_str());
- return dev_json_path;
-}
-
-void get_runtime_config_paths(const pal::string_t& path, const pal::string_t& name, pal::string_t* cfg, pal::string_t* dev_cfg)
-{
- cfg->assign(get_runtime_config_path(path, name));
- dev_cfg->assign(get_runtime_config_dev_path(path, name));
+ dev_cfg->assign(dev_json_path);
- trace::verbose(_X("Runtime config is cfg=%s dev=%s"), cfg->c_str(), dev_cfg->c_str());
+ trace::verbose(_X("Runtime config is cfg=%s dev=%s"), json_path.c_str(), dev_json_path.c_str());
}
pal::string_t get_dotnet_root_from_fxr_path(const pal::string_t &fxr_path)
diff --git a/src/installer/corehost/cli/hostmisc/utils.h b/src/installer/corehost/cli/hostmisc/utils.h
index 7de346c7bce..2f13193e608 100644
--- a/src/installer/corehost/cli/hostmisc/utils.h
+++ b/src/installer/corehost/cli/hostmisc/utils.h
@@ -45,8 +45,6 @@ size_t index_of_non_numeric(const pal::string_t& str, unsigned i);
bool try_stou(const pal::string_t& str, unsigned* num);
pal::string_t get_dotnet_root_env_var_name();
pal::string_t get_deps_from_app_binary(const pal::string_t& app_base, const pal::string_t& app);
-pal::string_t get_runtime_config_path(const pal::string_t& path, const pal::string_t& name);
-pal::string_t get_runtime_config_dev_path(const pal::string_t& path, const pal::string_t& name);
void get_runtime_config_paths(const pal::string_t& path, const pal::string_t& name, pal::string_t* cfg, pal::string_t* dev_cfg);
pal::string_t get_dotnet_root_from_fxr_path(const pal::string_t &fxr_path);