Remove libreborn.h: Part 2

This commit is contained in:
TheBrokenRail 2024-11-21 23:44:25 -05:00
parent fd26000fd4
commit 57aed4d0b3
34 changed files with 90 additions and 95 deletions

View File

@ -3,7 +3,7 @@
#include <libreborn/log.h> #include <libreborn/log.h>
#include <libreborn/env.h> #include <libreborn/env.h>
#include <libreborn/util.h> #include <libreborn/config.h>
#include <libreborn/exec.h> #include <libreborn/exec.h>
#include "../util/util.h" #include "../util/util.h"

View File

@ -2,6 +2,7 @@
#include <cerrno> #include <cerrno>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <cstring>
#include <libreborn/log.h> #include <libreborn/log.h>
#include <libreborn/util.h> #include <libreborn/util.h>

View File

@ -1,8 +1,3 @@
#include <sstream>
#include <cstring>
#include <sys/wait.h>
#include <sys/stat.h>
#include <libreborn/env.h> #include <libreborn/env.h>
#include "../util/util.h" #include "../util/util.h"

View File

@ -4,7 +4,6 @@
#include <cstdlib> #include <cstdlib>
#include <cstdio> #include <cstdio>
#include <csignal> #include <csignal>
#include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <ctime> #include <ctime>
#include <string> #include <string>
@ -13,6 +12,7 @@
#include <libreborn/exec.h> #include <libreborn/exec.h>
#include <libreborn/log.h> #include <libreborn/log.h>
#include <libreborn/util.h> #include <libreborn/util.h>
#include <libreborn/config.h>
#include "logger.h" #include "logger.h"

View File

@ -2,6 +2,7 @@
#include <libreborn/env.h> #include <libreborn/env.h>
#include <libreborn/util.h> #include <libreborn/util.h>
#include <libreborn/config.h>
#include "bootstrap/bootstrap.h" #include "bootstrap/bootstrap.h"
#include "options/parser.h" #include "options/parser.h"

View File

@ -3,6 +3,7 @@
#include <libreborn/config.h> #include <libreborn/config.h>
#include <libreborn/env.h> #include <libreborn/env.h>
#include <trampoline/types.h> #include <trampoline/types.h>
#include "parser.h" #include "parser.h"
// Globals // Globals

View File

@ -12,6 +12,7 @@ add_library(reborn-util SHARED
src/util/log.cpp src/util/log.cpp
src/util/cp437.cpp src/util/cp437.cpp
src/util/env.cpp src/util/env.cpp
src/util/config.cpp
src/util/flags/node.cpp src/util/flags/node.cpp
src/util/flags/flags.cpp src/util/flags/flags.cpp
src/util/flags/available-feature-flags # Show In IDE src/util/flags/available-feature-flags # Show In IDE

View File

@ -11,3 +11,8 @@
#cmakedefine MCPI_SKIN_SERVER "@MCPI_SKIN_SERVER@" #cmakedefine MCPI_SKIN_SERVER "@MCPI_SKIN_SERVER@"
#cmakedefine MCPI_DISCORD_INVITE "@MCPI_DISCORD_INVITE@" #cmakedefine MCPI_DISCORD_INVITE "@MCPI_DISCORD_INVITE@"
#cmakedefine MCPI_DOCUMENTATION "@MCPI_DOCUMENTATION@" #cmakedefine MCPI_DOCUMENTATION "@MCPI_DOCUMENTATION@"
// Access Configuration At Runtime
const char *reborn_get_version();
bool reborn_is_headless();
bool reborn_is_server();

View File

@ -20,9 +20,6 @@ void poll_fds(const std::vector<int> &fds, const std::function<void(int, size_t,
// Safe execvpe() // Safe execvpe()
__attribute__((noreturn)) void safe_execvpe(const char *const argv[], const char *const envp[]); __attribute__((noreturn)) void safe_execvpe(const char *const argv[], const char *const envp[]);
// Debug Tag
#define CHILD_PROCESS_TAG "(Child Process) "
// Run Command And Get Output // Run Command And Get Output
std::vector<unsigned char> *run_command(const char *const command[], int *exit_status); std::vector<unsigned char> *run_command(const char *const command[], int *exit_status);
bool is_exit_status_success(int status); bool is_exit_status_success(int status);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <cstring>
#include <dlfcn.h> #include <dlfcn.h>
#include <string> #include <string>
@ -27,7 +26,7 @@
}) })
// Hook Library Function // Hook Library Function
#define EXTERNAL_FUNC(name, return_type, args) \ #define HOOK(name, return_type, args) \
typedef return_type (*real_##name##_t)args; \ typedef return_type (*real_##name##_t)args; \
__attribute__((__unused__)) static real_##name##_t real_##name() { \ __attribute__((__unused__)) static real_##name##_t real_##name() { \
static real_##name##_t func = NULL; \ static real_##name##_t func = NULL; \
@ -39,9 +38,7 @@
} \ } \
} \ } \
return func; \ return func; \
} } \
#define HOOK(name, return_type, args) \
EXTERNAL_FUNC(name, return_type, args) \
extern "C" __attribute__((__used__)) return_type name args extern "C" __attribute__((__used__)) return_type name args
// Safe Version Of pipe() // Safe Version Of pipe()
@ -50,6 +47,7 @@ struct Pipe {
const int read; const int read;
const int write; const int write;
}; };
// Check If Two Percentages Are Different Enough To Be Logged // Check If Two Percentages Are Different Enough To Be Logged
bool is_progress_difference_significant(int32_t new_val, int32_t old_val); bool is_progress_difference_significant(int32_t new_val, int32_t old_val);
@ -57,11 +55,6 @@ bool is_progress_difference_significant(int32_t new_val, int32_t old_val);
int lock_file(const char *file); int lock_file(const char *file);
void unlock_file(const char *file, int fd); void unlock_file(const char *file, int fd);
// Access Configuration At Runtime
const char *reborn_get_version();
bool reborn_is_headless();
bool reborn_is_server();
// Check $DISPLAY // Check $DISPLAY
void reborn_check_display(); void reborn_check_display();

View File

@ -1,6 +1,8 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <cstring>
#include <cerrno>
#include <libreborn/libreborn.h> #include <libreborn/patch.h>
#include "patch-internal.h" #include "patch-internal.h"
// Limit Amount Of overwrite_calls() Calls // Limit Amount Of overwrite_calls() Calls

View File

@ -1,4 +1,4 @@
#include <libreborn/libreborn.h> #include <libreborn/patch.h>
#include "patch-internal.h" #include "patch-internal.h"
// Check Instruction // Check Instruction

View File

@ -6,7 +6,7 @@
#include <cstdint> #include <cstdint>
#include <cerrno> #include <cerrno>
#include <libreborn/libreborn.h> #include <libreborn/patch.h>
#include "patch-internal.h" #include "patch-internal.h"
// Overwrite Specific B(L) Instruction // Overwrite Specific B(L) Instruction

View File

@ -1,10 +1,11 @@
#include <vector> #include <vector>
#include <cstring>
#include <elf.h> #include <elf.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <link.h> #include <link.h>
#include <libreborn/libreborn.h> #include <libreborn/patch.h>
#include "patch-internal.h" #include "patch-internal.h"
// Track Segments // Track Segments

View File

@ -0,0 +1,32 @@
#include <cstdlib>
#include <libreborn/config.h>
#include <libreborn/env.h>
// Access Configuration At Runtime
const char *reborn_get_version() {
return MCPI_VERSION;
}
bool reborn_is_headless() {
static bool ret;
static bool is_set = false;
if (!is_set) {
ret = reborn_is_server();
if (getenv(_MCPI_FORCE_HEADLESS_ENV)) {
ret = true;
} else if (getenv(_MCPI_FORCE_NON_HEADLESS_ENV)) {
ret = false;
}
is_set = true;
}
return ret;
}
bool reborn_is_server() {
static int ret;
static bool is_set = false;
if (!is_set) {
ret = getenv(_MCPI_SERVER_MODE_ENV) != nullptr;
is_set = true;
}
return ret;
}

View File

@ -4,6 +4,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <cstring>
#include <libreborn/util.h> #include <libreborn/util.h>
#include <libreborn/log.h> #include <libreborn/log.h>
@ -133,6 +134,7 @@ __attribute__((noreturn)) void safe_execvpe(const char *const argv[], const char
} }
// Run Command And Get Output // Run Command And Get Output
#define CHILD_PROCESS_TAG "(Child Process) "
std::vector<unsigned char> *run_command(const char *const command[], int *exit_status) { std::vector<unsigned char> *run_command(const char *const command[], int *exit_status) {
// Run // Run
const std::optional<Process> child = fork_with_stdio(); const std::optional<Process> child = fork_with_stdio();

View File

@ -1,6 +1,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <cstring>
#include <libreborn/util.h> #include <libreborn/util.h>
#include <libreborn/config.h> #include <libreborn/config.h>
@ -50,34 +51,6 @@ void unlock_file(const char *file, const int fd) {
close(fd); close(fd);
} }
// Access Configuration At Runtime
const char *reborn_get_version() {
return MCPI_VERSION;
}
bool reborn_is_headless() {
static bool ret;
static bool is_set = false;
if (!is_set) {
ret = reborn_is_server();
if (getenv(_MCPI_FORCE_HEADLESS_ENV)) {
ret = true;
} else if (getenv(_MCPI_FORCE_NON_HEADLESS_ENV)) {
ret = false;
}
is_set = true;
}
return ret;
}
bool reborn_is_server() {
static int ret;
static int is_set = 0;
if (!is_set) {
ret = getenv(_MCPI_SERVER_MODE_ENV) != nullptr;
is_set = 1;
}
return ret;
}
// Check $DISPLAY // Check $DISPLAY
void reborn_check_display() { void reborn_check_display() {
if (!getenv("DISPLAY") && !getenv("WAYLAND_DISPLAY")) { if (!getenv("DISPLAY") && !getenv("WAYLAND_DISPLAY")) {

View File

@ -4,11 +4,9 @@
#include <AL/al.h> #include <AL/al.h>
#include <media-layer/audio.h> #include <media-layer/audio.h>
#include <libreborn/libreborn.h> #include <libreborn/log.h>
#include "file.h" #include "audio.h"
#include "engine.h"
#include "api.h"
// Store Audio Sources // Store Audio Sources
static std::vector<ALuint> sources; static std::vector<ALuint> sources;
@ -18,7 +16,6 @@ static std::vector<ALuint> sources;
static std::vector<ALuint> idle_sources; static std::vector<ALuint> idle_sources;
// Error Checking // Error Checking
#define AL_ERROR_CHECK() AL_ERROR_CHECK_MANUAL(alGetError())
#define AL_ERROR_CHECK_MANUAL(val) \ #define AL_ERROR_CHECK_MANUAL(val) \
{ \ { \
ALenum __err = val; \ ALenum __err = val; \
@ -26,6 +23,7 @@ static std::vector<ALuint> idle_sources;
ERR("OpenAL Error: %s", alGetString(__err)); \ ERR("OpenAL Error: %s", alGetString(__err)); \
} \ } \
} }
#define AL_ERROR_CHECK() AL_ERROR_CHECK_MANUAL(alGetError())
// Delete Sources // Delete Sources
void _media_audio_delete_sources() { void _media_audio_delete_sources() {

View File

@ -1,3 +0,0 @@
#pragma once
__attribute__((visibility("internal"))) void _media_audio_delete_sources();

View File

@ -0,0 +1,12 @@
#pragma once
#include <AL/al.h>
__attribute__((visibility("internal"))) void _media_audio_delete_sources();
__attribute__((visibility("internal"))) void _media_audio_init();
__attribute__((visibility("internal"))) void _media_audio_cleanup();
__attribute__((visibility("internal"))) int _media_audio_is_loaded();
__attribute__((visibility("internal"))) ALuint _media_audio_get_buffer(const char *source, const char *name);
__attribute__((visibility("internal"))) void _media_audio_delete_buffers();

View File

@ -2,11 +2,9 @@
#include <AL/alc.h> #include <AL/alc.h>
#include <AL/alext.h> #include <AL/alext.h>
#include <libreborn/libreborn.h> #include <libreborn/log.h>
#include "engine.h" #include "audio.h"
#include "file.h"
#include "api.h"
// Store Device // Store Device
static ALCdevice *device = nullptr; static ALCdevice *device = nullptr;

View File

@ -1,7 +0,0 @@
#pragma once
#include <AL/al.h>
__attribute__((visibility("internal"))) void _media_audio_init();
__attribute__((visibility("internal"))) void _media_audio_cleanup();
__attribute__((visibility("internal"))) int _media_audio_is_loaded();

View File

@ -6,10 +6,9 @@
#include <LIEF/ELF.hpp> #include <LIEF/ELF.hpp>
#include <libreborn/libreborn.h> #include <libreborn/log.h>
#include "file.h" #include "audio.h"
#include "engine.h"
// Load Symbol From ELF File // Load Symbol From ELF File
static void load_symbol(const char *source, const char *name, std::function<void(const unsigned char *, uint32_t)> callback) { static void load_symbol(const char *source, const char *name, std::function<void(const unsigned char *, uint32_t)> callback) {
@ -53,7 +52,7 @@ static ALuint load_sound(const char *source, const char *name) {
WARN("Symbol Too Small To Contain Audio Metadata: %s", name); WARN("Symbol Too Small To Contain Audio Metadata: %s", name);
return; return;
} }
audio_metadata *meta = (audio_metadata *) symbol; const audio_metadata *meta = (audio_metadata *) symbol;
// Check Frame Size // Check Frame Size
if (meta->frame_size != 1 && meta->frame_size != 2) { if (meta->frame_size != 1 && meta->frame_size != 2) {
@ -73,7 +72,7 @@ static ALuint load_sound(const char *source, const char *name) {
} }
// Load Data // Load Data
const int remaining_size = size - sizeof (audio_metadata); const int remaining_size = int(size - sizeof (audio_metadata));
const int data_size = meta->channels * meta->frames * meta->frame_size; const int data_size = meta->channels * meta->frames * meta->frame_size;
if (remaining_size < data_size) { if (remaining_size < data_size) {
WARN("Symbol Too Small To Contain Specified Audio Data: %s", name); WARN("Symbol Too Small To Contain Specified Audio Data: %s", name);
@ -107,7 +106,7 @@ static std::unordered_map<std::string, ALuint> buffers;
ALuint _media_audio_get_buffer(const char *source, const char *name) { ALuint _media_audio_get_buffer(const char *source, const char *name) {
// Check // Check
if (_media_audio_is_loaded()) { if (_media_audio_is_loaded()) {
if (buffers.count(name) > 0) { if (buffers.contains(name)) {
// Return // Return
return buffers[name]; return buffers[name];
} else { } else {

View File

@ -1,6 +0,0 @@
#pragma once
#include <AL/al.h>
__attribute__((visibility("internal"))) ALuint _media_audio_get_buffer(const char *source, const char *name);
__attribute__((visibility("internal"))) void _media_audio_delete_buffers();

View File

@ -2,8 +2,6 @@
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <libreborn/libreborn.h>
#include "window/media.h" #include "window/media.h"
// SDL Is Replaced With GLFW // SDL Is Replaced With GLFW

View File

@ -2,7 +2,7 @@
#define GLFW_INCLUDE_NONE #define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <libreborn/libreborn.h> #include <libreborn/log.h>
#include "media.h" #include "media.h"

View File

@ -2,7 +2,7 @@
#include <unistd.h> #include <unistd.h>
#include "media.h" #include "media.h"
#include "../audio/engine.h" #include "../audio/audio.h"
// Window // Window
GLFWwindow *glfw_window = nullptr; GLFWwindow *glfw_window = nullptr;

View File

@ -4,7 +4,10 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <libreborn/libreborn.h> #include <libreborn/log.h>
#include <libreborn/string.h>
#include <libreborn/glfw.h>
#include <libreborn/config.h>
#include <media-layer/core.h> #include <media-layer/core.h>

View File

@ -16,7 +16,7 @@ void media_toggle_fullscreen();
void media_swap_buffers(); void media_swap_buffers();
void media_cleanup(); void media_cleanup();
void media_get_framebuffer_size(int *width, int *height); void media_get_framebuffer_size(int *width, int *height);
void media_set_interactable(int is_interactable); void media_set_interactable(int toggle);
void media_disable_vsync(); void media_disable_vsync();
void media_set_raw_mouse_motion_enabled(int enabled); void media_set_raw_mouse_motion_enabled(int enabled);
int media_has_extension(const char *name); int media_has_extension(const char *name);

View File

@ -1,7 +1,8 @@
#include <cstdint> #include <cstdint>
#include <GLES/gl.h> #include <GLES/gl.h>
#include <libreborn/libreborn.h> #include <libreborn/log.h>
#include <libreborn/util.h>
#include "common/common.h" #include "common/common.h"

View File

@ -1,5 +1,5 @@
#include <unistd.h> #include <unistd.h>
#include <libreborn/libreborn.h> #include <libreborn/log.h>
#include <string> #include <string>
#include <sys/mman.h> #include <sys/mman.h>

View File

@ -1,4 +1,4 @@
#include <libreborn/libreborn.h> #include <libreborn/log.h>
#include "host.h" #include "host.h"

View File

@ -7,8 +7,6 @@
#include "common/common.h" #include "common/common.h"
#include <libreborn/libreborn.h>
// SDL Functions // SDL Functions
CALL(0, media_SDL_Init, int, (uint32_t flags)) CALL(0, media_SDL_Init, int, (uint32_t flags))

View File

@ -2,7 +2,7 @@
#include <cstring> #include <cstring>
#include <libreborn/log.h> #include <libreborn/log.h>
#include <libreborn/util.h> #include <libreborn/config.h>
#include <libreborn/env.h> #include <libreborn/env.h>
#include <libreborn/flags.h> #include <libreborn/flags.h>