generalization of syscalls
This commit is contained in:
+41
-19
@@ -24,12 +24,12 @@
|
||||
bool quited = false;
|
||||
|
||||
bool fileread(void *ctx, char *into, uint32_t bytes) {
|
||||
return com_std_syscall(0, (intptr_t)ctx, (intptr_t)into, bytes) == bytes;
|
||||
return com_std_read(ctx, into, bytes) == bytes;
|
||||
}
|
||||
|
||||
bool fileskip(void *ctx, uint32_t bytes) {
|
||||
return com_std_syscall(8, (intptr_t)ctx, bytes, 1) >= 0;
|
||||
}
|
||||
bool fileskip(void *ctx, uint32_t bytes) { return com_std_sfwd(ctx, bytes); }
|
||||
|
||||
#define AUTH_ENTRY_MAGIC_COOKIE "MIT-MAGIC-COOKIE-1"
|
||||
|
||||
static struct plr_x11_auth_entry {
|
||||
uint16_t family;
|
||||
@@ -39,10 +39,8 @@ static struct plr_x11_auth_entry {
|
||||
} plr_x11_read_auth_entry(struct com_bin *b, struct com_buf *buf) {
|
||||
struct plr_x11_auth_entry result = {0};
|
||||
|
||||
if (!com_bin_read_u16(b, &result.family)) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
if (!com_bin_read_u16(b, &result.family))
|
||||
goto BREAK;
|
||||
}
|
||||
uint16_t addres_len;
|
||||
if (!com_bin_read_u16(b, &addres_len))
|
||||
goto BREAK;
|
||||
@@ -75,6 +73,24 @@ BREAK:
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool plr_x11_handshake(struct plr_x11_auth_entry auth_entry) {
|
||||
struct {
|
||||
uint8_t endianness;
|
||||
uint8_t pad0;
|
||||
uint16_t major_version;
|
||||
uint16_t minor_version;
|
||||
uint16_t auth_len;
|
||||
uint16_t auth_data_len;
|
||||
uint16_t pad1;
|
||||
} __attribute__((packed)) request = {
|
||||
.endianness = 'l',
|
||||
.major_version = 11,
|
||||
.auth_len = sizeof(AUTH_ENTRY_MAGIC_COOKIE) - 1, // IS -1 NEEDED?
|
||||
.auth_data_len = auth_entry.auth_data->len,
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: correct error handling.
|
||||
extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
char test_string[] = "what is this?";
|
||||
@@ -106,15 +122,13 @@ extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
|
||||
/* TODO: Move init to separate func. */
|
||||
/* Open X11 socket for communication. */
|
||||
int const xfd = com_std_syscall(41, AF_UNIX, SOCK_STREAM, 0);
|
||||
if (xfd < 0) {
|
||||
com_std_fd const xfd = com_std_socket(false);
|
||||
if (!xfd) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct sockaddr_un const addr = {.sun_family = AF_UNIX,
|
||||
.sun_path = "/tmp/.X11-unix/X0"};
|
||||
if (com_std_syscall(42, xfd, (intptr_t)&addr, sizeof addr)) {
|
||||
if (!com_std_connect(xfd, false, "/tmp/.X11-unix/X0")) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -131,7 +145,7 @@ extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
/* Open it and parse. */
|
||||
int const xauthfd = com_std_syscall(2, (intptr_t)xauthpath, O_RDONLY, 0);
|
||||
com_std_fd const xauthfd = com_std_open(xauthpath, COM_STD_OPEN_READ);
|
||||
if (xauthfd < 0) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
return -1;
|
||||
@@ -143,13 +157,21 @@ extern int plr_display_x11_main(int argc, char *argv[]) {
|
||||
.flags = COM_BIN_BIG_ENDIAN,
|
||||
.interface = {.readn = fileread, .skipn = fileskip}};
|
||||
|
||||
struct plr_x11_auth_entry auth_entry =
|
||||
plr_x11_read_auth_entry(&xauthbin, xauthbuf);
|
||||
/* Loop over auth entries until we find magic cookie one. */
|
||||
struct plr_x11_auth_entry auth_entry;
|
||||
do {
|
||||
com_buf_clear(xauthbuf);
|
||||
auth_entry = plr_x11_read_auth_entry(&xauthbin, xauthbuf);
|
||||
} while (auth_entry.success && auth_entry.family != 256);
|
||||
if (!auth_entry.success) {
|
||||
com_std_printf("Failure to initialize X11\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
com_std_print_str(auth_entry.auth_name->data, auth_entry.auth_name->len,
|
||||
true);
|
||||
com_std_print_str(auth_entry.auth_data->data, auth_entry.auth_data->len,
|
||||
true);
|
||||
com_std_close(xauthfd);
|
||||
|
||||
/* TODO: Check for auth_entry.name == MAGIC ? */
|
||||
plr_x11_handshake(auth_entry);
|
||||
|
||||
com_buf_free(xauthbuf);
|
||||
|
||||
|
||||
+3
-2
@@ -1,8 +1,8 @@
|
||||
CC = clang
|
||||
RELEASE ?= 0 # Optimize.
|
||||
DEBUG ?= 1 # Emit debug info.
|
||||
DEBUG ?= 1 # Emit debug info.
|
||||
SQUEEZE ?= 0 # Nuclear option to save space.
|
||||
BITS ?= 64
|
||||
BITS ?= 64
|
||||
CFLAGS = -Wall -std=gnu99 -flto=thin -ffast-math -fno-ident -fvisibility=hidden
|
||||
ifeq ($(MAKECMDGOALS),linux)
|
||||
ifeq ($(RELEASE), 1)
|
||||
@@ -59,6 +59,7 @@ wasm: CFLAGS += --target=wasm32 -nostdlib -Wl,--no-entry -msimd128 -mbulk-memory
|
||||
wasm:
|
||||
$(CC) -o player.wasm $(WASM) $(CFLAGS)
|
||||
|
||||
# TODO: Use https://github.com/amindlost/pmodew
|
||||
dos: $(DOS) $(DEPS)
|
||||
wcl386 -bt=dos4g -ox -l=dos4g $(DOS)
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
#include "./draw.c"
|
||||
|
||||
#if COM_DEF_TARGET == COM_DEF_TARGET_LINUX
|
||||
#include "../Common/Std/linux.c"
|
||||
#include "../Common/Std/linux-amd64.c"
|
||||
#include "../Common/Timer/stub.c"
|
||||
#include "./Display/x11.c"
|
||||
#include "./Main/linux.c"
|
||||
|
||||
Reference in New Issue
Block a user