This C syscall example is just doing exit(42)

Signed-off-by: Benoît Canet <ben...@scylladb.com>
---
 syscall/Makefile     |  9 +++++++++
 syscall/module.py    |  3 +++
 syscall/syscall.c    | 16 ++++++++++++++++
 syscall/usr.manifest |  1 +
 4 files changed, 29 insertions(+)
 create mode 100644 syscall/Makefile
 create mode 100644 syscall/module.py
 create mode 100644 syscall/syscall.c
 create mode 100644 syscall/usr.manifest

diff --git a/syscall/Makefile b/syscall/Makefile
new file mode 100644
index 0000000..d749e10
--- /dev/null
+++ b/syscall/Makefile
@@ -0,0 +1,9 @@
+.PHONY: module
+module: syscall
+       echo '/syscall: $${MODULE_DIR}/syscall' > usr.manifest
+
+syscall: syscall.c
+       gcc -shared -fPIC -o syscall syscall.c
+
+clean:
+       rm -f syscall usr.manifest
diff --git a/syscall/module.py b/syscall/module.py
new file mode 100644
index 0000000..a681a02
--- /dev/null
+++ b/syscall/module.py
@@ -0,0 +1,3 @@
+from osv.modules import api
+
+default = api.run(cmdline="/syscall")
diff --git a/syscall/syscall.c b/syscall/syscall.c
new file mode 100644
index 0000000..2648bf3
--- /dev/null
+++ b/syscall/syscall.c
@@ -0,0 +1,16 @@
+int
+main(int argc, char *argv[])
+{
+  unsigned long syscall_nr = 60;
+  long exit_status = 42;
+
+  asm ("movq %0, %%rax\n"
+       "movq %1, %%rdi\n"
+       "syscall"
+    : /* output parameters, we aren't outputting anything, no none */
+      /* (none) */
+    : /* input parameters mapped to %0 and %1, repsectively */
+      "m" (syscall_nr), "m" (exit_status)
+    : /* registers that we are "clobbering", unneeded since we are calling 
exit */
+      "rax", "rdi");
+}
diff --git a/syscall/usr.manifest b/syscall/usr.manifest
new file mode 100644
index 0000000..acdf1da
--- /dev/null
+++ b/syscall/usr.manifest
@@ -0,0 +1 @@
+/syscall: ${MODULE_DIR}/syscall
-- 
2.7.4

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to