[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT/LIBNEWLIB PATCH 1/1] Add stubs for CPython2



Hey,

This patch is is quite big and some of the functions are not properly classified. I'll break it into a series of smaller patches.


Vlad


From: Vlad-Andrei BĂDOIU (78692)
Sent: Thursday, May 2, 2019 6:25:36 PM
To: minios-devel@xxxxxxxxxxxxx
Cc: felipe.huici@xxxxxxxxx; florian.schmidt@xxxxxxxxx; Vlad-Andrei BĂDOIU (78692)
Subject: [UNIKRAFT/LIBNEWLIB PATCH 1/1] Add stubs for CPython2
 
This patch adds the missing stubs needed by CPython2.
The sysexits.h and utsname.h are added. The dev.c file
is added for the stubs related to the devices.

Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
---
 Makefile.uk           |   1 +
 console.c             |  27 +++++-
 dev.c                 |  56 ++++++++++++
 file.c                |  27 ++++++
 include/sys/utsname.h |  23 +++++
 include/sysexits.h    | 114 +++++++++++++++++++++++
 process.c             | 206 ++++++++++++++++++++++++++++++++++++++++++
 pty.c                 |   8 ++
 resource.c            |  27 ++++++
 time.c                |   5 +
 10 files changed, 492 insertions(+), 2 deletions(-)
 create mode 100644 dev.c
 create mode 100644 include/sys/utsname.h
 create mode 100644 include/sysexits.h

diff --git a/Makefile.uk b/Makefile.uk
index 82e4e6e..9343796 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -113,6 +113,7 @@ LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/resource.c
 LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/pty.c
 LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/time.c|glue
 LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/locale.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/dev.c
 
 ################################################################################
 # Newlib/libc code -- argz
diff --git a/console.c b/console.c
index 4fd33cd..b93a126 100644
--- a/console.c
+++ b/console.c
@@ -37,7 +37,30 @@
 
 #include <uk/essentials.h>
 
-int isatty(int file __unused)
+#include <errno.h>
+#include <sys/stat.h>
+
+int isatty(int fd)
+{
+       struct stat buf;
+
+       if (fstat (fd, &buf) < 0) {
+               errno = EBADF;
+               return 0;
+       }
+       if (S_ISCHR (buf.st_mode))
+               return 1;
+
+       errno = ENOTTY;
+       return 0;
+}
+
+char *ttyname(int fd __unused)
+{
+       return 0;
+}
+
+char *ctermid(char *s __unused)
 {
-       return 1;
+       return 0;
 }
diff --git a/dev.c b/dev.c
new file mode 100644
index 0000000..e0e2650
--- /dev/null
+++ b/dev.c
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx
+ *
+ * Copyright (c) 2019, University Politehnica of Bucharest. 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.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#include <sys/types.h>
+
+unsigned int major(dev_t dev __unused)
+{
+        return 0;
+}
+
+unsigned int minor(dev_t dev __unused)
+{
+        return 0;
+}
+
+dev_t makedev(unsigned int maj __unused, unsigned int min __unused)
+{
+        return 0;
+}
+
+long fpathconf(int fd __unused, int name __unused)
+{
+        return 0;
+}
+
diff --git a/file.c b/file.c
index 02f1b6f..5704956 100644
--- a/file.c
+++ b/file.c
@@ -38,6 +38,8 @@
 #include <uk/plat/console.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <stdio.h>
+
 #undef errno
 extern int errno;
 
@@ -66,3 +68,28 @@ int munmap(void *addr __unused, size_t len __unused)
 {
         return 0;
 }
+
+int fchown(int fd __unused, uid_t owner __unused, gid_t group __unused)
+{
+        return 0;
+}
+
+int lchown(const char *pathname __unused, uid_t owner __unused, gid_t group __unused)
+{
+        return 0;
+}
+
+FILE *popen(const char *command __unused, const char *type __unused)
+{
+       return NULL;
+}
+
+int pclose(FILE *stream __unused)
+{
+       return 0;
+}
+
+int utimes(const char *filename __unused, const struct timeval times[2] __unused)
+{
+       return 0;
+}
diff --git a/include/sys/utsname.h b/include/sys/utsname.h
new file mode 100644
index 0000000..4de4c63
--- /dev/null
+++ b/include/sys/utsname.h
@@ -0,0 +1,23 @@
+/* libc/sys/linux/sys/utsname.h - System identification */
+
+/* Written 2000 by Werner Almesberger */
+
+
+#ifndef _SYS_UTSNAME_H
+#define _SYS_UTSNAME_H
+
+#define __UTSNAMELEN 65        /* synchronize with kernel */
+
+struct utsname {
+    char sysname[__UTSNAMELEN];
+    char nodename[__UTSNAMELEN];
+    char release[__UTSNAMELEN];
+    char version[__UTSNAMELEN];
+    char machine[__UTSNAMELEN];
+    char domainname[__UTSNAMELEN];
+};
+
+
+int uname(struct utsname *name);
+
+#endif
diff --git a/include/sysexits.h b/include/sysexits.h
new file mode 100644
index 0000000..37246b6
--- /dev/null
+++ b/include/sysexits.h
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 1987, 1993
+ *     The Regents of the University of California.  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.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ *
+ *     @(#)sysexits.h  8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef        _SYSEXITS_H
+#define        _SYSEXITS_H 1
+
+/*
+ *  SYSEXITS.H -- Exit status codes for system programs.
+ *
+ *     This include file attempts to categorize possible error
+ *     exit statuses for system programs, notably delivermail
+ *     and the Berkeley network.
+ *
+ *     Error numbers begin at EX__BASE to reduce the possibility of
+ *     clashing with other exit statuses that random programs may
+ *     already return.  The meaning of the codes is approximately
+ *     as follows:
+ *
+ *     EX_USAGE -- The command was used incorrectly, e.g., with
+ *             the wrong number of arguments, a bad flag, a bad
+ *             syntax in a parameter, or whatever.
+ *     EX_DATAERR -- The input data was incorrect in some way.
+ *             This should only be used for user's data & not
+ *             system files.
+ *     EX_NOINPUT -- An input file (not a system file) did not
+ *             exist or was not readable.  This could also include
+ *             errors like "No message" to a mailer (if it cared
+ *             to catch it).
+ *     EX_NOUSER -- The user specified did not exist.  This might
+ *             be used for mail addresses or remote logins.
+ *     EX_NOHOST -- The host specified did not exist.  This is used
+ *             in mail addresses or network requests.
+ *     EX_UNAVAILABLE -- A service is unavailable.  This can occur
+ *             if a support program or file does not exist.  This
+ *             can also be used as a catchall message when something
+ *             you wanted to do doesn't work, but you don't know
+ *             why.
+ *     EX_SOFTWARE -- An internal software error has been detected.
+ *             This should be limited to non-operating system related
+ *             errors as possible.
+ *     EX_OSERR -- An operating system error has been detected.
+ *             This is intended to be used for such things as "cannot
+ *             fork", "cannot create pipe", or the like.  It includes
+ *             things like getuid returning a user that does not
+ *             exist in the passwd file.
+ *     EX_OSFILE -- Some system file (e.g., /etc/passwd, /etc/utmp,
+ *             etc.) does not exist, cannot be opened, or has some
+ *             sort of error (e.g., syntax error).
+ *     EX_CANTCREAT -- A (user specified) output file cannot be
+ *             created.
+ *     EX_IOERR -- An error occurred while doing I/O on some file.
+ *     EX_TEMPFAIL -- temporary failure, indicating something that
+ *             is not really an error.  In sendmail, this means
+ *             that a mailer (e.g.) could not create a connection,
+ *             and the request should be reattempted later.
+ *     EX_PROTOCOL -- the remote system returned something that
+ *             was "not possible" during a protocol exchange.
+ *     EX_NOPERM -- You did not have sufficient permission to
+ *             perform the operation.  This is not intended for
+ *             file system problems, which should use NOINPUT or
+ *             CANTCREAT, but rather for higher level permissions.
+ */
+
+#define EX_OK          0       /* successful termination */
+
+#define EX__BASE       64      /* base value for error messages */
+
+#define EX_USAGE       64      /* command line usage error */
+#define EX_DATAERR     65      /* data format error */
+#define EX_NOINPUT     66      /* cannot open input */
+#define EX_NOUSER      67      /* addressee unknown */
+#define EX_NOHOST      68      /* host name unknown */
+#define EX_UNAVAILABLE 69      /* service unavailable */
+#define EX_SOFTWARE    70      /* internal software error */
+#define EX_OSERR       71      /* system error (e.g., can't fork) */
+#define EX_OSFILE      72      /* critical OS file missing */
+#define EX_CANTCREAT   73      /* can't create (user) output file */
+#define EX_IOERR       74      /* input/output error */
+#define EX_TEMPFAIL    75      /* temp failure; user is invited to retry */
+#define EX_PROTOCOL    76      /* remote error in protocol */
+#define EX_NOPERM      77      /* permission denied */
+#define EX_CONFIG      78      /* configuration error */
+
+#define EX__MAX        78      /* maximum listed value */
+
+#endif /* sysexits.h */
diff --git a/process.c b/process.c
index 096a12b..84c6030 100644
--- a/process.c
+++ b/process.c
@@ -37,6 +37,9 @@
 
 #include <time.h>
 #include <errno.h>
+#include <sys/resource.h>
+#include <pwd.h>
+#include <stdlib.h>
 #undef errno
 extern int errno;
 
@@ -73,3 +76,206 @@ int wait(int *status __unused)
         errno = ECHILD;
         return -1;
 }
+
+gid_t getegid(void)
+{
+        return 0;
+}
+
+uid_t geteuid(void)
+{
+        return 0;
+}
+
+gid_t getgid(void)
+{
+        return 0;
+}
+
+int getgroups(int size __unused, gid_t list[] __unused)
+{
+        return 0;
+}
+
+int initgroups(const char *user __unused, gid_t group __unused)
+{
+        return 0;
+}
+
+pid_t getpgid(pid_t pid __unused)
+{
+        return 0;
+}
+
+int setpgrp(void)
+{
+        return 0;
+}
+
+char *getlogin(void)
+{
+        return 0;
+}
+
+uid_t getuid(void)
+{
+        return 0;
+}
+
+int killpg(int pgrp __unused, int sig __unused)
+{
+        return 0;
+}
+
+int setuid(uid_t uid __unused)
+{
+        return 0;
+}
+
+int seteuid(uid_t euid __unused)
+{
+        return 0;
+}
+
+int setegid(gid_t egid __unused)
+{
+        return 0;
+}
+
+pid_t getppid(void)
+{
+        return 0;
+}
+
+int setgid(gid_t gid __unused)
+{
+        return 0;
+}
+
+pid_t wait3(int *wstatus __unused, int options __unused, struct rusage *rusage __unused)
+{
+        return 0;
+}
+
+pid_t wait4(pid_t pid __unused, int *wstatus __unused, int options __unused, struct rusage *rusage __unused)
+{
+        return 0;
+}
+
+pid_t waitpid(pid_t pid __unused, int *wstatus __unused, int options __unused)
+{
+        return 0;
+}
+
+pid_t getsid(pid_t pid __unused)
+{
+        return 0;
+}
+
+pid_t setsid(void)
+{
+        return 0;
+}
+
+int setreuid(uid_t ruid __unused, uid_t euid __unused)
+{
+        return 0;
+}
+
+int setregid(gid_t rgid __unused, gid_t egid __unused)
+{
+        return 0;
+}
+
+int setpgid(pid_t pid __unused, pid_t pgid __unused)
+{
+        return 0;
+}
+
+int setresuid(uid_t ruid __unused, uid_t euid __unused, uid_t suid __unused)
+{
+        return 0;
+}
+
+int getresuid(uid_t *ruid __unused, uid_t *euid __unused, uid_t *suid __unused)
+{
+        return 0;
+}
+
+int getresgid(gid_t *rgid __unused, gid_t *egid __unused, gid_t *sgid __unused)
+{
+        return 0;
+}
+
+int tcsetpgrp(int fd __unused, pid_t pgrp __unused)
+{
+        return 0;
+}
+
+pid_t tcgetpgrp(int fd __unused)
+{
+        return 0;
+}
+
+int pipe(int pipefd[2] __unused)
+{
+        return 0;
+}
+
+int setgroups(size_t size __unused, const gid_t *list __unused)
+{
+        return 0;
+}
+
+int sigaction(int sig __unused, const struct sigaction *restrict act __unused,
+             struct sigaction *restrict oact __unused)
+{
+        return 0;
+}
+
+unsigned int alarm(unsigned int seconds __unused)
+{
+        return 0;
+}
+
+int pause(void)
+{
+        return 0;
+}
+
+int siginterrupt(int sig __unused, int flag __unused)
+{
+        return 0;
+}
+
+struct passwd *getpwnam(const char *name __unused)
+{
+        return NULL;
+}
+
+int execv(const char *path __unused, char *const argv[] __unused)
+{
+        return 0;
+}
+
+int system(const char *command __unused)
+{
+        return 0;
+}
+
+struct passwd *getpwuid(uid_t uid __unused)
+{
+        struct passwd *p = malloc(sizeof(struct passwd));
+        p->pw_name = malloc(sizeof(char) * 10);
+        p->pw_passwd = malloc(sizeof(char) * 10);
+        p->pw_comment = malloc(sizeof(char) * 10);
+        p->pw_gecos = malloc(sizeof(char) * 10);
+        p->pw_dir = malloc(sizeof(char) * 10);
+        p->pw_shell = malloc(sizeof(char) * 10);
+        return p;
+}
+
+int sigemptyset(sigset_t *set)
+{
+       return 0;
+}
diff --git a/pty.c b/pty.c
index 46b554a..f33fb09 100644
--- a/pty.c
+++ b/pty.c
@@ -37,6 +37,7 @@
 
 #include <pty.h>
 #include <uk/essentials.h>
+#include <sys/types.h>
 
 int openpty(int *amaster __unused, int *aslave __unused, char *name __unused,
                 const struct termios *termp __unused,
@@ -44,3 +45,10 @@ int openpty(int *amaster __unused, int *aslave __unused, char *name __unused,
 {
         return 0;
 }
+
+pid_t forkpty(int *amaster __unused, char *name __unused,
+             const struct termios *termp __unused,
+            const struct winsize *winp __unused)
+{
+        return 0;
+}
diff --git a/resource.c b/resource.c
index 321854f..81ff928 100644
--- a/resource.c
+++ b/resource.c
@@ -36,6 +36,8 @@
  */
 
 #include <sys/resource.h>
+#include <sys/utsname.h>
+#include <limits.h>
 
 int getrlimit(int resource __unused, struct rlimit *rlim __unused)
 {
@@ -51,3 +53,28 @@ long sysconf(int name __unused)
 {
         return 0;
 }
+
+int getpagesize(void)
+{
+        return __PAGE_SIZE;
+}
+
+int getrusage(int who __unused, struct rusage *usage __unused)
+{
+        return 0;
+}
+
+int nice(int inc __unused)
+{
+        return 0;
+}
+
+int uname(struct utsname *buf __unused)
+{
+        return 0;
+}
+
+size_t confstr(int name __unused, char *buf __unused, size_t len __unused)
+{
+        return 0;
+}
diff --git a/time.c b/time.c
index dccf8a1..c1962be 100644
--- a/time.c
+++ b/time.c
@@ -150,3 +150,8 @@ int clock_gettime(clockid_t clk_id __unused, struct timespec *tp __unused)
         tp->tv_nsec = ukarch_time_subsec(now);
         return 0;
 }
+
+int usleep(useconds_t usec __unused)
+{
+        return 0;
+}
--
2.21.0

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.