diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-02-11 23:29:09 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-02-11 23:29:09 -0700 |
commit | 33197faf9b626acb6c2815786e6caa316df64a33 (patch) | |
tree | 7961e2a00bbc9ce84c4d63aaa40271eac5f7cd4a /src | |
parent | e008ac8d837ad11557c7625f3c311f230986d7f5 (diff) | |
download | wetterhorn-33197faf9b626acb6c2815786e6caa316df64a33.tar.gz wetterhorn-33197faf9b626acb6c2815786e6caa316df64a33.tar.bz2 wetterhorn-33197faf9b626acb6c2815786e6caa316df64a33.zip |
Move Main.hs to Config.hs and override _start()
Now if one tries to execute the built binary with 'stack run' or by just
executing it, a helpful message prints to the screen instead of the
segmentation fault that normally happens.
This technically makes things not portable to other architectures, but
it's all just window dressing and can be taken out if need be for other
architectures.
Diffstat (limited to 'src')
-rw-r--r-- | src/Config.hs | 8 | ||||
-rw-r--r-- | src/Main.hs | 17 | ||||
-rw-r--r-- | src/harness_adapter.c | 35 |
3 files changed, 43 insertions, 17 deletions
diff --git a/src/Config.hs b/src/Config.hs new file mode 100644 index 0000000..14326cb --- /dev/null +++ b/src/Config.hs @@ -0,0 +1,8 @@ +module Config () where + +import Wetterhorn.Core + +foreign export ccall wetterhorn :: IO Wetterhorn + +wetterhorn :: IO Wetterhorn +wetterhorn = initWetterhorn defaultConfig diff --git a/src/Main.hs b/src/Main.hs deleted file mode 100644 index 03b5018..0000000 --- a/src/Main.hs +++ /dev/null @@ -1,17 +0,0 @@ -{-# HLINT ignore "Use camelCase" #-} - -module Main (main) where - -import Control.Monad.Writer (MonadWriter (tell), execWriter) -import Text.Printf -import Wetterhorn.Core - -foreign export ccall wetterhorn :: IO Wetterhorn - -wetterhorn :: IO Wetterhorn -wetterhorn = - initWetterhorn - defaultConfig - -main :: IO () -main = putStrLn "This should be dynamically linked!\n" diff --git a/src/harness_adapter.c b/src/harness_adapter.c index 5a9b9a4..6ae8c66 100644 --- a/src/harness_adapter.c +++ b/src/harness_adapter.c @@ -5,8 +5,43 @@ #include "HsFFI.h" #include "plugin_interface.h" +#include <stdio.h> const char *plugin_name = "Wetterhorn"; void plugin_load(int argc, char **argv) { hs_init(&argc, &argv); } void plugin_teardown(opqst_t st) { hs_exit(); } + +const char msg[] = + "Wetterhorn Plugin v 0.01\n" + " This is a mere shared object file, meant to be a plugin for the " + "Wetterhorn" + " Compositor. To use this, please run 'wtr_harness -p [this_file]' to" + " use this plugin.\n"; +const int msg_sz = sizeof(msg); + + +__attribute__((naked)) void _start() { + + // Make system call to print the message + asm( + // Load the address of the string into rsi + "mov %0, %%rsi\n" + // Load the string length into edx + "mov %1, %%edx\n" + // Load the file descriptor for stdout into edi + "mov $1, %%edi\n" + // Load the syscall number for sys_write into eax + "mov $1, %%eax\n" + // Make the syscall + "syscall\n" + + // Exit the program. + "mov $0, %%rdi\n" + "mov $60, %%rax\n" + "syscall\n" + : + : "r"(msg), "r"(msg_sz) // Input: address of msg + : "%rsi", "%edx", "%edi" // Clobbered registers + ); +} |