1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2026-02-04 09:40:13 +03:00

support ARM64 on windows

This commit is contained in:
SaiXU
2026-01-30 11:36:39 +08:00
parent d8be1e4ddc
commit 875c4fa344
7 changed files with 279 additions and 44 deletions

View File

@ -136,6 +136,72 @@
"type": "STRING"
}
]
},
{
"name": "arm64-on-x64",
"description": "Cross compile Windows ARM64 on x64",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": ["msvc_arm64_x64"],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"variables": [
{
"name": "BUILD_NUMBER",
"value": "${env.BuildNumber}",
"type": "STRING"
},
{
"name": "CMAKE_SYSTEM_NAME",
"value": "Windows",
"type": "STRING"
},
{
"name": "CMAKE_SYSTEM_PROCESSOR",
"value": "arm64",
"type": "STRING"
},
{
"name": "CMAKE_C_COMPILER",
"value": "${env.VCINSTALLDIR}Tools/Llvm/bin/clang-cl.exe",
"type": "FILEPATH"
},
{
"name": "CMAKE_CXX_COMPILER",
"value": "${env.VCINSTALLDIR}Tools/Llvm/bin/clang-cl.exe",
"type": "FILEPATH"
},
{
"name": "CMAKE_C_COMPILER_TARGET",
"value": "arm64-windows-msvc",
"type": "STRING"
},
{
"name": "CMAKE_CXX_COMPILER_TARGET",
"value": "arm64-windows-msvc",
"type": "STRING"
},
{
"name": "CMAKE_EXE_LINKER_FLAGS",
"value": "/machine:ARM64",
"type": "STRING"
},
{
"name": "VCPKG_TARGET_TRIPLET",
"value": "arm64-windows-static",
"type": "STRING"
},
{
"name": "CMAKE_STATIC_LINKER_FLAGS",
"value": "/machine:ARM64",
"type": "STRING"
},
{
"name": "CMAKE_SHARED_LINKER_FLAGS",
"value": "/machine:ARM64",
"type": "STRING"
}
]
}
]
}

View File

@ -1,4 +1,4 @@
if(UNIX)
if(UNIX)
# Creates wrapper scripts and installs them in the user's binaries directory, which is usually "/usr/local/bin".
# This is required because symlinks use the folder they are in as working directory.
#
@ -59,6 +59,12 @@ add_definitions(-D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_S
include_directories(.)
if(WIN32)
if(IS_CROSS_COMPILATION MATCHES "arm64-on-x64")
set(CMAKE_SYSTEM_PROCESSOR "arm64")
else()
message("Setting QSPECTRE")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre")
endif()
add_definitions(-DWIN32 -D_WINDOWS -DOS_WIN32 -D_CRT_SECURE_NO_WARNINGS)
#
@ -69,9 +75,6 @@ if(WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf /DYNAMICBASE")
message("Setting QSPECTRE")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre")
message("Setting CETCOMPAT")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /CETCOMPAT")
@ -164,7 +167,36 @@ add_custom_target(hamcore-archive-build
ALL
DEPENDS "${BUILD_DIRECTORY}/hamcore.se2"
)
if(IS_CROSS_COMPILATION MATCHES "arm64-on-x64")
file(TO_CMAKE_PATH "${TOP_DIRECTORY}" TOP_DIRECTORY_NORM)
set(X64_HAMCORE_BUILDER
"${TOP_DIRECTORY_NORM}/out/build/x64-native/src/hamcorebuilder/hamcorebuilder.exe"
)
if(EXISTS "${X64_HAMCORE_BUILDER}")
message(STATUS "file exist (from TOP_DIRECTORY)")
endif()
# support cross compile, when you compile ARM64 version on X64 Platform
if(EXISTS "${X64_HAMCORE_BUILDER}")
message("X64_HAMCORE_BUILDER found: ${X64_HAMCORE_BUILDER}")
elseif(EXISTS("${TOP_DIRECTORY}/out/build/x64-native/src/hamcorebuilder/hamcorebuilder.exe"))
set(X64_HAMCORE_BUILDER "${TOP_DIRECTORY}/out/build/x64-native/src/hamcorebuilder/hamcorebuilder.exe")
else()
message("${TOP_DIRECTORY}/out/build/x64-native/src/hamcorebuilder/hamcorebuilder.exe")
message(FATAL_ERROR "X64_HAMCORE_BUILDER not found: ${X64_HAMCORE_BUILDER}, pls build x64-native version first")
endif()
message(STATUS "X64_HAMCORE_BUILDER = ${X64_HAMCORE_BUILDER}")
add_custom_command(
COMMENT "Building hamcore.se2 archive file..."
COMMAND ${X64_HAMCORE_BUILDER} "hamcore.se2" "${TOP_DIRECTORY}/src/bin/hamcore"
DEPENDS ${X64_HAMCORE_BUILDER} "${TOP_DIRECTORY}/src/bin/hamcore/"
OUTPUT "${BUILD_DIRECTORY}/hamcore.se2"
WORKING_DIRECTORY "${BUILD_DIRECTORY}"
VERBATIM
)
else()
add_custom_command(
COMMENT "Building hamcore.se2 archive file..."
COMMAND hamcorebuilder "hamcore.se2" "${TOP_DIRECTORY}/src/bin/hamcore"
@ -173,6 +205,7 @@ add_custom_command(
WORKING_DIRECTORY "${BUILD_DIRECTORY}"
VERBATIM
)
endif()
if(WIN32)
# PenCore

View File

@ -12,6 +12,15 @@ else()
add_library(cedar SHARED ${SOURCES_CEDAR} ${SOURCES_CEDAR_CPP} ${HEADERS_CEDAR})
endif()
if(MSVC)
target_compile_options(cedar PRIVATE /EHsc)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
target_compile_options(cedar PRIVATE /EHsc)
else()
target_compile_options(cedar PRIVATE -fexceptions)
endif()
endif()
set_target_properties(cedar
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${BUILD_DIRECTORY}"
@ -22,18 +31,21 @@ set_target_properties(cedar
target_link_libraries(cedar PUBLIC mayaqua)
cmake_host_system_information(RESULT HAS_SSE2 QUERY HAS_SSE2)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|arm64v8|ARM64")
message(STATUS "Target architecture is ARM64")
set(BLAKE2_SRC_PATH "${TOP_DIRECTORY}/3rdparty/BLAKE2/neon")
set(BLAKE2_SRC "${BLAKE2_SRC_PATH}/blake2s-neon.c")
else()
set(BLAKE2_SRC_PATH $<IF:$<BOOL:${HAS_SSE2}>,${TOP_DIRECTORY}/3rdparty/BLAKE2/sse,${TOP_DIRECTORY}/3rdparty/BLAKE2/ref>)
set(BLAKE2_SRC $<IF:$<BOOL:${HAS_SSE2}>,${BLAKE2_SRC_PATH}/blake2s.c,${BLAKE2_SRC_PATH}/blake2s-ref.c>)
target_include_directories(cedar PUBLIC ${BLAKE2_SRC_PATH})
target_sources(cedar PRIVATE ${BLAKE2_SRC})
if(HAS_SSE2)
# If SSE2 is enabled, a build failure occurs with MSVC because it doesn't define "__SSE2__".
# The fix consists in defining "HAVE_SSE2" manually, effectively overriding the check.
set_property(SOURCE ${BLAKE2_SRC} PROPERTY COMPILE_DEFINITIONS "HAVE_SSE2")
endif()
endif()
target_include_directories(cedar PUBLIC ${BLAKE2_SRC_PATH})
target_sources(cedar PRIVATE ${BLAKE2_SRC})
if(VCPKG_TARGET_TRIPLET)
find_package(unofficial-sodium CONFIG REQUIRED)

View File

@ -4462,9 +4462,13 @@ bool IsAesNiSupported()
// Unfortunately OpenSSL doesn't provide a function to do it
#ifdef _MSC_VER
#if defined(_M_X64) || defined(_M_IX86)
int regs[4]; // EAX, EBX, ECX, EDX
__cpuid(regs, 1);
supported = (regs[2] >> 25) & 1;
#elif defined(_M_ARM64)
return IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
#endif
#else // _MSC_VER
#if defined(CPU_FEATURES_ARCH_X86)
const X86Features features = GetX86Info().features;

View File

@ -5,7 +5,8 @@
// NDIS6.c
// Windows NDIS 6.2 Routine
#include <GlobalConst.h>
//#include <GlobalConst.h>
#include "GlobalConst.h"
#define NEO_DEVICE_DRIVER

View File

@ -12,15 +12,25 @@
#ifndef CPU_64
#define _X86_
#else // CPU_64
#ifndef NEO_IA64
#define _AMD64_
#define AMD64
#else // NEO_IA64
#ifdef CPU_ARM64
//#define _ARM64_
//#define ARM64
#elif defined(NEO_IA64)
#define _IA64_
#define IA64
#endif // NEO_IA64
#else
#define _AMD64_
#define AMD64
#endif
#endif // CPU_64
#define NDIS_MINIPORT_DRIVER
#ifdef CPU_ARM64
#define NDIS640_MINIPORT
#define NDIS_MINIPORT_MINIMUM_MAJOR_VERSION 6
#define NDIS_MINIPORT_MINIMUM_MINOR_VERSION 40
#define NEO_NDIS_MAJOR_VERSION 6
#define NEO_NDIS_MINOR_VERSION 40
#else
// NDIS 6.2
#define NDIS620_MINIPORT
#define NDIS_SUPPORT_NDIS61 1
@ -28,6 +38,8 @@
#define NEO_NDIS_MAJOR_VERSION 6
#define NEO_NDIS_MINOR_VERSION 20
#define NDIS_WDM 1
#endif
#include <wdm.h>
#include <ndis.h>

107
src/Neo6/Neo6.vcxproj Normal file
View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<ProjectGuid>{F7679B65-2FEC-469A-8BAC-B07BF4439422}</ProjectGuid>
<RootNamespace>Neo6</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
<DriverType>KMDF</DriverType>
<DriverTargetPlatform>Universal</DriverTargetPlatform>
<TargetName>Neo6_arm64_unsigned</TargetName>
<TargetExt>.sys</TargetExt>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>17.0.36310.24</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<IntDir>$(Platform)_$(Configuration)\</IntDir>
<IgnoreImportLibrary>true</IgnoreImportLibrary>
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<Midl />
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<IntrinsicFunctions>false</IntrinsicFunctions>
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
<TreatWarningAsError>false</TreatWarningAsError>
<AdditionalIncludeDirectories>$(ProjectDir)\..\;$(SolutionDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>ARM64;_ARM64_;CPU_64;WIN32;CPU_ARM64;NDEBUG;_WINDOWS;_USRDLL;NEO_EXPORTS;VPN_SPEED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>false</StringPooling>
<ExceptionHandling>
</ExceptionHandling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<StructMemberAlignment>8Bytes</StructMemberAlignment>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>false</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>CompileAsC</CompileAs>
<DisableSpecificWarnings>4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<!-- <PreLinkEvent>
<Command>$(SolutionDir)bin\BuildUtil.exe /CMD:GenerateVersionResource "$(TargetPath)" /OUT:"$(SolutionDir)tmp\VersionResources\$(ProjectName)_$(Platform).res" /PRODUCT:"SoftEther VPN"</Command>
</PreLinkEvent> -->
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
</ProjectReference>
<Link>
<OutputFile>$(OutDir)Neo6_arm64_unsigned.sys</OutputFile>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ntoskrnl.lib;wdm.lib;hal.lib;;ucrt.lib;ndis.lib;wdmsec.lib;ntdll.lib;Kernel32.lib;fwpkclnt.lib;libcntpr.lib;%(AdditionalDependencies)</AdditionalDependencies>
<!-- <ImportLibrary>$(SolutionDir)tmp\lib\$(Platform)_$(Configuration)\$(ProjectName).lib</ImportLibrary> -->
<TargetMachine>MachineARM64</TargetMachine>
</Link>
<!-- <PostBuildEvent>
<Command>$(SolutionDir)bin\BuildUtil.exe /CMD:SignCode "$(TargetPath)" /DEST:"$(TargetDir)Neo6_ARM64.sys" /COMMENT:"VPN Software" /KERNEL:yes /CERTID:0 /SHAMODE:0
$(SolutionDir)bin\BuildUtil.exe /CMD:SignCode "$(TargetPath)" /DEST:"$(TargetDir)Neo6_ARM64_win10.sys" /COMMENT:"VPN Software" /KERNEL:yes /CERTID:0 /SHAMODE:2
</Command>
</PostBuildEvent> -->
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="NDIS6.c" />
<ClCompile Include="Neo6.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="NDIS6.h" />
<ClInclude Include="Neo6.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Neo6.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>