From 7d468e4a0c675d03ac54e9edcb20cbdb50351ca7 Mon Sep 17 00:00:00 2001 From: thorpej Date: Tue, 10 Sep 1996 22:17:51 +0000 Subject: [PATCH] Iff __m68k__, use a `slight hack' to determine the magic of the executable we're doing a dynamic link for, and change the page size used for offset and size calculations if necessary. Allows the same ld.so to be used with mixed m68k4k and m68k8k executables and libraries. Thanks a million to Gordon Ross for the help in making this work! --- gnu/usr.bin/ld/rtld/rtld.c | 54 +++++++++++++++++++++++++++++++++++--- libexec/ld.aout_so/rtld.c | 54 +++++++++++++++++++++++++++++++++++--- 2 files changed, 100 insertions(+), 8 deletions(-) diff --git a/gnu/usr.bin/ld/rtld/rtld.c b/gnu/usr.bin/ld/rtld/rtld.c index 750c41b638c5..adc5d597dec4 100644 --- a/gnu/usr.bin/ld/rtld/rtld.c +++ b/gnu/usr.bin/ld/rtld/rtld.c @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.c,v 1.43 1996/01/14 00:35:17 pk Exp $ */ +/* $NetBSD: rtld.c,v 1.44 1996/09/10 22:17:51 thorpej Exp $ */ /* * Copyright (c) 1993 Paul Kranenburg * All rights reserved. @@ -58,6 +58,16 @@ #include "ld.h" +#ifdef __m68k__ +/* + * This is a slight hack to allow the same loader to be used on + * 4k and 8k __LDPGSZ executables. + */ +static int page_size = 0x2000; +#undef PAGSIZ +#define PAGSIZ page_size +#endif /* __m68k__ */ + #ifndef MAP_ANON #define MAP_ANON 0 #define anon_open() do { \ @@ -252,6 +262,8 @@ rtld(version, crtp, dp) md_relocate_simple(reloc, crtp->crt_ba, addr); } + /* Now (and NOT BEFORE this point) we can call externals. */ + if (version >= CRT_VERSION_BSD_4) __progname = crtp->crt_ldso; @@ -261,17 +273,51 @@ rtld(version, crtp, dp) /* Setup out (private) environ variable */ environ = crtp->crt_ep; - /* Get user and group identifiers */ + /* + * Make sure we do not allow the library search path + * to be modified through the environment if we are + * running either setuid or setgid. + */ uid = getuid(); euid = geteuid(); gid = getgid(); egid = getegid(); - careful = (uid != euid) || (gid != egid); - if (careful) { unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); } +#ifdef __m68k__ + /* + * Locate the a.out header and check the machine ID. + * If we see MID_M68K4K, we alter the page size we + * use for address calculations. This allows the + * same loader to be used for 4k and 8k executables + * and libraries. Trust me; the world is a better + * place because this. + */ + { + register long textaddr; + register struct exec *eh; + + /* XXX Assume this is near the start of text. */ + textaddr = ((long)crtp->crt_bp) & ~0xFFF; + eh = (struct exec *) textaddr; +#if 0 + xprintf("%s: textaddr is 0x%x\n", us, textaddr); + xprintf("\t magic=0x%x\n", eh->a_midmag); +#endif + /* + * Use this rather than N_PAGSIZ(), to be + * safe... + */ + if (N_GETMID((*eh)) == MID_M68K4K) + page_size = 0x1000; +#if 0 + xprintf("\t page_size=%d\n", page_size); +#endif + } +#endif /* __m68k__ */ + /* Setup directory search */ ld_library_path = getenv("LD_LIBRARY_PATH"); add_search_path(ld_library_path); diff --git a/libexec/ld.aout_so/rtld.c b/libexec/ld.aout_so/rtld.c index 750c41b638c5..adc5d597dec4 100644 --- a/libexec/ld.aout_so/rtld.c +++ b/libexec/ld.aout_so/rtld.c @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.c,v 1.43 1996/01/14 00:35:17 pk Exp $ */ +/* $NetBSD: rtld.c,v 1.44 1996/09/10 22:17:51 thorpej Exp $ */ /* * Copyright (c) 1993 Paul Kranenburg * All rights reserved. @@ -58,6 +58,16 @@ #include "ld.h" +#ifdef __m68k__ +/* + * This is a slight hack to allow the same loader to be used on + * 4k and 8k __LDPGSZ executables. + */ +static int page_size = 0x2000; +#undef PAGSIZ +#define PAGSIZ page_size +#endif /* __m68k__ */ + #ifndef MAP_ANON #define MAP_ANON 0 #define anon_open() do { \ @@ -252,6 +262,8 @@ rtld(version, crtp, dp) md_relocate_simple(reloc, crtp->crt_ba, addr); } + /* Now (and NOT BEFORE this point) we can call externals. */ + if (version >= CRT_VERSION_BSD_4) __progname = crtp->crt_ldso; @@ -261,17 +273,51 @@ rtld(version, crtp, dp) /* Setup out (private) environ variable */ environ = crtp->crt_ep; - /* Get user and group identifiers */ + /* + * Make sure we do not allow the library search path + * to be modified through the environment if we are + * running either setuid or setgid. + */ uid = getuid(); euid = geteuid(); gid = getgid(); egid = getegid(); - careful = (uid != euid) || (gid != egid); - if (careful) { unsetenv("LD_LIBRARY_PATH"); unsetenv("LD_PRELOAD"); } +#ifdef __m68k__ + /* + * Locate the a.out header and check the machine ID. + * If we see MID_M68K4K, we alter the page size we + * use for address calculations. This allows the + * same loader to be used for 4k and 8k executables + * and libraries. Trust me; the world is a better + * place because this. + */ + { + register long textaddr; + register struct exec *eh; + + /* XXX Assume this is near the start of text. */ + textaddr = ((long)crtp->crt_bp) & ~0xFFF; + eh = (struct exec *) textaddr; +#if 0 + xprintf("%s: textaddr is 0x%x\n", us, textaddr); + xprintf("\t magic=0x%x\n", eh->a_midmag); +#endif + /* + * Use this rather than N_PAGSIZ(), to be + * safe... + */ + if (N_GETMID((*eh)) == MID_M68K4K) + page_size = 0x1000; +#if 0 + xprintf("\t page_size=%d\n", page_size); +#endif + } +#endif /* __m68k__ */ + /* Setup directory search */ ld_library_path = getenv("LD_LIBRARY_PATH"); add_search_path(ld_library_path);