VirtualBox

Changeset 2445 in kBuild


Ignore:
Timestamp:
Jul 7, 2011 10:20:24 AM (14 years ago)
Author:
bird
Message:

need to wrap fopen as well.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Config.kmk

    r2434 r2445  
    321321  TEMPLATE_BIN_LDFLAGS.sparc64 += -m64
    322322 ifeq ($(KBUILD_TARGET),solaris)
    323   TEMPLATE_BIN_LIBS            += rt
     323  TEMPLATE_BIN_LIBS            += rt dl
    324324  TEMPLATE_BIN_LDFLAGS         += -Wl,-i
    325325 endif
  • trunk/src/lib/restartable-syscall-wrappers.c

    r2444 r2445  
    3838#include <sys/types.h>
    3939#include <sys/stat.h>
     40#include <dlfcn.h>
     41#include <errno.h>
    4042#include <fcntl.h>
    41 #include <errno.h>
    4243#include <stdarg.h>
     44#include <stddef.h>
     45#include <stdio.h>
    4346
    4447
     
    5558#endif
    5659
     60/** Optional '64' suffix string for dlsym.  */
     61#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
     62# define SYM_64_SUFFIX "64"
     63#else
     64# define SYM_64_SUFFIX ""
     65#endif
     66
    5767/** Mangle a syscall name with optional '64' suffix. */
    5868#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
     
    140150}
    141151
     152static int dlsym_libc(const char *pszSymbol, void **ppvSym)
     153{
     154    static void *s_pvLibc = NULL;
     155    void        *pvLibc;
     156    void        *pvSym;
     157
     158    /*
     159     * Open libc.
     160     */
     161    pvLibc = s_pvLibc;
     162    if (!pvLibc)
     163    {
     164#ifdef RTLD_NOLOAD
     165        pvLibc = dlopen("/libc/libc.so", RTLD_NOLOAD);
     166#else
     167        pvLibc = dlopen("/libc/libc.so", RTLD_GLOBAL);
     168#endif
     169        if (!pvLibc)
     170        {
     171            fprintf(stderr, "restartable-syscall-wrappers: failed to dlopen libc for resolving %s: %s\n",
     172                    pszSymbol, dlerror());
     173            errno = ENOSYS;
     174            return -1;
     175        }
     176        /** @todo check standard symbol? */
     177    }
     178
     179    /*
     180     * Resolve the symbol.
     181     */
     182    pvSym = dlsym(pvLibc, pszSymbol);
     183    if (!pvSym)
     184    {
     185        fprintf(stderr, "restartable-syscall-wrappers: failed to resolve %s: %s\n",
     186                pszSymbol, dlerror());
     187        errno = ENOSYS;
     188        return -1;
     189    }
     190
     191    *ppvSym = pvSym;
     192    return 0;
     193}
     194
     195FILE *fopen(const char *pszName, const char *pszMode)
     196{
     197    static union
     198    {
     199        FILE *(* pfnFopen)(const char *, const char *);
     200        void *pvSym;
     201    } s_u;
     202    FILE *pFile;
     203
     204    if (   !s_u.pfnFopen
     205        && dlsym_libc("fopen" SYM_64_SUFFIX, &s_u.pvSym) != 0)
     206        return NULL;
     207
     208    do
     209        pFile = s_u.pfnFopen(pszName, pszMode);
     210    while (!pFile && SHOULD_RESTART());
     211    return pFile;
     212}
     213
    142214/** @todo chmod, chown, chgrp, times, and possible some more. */
     215
     216
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette