Back to index

glibc  2.9
dl-machine.c
Go to the documentation of this file.
00001 /* Operating system support for run-time dynamic linker.  MIPS specific
00002    stuffs on Hurd.
00003    Copyright (C) 1996, 1997 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <hurd.h>
00022 #include <link.h>
00023 #include <unistd.h>
00024 #include <fcntl.h>
00025 #include <stdlib.h>
00026 #include <sys/mman.h>
00027 #include <assert.h>
00028 #include <sysdep.h>
00029 #include <mach/mig_support.h>
00030 #include "../stdio-common/_itoa.h"
00031 #include <stdarg.h>
00032 #include <ctype.h>
00033 #include <sys/stat.h>
00034 #include <libintl.h>
00035 
00036 void weak_function
00037 abort (void)
00038 {
00039   _exit (127);
00040 }
00041 
00042 
00043 #include <string.h>
00044 #include <mach/error.h>
00045 #include <errorlib.h>
00046 
00047 #undef _
00048 #define _(x) x
00049 
00050 /* Return a string describing the errno code in ERRNUM.  */
00051 char * weak_function
00052 _strerror_internal (int errnum, char *buf, size_t buflen)
00053 {
00054   int system;
00055   int sub;
00056   int code;
00057   const struct error_system *es;
00058   extern void __mach_error_map_compat (int *);
00059 
00060   __mach_error_map_compat (&errnum);
00061 
00062   system = err_get_system (errnum);
00063   sub = err_get_sub (errnum);
00064   code = err_get_code (errnum);
00065 
00066   if (system > err_max_system || ! __mach_error_systems[system].bad_sub)
00067     {
00068       const char *unk = _("Error in unknown error system: ");
00069       const size_t unklen = strlen (unk);
00070       char *p = buf + buflen;
00071       *--p = '\0';
00072       p = _itoa (errnum, p, 16, 1);
00073       return memcpy (p - unklen, unk, unklen);
00074     }
00075 
00076   es = &__mach_error_systems[system];
00077 
00078   if (sub >= es->max_sub)
00079     return (char *) es->bad_sub;
00080 
00081   if (code >= es->subsystem[sub].max_code)
00082     {
00083       const char *unk = _("Unknown error ");
00084       const size_t unklen = strlen (unk);
00085       char *p = buf + buflen;
00086       size_t len = strlen (es->subsystem[sub].subsys_name);
00087       *--p = '\0';
00088       p = _itoa (errnum, p, 16, 1);
00089       *p-- = ' ';
00090       p = memcpy (p - len, es->subsystem[sub].subsys_name, len);
00091       return memcpy (p - unklen, unk, unklen);
00092     }
00093 
00094   return (char *) _(es->subsystem[sub].codes[code]);
00095 }
00096 
00097 /* Read the whole contents of FILE into new mmap'd space with given
00098    protections.  The size of the file is returned in SIZE.  */
00099 void *
00100 _dl_sysdep_read_whole_file (const char *file, size_t *size, int prot)
00101 {
00102   struct stat stat;
00103   mach_port_t memobj_rd;
00104   void *contents;
00105   error_t err;
00106 
00107   memobj_rd = __open (file, O_RDONLY, 0);
00108   if (memobj_rd)
00109     {
00110       err = __io_stat ((file_t) memobj_rd, &stat);
00111       if (err)
00112        {
00113          __hurd_fail (err);
00114          contents = 0;
00115        }
00116       else
00117        {
00118          /* Map a copy of the file contents.  */
00119          contents = __mmap (0, stat.st_size, prot, MAP_COPY, memobj_rd, 0);
00120          if (contents == (void *)-1)
00121            contents = 0;
00122          else
00123            *size = stat.st_size;
00124        }
00125 
00126       __mach_port_deallocate (__mach_task_self (), memobj_rd);
00127     }
00128   else
00129     contents = 0;
00130 
00131   return contents;
00132 }