aboutsummaryrefslogtreecommitdiff
path: root/elymas
diff options
context:
space:
mode:
authorDrahflow <drahflow@gmx.de>2013-08-06 23:09:40 +0200
committerDrahflow <drahflow@gmx.de>2013-08-06 23:09:40 +0200
commita8d7ccc4e6b9f5edaa81fc961ff462ba56a43897 (patch)
tree8bb063d643b56fe0d90348d76da6cf541920e4ca /elymas
parenta0f5e44d1cd8f3d4b12463bf9d0401f0d5623057 (diff)
More syscalls translated
Diffstat (limited to 'elymas')
-rw-r--r--elymas/lib/bin.ey22
-rw-r--r--elymas/lib/sys/linux.ey53
2 files changed, 64 insertions, 11 deletions
diff --git a/elymas/lib/bin.ey b/elymas/lib/bin.ey
index 4fe1f4a..74caa04 100644
--- a/elymas/lib/bin.ey
+++ b/elymas/lib/bin.ey
@@ -2,13 +2,21 @@
# as binary data structures
<
- # 0 -> string
- # 0 <- string from 9th byte onwards
- # 1 <- first 8 bytes of string interpreted as 64bit unsigned int
- { ==s
- [ [ 0 1 2 3 4 5 6 7 ] s each ] 256 math .unbase
- 8 s str .postfix
- } /scanu64 deff
+ <
+ # 0 -> number of bytes to combine into unsigned int
+ # 1 -> string
+ # 0 <- string from (w+1)th byte onwards
+ # 1 <- first w bytes of string interpreted as unsigned int
+ { ==w ==s
+ w s str .postfix
+ [ 0 w range s each ] 256 math .unbase
+ } /uw deff
+
+ { 8 uw } /u64 deff
+ { 4 uw } /u32 deff
+ { 2 uw } /u16 deff
+ { 1 uw } /u8 deff
+ > /scan defv
> /bin defv
# vim: syn=elymas
diff --git a/elymas/lib/sys/linux.ey b/elymas/lib/sys/linux.ey
index 0c65bbc..87e28cb 100644
--- a/elymas/lib/sys/linux.ey
+++ b/elymas/lib/sys/linux.ey
@@ -1,5 +1,6 @@
-# The idea of sys .linux is to define an isomorphic yet
+# The idea of sys .linux is to define an near-isomorphic yet
# elymas-style interface to syscalls
+# argument order tends to follow kernel API
<
43 ==ACCEPT
@@ -306,15 +307,59 @@
1 ==WRITE
20 ==WRITEV
+ 0 ==errno
+
+ bin .scan "->" via
+
+ # defines a syscall which has identical argument order
+ # to kernel API and returns the raw return value
+ { # ==name ==f
+ -01
+ { sys .asm .syscall =errno } ;
+ -01
+ deff
+ }' /defStdSyscall deff
+
+ { 0 0 0 0 0 CLOSE } /close defStdSyscall
+
# 0 <- raw return value
# 1 <- seconds since 1970
# 2 <- microseconds since 1970
{
# struct timeval takes 16 bytes on a x64
- 16 str .alloc ==timeval
- timeval 0 0 0 0 0 GETTIMEOFDAY sys .asm .syscall --
- timeval bin .scanu64 bin .scanu64 -123
+ 16 str .alloc ==buf
+ buf 0 0 0 0 0 GETTIMEOFDAY sys .asm .syscall =errno
+ buf ->u64 -01 ->u64
+ -023
} /gettimeofday deff
+
+ # 0 -> path to stat
+ # 0 <- raw return value
+ # 1 <- (struct stat)-like scope
+ {
+ # struct stat takes 144 bytes on a x64
+ 144 str .alloc ==buf
+ buf 0 0 0 0 STAT sys .asm .syscall =errno
+ buf <
+ ->u64 ==dev
+ ->u64 ==ino
+ ->u64 ==mode
+ ->u64 ==nlink
+ ->u64 ==uid
+ ->u64 ==gid
+ ->u64 ==rdev
+ ->u64 ==size
+ ->u64 ==blksize
+ ->u64 ==blocks
+ ->u64 ==atime
+ ->u64 ==mtime
+ ->u64 ==ctime
+ > -02
+ } /stat deff
+
+ { 0 0 0 OPEN } /open defStdSyscall
+ { 0 0 0 READ } /read defStdSyscall
+ { 0 0 0 WRITE } /write defStdSyscall
> /linux sys .defv
# vim: syn=elymas