VirtualBox

Ignore:
Timestamp:
Jul 12, 2011 12:50:50 PM (14 years ago)
Author:
bird
Message:

restartable-syscall-wrappers.c: Redid the wrapping to make sure we cover the ones with the '64' suffix as well as the ones without it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/restartable-syscall-wrappers.c

    r2449 r2468  
    3838#include <sys/types.h>
    3939#include <sys/stat.h>
     40#include <utime.h>
    4041#include <dlfcn.h>
    4142#include <errno.h>
     
    8081#define XSTR(x)         XSTR_INNER(x)
    8182
    82 
    83 
    84 extern int WRAP64(open)(const char *pszName, int fFlags, ...);
    85 int open(const char *pszName, int fFlags, ...)
    86 {
    87     mode_t      fMode;
    88     va_list     va;
    89     int         fd;
    90 
    91     va_start(va, fFlags);
    92     fMode = va_arg(va, mode_t);
    93     va_end(va);
    94 
    95     do
    96         fd = WRAP64(open)(pszName, fFlags, fMode);
    97     while (fd == -1 && SHOULD_RESTART());
    98     return fd;
    99 }
    100 
    101 
    102 #if !defined(KBUILD_OS_LINUX) /* no wrapper */
    103 extern int WRAP(mkdir)(const char *pszName, mode_t fMode);
    104 int mkdir(const char *pszName, mode_t fMode)
    105 {
    106     int rc;
    107     do
    108         rc = WRAP(mkdir)(pszName, fMode);
    109     while (rc == -1 && SHOULD_RESTART());
    110     return rc;
    111 }
    112 #endif
    113 
    114 extern int WRAP64(stat)(const char *pszName, struct stat *pStBuf);
    115 int stat(const char *pszName, struct stat *pStBuf)
    116 {
    117     int rc;
    118     do
    119         rc = WRAP64(stat)(pszName, pStBuf);
    120     while (rc == -1 && SHOULD_RESTART());
    121     return rc;
    122 }
    123 
    124 extern int WRAP64(lstat)(const char *pszName, struct stat *pStBuf);
    125 int lstat(const char *pszName, struct stat *pStBuf)
    126 {
    127     int rc;
    128     do
    129         rc = WRAP64(lstat)(pszName, pStBuf);
    130     while (rc == -1 && SHOULD_RESTART());
    131     return rc;
    132 }
    133 
    134 extern ssize_t WRAP(read)(int fd, void *pvBuf, size_t cbBuf);
    135 ssize_t read(int fd, void *pvBuf, size_t cbBuf)
    136 {
    137     ssize_t cbRead;
    138     do
    139         cbRead = WRAP(read)(fd, pvBuf, cbBuf);
    140     while (cbRead == -1 && SHOULD_RESTART());
    141     return cbRead;
    142 }
    143 
    144 extern ssize_t WRAP(write)(int fd, void *pvBuf, size_t cbBuf);
    145 ssize_t write(int fd, void *pvBuf, size_t cbBuf)
    146 {
    147     ssize_t cbWritten;
    148     do
    149         cbWritten = WRAP(write)(fd, pvBuf, cbBuf);
    150     while (cbWritten == -1 && SHOULD_RESTART());
    151     return cbWritten;
    152 }
    15383
    15484static int dlsym_libc(const char *pszSymbol, void **ppvSym)
     
    213143}
    214144
    215 #undef fopen
    216 FILE *fopen(const char *pszName, const char *pszMode)
     145
     146
     147int open(const char *pszPath, int fFlags, ...)
    217148{
     149    mode_t      fMode;
     150    va_list     va;
     151    int         fd;
    218152    static union
    219153    {
    220         FILE *(* pfnFOpen)(const char *, const char *);
     154        int (* pfnReal)(const char *, int, mode_t);
    221155        void *pvSym;
    222156    } s_u;
    223     FILE *pFile;
    224 
    225     if (   !s_u.pfnFOpen
    226         && dlsym_libc("fopen", &s_u.pvSym) != 0)
    227         return NULL;
     157
     158    if (   !s_u.pfnReal
     159        && dlsym_libc("open", &s_u.pvSym) != 0)
     160        return -1;
     161
     162    va_start(va, fFlags);
     163    fMode = va_arg(va, mode_t);
     164    va_end(va);
    228165
    229166    do
    230         pFile = s_u.pfnFOpen(pszName, pszMode);
    231     while (!pFile && SHOULD_RESTART());
    232     return pFile;
     167        fd = s_u.pfnReal(pszPath, fFlags, fMode);
     168    while (fd == -1 && SHOULD_RESTART());
     169    return fd;
    233170}
    234171
    235 #undef fopen64
    236 FILE *fopen64(const char *pszName, const char *pszMode)
     172int open64(const char *pszPath, int fFlags, ...)
    237173{
     174    mode_t      fMode;
     175    va_list     va;
     176    int         fd;
    238177    static union
    239178    {
    240         FILE *(* pfnFOpen64)(const char *, const char *);
     179        int (* pfnReal)(const char *, int, mode_t);
    241180        void *pvSym;
    242181    } s_u;
    243     FILE *pFile;
    244 
    245     if (   !s_u.pfnFOpen64
    246         && dlsym_libc("fopen64", &s_u.pvSym) != 0)
    247         return NULL;
     182
     183    if (   !s_u.pfnReal
     184        && dlsym_libc("open64", &s_u.pvSym) != 0)
     185        return -1;
     186
     187    va_start(va, fFlags);
     188    fMode = va_arg(va, mode_t);
     189    va_end(va);
    248190
    249191    do
    250         pFile = s_u.pfnFOpen64(pszName, pszMode);
    251     while (!pFile && SHOULD_RESTART());
    252     return pFile;
     192        fd = s_u.pfnReal(pszPath, fFlags, fMode);
     193    while (fd == -1 && SHOULD_RESTART());
     194    return fd;
    253195}
    254196
    255 /** @todo chmod, chown, chgrp, times, and possible some more. */
    256 
     197#define WRAP_FN(a_Name, a_ParamsWithTypes, a_ParamsNoType, a_RetType, a_RetFailed) \
     198    a_RetType a_Name a_ParamsWithTypes \
     199    { \
     200        static union \
     201        { \
     202            a_RetType (* pfnReal) a_ParamsWithTypes; \
     203            void *pvSym; \
     204        } s_u; \
     205        a_RetType rc; \
     206        \
     207        if (   !s_u.pfnReal \
     208            && dlsym_libc(#a_Name, &s_u.pvSym) != 0) \
     209            return a_RetFailed; \
     210        \
     211        do \
     212            rc = s_u.pfnReal a_ParamsNoType; \
     213        while (rc == a_RetFailed && SHOULD_RESTART()); \
     214        return rc; \
     215    } typedef int ignore_semi_colon_##a_Name
     216
     217#undef mkdir
     218WRAP_FN(mkdir, (const char *pszPath, mode_t fMode), (pszPath, fMode), int, -1);
     219
     220#undef rmdir
     221WRAP_FN(rmdir, (const char *pszPath, mode_t fMode), (pszPath, fMode), int, -1);
     222
     223#undef unlink
     224WRAP_FN(unlink, (const char *pszPath), (pszPath), int, -1);
     225
     226#undef remove
     227WRAP_FN(remove, (const char *pszPath), (pszPath), int, -1);
     228
     229#undef symlink
     230WRAP_FN(symlink, (const char *pszFrom, const char *pszTo), (pszFrom, pszTo), int, -1);
     231
     232#undef link
     233WRAP_FN(link, (const char *pszFrom, const char *pszTo), (pszFrom, pszTo), int, -1);
     234
     235#undef stat
     236WRAP_FN(stat, (const char *pszPath, struct stat *pStBuf), (pszPath, pStBuf), int, -1);
     237#undef stat64
     238WRAP_FN(stat64, (const char *pszPath, struct stat *pStBuf), (pszPath, pStBuf), int, -1);
     239
     240#undef lstat
     241WRAP_FN(lstat, (const char *pszPath, struct stat *pStBuf), (pszPath, pStBuf), int, -1);
     242#undef lstat64
     243WRAP_FN(lstat64, (const char *pszPath, struct stat *pStBuf), (pszPath, pStBuf), int, -1);
     244
     245#undef read
     246WRAP_FN(read, (int fd, void *pvBuf, size_t cbBuf), (fd, pvBuf, cbBuf), ssize_t, -1);
     247
     248#undef write
     249WRAP_FN(write, (int fd, void *pvBuf, size_t cbBuf), (fd, pvBuf, cbBuf), ssize_t, -1);
     250
     251#undef fopen
     252WRAP_FN(fopen, (const char *pszPath, const char *pszMode), (pszPath, pszMode), FILE *, NULL);
     253#undef fopen64
     254WRAP_FN(fopen64, (const char *pszPath, const char *pszMode), (pszPath, pszMode), FILE *, NULL);
     255
     256#undef chmod
     257WRAP_FN(chmod, (const char *pszPath, mode_t fMode), (pszPath, fMode), int, -1);
     258#undef lchmod
     259WRAP_FN(lchmod, (const char *pszPath, mode_t fMode), (pszPath, fMode), int, -1);
     260
     261#undef chown
     262WRAP_FN(chown, (const char *pszPath, uid_t uid, gid_t gid), (pszPath, uid, gid), int, -1);
     263#undef lchown
     264WRAP_FN(lchown, (const char *pszPath, uid_t uid, gid_t gid), (pszPath, uid, gid), int, -1);
     265
     266#undef utime
     267WRAP_FN(utime, (const char *pszPath, const struct utimbuf *pTimes), (pszPath, pTimes), int, -1);
     268
     269#undef utimes
     270WRAP_FN(utimes, (const char *pszPath, const struct timeval *paTimes), (pszPath, paTimes), int, -1);
     271
     272#undef pathconf
     273WRAP_FN(pathconf, (const char *pszPath, int iCfgNm), (pszPath, iCfgNm), long, -1);
     274
     275
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