godot/drivers/unix/os_unix.cpp

/**************************************************************************/
/*  os_unix.cpp                                                           */
/**************************************************************************/
/*                         This file is part of:                          */
/*                             GODOT ENGINE                               */
/*                        https://godotengine.org                         */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */
/*                                                                        */
/* Permission is hereby granted, free of charge, to any person obtaining  */
/* a copy of this software and associated documentation files (the        */
/* "Software"), to deal in the Software without restriction, including    */
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

#include "os_unix.h"

#ifdef UNIX_ENABLED

#include "core/config/project_settings.h"
#include "core/debugger/engine_debugger.h"
#include "core/debugger/script_debugger.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "drivers/unix/file_access_unix_pipe.h"
#include "drivers/unix/net_socket_posix.h"
#include "drivers/unix/thread_posix.h"
#include "servers/rendering_server.h"

#if defined(__APPLE__)
#include <mach-o/dyld.h>
#include <mach/host_info.h>
#include <mach/mach_host.h>
#include <mach/mach_time.h>
#include <sys/sysctl.h>
#endif

#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
#include <sys/param.h>
#include <sys/sysctl.h>
#endif

#if defined(__FreeBSD__)
#include <kvm.h>
#endif

#if defined(__OpenBSD__)
#include <sys/swap.h>
#include <uvm/uvmexp.h>
#endif

#if defined(__NetBSD__)
#include <uvm/uvm_extern.h>
#endif

#include <dlfcn.h>
#include <errno.h>
#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#ifndef RTLD_DEEPBIND
#define RTLD_DEEPBIND
#endif

#ifndef SANITIZERS_ENABLED
#define GODOT_DLOPEN_MODE
#else
#define GODOT_DLOPEN_MODE
#endif

#if defined(MACOS_ENABLED) || (defined(__ANDROID_API__) && __ANDROID_API__ >= 28)
// Random location for getentropy. Fitting.
#include <sys/random.h>
#define UNIX_GET_ENTROPY
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__GLIBC_MINOR__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 26))
// In <unistd.h>.
// One day... (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700)
// https://publications.opengroup.org/standards/unix/c211
#define UNIX_GET_ENTROPY
#endif

#if !defined(UNIX_GET_ENTROPY) && !defined(NO_URANDOM)
#include <fcntl.h>
#endif

/// Clock Setup function (used by get_ticks_usec)
static uint64_t _clock_start =;
#if defined(__APPLE__)
static double _clock_scale = 0;
static void _setup_clock() {
	mach_timebase_info_data_t info;
	kern_return_t ret = mach_timebase_info(&info);
	ERR_FAIL_COND_MSG(ret != 0, "OS CLOCK IS NOT WORKING!");
	_clock_scale = ((double)info.numer / (double)info.denom) / 1000.0;
	_clock_start = mach_absolute_time() * _clock_scale;
}
#else
#if defined(CLOCK_MONOTONIC_RAW) && !defined(WEB_ENABLED) // This is a better clock on Linux.
#define GODOT_CLOCK
#else
#define GODOT_CLOCK
#endif
static void _setup_clock() {}
#endif

static void handle_interrupt(int sig) {}

void OS_Unix::initialize_debugging() {}

int OS_Unix::unix_initialize_audio(int p_audio_driver) {}

void OS_Unix::initialize_core() {}

void OS_Unix::finalize_core() {}

Vector<String> OS_Unix::get_video_adapter_driver_info() const {}

String OS_Unix::get_stdin_string() {}

Error OS_Unix::get_entropy(uint8_t *r_buffer, int p_bytes) {}

String OS_Unix::get_name() const {}

String OS_Unix::get_distribution_name() const {}

String OS_Unix::get_version() const {}

double OS_Unix::get_unix_time() const {}

OS::DateTime OS_Unix::get_datetime(bool p_utc) const {}

OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {}

void OS_Unix::delay_usec(uint32_t p_usec) const {}

uint64_t OS_Unix::get_ticks_usec() const {}

Dictionary OS_Unix::get_memory_info() const {}

Dictionary OS_Unix::execute_with_pipe(const String &p_path, const List<String> &p_arguments, bool p_blocking) {}

Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex, bool p_open_console) {}

Error OS_Unix::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id, bool p_open_console) {}

Error OS_Unix::kill(const ProcessID &p_pid) {}

int OS_Unix::get_process_id() const {}

bool OS_Unix::is_process_running(const ProcessID &p_pid) const {}

int OS_Unix::get_process_exit_code(const ProcessID &p_pid) const {}

String OS_Unix::get_locale() const {}

Error OS_Unix::open_dynamic_library(const String &p_path, void *&p_library_handle, GDExtensionData *p_data) {}

Error OS_Unix::close_dynamic_library(void *p_library_handle) {}

Error OS_Unix::get_dynamic_library_symbol_handle(void *p_library_handle, const String &p_name, void *&p_symbol_handle, bool p_optional) {}

Error OS_Unix::set_cwd(const String &p_cwd) {}

bool OS_Unix::has_environment(const String &p_var) const {}

String OS_Unix::get_environment(const String &p_var) const {}

void OS_Unix::set_environment(const String &p_var, const String &p_value) const {}

void OS_Unix::unset_environment(const String &p_var) const {}

String OS_Unix::get_user_data_dir() const {}

String OS_Unix::get_executable_path() const {}

void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify, ErrorType p_type) {}

UnixTerminalLogger::~UnixTerminalLogger() {}

OS_Unix::OS_Unix() {}

#endif