Changeset 117751 for trunk/base


Ignore:
Timestamp:
Mar 10, 2014, 9:55:33 PM (10 years ago)
Author:
cal@…
Message:

darwintrace: use modern interposing, avoid DYLD_FORCE_FLAT_NAMESPACE that's no longer necessary with interposing, #29228, patch by gauravb7090

Location:
trunk/base/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/darwintracelib1.0/access.c

    r114131 r117751  
    4242#include <unistd.h>
    4343
    44 int access(const char *path, int amode) {
     44int _dt_access(const char *path, int amode) {
    4545#define access(x, y) syscall(SYS_access, (x), (y))
    4646        __darwintrace_setup();
     
    6060#undef access
    6161}
     62
     63DARWINTRACE_INTERPOSE(_dt_access, access);
  • trunk/base/src/darwintracelib1.0/close.c

    r113026 r117751  
    5151 * will be set to the FD to be closed when closing should be allowed.
    5252 */
    53 int close(int fd) {
     53int _dt_close(int fd) {
    5454#define close(x) syscall(SYS_close, (x))
    5555        __darwintrace_setup();
     
    6767#undef close
    6868}
     69
     70DARWINTRACE_INTERPOSE(_dt_close, close);
  • trunk/base/src/darwintracelib1.0/darwintrace.h

    r114131 r117751  
    4343#include <stdbool.h>
    4444#include <stdio.h>
     45
     46/**
     47 * DARWINTRACE_INTERPOSE: provides a way to override standard library functions
     48 * with your own implementations.
     49 */
     50#ifndef DARWINTRACE_INTERPOSE
     51#define DARWINTRACE_INTERPOSE(_replacement, _replacee) \
     52__attribute__((used)) static struct { \
     53        const void *replacement; \
     54        const void *replacee; \
     55} _interpose_##_replacee \
     56__attribute__((section ("__DATA,__interpose"))) = { \
     57        (const void *) (unsigned long) &_replacement, \
     58        (const void *) (unsigned long) &_replacee \
     59}
     60#endif
    4561
    4662/**
  • trunk/base/src/darwintracelib1.0/dup2.c

    r113026 r117751  
    4949 * FDs are numbered in ascending order.
    5050 */
    51 int dup2(int filedes, int filedes2) {
     51int _dt_dup2(int filedes, int filedes2) {
    5252#define dup2(x, y) syscall(SYS_dup2, (x), (y))
    5353        __darwintrace_setup();
     
    7676#undef dup2
    7777}
     78
     79DARWINTRACE_INTERPOSE(_dt_dup2, dup2);
  • trunk/base/src/darwintracelib1.0/mkdir.c

    r114166 r117751  
    5454 * outside the sandbox that already exist.
    5555 */
    56 int mkdir(const char *path, mode_t mode) {
     56int _dt_mkdir(const char *path, mode_t mode) {
    5757#define mkdir(x,y) syscall(SYS_mkdir, (x), (y))
    5858#define lstat(x,y) syscall(LSTATSYSNUM, (x), (y))
     
    7979#undef mkdir
    8080}
     81
     82DARWINTRACE_INTERPOSE(_dt_mkdir, mkdir);
  • trunk/base/src/darwintracelib1.0/open.c

    r114131 r117751  
    4949 * when attempting to create a file, i.e., when \c O_CREAT is set.
    5050 */
    51 int open(const char *path, int flags, ...) {
     51int _dt_open(const char *path, int flags, ...) {
    5252#define open(x,y,z) syscall(SYS_open, (x), (y), (z))
    5353        __darwintrace_setup();
     
    7171#undef open
    7272}
     73
     74DARWINTRACE_INTERPOSE(_dt_open, open);
  • trunk/base/src/darwintracelib1.0/proc.c

    r114131 r117751  
    255255 * using \c check_interpreter.
    256256 */
    257 int execve(const char *path, char *const argv[], char *const envp[]) {
     257int _dt_execve(const char *path, char *const argv[], char *const envp[]) {
    258258#define execve(x,y,z) syscall(SYS_execve, (x), (y), (z))
    259259        __darwintrace_setup();
     
    290290}
    291291
     292DARWINTRACE_INTERPOSE(_dt_execve, execve);
     293
    292294#if defined(HAVE_SPAWN_H) && defined(HAVE_POSIX_SPAWN)
    293295// Let's save some typing work...
     
    304306 * using \c check_interpreter.
    305307 */
    306 int posix_spawn(pid_t *restrict pid, const char *restrict path, const posix_spawn_file_actions_t *file_actions,
     308int _dt_posix_spawn(pid_t *restrict pid, const char *restrict path, const posix_spawn_file_actions_t *file_actions,
    307309                const posix_spawnattr_t *restrict attrp, char *const argv[restrict], char *const envp[restrict]) {
    308310        __darwintrace_setup();
    309311
    310         static posix_spawn_t prev_posix_spawn = NULL;
    311312        int result = 0;
    312313
     
    340341                         * either, because that will fail with an invalid argument. Thus,
    341342                         * we need to call the original posix_spawn from here. */
    342                         // retrieve the original posix_spawn function
    343                         if (prev_posix_spawn == NULL) {
    344                                 prev_posix_spawn = (posix_spawn_t) dlsym(RTLD_NEXT, "posix_spawn");
    345                         }
    346343                        // call the original posix_spawn function, but restore environment
    347344                        char **newenv = restore_env(envp);
    348                         result = prev_posix_spawn(pid, path, file_actions, attrp, argv, newenv);
     345                        result = posix_spawn(pid, path, file_actions, attrp, argv, newenv);
    349346                        free(newenv);
    350347                }
     
    355352        return result;
    356353}
     354
     355DARWINTRACE_INTERPOSE(_dt_posix_spawn, posix_spawn);
    357356#endif
  • trunk/base/src/darwintracelib1.0/readdir.c

    r113026 r117751  
    6767};
    6868
    69 size_t __getdirentries64(int fd, void *buf, size_t bufsize, __darwin_off_t *basep) {
     69size_t _dt_getdirentries64(int fd, void *buf, size_t bufsize, __darwin_off_t *basep) {
    7070#define __getdirentries64(w,x,y,z) syscall(SYS_getdirentries64, (w), (x), (y), (z))
    7171        __darwintrace_setup();
     
    106106}
    107107
     108// __getdirentries64(2) is private API. There's no header for it.
     109size_t __getdirentries64(int fd, void *buf, size_t bufsize, __darwin_off_t *basep);
     110DARWINTRACE_INTERPOSE(_dt_getdirentries64, __getdirentries64);
     111
    108112#endif /* defined(__DARWIN_64_BIT_INO_T) */
    109113
     
    118122#pragma pack()
    119123
    120 int getdirentries(int fd, char *buf, int nbytes, long *basep) {
     124int _dt_getdirentries(int fd, char *buf, int nbytes, long *basep) {
    121125#define getdirentries(w,x,y,z) syscall(SYS_getdirentries, (w), (x), (y), (z))
    122126        __darwintrace_setup();
     
    155159#undef getdirentries
    156160}
     161
     162int getdirentries(int fd, char *buf, int nbytes, long *basep);
     163DARWINTRACE_INTERPOSE(_dt_getdirentries, getdirentries);
  • trunk/base/src/darwintracelib1.0/readlink.c

    r114131 r117751  
    4747 */
    4848#ifdef READLINK_IS_NOT_P1003_1A
    49 int readlink(const char *path, char *buf, int bufsiz) {
     49int _dt_readlink(const char *path, char *buf, int bufsiz) {
    5050#else
    51 ssize_t readlink(const char *path, char *buf, size_t bufsiz) {
     51ssize_t _dt_readlink(const char *path, char *buf, size_t bufsiz) {
    5252#endif
    5353#define readlink(x,y,z) syscall(SYS_readlink, (x), (y), (z))
     
    7070#undef readlink
    7171}
     72
     73DARWINTRACE_INTERPOSE(_dt_readlink, readlink);
  • trunk/base/src/darwintracelib1.0/rename.c

    r114131 r117751  
    4747 * sandbox.
    4848 */
    49 int rename(const char *from, const char *to) {
     49int _dt_rename(const char *from, const char *to) {
    5050#define rename(x,y) syscall(SYS_rename, (x), (y))
    5151        __darwintrace_setup();
     
    6868#undef rename
    6969}
     70
     71DARWINTRACE_INTERPOSE(_dt_rename, rename);
  • trunk/base/src/darwintracelib1.0/rmdir.c

    r114131 r117751  
    4747 * sandbox.
    4848 */
    49 int rmdir(const char *path) {
     49int _dt_rmdir(const char *path) {
    5050#define rmdir(x) syscall(SYS_rmdir, (x))
    5151        __darwintrace_setup();
     
    6565#undef rmdir
    6666}
     67
     68DARWINTRACE_INTERPOSE(_dt_rmdir, rmdir);
  • trunk/base/src/darwintracelib1.0/stat.c

    r114131 r117751  
    4848 * sandbox.
    4949 */
    50 int stat(const char *path, void *sb) {
     50int _dt_stat(const char *path, void *sb) {
    5151#define stat(path, sb) syscall(SYS_stat, path, sb)
    5252        __darwintrace_setup();
     
    6767}
    6868
     69// We don't include sys/stat.h because it would rewrite all stat function
     70// calls, but we need the declaration of stat here.
     71int stat(const char *path, void *sb);
     72DARWINTRACE_INTERPOSE(_dt_stat, stat);
     73
    6974// Don't provide stat64 on systems that have no stat64 syscall
    7075#ifdef SYS_stat64
    71 int stat64(const char *path, void *sb) {
     76int _dt_stat64(const char *path, void *sb) {
    7277#define stat64(path, sb) syscall(SYS_stat64, path, sb)
    7378        __darwintrace_setup();
     
    8792#undef stat64
    8893}
     94int stat64(const char *path, void *sb);
     95DARWINTRACE_INTERPOSE(_dt_stat64, stat64);
    8996
    90 int stat$INODE64(const char *path, void *sb) {
    91         return stat64(path, sb);
    92 }
     97int stat$INODE64(const char *path, void *sb);
     98DARWINTRACE_INTERPOSE(_dt_stat64, stat$INODE64);
     99
    93100#endif /* defined(SYS_stat64) */
    94101
    95 int lstat(const char *path, void *sb) {
     102int _dt_lstat(const char *path, void *sb) {
    96103#define lstat(path, sb) syscall(SYS_lstat, path, sb)
    97104        __darwintrace_setup();
     
    113120}
    114121
     122int lstat(const char *path, void *sb);
     123DARWINTRACE_INTERPOSE(_dt_lstat, lstat);
     124
    115125// Don't provide lstat64 on systems that have no lstat64 syscall
    116126#ifdef SYS_lstat64
    117 int lstat64(const char *path, void *sb) {
     127int _dt_lstat64(const char *path, void *sb) {
    118128#define lstat64(path, sb) syscall(SYS_lstat64, path, sb)
    119129        __darwintrace_setup();
     
    135145}
    136146
    137 int lstat$INODE64(const char *path, void *sb) {
    138         return lstat64(path, sb);
    139 }
     147int lstat64(const char *path, void *sb);
     148DARWINTRACE_INTERPOSE(_dt_lstat64, lstat64);
     149
     150int lstat$INODE64(const char *path, void *sb);
     151DARWINTRACE_INTERPOSE(_dt_lstat64, lstat$INODE64);
     152
    140153#endif /* defined(SYS_lstat64) */
  • trunk/base/src/darwintracelib1.0/unlink.c

    r114131 r117751  
    4747 * of the sandbox and simulate non-existence of the file instead.
    4848 */
    49 int unlink(const char *path) {
     49int _dt_unlink(const char *path) {
    5050#define unlink(x) syscall(SYS_unlink, (x))
    5151        __darwintrace_setup();
     
    6565#undef unlink
    6666}
     67
     68DARWINTRACE_INTERPOSE(_dt_unlink, unlink);
  • trunk/base/src/port1.0/porttrace.tcl

    r116781 r117751  
    6767                set env(DYLD_INSERT_LIBRARIES) ${tracelib_path}
    6868            }
    69             set env(DYLD_FORCE_FLAT_NAMESPACE) 1
    7069            set env(DARWINTRACE_LOG) "$trace_fifo"
    7170            # The sandbox is limited to:
     
    171170    if {${os.platform} == "darwin"} {
    172171        global env trace_fifo macosx_version
    173         foreach var {DYLD_INSERT_LIBRARIES DYLD_FORCE_FLAT_NAMESPACE DARWINTRACE_LOG DARWINTRACE_SANDBOX_BOUNDS} {
     172        foreach var {DYLD_INSERT_LIBRARIES DARWINTRACE_LOG} {
    174173            array unset env $var
    175174            if {$macosx_version eq "10.5"} {
Note: See TracChangeset for help on using the changeset viewer.