lib/uri: Always load high on uri_open() on x86_64/UEFI
diff --git a/common/fs/file.s2.c b/common/fs/file.s2.c
index 8528f19a..80aa2ff7 100644
--- a/common/fs/file.s2.c
+++ b/common/fs/file.s2.c
@@ -117,7 +117,18 @@ void *freadall_mode(struct file_handle *fd, uint32_t type, bool allow_high_alloc
#endif
return fd->fd;
}
+#if defined (UEFI) && defined (__x86_64__)
+ if (!allow_high_allocs && (uintptr_t)fd->fd >= 0x100000000) {
+ void *newptr = ext_mem_alloc_type(fd->size, type);
+ memcpy(newptr, fd->fd, fd->size);
+ pmm_free(fd->fd, fd->size);
+ fd->fd = newptr;
+ } else {
+#endif
memmap_alloc_range((uint64_t)(size_t)fd->fd, ALIGN_UP(fd->size, 4096), type, 0, true, false, false);
+#if defined (UEFI) && defined (__x86_64__)
+ }
+#endif
fd->readall = true;
#if defined (__i386__)
if (allow_high_allocs == true) {
diff --git a/common/lib/uri.c b/common/lib/uri.c
index bcc05d00..5339e0c5 100644
--- a/common/lib/uri.c
+++ b/common/lib/uri.c
@@ -206,10 +206,6 @@ static struct file_handle *uri_boot_dispatch(char *s_part, char *path) {
return fopen(volume, path);
}
-#if defined (UEFI) && defined (__x86_64__)
-bool uri_open_allow_high = false;
-#endif
-
struct file_handle *uri_open(char *uri) {
struct file_handle *ret;
@@ -243,8 +239,7 @@ struct file_handle *uri_open(char *uri) {
if (hash != NULL && ret != NULL) {
uint8_t out_buf[BLAKE2B_OUT_BYTES];
#if defined (UEFI) && defined (__x86_64__)
- void *file_buf = freadall_mode(ret, MEMMAP_BOOTLOADER_RECLAIMABLE, uri_open_allow_high);
- uri_open_allow_high = false;
+ void *file_buf = freadall_mode(ret, MEMMAP_BOOTLOADER_RECLAIMABLE, true);
#else
void *file_buf = freadall(ret, MEMMAP_BOOTLOADER_RECLAIMABLE);
#endif
diff --git a/common/lib/uri.h b/common/lib/uri.h
index 8691df91..d15a5494 100644
--- a/common/lib/uri.h
+++ b/common/lib/uri.h
@@ -4,10 +4,6 @@
#include <stdbool.h>
#include <fs/file.h>
-#if defined (UEFI) && defined (__x86_64__)
-extern bool uri_open_allow_high;
-#endif
-
bool uri_resolve(char *uri, char **resource, char **root, char **path, char **hash);
struct file_handle *uri_open(char *uri);
diff --git a/common/protos/linux.c b/common/protos/linux.c
index 1eee9a9b..05398681 100644
--- a/common/protos/linux.c
+++ b/common/protos/linux.c
@@ -393,9 +393,6 @@ noreturn void linux_load(char *config, char *cmdline) {
break;
struct file_handle *module;
-#if defined (UEFI) && defined (__x86_64__)
- uri_open_allow_high = true;
-#endif
if ((module = uri_open(module_path)) == NULL)
panic(true, "linux: Failed to open module with path `%s`. Is the path correct?", module_path);
@@ -450,9 +447,6 @@ noreturn void linux_load(char *config, char *cmdline) {
struct file_handle *module;
-#if defined (UEFI) && defined (__x86_64__)
- uri_open_allow_high = true;
-#endif
if ((module = uri_open(module_path)) == NULL)
panic(true, "linux: Could not open `%#`", module_path);
