[misc] arch/cpu refactoring

* Move the cpu.c/cpu.h in more logical places and remove these sources files.
* Add detection for LoongArch64 EFI bootloaders.
* Pass the detected CPU arch when invoking Fido.
* Also fix some Bled Coverity warnings.
This commit is contained in:
Pete Batard 2024-12-02 19:04:51 +00:00
parent 8f3a9c1c7c
commit 79f1209ab9
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
16 changed files with 121 additions and 260 deletions

View file

@ -381,7 +381,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\src\badblocks.c" />
<ClCompile Include="..\src\cpu.c" />
<ClCompile Include="..\src\dos_locale.c" />
<ClCompile Include="..\src\drive.c" />
<ClCompile Include="..\src\format.c" />
@ -413,7 +412,6 @@
<ClInclude Include="..\res\grub\grub_version.h" />
<ClInclude Include="..\src\badblocks.h" />
<ClInclude Include="..\src\bled\bled.h" />
<ClInclude Include="..\src\cpu.h" />
<ClInclude Include="..\src\drive.h" />
<ClInclude Include="..\src\format.h" />
<ClInclude Include="..\src\gpt_types.h" />

View file

@ -93,9 +93,6 @@
<ClCompile Include="..\src\wue.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\cpu.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\rufus.h">
@ -194,9 +191,6 @@
<ClInclude Include="..\src\vhd.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\cpu.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\res\rufus.ico">

View file

@ -17,7 +17,7 @@ AM_V_WINDRES = $(AM_V_WINDRES_$(V))
%_rc.o: %.rc ../res/loc/embedded.loc
$(AM_V_WINDRES) $(AM_RCFLAGS) -i $< -o $@
rufus_SOURCES = badblocks.c cpu.c dev.c dos.c dos_locale.c drive.c format.c format_ext.c format_fat32.c hash.c icon.c iso.c \
rufus_SOURCES = badblocks.c dev.c dos.c dos_locale.c drive.c format.c format_ext.c format_fat32.c hash.c icon.c iso.c \
localization.c net.c parser.c pki.c process.c re.c rufus.c smart.c stdfn.c stdio.c stdlg.c syslinux.c ui.c vhd.c wue.c
rufus_CFLAGS = -I$(srcdir)/ms-sys/inc -I$(srcdir)/syslinux/libfat -I$(srcdir)/syslinux/libinstaller -I$(srcdir)/syslinux/win -I$(srcdir)/libcdio $(AM_CFLAGS) \
-DEXT2_FLAT_INCLUDES=0 -DSOLUTION=rufus

View file

@ -87,12 +87,11 @@ mkinstalldirs = $(install_sh) -d
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
PROGRAMS = $(noinst_PROGRAMS)
am_rufus_OBJECTS = rufus-badblocks.$(OBJEXT) rufus-cpu.$(OBJEXT) \
rufus-dev.$(OBJEXT) rufus-dos.$(OBJEXT) \
rufus-dos_locale.$(OBJEXT) rufus-drive.$(OBJEXT) \
rufus-format.$(OBJEXT) rufus-format_ext.$(OBJEXT) \
rufus-format_fat32.$(OBJEXT) rufus-hash.$(OBJEXT) \
rufus-icon.$(OBJEXT) rufus-iso.$(OBJEXT) \
am_rufus_OBJECTS = rufus-badblocks.$(OBJEXT) rufus-dev.$(OBJEXT) \
rufus-dos.$(OBJEXT) rufus-dos_locale.$(OBJEXT) \
rufus-drive.$(OBJEXT) rufus-format.$(OBJEXT) \
rufus-format_ext.$(OBJEXT) rufus-format_fat32.$(OBJEXT) \
rufus-hash.$(OBJEXT) rufus-icon.$(OBJEXT) rufus-iso.$(OBJEXT) \
rufus-localization.$(OBJEXT) rufus-net.$(OBJEXT) \
rufus-parser.$(OBJEXT) rufus-pki.$(OBJEXT) \
rufus-process.$(OBJEXT) rufus-re.$(OBJEXT) \
@ -285,7 +284,7 @@ AM_V_WINDRES_0 = @echo " RC $@";$(WINDRES)
AM_V_WINDRES_1 = $(WINDRES)
AM_V_WINDRES_ = $(AM_V_WINDRES_$(AM_DEFAULT_VERBOSITY))
AM_V_WINDRES = $(AM_V_WINDRES_$(V))
rufus_SOURCES = badblocks.c cpu.c dev.c dos.c dos_locale.c drive.c format.c format_ext.c format_fat32.c hash.c icon.c iso.c \
rufus_SOURCES = badblocks.c dev.c dos.c dos_locale.c drive.c format.c format_ext.c format_fat32.c hash.c icon.c iso.c \
localization.c net.c parser.c pki.c process.c re.c rufus.c smart.c stdfn.c stdio.c stdlg.c syslinux.c ui.c vhd.c wue.c
rufus_CFLAGS = -I$(srcdir)/ms-sys/inc -I$(srcdir)/syslinux/libfat -I$(srcdir)/syslinux/libinstaller -I$(srcdir)/syslinux/win -I$(srcdir)/libcdio $(AM_CFLAGS) \
@ -355,12 +354,6 @@ rufus-badblocks.o: badblocks.c
rufus-badblocks.obj: badblocks.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-badblocks.obj `if test -f 'badblocks.c'; then $(CYGPATH_W) 'badblocks.c'; else $(CYGPATH_W) '$(srcdir)/badblocks.c'; fi`
rufus-cpu.o: cpu.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-cpu.o `test -f 'cpu.c' || echo '$(srcdir)/'`cpu.c
rufus-cpu.obj: cpu.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-cpu.obj `if test -f 'cpu.c'; then $(CYGPATH_W) 'cpu.c'; else $(CYGPATH_W) '$(srcdir)/cpu.c'; fi`
rufus-dev.o: dev.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-dev.o `test -f 'dev.c' || echo '$(srcdir)/'`dev.c

View file

@ -9,7 +9,6 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
{
struct tm tm_time;
struct tm *ptm = &tm_time; //localtime(&file_header->mtime);
char modestr[12];
#if ENABLE_FEATURE_TAR_UNAME_GNAME
char uid[sizeof(int)*3 + 2];
@ -29,8 +28,8 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
/*sprintf(gid, "%u", (unsigned)file_header->gid);*/
group = utoa(file_header->gid);
}
printf("%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
bb_mode_string(modestr, file_header->mode),
printf("%u %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
file_header->mode,
user,
group,
file_header->size,
@ -46,8 +45,8 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header)
localtime_r(&file_header->mtime, ptm);
printf("%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
bb_mode_string(modestr, file_header->mode),
printf("%u %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
file_header->mode,
(unsigned)file_header->uid,
(unsigned)file_header->gid,
file_header->size,

View file

@ -180,7 +180,6 @@ static inline void *xrealloc(void *ptr, size_t size) {
#define bb_msg_read_error "read error"
#define bb_msg_write_error "write error"
#define bb_mode_string(str, mode) str
#define bb_make_directory(path, mode, flags) SHCreateDirectoryExU(NULL, path, NULL)
static inline int link(const char *oldpath, const char *newpath) { errno = ENOSYS; return -1; }

123
src/cpu.c
View file

@ -1,123 +0,0 @@
/*
* Rufus: The Reliable USB Formatting Utility
* CPU features detection
* Copyright © 2022 Pete Batard <pete@akeo.ie>
* Copyright © 2022 Jeffrey Walton <noloader@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cpu.h"
#if (defined(CPU_X86_SHA1_ACCELERATION) || defined(CPU_X86_SHA256_ACCELERATION))
#if defined(RUFUS_MSC_VERSION)
#include <intrin.h>
#elif (defined(RUFUS_GCC_VERSION) || defined(RUFUS_CLANG_VERSION))
#include <x86Intrin.h>
#elif defined(RUFUS_INTEL_VERSION)
#include <immintrin.h>
#endif
#endif
BOOL cpu_has_sha1_accel = FALSE;
BOOL cpu_has_sha256_accel = FALSE;
/*
* Three elements must be in place to make a meaningful call to the
* DetectSHA###Acceleration() calls. First, the compiler must support
* the underlying intrinsics. Second, the platform must provide a
* cpuid() function. And third, the cpu must actually support the SHA-1
* and SHA-256 instructions.
*
* If any of the conditions are not met, then DetectSHA###Acceleration()
* returns FALSE.
*/
/*
* Detect if the processor supports SHA-1 acceleration. We only check for
* the three ISAs we need - SSSE3, SSE4.1 and SHA. We don't check for OS
* support or XSAVE because that's been enabled since Windows 2000.
*/
BOOL DetectSHA1Acceleration(void)
{
#if defined(CPU_X86_SHA1_ACCELERATION)
#if defined(_MSC_VER)
uint32_t regs0[4] = {0,0,0,0}, regs1[4] = {0,0,0,0}, regs7[4] = {0,0,0,0};
const uint32_t SSSE3_BIT = 1u << 9; /* Function 1, Bit 9 of ECX */
const uint32_t SSE41_BIT = 1u << 19; /* Function 1, Bit 19 of ECX */
const uint32_t SHA_BIT = 1u << 29; /* Function 7, Bit 29 of EBX */
__cpuid(regs0, 0);
const uint32_t highest = regs0[0]; /*EAX*/
if (highest >= 0x01) {
__cpuidex(regs1, 1, 0);
}
if (highest >= 0x07) {
__cpuidex(regs7, 7, 0);
}
return (regs1[2] /*ECX*/ & SSSE3_BIT) && (regs1[2] /*ECX*/ & SSE41_BIT) && (regs7[1] /*EBX*/ & SHA_BIT) ? TRUE : FALSE;
#elif defined(__GNUC__) || defined(__clang__)
/* __builtin_cpu_supports available in GCC 4.8.1 and above */
return __builtin_cpu_supports("ssse3") && __builtin_cpu_supports("sse4.1") && __builtin_cpu_supports("sha") ? TRUE : FALSE;
#elif defined(__INTEL_COMPILER)
/* https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_may_i_use_cpu_feature */
return _may_i_use_cpu_feature(_FEATURE_SSSE3|_FEATURE_SSE4_1|_FEATURE_SHA) ? TRUE : FALSE;
#else
return FALSE;
#endif
#else
return FALSE;
#endif
}
/*
* Detect if the processor supports SHA-256 acceleration. We only check for
* the three ISAs we need - SSSE3, SSE4.1 and SHA. We don't check for OS
* support or XSAVE because that's been enabled since Windows 2000.
*/
BOOL DetectSHA256Acceleration(void)
{
#if defined(CPU_X86_SHA256_ACCELERATION)
#if defined(_MSC_VER)
uint32_t regs0[4] = {0,0,0,0}, regs1[4] = {0,0,0,0}, regs7[4] = {0,0,0,0};
const uint32_t SSSE3_BIT = 1u << 9; /* Function 1, Bit 9 of ECX */
const uint32_t SSE41_BIT = 1u << 19; /* Function 1, Bit 19 of ECX */
const uint32_t SHA_BIT = 1u << 29; /* Function 7, Bit 29 of EBX */
__cpuid(regs0, 0);
const uint32_t highest = regs0[0]; /*EAX*/
if (highest >= 0x01) {
__cpuidex(regs1, 1, 0);
}
if (highest >= 0x07) {
__cpuidex(regs7, 7, 0);
}
return (regs1[2] /*ECX*/ & SSSE3_BIT) && (regs1[2] /*ECX*/ & SSE41_BIT) && (regs7[1] /*EBX*/ & SHA_BIT) ? TRUE : FALSE;
#elif defined(__GNUC__) || defined(__clang__)
/* __builtin_cpu_supports available in GCC 4.8.1 and above */
return __builtin_cpu_supports("ssse3") && __builtin_cpu_supports("sse4.1") && __builtin_cpu_supports("sha") ? TRUE : FALSE;
#elif defined(__INTEL_COMPILER)
/* https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_may_i_use_cpu_feature */
return _may_i_use_cpu_feature(_FEATURE_SSSE3|_FEATURE_SSE4_1|_FEATURE_SHA) ? TRUE : FALSE;
#else
return FALSE;
#endif
#else
return FALSE;
#endif
}

View file

@ -1,79 +0,0 @@
/*
* Rufus: The Reliable USB Formatting Utility
* CPU features detection
* Copyright © 2022 Pete Batard <pete@akeo.ie>
* Copyright © 2022 Jeffrey Walton <noloader@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Primarily added to support SHA instructions on x86 machines.
* SHA acceleration is becoming as ubiquitous as AES acceleration.
* SHA support was introduced in Intel Goldmont architecture, like
* Celeron J3455 and Pentium J4205. The instructions are now present
* in AMD Ryzen 3 (Zen architecture) and above, and Intel Core
* 10th-gen processors (Ice Lake), 11th-gen processors (Rocket Lake)
* and above.
*
* Typical benchmarks for x86 SHA acceleration is about a 6x to 10x
* speedup over a C/C++ implementation. The rough measurements are
* 1.0 to 1.8 cpb for SHA-1, and 1.5 to 2.5 cpb for SHA-256. On a
* Celeron J3455, that's 1.1 GB/s for SHA-1 and 800 MB/s for SHA-256.
* On a 10th-gen Core i5, that's about 1.65 GB/s for SHA-1 and about
* 1.3 GB/s for SHA-256.
*/
#include "rufus.h"
#pragma once
#ifdef _MSC_VER
#define RUFUS_MSC_VERSION (_MSC_VER)
#if (RUFUS_MSC_VERSION < 1900)
#error "Your compiler is too old to build this application"
#endif
#endif
#if defined(__GNUC__)
#define RUFUS_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#if (RUFUS_GCC_VERSION < 40900)
#error "Your compiler is too old to build this application"
#endif
#endif
#ifdef __INTEL_COMPILER
#define RUFUS_INTEL_VERSION (__INTEL_COMPILER)
#if (RUFUS_INTEL_VERSION < 1600)
#error "Your compiler is too old to build this application"
#endif
#endif
#if defined(__clang__)
#define RUFUS_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
#if (RUFUS_CLANG_VERSION < 30400)
#error "Your compiler is too old to build this application"
#endif
#endif
#if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || \
defined(_X86_) || defined(__I86__) || defined(__x86_64__))
#define CPU_X86_SHA1_ACCELERATION 1
#define CPU_X86_SHA256_ACCELERATION 1
#endif
extern BOOL cpu_has_sha1_accel, cpu_has_sha256_accel;
extern BOOL DetectSHA1Acceleration(void);
extern BOOL DetectSHA256Acceleration(void);

View file

@ -65,11 +65,11 @@
#include <string.h>
#include <inttypes.h>
#include <errno.h>
#include <intrin.h>
#include <windows.h>
#include <windowsx.h>
#include "db.h"
#include "cpu.h"
#include "rufus.h"
#include "winio.h"
#include "missing.h"
@ -77,14 +77,10 @@
#include "msapi_utf8.h"
#include "localization.h"
/* Includes for SHA-1 and SHA-256 intrinsics */
#if defined(CPU_X86_SHA1_ACCELERATION) || defined(CPU_X86_SHA256_ACCELERATION)
#if defined(_MSC_VER)
#include <immintrin.h>
#elif defined(__GNUC__)
#include <stdint.h>
#include <x86intrin.h>
#endif
#if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || \
defined(_X86_) || defined(__I86__) || defined(__x86_64__))
#define CPU_X86_SHA1_ACCELERATION 1
#define CPU_X86_SHA256_ACCELERATION 1
#endif
#if defined(_MSC_VER)
@ -107,6 +103,7 @@ char hash_str[HASH_MAX][150];
HANDLE data_ready[HASH_MAX] = { 0 }, thread_ready[HASH_MAX] = { 0 };
DWORD read_size[NUM_BUFFERS];
BOOL enable_extra_hashes = FALSE, validate_md5sum = FALSE;
BOOL cpu_has_sha1_accel = FALSE, cpu_has_sha256_accel = FALSE;
uint8_t ALIGNED(64) buffer[NUM_BUFFERS][BUFFER_SIZE];
uint8_t* pe256ssp = NULL;
uint32_t proc_bufnum, hash_count[HASH_MAX] = { MD5_HASHSIZE, SHA1_HASHSIZE, SHA256_HASHSIZE, SHA512_HASHSIZE };
@ -119,6 +116,78 @@ extern const char* efi_archname[ARCH_MAX];
extern char* sbat_level_txt;
extern BOOL expert_mode, usb_debug;
/*
* Detect if the processor supports SHA-1 acceleration. We only check for
* the three ISAs we need - SSSE3, SSE4.1 and SHA. We don't check for OS
* support or XSAVE because that's been enabled since Windows 2000.
*/
BOOL DetectSHA1Acceleration(void)
{
#if defined(CPU_X86_SHA1_ACCELERATION)
#if defined(_MSC_VER)
uint32_t regs0[4] = { 0,0,0,0 }, regs1[4] = { 0,0,0,0 }, regs7[4] = { 0,0,0,0 };
const uint32_t SSSE3_BIT = 1u << 9; /* Function 1, Bit 9 of ECX */
const uint32_t SSE41_BIT = 1u << 19; /* Function 1, Bit 19 of ECX */
const uint32_t SHA_BIT = 1u << 29; /* Function 7, Bit 29 of EBX */
__cpuid(regs0, 0);
const uint32_t highest = regs0[0]; /*EAX*/
if (highest >= 0x01) {
__cpuidex(regs1, 1, 0);
}
if (highest >= 0x07) {
__cpuidex(regs7, 7, 0);
}
return (regs1[2] /*ECX*/ & SSSE3_BIT) && (regs1[2] /*ECX*/ & SSE41_BIT) && (regs7[1] /*EBX*/ & SHA_BIT) ? TRUE : FALSE;
#elif defined(__GNUC__) || defined(__clang__)
/* __builtin_cpu_supports available in GCC 4.8.1 and above */
return __builtin_cpu_supports("ssse3") && __builtin_cpu_supports("sse4.1") && __builtin_cpu_supports("sha") ? TRUE : FALSE;
#else
return FALSE;
#endif
#else
return FALSE;
#endif
}
/*
* Detect if the processor supports SHA-256 acceleration. We only check for
* the three ISAs we need - SSSE3, SSE4.1 and SHA. We don't check for OS
* support or XSAVE because that's been enabled since Windows 2000.
*/
BOOL DetectSHA256Acceleration(void)
{
#if defined(CPU_X86_SHA256_ACCELERATION)
#if defined(_MSC_VER)
uint32_t regs0[4] = { 0,0,0,0 }, regs1[4] = { 0,0,0,0 }, regs7[4] = { 0,0,0,0 };
const uint32_t SSSE3_BIT = 1u << 9; /* Function 1, Bit 9 of ECX */
const uint32_t SSE41_BIT = 1u << 19; /* Function 1, Bit 19 of ECX */
const uint32_t SHA_BIT = 1u << 29; /* Function 7, Bit 29 of EBX */
__cpuid(regs0, 0);
const uint32_t highest = regs0[0]; /*EAX*/
if (highest >= 0x01) {
__cpuidex(regs1, 1, 0);
}
if (highest >= 0x07) {
__cpuidex(regs7, 7, 0);
}
return (regs1[2] /*ECX*/ & SSSE3_BIT) && (regs1[2] /*ECX*/ & SSE41_BIT) && (regs7[1] /*EBX*/ & SHA_BIT) ? TRUE : FALSE;
#elif defined(__GNUC__) || defined(__clang__)
/* __builtin_cpu_supports available in GCC 4.8.1 and above */
return __builtin_cpu_supports("ssse3") && __builtin_cpu_supports("sse4.1") && __builtin_cpu_supports("sha") ? TRUE : FALSE;
#else
return FALSE;
#endif
#else
return FALSE;
#endif
}
/*
* Rotate 32 or 64 bit integers by n bytes.
* Don't bother trying to hand-optimize those, as the

View file

@ -99,7 +99,7 @@ static const char* casper_dirname = "/casper";
static const char* proxmox_dirname = "/proxmox";
const char* efi_dirname = "/efi/boot";
const char* efi_bootname[3] = { "boot", "grub", "mm" };
const char* efi_archname[ARCH_MAX] = { "", "ia32", "x64", "arm", "aa64", "ia64", "riscv64", "ebc" };
const char* efi_archname[ARCH_MAX] = { "", "ia32", "x64", "arm", "aa64", "ia64", "riscv64", "loongarch64", "ebc" };
static const char* sources_str = "/sources";
static const char* wininst_name[] = { "install.wim", "install.esd", "install.swm" };
// We only support GRUB/BIOS (x86) that uses a standard config dir (/boot/grub/i386-pc/)
@ -1801,7 +1801,7 @@ BOOL HasEfiImgBootLoaders(void)
for (i = 0; i < ARRAYSIZE(efi_archname); i++) {
static_sprintf(bootloader_name, "boot%s.efi", efi_archname[i]);
// TODO: bootriscv###.efi will need LFN support but cross that bridge when/if we get there...
// TODO: bootriscv64.efi and bootloongarch64.efi need LFN support
if (strlen(bootloader_name) > 12)
continue;
for (j = 0, k = 0; bootloader_name[j] != 0; j++) {

View file

@ -18,6 +18,7 @@
*/
#include <windows.h>
#include <intrin.h>
#pragma once
@ -40,10 +41,10 @@
* line has already been fetched, or if the address is invalid.
*/
#if defined(__GNUC__) || defined(__clang__)
#define PREFETCH64(m) do { __builtin_prefetch(m, 0, 0); __builtin_prefetch(m+32, 0, 0); } while(0)
#define PREFETCH64(m) do { __builtin_prefetch((m), 0, 0); __builtin_prefetch((m) + 32, 0, 0); } while(0)
#elif defined(_MSC_VER)
#if defined(_M_IX86) || defined (_M_X64)
#define PREFETCH64(m) do { _m_prefetch(m); _m_prefetch(m+32); } while(0)
#define PREFETCH64(m) do { _m_prefetch((void*)(m)); _m_prefetch((void*)((m) + 32)); } while(0)
#else
// _m_prefetch() doesn't seem to exist for MSVC/ARM
#define PREFETCH64(m)

View file

@ -60,6 +60,7 @@ HANDLE update_check_thread = NULL;
extern loc_cmd* selected_locale;
extern HANDLE dialog_handle;
extern BOOL is_x86_64;
extern USHORT NativeMachine;
static DWORD error_code, fido_len = 0;
static BOOL force_update_check = FALSE;
static const char* request_headers = "Accept-Encoding: gzip, deflate";
@ -522,6 +523,9 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
#endif
vuprintf("Using %s for the update check", RUFUS_URL);
for (k = 0; (k < max_channel) && (!found_new_version); k++) {
// Get the arch name and convert it lowercase
char* archname = strdup(GetArchName(WindowsVersion.Arch));
safe_strtolower(archname);
// Free any previous buffers we might have used
safe_free(buf);
safe_free(sig);
@ -533,7 +537,8 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
// This allows sunsetting OS versions (eg XP) or providing different downloads for different archs/groups.
// Note that for BETAs, we only catter for x64 regardless of the OS arch.
static_sprintf(urlpath, "%s%s%s_win_%s_%lu.%lu.ver", APPLICATION_NAME, (k == 0) ? "": "_",
(k == 0) ? "" : channel[k], GetArchName(WindowsVersion.Arch), WindowsVersion.Major, WindowsVersion.Minor);
(k == 0) ? "" : channel[k], archname, WindowsVersion.Major, WindowsVersion.Minor);
safe_free(archname);
vuprintf("Base update check: %s", urlpath);
for (i = 0, j = (int)safe_strlen(urlpath) - 5; (j > 0) && (i < ARRAYSIZE(verpos)); j--) {
if ((urlpath[j] == '.') || (urlpath[j] == '_')) {
@ -796,8 +801,8 @@ static DWORD WINAPI DownloadISOThread(LPVOID param)
}
static_sprintf(cmdline, "\"%s\" -NonInteractive -Sta -NoProfile ExecutionPolicy Bypass "
"-File \"%s\" -PipeName %s -LocData \"%s\" -Icon \"%s\" -AppTitle \"%s\"",
powershell_path, script_path, &pipe[9], locale_str, icon_path, lmprintf(MSG_149));
"-File \"%s\" -PipeName %s -LocData \"%s\" -Icon \"%s\" -AppTitle \"%s\" -PlatformArch \"%s\"",
powershell_path, script_path, &pipe[9], locale_str, icon_path, lmprintf(MSG_149), GetArchName(NativeMachine));
#ifndef RUFUS_TEST
// For extra security, even after we validated that the LZMA download is properly

View file

@ -893,7 +893,7 @@ static __inline char* get_sanitized_token_data_buffer(const char* token, unsigne
size_t i;
char* data = get_token_data_buffer(token, n, buffer, buffer_size);
if (data != NULL) {
for (i=0; i<strlen(data); i++) {
for (i = 0; i < strlen(data); i++) {
if ((data[i] == '\\') && (data[i+1] == 'n')) {
data[i] = '\r';
data[i+1] = '\n';
@ -953,6 +953,7 @@ void parse_update(char* buf, size_t len)
safe_free(data);
}
static_sprintf(download_url_name, "download_url_%s", GetArchName(WindowsVersion.Arch));
safe_strtolower(download_url_name);
update.download_url = get_sanitized_token_data_buffer(download_url_name, 1, buf, len);
if (update.download_url == NULL)
update.download_url = get_sanitized_token_data_buffer("download_url", 1, buf, len);

View file

@ -48,7 +48,6 @@
#include "ui.h"
#include "re.h"
#include "cpu.h"
#include "vhd.h"
#include "wue.h"
#include "drive.h"
@ -69,7 +68,7 @@ static const char* cmdline_hogger = ".\\rufus.com";
static const char* ep_reg = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
static const char* vs_reg = "Software\\Microsoft\\VisualStudio";
static const char* arch_name[ARCH_MAX] = {
"unknown", "x86_32", "x86_64", "ARM", "ARM64", "Itanic", "RISC-V 64", "EBC" };
"unknown", "x86_32", "x86_64", "ARM", "ARM64", "IA64", "RISC-V 64", "LoongArch 64", "EBC" };
static BOOL existing_key = FALSE; // For LGP set/restore
static BOOL size_check = TRUE;
static BOOL log_displayed = FALSE;
@ -93,7 +92,7 @@ static char uppercase_select[2][64], uppercase_start[64], uppercase_close[64], u
extern HANDLE update_check_thread, wim_thread;
extern BOOL enable_iso, enable_joliet, enable_rockridge, enable_extra_hashes, is_bootloader_revoked;
extern BOOL validate_md5sum;
extern BOOL validate_md5sum, cpu_has_sha1_accel, cpu_has_sha256_accel;
extern BYTE* fido_script;
extern HWND hFidoDlg;
extern uint8_t* grub2_buf;
@ -118,6 +117,7 @@ uint32_t dur_mins, dur_secs;
loc_cmd* selected_locale = NULL;
WORD selected_langid = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
DWORD MainThreadId;
USHORT NativeMachine = IMAGE_FILE_MACHINE_UNKNOWN;
HWND hDeviceList, hPartitionScheme, hTargetSystem, hFileSystem, hClusterSize, hLabel, hBootType, hNBPasses, hLog = NULL;
HWND hImageOption, hLogDialog = NULL, hProgress = NULL;
HANDLE dialog_handle = NULL, format_thread = NULL;
@ -1963,7 +1963,7 @@ static void InitDialog(HWND hDlg)
{
DWORD len;
HDC hDC;
USHORT ProcessMachine = IMAGE_FILE_MACHINE_UNKNOWN, NativeMachine = IMAGE_FILE_MACHINE_UNKNOWN;
USHORT ProcessMachine = IMAGE_FILE_MACHINE_UNKNOWN;
int i, lfHeight;
char tmp[128], *token, *buf, *ext, *msg;
static char* resource[2] = { MAKEINTRESOURCEA(IDR_SL_LDLINUX_V4_SYS), MAKEINTRESOURCEA(IDR_SL_LDLINUX_V6_SYS) };

View file

@ -183,6 +183,7 @@ static __inline void safe_strcp(char* dst, const size_t dst_max, const char* src
#else
#define safe_vsnprintf vsnprintf
#endif
#define safe_strtolower(str) do { if (str != NULL) CharLowerA(str); } while(0)
static __inline void static_repchr(char* p, char s, char r) {
if (p != NULL) while (*p != 0) { if (*p == s) *p = r; p++; }
}
@ -377,7 +378,7 @@ typedef struct {
uint16_t revision;
} winver_t;
/* We can't use the Microsoft enums as we want to have RISC-V */
/* We can't use the Microsoft enums as we want to have RISC-V and LoongArch */
enum ArchType {
ARCH_UNKNOWN = 0,
ARCH_X86_32,
@ -386,6 +387,7 @@ enum ArchType {
ARCH_ARM_64,
ARCH_IA_64,
ARCH_RISCV_64,
ARCH_LOONGARCH_64,
ARCH_EBC,
ARCH_MAX
};
@ -597,11 +599,11 @@ static __inline const char* GetArchName(USHORT uArch)
case IMAGE_FILE_MACHINE_I386:
return "x86";
case IMAGE_FILE_MACHINE_ARM64:
return "arm64";
return "ARM64";
case IMAGE_FILE_MACHINE_ARM:
return "arm";
return "ARM32";
default:
return "unknown";
return "Unknown";
}
}
@ -830,6 +832,8 @@ extern HANDLE CreateFileWithTimeout(LPCSTR lpFileName, DWORD dwDesiredAccess, DW
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile, DWORD dwTimeOut);
extern BOOL SetThreadAffinity(DWORD_PTR* thread_affinity, size_t num_threads);
extern BOOL DetectSHA1Acceleration(void);
extern BOOL DetectSHA256Acceleration(void);
extern BOOL HashFile(const unsigned type, const char* path, uint8_t* sum);
extern BOOL PE256Buffer(uint8_t* buf, uint32_t len, uint8_t* hash);
extern void UpdateMD5Sum(const char* dest_dir, const char* md5sum_name);

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 4.7.2212"
CAPTION "Rufus 4.7.2213"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -399,8 +399,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,7,2212,0
PRODUCTVERSION 4,7,2212,0
FILEVERSION 4,7,2213,0
PRODUCTVERSION 4,7,2213,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -418,13 +418,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "4.7.2212"
VALUE "FileVersion", "4.7.2213"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2024 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-4.7.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "4.7.2212"
VALUE "ProductVersion", "4.7.2213"
END
END
BLOCK "VarFileInfo"