Path: blob/master/platform/linuxbsd/godot_linuxbsd.cpp
20879 views
/**************************************************************************/1/* godot_linuxbsd.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "os_linuxbsd.h"3132#include "core/profiling/profiling.h"33#include "main/main.h"3435#include <unistd.h>36#include <climits>37#include <clocale>38#include <cstdlib>3940#if defined(SANITIZERS_ENABLED)41#include <sys/resource.h>42#endif4344#if defined(__x86_64) || defined(__x86_64__)45void __cpuid(int *r_cpuinfo, int p_info) {46// Note: Some compilers have a buggy `__cpuid` intrinsic, using inline assembly (based on LLVM-20 implementation) instead.47__asm__ __volatile__(48"xchgq %%rbx, %q1;"49"cpuid;"50"xchgq %%rbx, %q1;"51: "=a"(r_cpuinfo[0]), "=r"(r_cpuinfo[1]), "=c"(r_cpuinfo[2]), "=d"(r_cpuinfo[3])52: "0"(p_info));53}54#endif5556// For export templates, add a section; the exporter will patch it to enclose57// the data appended to the executable (bundled PCK).58#if !defined(TOOLS_ENABLED) && defined(__GNUC__)59static const char dummy[8] __attribute__((section("pck"), used)) = { 0 };6061// Dummy function to prevent LTO from discarding "pck" section.62extern "C" const char *pck_section_dummy_call() __attribute__((used));63extern "C" const char *pck_section_dummy_call() {64return &dummy[0];65}66#endif6768int main(int argc, char *argv[]) {69#if defined(__x86_64) || defined(__x86_64__)70int cpuinfo[4];71__cpuid(cpuinfo, 0x01);7273if (!(cpuinfo[2] & (1 << 20))) {74printf("A CPU with SSE4.2 instruction set support is required.\n");7576int ret = system("zenity --warning --title \"Godot Engine\" --text \"A CPU with SSE4.2 instruction set support is required.\" 2> /dev/null");77if (ret != 0) {78ret = system("kdialog --title \"Godot Engine\" --sorry \"A CPU with SSE4.2 instruction set support is required.\" 2> /dev/null");79}80if (ret != 0) {81ret = system("Xdialog --title \"Godot Engine\" --msgbox \"A CPU with SSE4.2 instruction set support is required.\" 0 0 2> /dev/null");82}83if (ret != 0) {84ret = system("xmessage -center -title \"Godot Engine\" \"A CPU with SSE4.2 instruction set support is required.\" 2> /dev/null");85}86abort();87}88#endif8990#if defined(SANITIZERS_ENABLED)91// Note: Set stack size to be at least 30 MB (vs 8 MB default) to avoid overflow, address sanitizer can increase stack usage up to 3 times.92struct rlimit stack_lim = { 0x1E00000, 0x1E00000 };93setrlimit(RLIMIT_STACK, &stack_lim);94#endif9596godot_init_profiler();9798OS_LinuxBSD os;99100setlocale(LC_CTYPE, "");101102// We must override main when testing is enabled103TEST_MAIN_OVERRIDE104105char *cwd = (char *)malloc(PATH_MAX);106ERR_FAIL_NULL_V(cwd, ERR_OUT_OF_MEMORY);107char *ret = getcwd(cwd, PATH_MAX);108109Error err = Main::setup(argv[0], argc - 1, &argv[1]);110111if (err != OK) {112free(cwd);113if (err == ERR_HELP) { // Returned by --help and --version, so success.114return EXIT_SUCCESS;115}116return EXIT_FAILURE;117}118119if (Main::start() == EXIT_SUCCESS) {120os.run();121} else {122os.set_exit_code(EXIT_FAILURE);123}124Main::cleanup();125126if (ret) { // Previous getcwd was successful127if (chdir(cwd) != 0) {128ERR_PRINT("Couldn't return to previous working directory.");129}130}131free(cwd);132133godot_cleanup_profiler();134return os.get_exit_code();135}136137138