From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id 15FF73857C74 for ; Tue, 8 Jun 2021 05:09:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 15FF73857C74 Received: from vapier.lan (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 5E3F2340BDD for ; Tue, 8 Jun 2021 05:09:52 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH] sim: start unifying portability shims Date: Tue, 8 Jun 2021 01:09:51 -0400 Message-Id: <20210608050951.23870-1-vapier@gentoo.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Jun 2021 05:10:08 -0000 There are some functions that gnulib does not yet provide fallbacks for, so start a common file of our own for holding existing stubs. --- sim/bfin/configure.ac | 2 +- sim/bfin/interp.c | 20 +----------- sim/common/Make-common.in | 2 +- sim/common/portability.c | 67 +++++++++++++++++++++++++++++++++++++++ sim/common/portability.h | 47 +++++++++++++++++++++++++++ sim/cris/traps.c | 1 + sim/m32r/traps-linux.c | 1 + sim/m4/sim_ac_common.m4 | 6 ++++ 8 files changed, 125 insertions(+), 21 deletions(-) create mode 100644 sim/common/portability.c create mode 100644 sim/common/portability.h diff --git a/sim/bfin/configure.ac b/sim/bfin/configure.ac index 8fef4d47d00c..e052df4d8b38 100644 --- a/sim/bfin/configure.ac +++ b/sim/bfin/configure.ac @@ -42,7 +42,7 @@ SIM_AC_OPTION_HARDWARE(\ eth_phy \ ) -AC_CHECK_FUNCS_ONCE([getuid getgid geteuid getegid setuid setgid kill pread]) +AC_CHECK_FUNCS_ONCE([kill pread]) AC_CHECK_HEADERS_ONCE(m4_flatten([ linux/if_tun.h linux/mii.h diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c index 34357201934c..80e543ed53fc 100644 --- a/sim/bfin/interp.c +++ b/sim/bfin/interp.c @@ -30,6 +30,7 @@ #include #include +#include "portability.h" #include "sim/callback.h" #include "gdb/signals.h" #include "sim-main.h" @@ -74,25 +75,6 @@ #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:" diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in index f32026e179d3..4b2587985379 100644 --- a/sim/common/Make-common.in +++ b/sim/common/Make-common.in @@ -258,7 +258,7 @@ EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBINTL) $(LIBIBERTY_LIB) \ COMMON_OBJS = ../common/version.o -LIB_OBJS = callback.o modules.o syscall.o targ-map.o $(COMMON_OBJS) $(SIM_OBJS) +LIB_OBJS = callback.o modules.o portability.o syscall.o targ-map.o $(COMMON_OBJS) $(SIM_OBJS) COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) LINK_FOR_BUILD = $(CC_FOR_BUILD) $(BUILD_CFLAGS) $(LDFLAGS_FOR_BUILD) -o $@ diff --git a/sim/common/portability.c b/sim/common/portability.c new file mode 100644 index 000000000000..f0ccc46d37eb --- /dev/null +++ b/sim/common/portability.c @@ -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 . */ + +/* This must come before any other includes. */ +#include "defs.h" + +#include + +#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 index 000000000000..12971f6a1075 --- /dev/null +++ b/sim/common/portability.h @@ -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 . */ + +#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 diff --git a/sim/cris/traps.c b/sim/cris/traps.c index 99344a283df9..a55f7dfb9927 100644 --- a/sim/cris/traps.c +++ b/sim/cris/traps.c @@ -20,6 +20,7 @@ along with this program. If not, see . */ /* 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" diff --git a/sim/m32r/traps-linux.c b/sim/m32r/traps-linux.c index 63ed13788a51..1e3a08497e90 100644 --- a/sim/m32r/traps-linux.c +++ b/sim/m32r/traps-linux.c @@ -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" diff --git a/sim/m4/sim_ac_common.m4 b/sim/m4/sim_ac_common.m4 index aa10a6502722..80198f853264 100644 --- a/sim/m4/sim_ac_common.m4 +++ b/sim/m4/sim_ac_common.m4 @@ -54,11 +54,17 @@ AC_CHECK_HEADERS_ONCE(m4_flatten([ AC_CHECK_FUNCS_ONCE(m4_flatten([ __setfpucw ftruncate + getegid + geteuid + getgid getrusage + getuid lstat mmap munmap posix_fallocate + setgid + setuid sigaction strsignal time -- 2.31.1