Inital (stash) commit

This commit is contained in:
2023-05-12 22:23:58 +02:00
commit f86ed5fda6
14 changed files with 558 additions and 0 deletions

1
hs/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
dist-newstlye

19
hs/csrc/pre.c Normal file
View File

@@ -0,0 +1,19 @@
#include <unistd.h>
#include <string.h>
extern void hs_init(int*, char***);
extern void hs_exit();
extern void setup();
int argc = 0;
char* argv[] = { NULL };
char** pargv = argv;
void __attribute__((constructor)) pre() {
hs_init(&argc, &pargv);
setup();
}
void __attribute__((destructor)) post() {
hs_exit();
}

52
hs/loud.cabal Normal file
View File

@@ -0,0 +1,52 @@
cabal-version: 3.4
name: loud
version: 0.1.0
-- synopsis:
-- description:
license: MIT
license-file: LICENSE
author: Sivert V. Sæther
maintainer: gmail@sivert.pw
category: Prank
build-type: Simple
extra-source-files: cbits
common warnings
ghc-options: -Wall
foreign-library loud
type: native-shared
other-extensions: CApiFFI
other-modules: Loud
build-depends:
bytestring ^>= 0.11.4.0,
vector ^>= 0.13.0.0,
base ^>= 4.18.0.0
hs-source-dirs: src
-- asm-sources: pre.s
c-sources: csrc/pre.c
default-language: GHC2021
library
import: warnings
exposed-modules: Loud
other-extensions: CApiFFI
build-depends:
bytestring ^>= 0.11.4.0,
vector ^>= 0.13.0.0,
base ^>= 4.18.0.0,
mmap ^>= 0.5.9
hs-source-dirs: src
asm-sources: pre.s
-- c-sources: csrc/pre.c
default-language: GHC2021
test-suite loud-test
import: warnings
default-language: GHC2021
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Main.hs
build-depends:
base ^>=4.18.0.0,
loud

23
hs/pre.s Normal file
View File

@@ -0,0 +1,23 @@
.intel_syntax noprefix
.file "pre.s"
.text
.extern hs_init
.extern setup
.section .init_array, "aw"
.quad pre
.text
.global pre
.type pre, @function
pre:
pushq rbp
movq rbp, rsp
subq rsp, 16
call hs_init
call setup
leave
ret

22
hs/src/Loud.hs Normal file
View File

@@ -0,0 +1,22 @@
module Loud ( write ) where
import Data.String ( fromString )
import Data.ByteString
import Foreign.Ptr
import Foreign.C
setup :: IO ()
setup = putStrLn "Fuck you!"
write :: IO Int
write = do
let msg = "Hello, Haskell!\n"
useAsCStringLen (fromString msg :: ByteString) sus_write
sus_write :: CStringLen -> IO Int
sus_write (cstr, len) = _syscall 1 1 (minusPtr cstr nullPtr) len 0 0
foreign import ccall "syscall"
_syscall :: Int -> Int -> Int -> Int -> Int -> Int -> IO Int
foreign export ccall setup :: IO ()

6
hs/test/Main.hs Normal file
View File

@@ -0,0 +1,6 @@
module Main (main) where
import Loud ( write )
main :: IO Int
main = write