Path: blob/master/platform/linuxbsd/godot_linuxbsd.cpp
10277 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 "main/main.h"3334#include <unistd.h>35#include <climits>36#include <clocale>37#include <cstdlib>3839#if defined(SANITIZERS_ENABLED)40#include <sys/resource.h>41#endif4243// For export templates, add a section; the exporter will patch it to enclose44// the data appended to the executable (bundled PCK).45#if !defined(TOOLS_ENABLED) && defined(__GNUC__)46static const char dummy[8] __attribute__((section("pck"), used)) = { 0 };4748// Dummy function to prevent LTO from discarding "pck" section.49extern "C" const char *pck_section_dummy_call() __attribute__((used));50extern "C" const char *pck_section_dummy_call() {51return &dummy[0];52}53#endif5455int main(int argc, char *argv[]) {56#if defined(SANITIZERS_ENABLED)57// 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.58struct rlimit stack_lim = { 0x1E00000, 0x1E00000 };59setrlimit(RLIMIT_STACK, &stack_lim);60#endif6162OS_LinuxBSD os;6364setlocale(LC_CTYPE, "");6566// We must override main when testing is enabled67TEST_MAIN_OVERRIDE6869char *cwd = (char *)malloc(PATH_MAX);70ERR_FAIL_NULL_V(cwd, ERR_OUT_OF_MEMORY);71char *ret = getcwd(cwd, PATH_MAX);7273Error err = Main::setup(argv[0], argc - 1, &argv[1]);7475if (err != OK) {76free(cwd);77if (err == ERR_HELP) { // Returned by --help and --version, so success.78return EXIT_SUCCESS;79}80return EXIT_FAILURE;81}8283if (Main::start() == EXIT_SUCCESS) {84os.run();85} else {86os.set_exit_code(EXIT_FAILURE);87}88Main::cleanup();8990if (ret) { // Previous getcwd was successful91if (chdir(cwd) != 0) {92ERR_PRINT("Couldn't return to previous working directory.");93}94}95free(cwd);9697return os.get_exit_code();98}99100101