From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Wei Liu" <wei.liu2@citrix.com>,
jonathan.ludlam@citrix.com,
"Ian Jackson" <ian.jackson@eu.citrix.com>,
christian.lindig@citrix.com, dave@recoil.org,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH for-4.9 1/2] oxenstored: add an Unix syscall C extension
Date: Fri, 14 Apr 2017 11:20:17 +0100 [thread overview]
Message-ID: <20170414102018.14853-2-wei.liu2@citrix.com> (raw)
In-Reply-To: <20170414102018.14853-1-wei.liu2@citrix.com>
Currently there is only uname syscall in it.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: dave@recoil.org
Cc: christian.lindig@citrix.com
Cc: jonathan.ludlam@citrix.com
Cc: Roger Pau Monné <roger.pau@citrix.com>
---
tools/ocaml/xenstored/Makefile | 9 ++++--
tools/ocaml/xenstored/unix_syscalls.ml | 29 ++++++++++++++++++
tools/ocaml/xenstored/unix_syscalls.mli | 29 ++++++++++++++++++
tools/ocaml/xenstored/unix_syscalls_stubs.c | 46 +++++++++++++++++++++++++++++
4 files changed, 110 insertions(+), 3 deletions(-)
create mode 100644 tools/ocaml/xenstored/unix_syscalls.ml
create mode 100644 tools/ocaml/xenstored/unix_syscalls.mli
create mode 100644 tools/ocaml/xenstored/unix_syscalls_stubs.c
diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile
index d23883683d..cfd4d81b9e 100644
--- a/tools/ocaml/xenstored/Makefile
+++ b/tools/ocaml/xenstored/Makefile
@@ -18,12 +18,14 @@ OCAMLINCLUDE += \
-I $(OCAML_TOPLEVEL)/libs/xc \
-I $(OCAML_TOPLEVEL)/libs/eventchn
-LIBS = syslog.cma syslog.cmxa select.cma select.cmxa
+LIBS = syslog.cma syslog.cmxa select.cma select.cmxa unix_syscalls.cma unix_syscalls.cmxa
syslog_OBJS = syslog
syslog_C_OBJS = syslog_stubs
select_OBJS = select
select_C_OBJS = select_stubs
-OCAML_LIBRARY = syslog select
+unix_syscalls_C_OBJS = unix_syscalls_stubs
+unix_syscalls_OBJS = unix_syscalls
+OCAML_LIBRARY = syslog select unix_syscalls
LIBS += systemd.cma systemd.cmxa
systemd_OBJS = systemd
@@ -58,13 +60,14 @@ OBJS = paths \
process \
xenstored
-INTF = symbol.cmi trie.cmi syslog.cmi systemd.cmi select.cmi
+INTF = symbol.cmi trie.cmi syslog.cmi systemd.cmi select.cmi unix_syscalls.cmi
XENSTOREDLIBS = \
unix.cmxa \
-ccopt -L -ccopt . syslog.cmxa \
-ccopt -L -ccopt . systemd.cmxa \
-ccopt -L -ccopt . select.cmxa \
+ -ccopt -L -ccopt . unix_syscalls.cmxa \
-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/mmap $(OCAML_TOPLEVEL)/libs/mmap/xenmmap.cmxa \
-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/eventchn/xeneventchn.cmxa \
-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xenctrl.cmxa \
diff --git a/tools/ocaml/xenstored/unix_syscalls.ml b/tools/ocaml/xenstored/unix_syscalls.ml
new file mode 100644
index 0000000000..b52a07967d
--- /dev/null
+++ b/tools/ocaml/xenstored/unix_syscalls.ml
@@ -0,0 +1,29 @@
+(*
+ * unix_syscalls.ml
+ *
+ * Stubs for unix syscalls
+ *
+ * Copyright (C) 2017 Wei Liu <wei.liu2@citrix.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License, version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *)
+
+type utsname = {
+ sysname: string;
+ nodename: string;
+ release: string;
+ version: string;
+ machine: string;
+}
+
+external uname : unit -> utsname = "unix_uname"
diff --git a/tools/ocaml/xenstored/unix_syscalls.mli b/tools/ocaml/xenstored/unix_syscalls.mli
new file mode 100644
index 0000000000..8e9adaf0a4
--- /dev/null
+++ b/tools/ocaml/xenstored/unix_syscalls.mli
@@ -0,0 +1,29 @@
+(*
+ * unix_syscalls.mli
+ *
+ * Stubs for unix syscalls
+ *
+ * Copyright (C) 2017 Wei Liu <wei.liu2@citrix.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License, version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *)
+
+type utsname = {
+ sysname: string;
+ nodename: string;
+ release: string;
+ version: string;
+ machine: string;
+}
+
+external uname : unit -> utsname = "unix_uname"
diff --git a/tools/ocaml/xenstored/unix_syscalls_stubs.c b/tools/ocaml/xenstored/unix_syscalls_stubs.c
new file mode 100644
index 0000000000..1cd46d0834
--- /dev/null
+++ b/tools/ocaml/xenstored/unix_syscalls_stubs.c
@@ -0,0 +1,46 @@
+/*
+ * unix_syscalls_stub.c
+ *
+ * Stubs for unix syscalls
+ *
+ * Copyright (C) 2017 Wei Liu <wei.liu2@citrix.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License, version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/utsname.h>
+#include <caml/mlvalues.h>
+#include <caml/memory.h>
+#include <caml/fail.h>
+#include <caml/alloc.h>
+#include <caml/signals.h>
+#include <caml/unixsupport.h>
+
+CAMLprim value unix_uname(value ignored)
+{
+ CAMLparam1(ignored);
+ CAMLlocal1(utsname);
+ struct utsname buf;
+
+ if (uname(&buf))
+ uerror("uname", Nothing);
+
+ utsname = caml_alloc(5, 0);
+ Store_field(utsname, 0, caml_copy_string(buf.sysname));
+ Store_field(utsname, 1, caml_copy_string(buf.nodename));
+ Store_field(utsname, 2, caml_copy_string(buf.release));
+ Store_field(utsname, 3, caml_copy_string(buf.version));
+ Store_field(utsname, 4, caml_copy_string(buf.machine));
+
+ CAMLreturn(utsname);
+}
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-04-14 10:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-14 10:20 [PATCH for-4.9 0/2] oxenstored: make it work on FreeBSD Wei Liu
2017-04-14 10:20 ` Wei Liu [this message]
2017-04-18 10:14 ` [PATCH for-4.9 1/2] oxenstored: add an Unix syscall C extension Ian Jackson
2017-04-14 10:20 ` [PATCH for-4.9 2/2] oxenstored: make it work on FreeBSD Wei Liu
2017-04-14 10:32 ` [PATCH for-4.9] oxenstored: remove "_proc" in names Wei Liu
2017-04-18 10:15 ` Ian Jackson
2017-04-18 10:16 ` [PATCH for-4.9 2/2] oxenstored: make it work on FreeBSD Ian Jackson
2017-04-18 10:22 ` Christian Lindig
2017-04-18 9:46 ` [PATCH for-4.9 0/2] " Christian Lindig
2017-04-18 9:59 ` Wei Liu
2017-04-18 10:11 ` Christian Lindig
2017-04-18 13:07 ` Wei Liu
2017-04-18 10:11 ` Christian Lindig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170414102018.14853-2-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=christian.lindig@citrix.com \
--cc=dave@recoil.org \
--cc=ian.jackson@eu.citrix.com \
--cc=jonathan.ludlam@citrix.com \
--cc=roger.pau@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).