home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / LIBC / LIBC-4.6 / LIBC-4 / libc-linux / sysdeps / linux / __load.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-19  |  4.4 KB  |  143 lines

  1. /*
  2.  * Copyright (c) 1993 Eric Youngdale, Peter MacDonald, David Engel
  3.  * and Hongjiu Lu.
  4.  *
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. The name of the above contributors may not be
  13.  *    used to endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  *
  16.  * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
  17.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  20.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26.  * SUCH DAMAGE.
  27.  */
  28.  
  29. /* Notice of general intent:
  30.  *
  31.  * The linux operating system generally contains large amounts of code
  32.  * that fall under the GNU General Public License, or GPL for short.
  33.  * This file contains source code that by it's very nature would always
  34.  * be linked with an application program, and because of this a GPL type
  35.  * of copyright on this file would place restrictions upon the
  36.  * distribution of binary-only commercial software.  Since the goal of the
  37.  * Linux project as a whole is not to discourage the development and
  38.  * distribution of commercial software for Linux, this file has been placed
  39.  * under a more relaxed BSD-style of copyright.
  40.  *
  41.  * It is the general understanding of the above contributors that a
  42.  * program executable linked to a library containing code that falls
  43.  * under the GPL or GLPL style of license is not subject to the terms of
  44.  * the GPL or GLPL license if the program executable(s) that are supplied
  45.  * are linked to a shared library form of the GPL or GLPL library, and as long
  46.  * as the form of the shared library is such that it is possible for
  47.  * the end user to modify and rebuild the library and use it in
  48.  * conjunction with the program executable.
  49.  */
  50.  
  51. #include <unistd.h>
  52. #include <syscall.h>
  53. #include <stdarg.h>
  54. #include <sharedlib.h>
  55. #include <errno.h>
  56. #include <sys/mman.h>
  57. #include "config.h"
  58. #include "fixups.h"
  59.  
  60. static int errno = 0;
  61.  
  62. static
  63. _syscall1(int,exit,int,code)
  64.  
  65. static
  66. _syscall1(int,uselib,const char *,filename)
  67.  
  68. static
  69. _syscall3(ssize_t,write,int,fd,const void *,buf,size_t,count)
  70.  
  71. static
  72. _syscall2(int,munmap,caddr_t,addr,size_t,len)
  73.  
  74. extern struct libentry * __SHARED_LIBRARIES__[];
  75. extern struct fixuplist  _SHARABLE_CONFLICTS__;
  76.  
  77. #if 0
  78. /* This change seems not correct. H.J. */
  79.  
  80. #undef data_set_element
  81. #include <gnu-stabs.h>
  82.  
  83. static const char const __shared_dummy__ = 0;
  84.  
  85. /* Magic number used by DLL code to make sure this is a real list. */
  86. static unsigned int __shared_dummy1__ = 0xfeeb1ed3;
  87.  
  88. data_set_element (__SHARED_LIBRARIES__, __shared_dummy__);
  89. data_set_element (_SHARABLE_CONFLICTS__, __shared_dummy1__);
  90. #endif
  91.  
  92. void
  93. __load_shared_libraries (int argc, char **argv, char **envp)
  94. {
  95.     if (__SHARED_LIBRARIES__[2])
  96.     {
  97.     unsigned mapinfo[2];
  98.     /* this must be volatile to work with -O, GCC bug? */
  99.     volatile loadptr loader = (loadptr)LDSO_ADDR;
  100.  
  101. #ifdef LDSO_IMAGE1
  102.     if (uselib(LDSO_IMAGE) && uselib(LDSO_IMAGE1))
  103. #else
  104.     if (uselib(LDSO_IMAGE))
  105. #endif
  106.     {
  107.         char *p = argv[0];
  108. #ifdef LDSO_IMAGE1
  109.         char errmsg[] = ": can't load dynamic linker '"
  110.         LDSO_IMAGE
  111.         " nor "
  112.         LDSO_IMAGE1
  113.         "'\n";
  114. #else
  115.         char errmsg[] = ": can't load dynamic linker '" LDSO_IMAGE "'\n";
  116. #endif
  117.  
  118.         if (p)
  119.         {
  120.         while (*p) p++;
  121.         write(2, argv[0], p-argv[0]);
  122.         }
  123.  
  124.         write(2, errmsg, sizeof errmsg - 1);
  125.         while (1) exit(128);
  126.     }
  127.  
  128.     loader((argc <= 0) ? FUNC_LDD : FUNC_LINK, mapinfo, argv[0],
  129.            envp, __SHARED_LIBRARIES__, &_SHARABLE_CONFLICTS__);
  130.  
  131.     munmap((caddr_t)mapinfo[0], mapinfo[1]);
  132.     }
  133.     else 
  134.     {
  135.     char msg[] = "\tstatically linked\n";
  136.  
  137.     if (argc<=0)
  138.         write (2, msg, sizeof msg - 1);
  139.     }
  140.     if (argc <= 0)
  141. while (1) exit(0);
  142. }
  143.