]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/linuxu: Add fstat, open and close host system calls
authorAlexander Jung <a.jung@lancs.ac.uk>
Mon, 12 Apr 2021 10:39:59 +0000 (12:39 +0200)
committerUnikraft <monkey@unikraft.io>
Mon, 5 Jul 2021 04:47:27 +0000 (04:47 +0000)
 * Add system call number for arm_32 and x86_64 for the `fstat`
   system call;
 * Implement system call wrapper function for `open`, `close` and
   `fstat`;
 * Add `MAP_PRIVATE` constant for use with `mmap`.

Signed-off-by: Robert Hrusecky <roberth@cs.utexas.edu>
Signed-off-by: Omar Jamil <omarj2898@gmail.com>
Signed-off-by: Sachin Beldona <sachinbeldona@utexas.edu>
Signed-off-by: Gabriel Mocanu <gabi.mocanu98@gmail.com>
Signed-off-by: Alexander Jung <a.jung@lancs.ac.uk>
Reviewed-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Pull-Request: #179

plat/linuxu/include/linuxu/mode.h [new file with mode: 0644]
plat/linuxu/include/linuxu/setup.h
plat/linuxu/include/linuxu/stat.h [new file with mode: 0644]
plat/linuxu/include/linuxu/syscall-arm_32.h
plat/linuxu/include/linuxu/syscall-x86_64.h
plat/linuxu/include/linuxu/syscall.h

diff --git a/plat/linuxu/include/linuxu/mode.h b/plat/linuxu/include/linuxu/mode.h
new file mode 100644 (file)
index 0000000..3eed2d5
--- /dev/null
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Alexander Jung <a.jung@lancs.ac.uk>
+ *
+ * Copyright (c) 2021, Lancaster University. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __LINUXU_MODE_H__
+#define __LINUXU_MODE_H__
+
+typedef unsigned int k_mode_t;
+
+#define K_O_RDONLY 0x0000
+
+#endif /* __LINUXU_MODE_H__ */
index a4f23f37eb84ea1d486e701d954d4d57dc4dd93a..7ed6d7e637a6b14ea51a3208a069da2722c15078 100644 (file)
 
 #include <sys/types.h>
 
+struct liblinuxuplat_memregion {
+       void *base;
+       size_t len;
+};
+
 struct liblinuxuplat_opts {
+       struct liblinuxuplat_memregion heap;
+       struct liblinuxuplat_memregion initrd;
        struct {
                void *base;
                size_t len;
diff --git a/plat/linuxu/include/linuxu/stat.h b/plat/linuxu/include/linuxu/stat.h
new file mode 100644 (file)
index 0000000..2a1c37a
--- /dev/null
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Alexander Jung <a.jung@lancs.ac.uk>
+ *
+ * Copyright (c) 2021, Lancaster University. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __LINUXU_STAT_H__
+#define __LINUXU_STAT_H__
+
+#include <linuxu/time.h>
+#include <linuxu/mode.h>
+
+typedef __u64 k_dev_t;
+typedef __u64 k_ino_t;
+typedef __u32 k_nlink_t;
+typedef unsigned int k_uid_t;
+typedef unsigned int k_gid_t;
+typedef unsigned int k_id_t;
+typedef __off k_off_t;
+typedef long k_blksize_t;
+typedef __s64 k_blkcnt_t;
+
+
+struct k_stat {
+       k_dev_t st_dev;
+       k_ino_t st_ino;
+       k_nlink_t st_nlink;
+       k_mode_t st_mode;
+       k_uid_t st_uit;
+       k_gid_t st_gid;
+
+       unsigned int __pad0;
+
+       k_dev_t st_rdev;
+       k_off_t st_size;
+       k_blksize_t st_blksize;
+       k_blkcnt_t st_blocks;
+
+       struct k_timespec st_atim;
+       struct k_timespec st_mtim;
+       struct k_timespec st_ctim;
+};
+
+#endif /* __LINUXU_STAT_H__ */
index 399e167e8e8ced28cc582d31a8ce802b953928df..b3b27cc17f65e5c4d4a31739650f05932b52d43f 100644 (file)
@@ -44,6 +44,7 @@
 #define __SC_MUNMAP    91
 #define __SC_EXIT       1
 #define __SC_IOCTL     54
+#define __SC_FSTAT    108
 #define __SC_RT_SIGPROCMASK   126
 #define __SC_ARCH_PRCTL       172
 #define __SC_RT_SIGACTION     174
index 3e43b3f17f9f6ef233795ad765ef19c80f17e1b9..990eb109b31d5afdeace55a8c4d914b1ab30e8be 100644 (file)
@@ -40,6 +40,7 @@
 #define __SC_WRITE   1
 #define __SC_OPEN    2
 #define __SC_CLOSE   3
+#define __SC_FSTAT   5
 #define __SC_MMAP    9
 #define __SC_MUNMAP 11
 #define __SC_RT_SIGACTION   13
index 949c04253f01f0b8d97783785f060f3421ac7885..55a2103c6832e7595eeffbd8540a19e504c6b034 100644 (file)
@@ -35,6 +35,8 @@
 #define __SYSCALL_H__
 
 #include <linuxu/time.h>
+#include <linuxu/stat.h>
+#include <linuxu/mode.h>
 #include <sys/types.h>
 #include <linuxu/signal.h>
 
 #error "Unsupported architecture"
 #endif
 
+static inline int sys_open(const char *pathname, int flags, k_mode_t mode)
+{
+       return (int)syscall3(__SC_OPEN,
+                           (long) (pathname),
+                           (long) (flags),
+                           (long) (mode));
+}
+
+static inline int sys_close(int fd)
+{
+       return (int)syscall1(__SC_CLOSE,
+                            (long) (fd));
+}
+
 static inline ssize_t sys_read(int fd, const char *buf, size_t len)
 {
        return (ssize_t) syscall3(__SC_READ,
@@ -62,6 +78,14 @@ static inline ssize_t sys_write(int fd, const char *buf, size_t len)
                                  (long) (len));
 }
 
+struct stat;
+static inline int sys_fstat(int fd, struct k_stat *statbuf)
+{
+       return (int)syscall2(__SC_FSTAT,
+                            (long)(fd),
+                            (long)(statbuf));
+}
+
 static inline int sys_exit(int status)
 {
        return (int) syscall1(__SC_EXIT,
@@ -79,6 +103,7 @@ static inline int sys_clock_gettime(k_clockid_t clk_id, struct k_timespec *tp)
  * Please note that on failure sys_mmap() is returning -errno
  */
 #define MAP_SHARED    (0x01)
+#define MAP_PRIVATE   (0x02)
 #define MAP_ANONYMOUS (0x20)
 #define PROT_NONE     (0x0)
 #define PROT_READ     (0x1)