This commit is contained in:
nakst 2021-12-14 10:07:26 +00:00
parent 2d6baf19a0
commit a3aaf6e85d
5 changed files with 201 additions and 44 deletions

View File

@ -78,15 +78,6 @@ const EsInstanceClassEditorSettings editorSettings = {
ES_ICON_IMAGE_X_GENERIC,
};
const EsStyle styleBitmapSizeTextbox = {
.inherit = ES_STYLE_TEXTBOX_BORDERED_SINGLE_COMPACT,
.metrics = {
.mask = ES_THEME_METRICS_PREFERRED_WIDTH,
.preferredWidth = 80,
},
};
const EsStyle styleImageMenuTable = {
.inherit = ES_STYLE_PANEL_FORM_TABLE,
@ -685,7 +676,7 @@ void MenuImage(Instance *instance, EsElement *element, EsCommand *) {
bytes = EsStringFormat(buffer, sizeof(buffer), "%d", instance->bitmapHeight);
EsTextDisplayCreate(table, ES_CELL_H_RIGHT, ES_STYLE_TEXT_LABEL, INTERFACE_STRING(ImageEditorPropertyHeight));
textbox = EsTextboxCreate(table, ES_TEXTBOX_EDIT_BASED, &styleBitmapSizeTextbox);
textbox = EsTextboxCreate(table, ES_TEXTBOX_EDIT_BASED, ES_STYLE_TEXTBOX_BORDERED_SINGLE_MEDIUM);
EsTextboxInsert(textbox, buffer, bytes, false);
textbox->userData.i = 1;
textbox->messageUser = BitmapSizeTextboxMessage;

View File

@ -36,16 +36,6 @@ struct SettingsControl {
EsElement *element;
};
const EsStyle styleSettingsGroupContainer = {
.inherit = ES_STYLE_BUTTON_GROUP_CONTAINER,
.metrics = {
.mask = ES_THEME_METRICS_PREFERRED_WIDTH | ES_THEME_METRICS_INSETS,
.insets = ES_RECT_1(5),
.preferredWidth = 400,
},
};
const EsStyle styleAllSettingsGroupContainer = {
.metrics = {
.mask = ES_THEME_METRICS_PREFERRED_WIDTH | ES_THEME_METRICS_INSETS | ES_THEME_METRICS_GAP_ALL,
@ -80,17 +70,6 @@ const uint32_t windowColors[][7] = {
{ 0xFFB7BBC5, 0xFFB8BABE, 0xFF9A9BA0, 0xFF85878B, 0xFFE9E9EA, 0xFFDEDFE1, 0xFFB9BABC },
};
const EsStyle styleSettingsGroupContainer3 = {
.inherit = ES_STYLE_BUTTON_GROUP_CONTAINER,
.metrics = {
.mask = ES_THEME_METRICS_PREFERRED_WIDTH | ES_THEME_METRICS_INSETS | ES_THEME_METRICS_GAP_MAJOR,
.insets = ES_RECT_1(15),
.preferredWidth = 600,
.gapMajor = 15,
},
};
const EsStyle styleSettingsCheckboxGroup = {
.metrics = {
.mask = ES_THEME_METRICS_GAP_MAJOR | ES_THEME_METRICS_GAP_MINOR,

View File

@ -4,7 +4,6 @@
#include <module.h>
// TODO Device attach and detach.
// TODO Babble error recovery.
#define SPEED_LOW (1)

View File

@ -358,12 +358,13 @@ void BuildUtilities() {
#define BUILD_UTILITY(x, y, z) \
if (CheckDependencies("Utilities." x)) { \
if (!CallSystem("gcc -MMD util/" z x ".c -o bin/" x " -g -std=c2x " WARNING_FLAGS " " y)) { \
if (!CallSystem("gcc -MMD util/" z x ".c -o bin/" x " -g " WARNING_FLAGS " " y)) { \
ParseDependencies("bin/" x ".d", "Utilities." x, false); \
} \
}
BUILD_UTILITY("render_svg", "-lm", "");
BUILD_UTILITY("change_sysroot", "", "");
BUILD_UTILITY("build_core", "-pthread -DPARALLEL_BUILD", "");
if (canBuildLuigi) {
@ -520,14 +521,16 @@ void Run(int emulator, int log, int debug) {
serialFlags[0] = 0;
}
CallSystemF("%s %s " QEMU_EXECUTABLE " %s%s %s -m %d %s -smp cores=%d -cpu Haswell "
if (CallSystemF("%s %s " QEMU_EXECUTABLE " %s%s %s -m %d %s -smp cores=%d -cpu Haswell "
" -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0,id=mykeyboard -device usb-mouse,bus=xhci.0,id=mymouse "
" -netdev user,id=u1 -device e1000,netdev=u1 -object filter-dump,id=f1,netdev=u1,file=bin/net.dat "
" %s %s %s %s %s %s %s ",
audioFlags, IsOptionEnabled("Emulator.RunWithSudo") ? "sudo " : "", drivePrefix, driveFlags, cdromFlags,
atoi(GetOptionString("Emulator.MemoryMB")),
debug ? (debug == DEBUG_NONE ? "-enable-kvm" : "-s -S") : "-s",
cpuCores, audioFlags2, logFlags, usbFlags, usbFlags2, secondaryDriveFlags, biosFlags, serialFlags);
cpuCores, audioFlags2, logFlags, usbFlags, usbFlags2, secondaryDriveFlags, biosFlags, serialFlags)) {
printf("Unable to start Qemu. To manually run the system, use the drive image located at \"bin/drive\".\n");
}
} break;
case EMULATOR_BOCHS: {
@ -573,6 +576,8 @@ void BuildCrossCompiler() {
printf("- You must fully update your system before building.\n\n");
bool missingPackages = false;
bool missingLibraries = false;
if (CallSystem("which g++ > /dev/null 2>&1")) { printf("Error: Missing GCC/G++.\n"); missingPackages = true; }
if (CallSystem("which make > /dev/null 2>&1")) { printf("Error: Missing GNU Make.\n"); missingPackages = true; }
if (CallSystem("which bison > /dev/null 2>&1")) { printf("Error: Missing GNU Bison.\n"); missingPackages = true; }
@ -588,16 +593,24 @@ void BuildCrossCompiler() {
if (CallSystem("which awk > /dev/null 2>&1")) { printf("Error: Missing awk.\n"); missingPackages = true; }
#ifdef __APPLE__
if (CallSystem("gcc -L/opt/homebrew/lib -lmpc 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU MPC.\n"); missingPackages = true; }
if (CallSystem("gcc -L/opt/homebrew/lib -lmpfr 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU MPFR.\n"); missingPackages = true; }
if (CallSystem("gcc -L/opt/homebrew/lib -lgmp 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU GMP.\n"); missingPackages = true; }
if (CallSystem("gcc -L/opt/homebrew/lib -lmpc 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU MPC.\n"); missingLibraries = true; }
if (CallSystem("gcc -L/opt/homebrew/lib -lmpfr 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU MPFR.\n"); missingLibraries = true; }
if (CallSystem("gcc -L/opt/homebrew/lib -lgmp 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU GMP.\n"); missingLibraries = true; }
#else
if (CallSystem("gcc -lmpc 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU MPC.\n"); missingPackages = true; }
if (CallSystem("gcc -lmpfr 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU MPFR.\n"); missingPackages = true; }
if (CallSystem("gcc -lgmp 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU GMP.\n"); missingPackages = true; }
if (CallSystem("gcc -lmpc 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU MPC.\n"); missingLibraries = true; }
if (CallSystem("gcc -lmpfr 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU MPFR.\n"); missingLibraries = true; }
if (CallSystem("gcc -lgmp 2>&1 | grep -i undefined > /dev/null")) { printf("Error: Missing GNU GMP.\n"); missingLibraries = true; }
#endif
if (missingPackages) exit(0);
if (missingPackages || missingLibraries) {
if (missingLibraries) {
printf("Make sure you install the *development* versions of MPC, MPFR and GMP.\n"
"Depending on your package manager, you might have to suffix the package name with \"-dev\" or \"-devel\".\n"
"For example, on Ubuntu, you can run: \"apt-get install libgmp-dev libmpc-dev libmpfr.dev\".\n");
}
exit(0);
}
char installationFolder[4096];
char sysrootFolder[4096];
@ -1197,7 +1210,14 @@ void DoCommand(const char *l) {
CallSystem("mv bin/installer_metadata.dat root/Installer\\ Data/metadata.dat");
} else if (0 == strcmp(l, "config")) {
BuildUtilities();
CallSystem("bin/config_editor");
if (CallSystem("bin/config_editor")) {
printf("The config editor could not be opened.\n"
"This likely means your system does not have X11 setup.\n"
"If needed, you can manually modify the config file, \"bin/config.ini\".\n"
"See the \"options\" array in \"util/build_common.h\" for a list of options.\n"
"But please bare in mind that manually editing the config file is not recommended.\n");
}
} else if (0 == strcmp(l, "designer2")) {
BuildUtilities();
CallSystem("bin/designer2");
@ -1325,7 +1345,7 @@ void DoCommand(const char *l) {
closedir(directory);
} else if (0 == memcmp(l, "do ", 3)) {
CallSystem(l + 3);
} else if (0 == memcmp(l, "live ", 5)) {
} else if (0 == memcmp(l, "live ", 5) || 0 == strcmp(l, "live")) {
if (interactiveMode) {
fprintf(stderr, "This command cannot be used in interactive mode. Type \"quit\" and then run \"./start.sh live <...>\".\n");
return;

168
util/change_sysroot.c Normal file
View File

@ -0,0 +1,168 @@
// gcc -o bin/change_sysroot util/change_sysroot.c -Wall -Wextra
// ./change_sysroot "/home/runner/work/build-gcc-x86_64-essence/build-gcc-x86_64-essence/essence/root/" $SYSROOT ...
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <stdbool.h>
#include <unistd.h>
#include <wait.h>
#include <limits.h>
#include <syscall.h>
#include <sys/ptrace.h>
#include <sys/user.h>
const char *needle;
const char *replaceWith;
bool GetReplacement(const char *original, char *buffer) {
if (0 == memcmp(needle, original, strlen(needle))) {
strcpy(buffer, replaceWith);
strcat(buffer, original + strlen(needle));
// fprintf(stderr, "'%s' -> '%s'\n", original, buffer);
return true;
} else {
return false;
}
}
char *ReadString(pid_t pid, uintptr_t address) {
char *buffer = NULL;
uintptr_t position = 0;
uintptr_t capacity = 0;
while (true) {
char b = ptrace(PTRACE_PEEKDATA, pid, address, 0);
if (position == capacity) {
capacity = (capacity + 8) * 2;
buffer = realloc(buffer, capacity);
}
buffer[position] = b;
position++, address++;
if (b == 0) {
break;
}
}
return realloc(buffer, position);
}
uintptr_t WriteString(pid_t pid, uintptr_t rsp, const char *string) {
uintptr_t address = rsp - 128 /* red zone */ - strlen(string) - sizeof(uintptr_t) /* POKEDATA writes words */;
for (int i = 0; true; i++) {
uintptr_t c = string[i];
ptrace(PTRACE_POKEDATA, pid, (void *) (address + i), (void *) c);
if (!c) break;
}
return address;
}
bool ReplaceString(pid_t pid, uintptr_t rsp, uintptr_t *address) {
char *original = ReadString(pid, *address);
char buffer[PATH_MAX];
bool modified = GetReplacement(original, buffer);
if (modified) *address = WriteString(pid, rsp, buffer);
free(original);
return modified;
}
int main(int argc, char **argv) {
if (argc < 4) {
fprintf(stderr, "Usage: %s <path to replace> <what to replace with> <executable> <arguments to executable>\n", argv[0]);
return 1;
}
needle = argv[1];
replaceWith = argv[2];
pid_t basePID;
{
pid_t pid = vfork();
if (pid == 0) {
ptrace(PTRACE_TRACEME, 0, 0, 0);
execvp(argv[3], &argv[3]);
}
waitpid(pid, 0, 0);
ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_EXITKILL | PTRACE_O_TRACEVFORK);
ptrace(PTRACE_SYSCALL, pid, 0, 0);
basePID = pid;
}
while (kill(basePID, 0) == 0 /* still alive */) {
struct user_regs_struct registers = { 0 };
pid_t pid = waitpid(-1, 0, 0);
ptrace(PTRACE_GETREGS, pid, 0, &registers);
if (registers.orig_rax == SYS_access
|| registers.orig_rax == SYS_lstat
|| registers.orig_rax == SYS_readlink
|| registers.orig_rax == SYS_stat
|| registers.orig_rax == SYS_unlink) {
if (ReplaceString(pid, registers.rsp, (uintptr_t *) &registers.rdi)) {
ptrace(PTRACE_SETREGS, pid, 0, &registers);
}
} else if (registers.orig_rax == SYS_faccessat2
|| registers.orig_rax == SYS_newfstatat
|| registers.orig_rax == SYS_openat) {
if (ReplaceString(pid, registers.rsp, (uintptr_t *) &registers.rsi)) {
ptrace(PTRACE_SETREGS, pid, 0, &registers);
}
} else if (registers.orig_rax == SYS_arch_prctl
|| registers.orig_rax == SYS_brk
|| registers.orig_rax == SYS_chmod
|| registers.orig_rax == SYS_close
|| registers.orig_rax == SYS_exit_group
|| registers.orig_rax == SYS_execve
|| registers.orig_rax == SYS_fcntl
|| registers.orig_rax == SYS_fstat
|| registers.orig_rax == SYS_getcwd
|| registers.orig_rax == SYS_getrandom
|| registers.orig_rax == SYS_getrusage
|| registers.orig_rax == SYS_ioctl
|| registers.orig_rax == SYS_lseek
|| registers.orig_rax == SYS_mmap
|| registers.orig_rax == SYS_mprotect
|| registers.orig_rax == SYS_munmap
|| registers.orig_rax == SYS_pipe2
|| registers.orig_rax == SYS_pread64
|| registers.orig_rax == SYS_prlimit64
|| registers.orig_rax == SYS_read
|| registers.orig_rax == SYS_rt_sigaction
|| registers.orig_rax == SYS_rt_sigprocmask
|| registers.orig_rax == SYS_set_robust_list
|| registers.orig_rax == SYS_set_tid_address
|| registers.orig_rax == SYS_sysinfo
|| registers.orig_rax == SYS_umask
|| registers.orig_rax == SYS_vfork
|| registers.orig_rax == SYS_wait4
|| registers.orig_rax == SYS_write) {
// Allow through.
} else {
printf("unhandled syscall %llu\n", registers.orig_rax);
}
ptrace(PTRACE_SYSCALL, pid, 0, 0);
waitpid(pid, 0, 0);
if (ptrace(PTRACE_GETREGS, pid, 0, &registers) == -1) {
// The process has likely exited.
} else {
ptrace(PTRACE_SYSCALL, pid, 0, 0);
}
}
return 0;
}