sim: start unifying portability shims
authorMike Frysinger <vapier@gentoo.org>
Sat, 29 May 2021 20:07:43 +0000 (16:07 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sun, 13 Jun 2021 03:51:35 +0000 (23:51 -0400)
There are some functions that gnulib does not yet provide fallbacks
for, so start a common file of our own for holding existing stubs.

12 files changed:
sim/Makefile.in
sim/bfin/ChangeLog
sim/bfin/interp.c
sim/common/ChangeLog
sim/common/Make-common.in
sim/common/local.mk
sim/common/portability.c [new file with mode: 0644]
sim/common/portability.h [new file with mode: 0644]
sim/cris/ChangeLog
sim/cris/traps.c
sim/m32r/ChangeLog
sim/m32r/traps-linux.c

index dbfde78da597bb26ff9da4c2a68e88d2bb909e80..c710449d718c0ece7d9efa7054ba1a6e79ba5552 100644 (file)
@@ -228,6 +228,7 @@ common_libcommon_a_AR = $(AR) $(ARFLAGS)
 common_libcommon_a_LIBADD =
 am__dirstamp = $(am__leading_dot)dirstamp
 am_common_libcommon_a_OBJECTS =  \
+       common/common_libcommon_a-portability.$(OBJEXT) \
        common/common_libcommon_a-sim-load.$(OBJEXT) \
        common/common_libcommon_a-version.$(OBJEXT)
 common_libcommon_a_OBJECTS = $(am_common_libcommon_a_OBJECTS)
@@ -756,6 +757,7 @@ common_libcommon_a_CPPFLAGS = \
        -I..
 
 common_libcommon_a_SOURCES = \
+       common/portability.c \
        common/sim-load.c \
        common/version.c
 
@@ -871,6 +873,8 @@ common/$(am__dirstamp):
 common/$(DEPDIR)/$(am__dirstamp):
        @$(MKDIR_P) common/$(DEPDIR)
        @: > common/$(DEPDIR)/$(am__dirstamp)
+common/common_libcommon_a-portability.$(OBJEXT):  \
+       common/$(am__dirstamp) common/$(DEPDIR)/$(am__dirstamp)
 common/common_libcommon_a-sim-load.$(OBJEXT): common/$(am__dirstamp) \
        common/$(DEPDIR)/$(am__dirstamp)
 common/common_libcommon_a-version.$(OBJEXT): common/$(am__dirstamp) \
@@ -987,6 +991,7 @@ mostlyclean-compile:
 distclean-compile:
        -rm -f *.tab.c
 
+@AMDEP_TRUE@@am__include@ @am__quote@common/$(DEPDIR)/common_libcommon_a-portability.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@common/$(DEPDIR)/common_libcommon_a-sim-load.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@common/$(DEPDIR)/common_libcommon_a-version.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@igen/$(DEPDIR)/filter.Po@am__quote@
@@ -1030,6 +1035,20 @@ distclean-compile:
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
 
+common/common_libcommon_a-portability.o: common/portability.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(common_libcommon_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT common/common_libcommon_a-portability.o -MD -MP -MF common/$(DEPDIR)/common_libcommon_a-portability.Tpo -c -o common/common_libcommon_a-portability.o `test -f 'common/portability.c' || echo '$(srcdir)/'`common/portability.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) common/$(DEPDIR)/common_libcommon_a-portability.Tpo common/$(DEPDIR)/common_libcommon_a-portability.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='common/portability.c' object='common/common_libcommon_a-portability.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(common_libcommon_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o common/common_libcommon_a-portability.o `test -f 'common/portability.c' || echo '$(srcdir)/'`common/portability.c
+
+common/common_libcommon_a-portability.obj: common/portability.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(common_libcommon_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT common/common_libcommon_a-portability.obj -MD -MP -MF common/$(DEPDIR)/common_libcommon_a-portability.Tpo -c -o common/common_libcommon_a-portability.obj `if test -f 'common/portability.c'; then $(CYGPATH_W) 'common/portability.c'; else $(CYGPATH_W) '$(srcdir)/common/portability.c'; fi`
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) common/$(DEPDIR)/common_libcommon_a-portability.Tpo common/$(DEPDIR)/common_libcommon_a-portability.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='common/portability.c' object='common/common_libcommon_a-portability.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(common_libcommon_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o common/common_libcommon_a-portability.obj `if test -f 'common/portability.c'; then $(CYGPATH_W) 'common/portability.c'; else $(CYGPATH_W) '$(srcdir)/common/portability.c'; fi`
+
 common/common_libcommon_a-sim-load.o: common/sim-load.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(common_libcommon_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT common/common_libcommon_a-sim-load.o -MD -MP -MF common/$(DEPDIR)/common_libcommon_a-sim-load.Tpo -c -o common/common_libcommon_a-sim-load.o `test -f 'common/sim-load.c' || echo '$(srcdir)/'`common/sim-load.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) common/$(DEPDIR)/common_libcommon_a-sim-load.Tpo common/$(DEPDIR)/common_libcommon_a-sim-load.Po
index 52ba04fc65175673196916c9fc1ea9f6ca626779..9a8777de776e3434e05b1fc0f5bfabd51c635e89 100644 (file)
@@ -1,3 +1,8 @@
+2021-06-12  Mike Frysinger  <vapier@gentoo.org>
+
+       * interp.c: Include portability.h.
+       (getuid, getgid, geteuid, getegid setuid, setgid): Delete.
+
 2021-06-12  Mike Frysinger  <vapier@gentoo.org>
 
        * configure.ac: Delete call to SIM_AC_OPTION_ALIGNMENT.
index 2e9696f8bfe14f16680df227c7ae4fc937fb8fc8..10de001d7ce75630d78cf8592c3eab47b729a331 100644 (file)
@@ -30,6 +30,7 @@
 #include <unistd.h>
 #include <sys/time.h>
 
+#include "portability.h"
 #include "sim/callback.h"
 #include "gdb/signals.h"
 #include "sim-main.h"
 #include "dv-bfin_cec.h"
 #include "dv-bfin_mmu.h"
 
-#ifndef HAVE_GETUID
-# define getuid() 0
-#endif
-#ifndef HAVE_GETGID
-# define getgid() 0
-#endif
-#ifndef HAVE_GETEUID
-# define geteuid() 0
-#endif
-#ifndef HAVE_GETEGID
-# define getegid() 0
-#endif
-#ifndef HAVE_SETUID
-# define setuid(uid) -1
-#endif
-#ifndef HAVE_SETGID
-# define setgid(gid) -1
-#endif
-
 static const char cb_linux_stat_map_32[] =
 /* Linux kernel 32bit layout:  */
 "st_dev,2:space,2:st_ino,4:st_mode,2:st_nlink,2:st_uid,2:st_gid,2:st_rdev,2:"
index 5d713c63bf4ff29f1c03b8c4debdf986e1462288..8f44658c7d3f20fa5c0ce55ac7245085f3d1b15b 100644 (file)
@@ -1,3 +1,9 @@
+2021-06-12  Mike Frysinger  <vapier@gentoo.org>
+
+       * Make-common.in (COMMON_OBJS_NAMES): Add portability.o.
+       * local.mk (%C%_libcommon_a_SOURCES): Add %D%/portability.c.
+       * portability.c, portability.h: New files.
+
 2021-06-12  Mike Frysinger  <vapier@gentoo.org>
 
        * Make-common.in (SIM_NEW_COMMON_OBJS): Move sim-load.o to ...
index 8454d165830f0e7b5d4174228d81e764c882789c..7a5bbc1a985c3a78c03d6202f85e52feaeb11e27 100644 (file)
@@ -254,6 +254,7 @@ EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL) $(LIBIBERTY_LIB) \
        $(CONFIG_LIBS) $(SIM_EXTRA_LIBS) $(LIBDL) $(LIBGNU) $(LIBGNU_EXTRA_LIBS)
 
 COMMON_OBJS_NAMES = \
+       portability.o \
        sim-load.o \
        version.o
 COMMON_OBJS = $(COMMON_OBJS_NAMES:%=../common/common_libcommon_a-%)
index a340febfcdd1973c74a0ae4a6b017ac089d5e61a..076335d0b42703d29b008055e9000d4af8870530 100644 (file)
@@ -34,6 +34,7 @@ noinst_LIBRARIES += %D%/libcommon.a
        -I../bfd \
        -I..
 %C%_libcommon_a_SOURCES = \
+       %D%/portability.c \
        %D%/sim-load.c \
        %D%/version.c
 
diff --git a/sim/common/portability.c b/sim/common/portability.c
new file mode 100644 (file)
index 0000000..f0ccc46
--- /dev/null
@@ -0,0 +1,67 @@
+/* Portability shims for missing OS support.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   Contributed by Mike Frysinger.
+
+This file is part of the GNU Simulators.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* This must come before any other includes.  */
+#include "defs.h"
+
+#include <unistd.h>
+
+#include "portability.h"
+
+#ifndef HAVE_GETEGID
+int getegid(void)
+{
+  return 0;
+}
+#endif
+
+#ifndef HAVE_GETEUID
+int geteuid(void)
+{
+  return 0;
+}
+#endif
+
+#ifndef HAVE_GETGID
+int getgid(void)
+{
+  return 0;
+}
+#endif
+
+#ifndef HAVE_GETUID
+int getuid(void)
+{
+  return 0;
+}
+#endif
+
+#ifndef HAVE_SETGID
+int setgid(int gid)
+{
+  return -1;
+}
+#endif
+
+#ifndef HAVE_SETUID
+int setuid(int uid)
+{
+  return -1;
+}
+#endif
diff --git a/sim/common/portability.h b/sim/common/portability.h
new file mode 100644 (file)
index 0000000..12971f6
--- /dev/null
@@ -0,0 +1,47 @@
+/* Portability shims for missing OS support.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   Contributed by Mike Frysinger.
+
+This file is part of the GNU Simulators.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef PORTABILITY_H
+#define PORTABILITY_H
+
+#ifndef HAVE_GETEGID
+int getegid(void);
+#endif
+
+#ifndef HAVE_GETEUID
+int geteuid(void);
+#endif
+
+#ifndef HAVE_GETGID
+int getgid(void);
+#endif
+
+#ifndef HAVE_GETUID
+int getuid(void);
+#endif
+
+#ifndef HAVE_SETGID
+int setgid(int gid);
+#endif
+
+#ifndef HAVE_SETUID
+int setuid(int uid);
+#endif
+
+#endif
index 2f4be8d947812a0674104a27d36bea5f19bdba3d..4cbd80816e2d1b5c0b2344450ea1e16fe8dde88e 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-12  Mike Frysinger  <vapier@gentoo.org>
+
+       * traps.c: Include portability.h.
+
 2021-06-12  Mike Frysinger  <vapier@gentoo.org>
 
        * dv-rv.c: Delete HAVE_SYS_SELECT_H.
index 99344a283df98020352ada80fc1ca5a8c72d38a3..a55f7dfb99274112a4ced09a58cceff58d4ab4c7 100644 (file)
@@ -20,6 +20,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 /* This must come before any other includes.  */
 #include "defs.h"
 
+#include "portability.h"
 #include "sim-main.h"
 #include "sim-syscall.h"
 #include "sim-options.h"
index 69795b334f676f6e9f1baf0582146b51b9606da7..1786c526e553c13cccc8e5017436ba6b2f4e72f5 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-12  Mike Frysinger  <vapier@gentoo.org>
+
+       * traps-linux.c: Include portability.h.
+
 2021-06-12  Mike Frysinger  <vapier@gentoo.org>
 
        * configure.ac: Delete call to SIM_AC_OPTION_ALIGNMENT.
index 63ed13788a51a3519bd9c773019276f522044bab..1e3a08497e90fc155895860d59bbb7b00373f66d 100644 (file)
@@ -20,6 +20,7 @@
 /* This must come before any other includes.  */
 #include "defs.h"
 
+#include "portability.h"
 #include "sim-main.h"
 #include "sim-syscall.h"
 #include "syscall.h"