Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
cmake_minimum_required(VERSION 3.12)

if (COMPILER_TARGET)
set(CMAKE_C_COMPILER_TARGET "${COMPILER_TARGET}")
set(CMAKE_CXX_COMPILER_TARGET "${COMPILER_TARGET}")
set(CMAKE_ASM_COMPILER_TARGET "${COMPILER_TARGET}")
endif()

project(native_client C CXX ASM)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(DaemonPlatform/Platform)
include(NaClFlags)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()

option(BUILD_NACL_LOADER "Build the sel_ldr program." ON)

if (LINUX)
option(BUILD_NACL_HELPER_BOOTSTRAP "Build the nacl_helper_bootstrap program on platforms requiring it." ON)
endif()

# TODO(arbenson): remove this once binutils bug is fixed (see
# src/trusted/service_runtime/arch/x86_64/sel_addrspace_posix_x86_64.c)
if (BUILD_NACL_LOADER AND ARCH_amd64 AND NOT WIN32)
option(USE_AMD64_ZERO_BASED_SANDBOX "Allow the zero-based sandbox model to run insecurely." OFF)
list(APPEND INHERITED_OPTIONS "USE_AMD64_ZERO_BASED_SANDBOX")
endif()

if (BUILD_NACL_LOADER AND WIN32)
option(FORCE_NO_TRUSTED_BUILD "Prevent use of trusted toolchain." OFF)
endif()

if (BUILD_NACL_LOADER AND WIN32)
set(REQUIRE_MASM ON)
endif()

if (BUILD_NACL_LOADER AND APPLE)
set(REQUIRE_PYTHON ON)
endif()

if (BUILD_NACL_HELPER_BOOTSTRAP)
set(REQUIRE_PYTHON ON)
endif()

if (REQUIRE_PYTHON)
if (NOT PYTHON)
find_program(PYTHON NAMES "python3" DOC "Path to the python3 executable." REQUIRED)
endif()
endif()

if (REQUIRE_MASM)
if (NOT MSVC AND NOT CMAKE_ASM_MASM_COMPILER)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include-hax/fake_masm")

find_program(JWASM NAMES "jwasm" DOC "Path to the JWasm executable." REQUIRED)

set(CMAKE_ASM_MASM_COMPILER "${JWASM}")

if (ARCH_i686)
list(APPEND CMAKE_ASM_MASM_FLAGS "-coff")
elseif(ARCH_amd64)
list(APPEND CMAKE_ASM_MASM_FLAGS "-win64")
endif()
endif()

enable_language(ASM_MASM)
endif()

include_directories("include-hax")

if (ARCH_i686)
set(ARCH_SUFFIX "_x86_32")
elseif (ARCH_amd64)
set(ARCH_SUFFIX "_X86_64")
elseif (ARCH_armhf OR ARCH_armel)
set(ARCH_SUFFIX "_arm")
elseif (ARCH_mipsel)
set(ARCH_SUFFIX "_mips32")
endif()

if (BUILD_NACL_LOADER)
add_subdirectory(src/shared/gio)
add_subdirectory(src/shared/imc)
add_subdirectory(src/shared/platform)
add_subdirectory(src/trusted/cpu_features)
add_subdirectory(src/trusted/debug_stub)
add_subdirectory(src/trusted/desc)
add_subdirectory(src/trusted/fault_injection)
add_subdirectory(src/trusted/interval_multiset)
add_subdirectory(src/trusted/nacl_base)
add_subdirectory(src/trusted/perf_counter)
add_subdirectory(src/trusted/platform_qualify)
add_subdirectory(src/trusted/validator)

if (ARCH_i686 OR ARCH_amd64)
add_subdirectory(src/trusted/validator_x86)
add_subdirectory(src/trusted/validator_ragel)
elseif (ARCH_armhf OR ARCH_armel)
add_subdirectory(src/trusted/validator_arm)
elseif (ARCH_mipsel)
add_subdirectory(src/trusted/validator_mips)
endif()
endif()

if (BUILD_NACL_LOADER)
add_subdirectory(src/trusted/service_runtime)
endif()

if (BUILD_NACL_HELPER_BOOTSTRAP)
add_subdirectory(src/trusted/service_runtime/linux)
endif()
117 changes: 117 additions & 0 deletions cmake/DaemonPlatform/Architecture.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Daemon BSD Source Code
# Copyright (c) 2022, Daemon Developers
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the <organization> nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

################################################################################
# Architecture detection.
################################################################################

# When adding a new architecture, look at all the places ARCH is used

try_compile(BUILD_RESULT
"${CMAKE_BINARY_DIR}"
"${CMAKE_CURRENT_LIST_DIR}/Architecture/Architecture.cpp"
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
OUTPUT_VARIABLE BUILD_LOG
)

# Setting -Werror in CXXFLAGS would produce errors instead of warning
# but that should not break the architecture detection,
# so we only print a CMake warning there and use BUILD_LOG content to
# detect unsupported platforms.
# Catching compilation error is still useful, for example to detect
# undefined types, missing header or things like that.
# Setting USE_WERROR to ON doesn't print this warning.
if (NOT BUILD_RESULT)
message(WARNING
"Failed to build Architecture.cpp\n"
"Setting -Werror in CXXFLAGS can produce false positive errors\n"
"${BUILD_LOG}"
)
endif()

string(REGEX MATCH "DAEMON_ARCH_([a-zA-Z0-9_]+)" ARCH_DEFINE "${BUILD_LOG}")
string(REPLACE "DAEMON_ARCH_" "" ARCH "${ARCH_DEFINE}")

if (NOT ARCH)
message(FATAL_ERROR
"Missing DAEMON_ARCH, there is a mistake in Architecture.cpp\n"
"${BUILD_LOG}"
)
elseif(ARCH STREQUAL "unsupported")
message(FATAL_ERROR "Architecture not supported")
endif()

message(STATUS "Detected target architecture: ${ARCH}")

add_definitions(-D${ARCH_DEFINE})

# This string can be modified without breaking compatibility.
daemon_add_buildinfo("char*" "DAEMON_ARCH_STRING" "\"${ARCH}\"")

# Modifying NACL_ARCH breaks engine compatibility with nexe game binaries
# since NACL_ARCH contributes to the nexe file name.
set(NACL_ARCH "${ARCH}")
if (LINUX OR FREEBSD)
set(ARMHF_USAGE arm64 armel)
if (ARCH IN_LIST ARMHF_USAGE)
# Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch.
# The nexe is system agnostic so there should be no difference with armel.
set(NACL_ARCH "armhf")
endif()
elseif(APPLE)
if ("${ARCH}" STREQUAL arm64)
# You can get emulated NaCl going like this:
# cp external_deps/macos-amd64-default_10/{nacl_loader,irt_core-amd64.nexe} build/
set(NACL_ARCH "amd64")
endif()
endif()

daemon_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${NACL_ARCH}\"")

option(USE_ARCH_INTRINSICS "Enable custom code using intrinsics functions or asm declarations" ON)
mark_as_advanced(USE_ARCH_INTRINSICS)

macro(set_arch_intrinsics name)
if (USE_ARCH_INTRINSICS)
message(STATUS "Enabling ${name} architecture intrinsics")
add_definitions(-DDAEMON_USE_ARCH_INTRINSICS_${name}=1)
else()
message(STATUS "Disabling ${name} architecture intrinsics")
endif()
endmacro()

if (USE_ARCH_INTRINSICS)
add_definitions(-DDAEMON_USE_ARCH_INTRINSICS=1)
endif()

set_arch_intrinsics(${ARCH})

set(amd64_PARENT "i686")
set(arm64_PARENT "armhf")

if (${ARCH}_PARENT)
set_arch_intrinsics(${${ARCH}_PARENT})
endif()
114 changes: 114 additions & 0 deletions cmake/DaemonPlatform/Architecture/Architecture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
===========================================================================
Daemon BSD Source Code
Copyright (c) 2022, Daemon Developers
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Daemon developers nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
===========================================================================
*/

/* The qprocessordetection.h file doesn't detect endianness for some
platforms including ppc64, but we know how to do it for them. */

#include <stdint.h>

/* This source file includes qprocessordetection.h from Qt:

- https://github.com/qt/qtbase/blob/dev/src/corelib/global/qprocessordetection.h
https://raw.githubusercontent.com/qt/qtbase/dev/src/corelib/global/qprocessordetection.h

Always update by downloading new version from Qt, do not edit by hand.

This source file and the qprocessordetection.h header do not contribute to the
produced engine and game binaries in any way that can be subject to copyright. */

#include "qprocessordetection.h"

/* The architecture names are loosely inspired by Debian conventions:
https://wiki.debian.org/ArchitectureSpecificsMemo

Except we don't have the same technical debt so we don't have
to name i686 as i386 for backward compatibility purpose neither
care of platform name variants that are meant to distinguish
platform variants we cannot support anyway. */

/* PNaCl virtual machines. */
#if defined(__native_client__)
#pragma message("DAEMON_ARCH_nacl")

/* Wasm virtual machines, work in progress. */
#elif defined(Q_PROCESSOR_WASM)
#pragma message("DAEMON_ARCH_wasm")

/* Devices like:
- IBM PC compatibles and derivatives,
- Apple Intel-based mac,
- Steam Deck, Atari VCS consoles… */

#elif defined(Q_PROCESSOR_X86_64)
#pragma message("DAEMON_ARCH_amd64")

#elif defined(Q_PROCESSOR_X86_32)
// Assume at least i686. Detecting older revisions would be unlikely to work here
// because the revisions are likely configured by flags, but this file is "compiled"
// without most command-line flags.
#pragma message("DAEMON_ARCH_i686")

/* Devices like:
- Raspberry Pi,
- Apple M1-based mac,
- Android phones and tablets… */

#elif defined(Q_PROCESSOR_ARM_64)
#pragma message("DAEMON_ARCH_arm64")

#elif defined(Q_PROCESSOR_ARM_32) && defined(__ARM_PCS_VFP)
#pragma message("DAEMON_ARCH_armhf")

#elif defined(Q_PROCESSOR_ARM_32) && !defined(__ARM_PCS_VFP)
#pragma message("DAEMON_ARCH_armel")

/* Devices like:
- Raptor Computing Systems Talos, Blackbird… */

#elif defined(Q_PROCESSOR_POWER_64) && Q_BYTE_ORDER == Q_BIG_ENDIAN
#pragma message("DAEMON_ARCH_ppc64")

#elif defined(Q_PROCESSOR_POWER_64) && Q_BYTE_ORDER == Q_LITTLE_ENDIAN
#pragma message("DAEMON_ARCH_ppc64el")

/* Devices like:
- SiFive HiFive Unmatched, Horse Creek… */

#elif defined(Q_PROCESSOR_RISCV_64)
#pragma message("DAEMON_ARCH_riscv64")

#else
#pragma message("DAEMON_ARCH_unknown")
#endif

// Make the compilation succeeds if architecture is supported.
int main(int argc, char** argv) {
return 0;
}
Loading