Ticket #29228: patch-src-darwintrace1.0.in.diff

File patch-src-darwintrace1.0.in.diff, 9.4 KB (added by gauravb7090@…, 11 years ago)
  • access.c

     
    4141#include <sys/syscall.h>
    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();
    4747
     
    5959        return result;
    6060#undef access
    6161}
     62DARWINTRACE_INTERPOSE(_dt_access,access);
  • close.c

     
    5050 * need to. This possibility is the \c __darwintrace_close_sock variable, which
    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();
    5656
     
    6666        return close(fd);
    6767#undef close
    6868}
     69DARWINTRACE_INTERPOSE(_dt_close,close);
  • darwintrace.c

     
    7777        return result;
    7878}
    7979#endif
     80DARWINTRACE_INTERPOSE(strlcpy,strlcpy);
    8081
    8182#include "../pextlib1.0/strlcat.c"
    8283
     
    158159        return (pthread_t) pthread_getspecific(tid_key);
    159160}
    160161
     162
    161163/**
    162164 * Convenience setter function for the thread-local darwintrace socket
    163165 */
  • darwintrace.h

     
    4444#include <stdio.h>
    4545
    4646/**
     47 * DARWINTRACE_INTERPOSE: provides a way to override standard library functions with your own implementations
     48 */
     49#ifndef DARWINTRACE_INTERPOSE
     50#define DARWINTRACE_INTERPOSE(_replacement,_replacee) \
     51__attribute__((used)) static struct { \
     52        const void* replacement; \
     53        const void* replacee; \
     54} _interpose_##_replacee \
     55__attribute__ ((section ("__DATA,__interpose"))) = { \
     56        (const void*)(unsigned long)&_replacement, \
     57        (const void*)(unsigned long)&_replacee \
     58}
     59#endif
     60
     61/**
    4762 * DARWINTRACE_DEBUG: verbose output of operations to debug darwintrace
    4863 */
    4964#ifndef DARWINTRACE_DEBUG
  • dup2.c

     
    4848 * attempts to overwrite it using \c dup(2). Shells tend to do that a lot when
    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();
    5454
     
    7575        return dup2(filedes, filedes2);
    7676#undef dup2
    7777}
     78DARWINTRACE_INTERPOSE(_dt_dup2,dup2);
  • mkdir.c

     
    5353 * the sandbox. Will silently do nothing and return success for directories
    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))
    5959        __darwintrace_setup();
     
    7878#undef lstat
    7979#undef mkdir
    8080}
     81DARWINTRACE_INTERPOSE(_dt_mkdir,mkdir);
  • open.c

     
    4848 * Indicates the file does not exist on sandbox violation, or permission denied
    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();
    5454        int result = 0;
     
    7070        return result;
    7171#undef open
    7272}
     73DARWINTRACE_INTERPOSE(_dt_open,open);
  • proc.c

     
    254254 * exist, if it's outside the sandbox. Also checks for potential interpreters
    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();
    260260
     
    288288        return result;
    289289#undef execve
    290290}
     291DARWINTRACE_INTERPOSE(_dt_execve,execve);
    291292
    292293#if defined(HAVE_SPAWN_H) && defined(HAVE_POSIX_SPAWN)
    293294// Let's save some typing work...
     
    303304 * exist, if it's outside the sandbox. Also checks for potential interpreters
    304305 * using \c check_interpreter.
    305306 */
    306 int posix_spawn(pid_t *restrict pid, const char *restrict path, const posix_spawn_file_actions_t *file_actions,
     307int _dt_posix_spawn(pid_t *restrict pid, const char *restrict path, const posix_spawn_file_actions_t *file_actions,
    307308                const posix_spawnattr_t *restrict attrp, char *const argv[restrict], char *const envp[restrict]) {
    308309        __darwintrace_setup();
    309310
     
    355356        return result;
    356357}
    357358#endif
     359DARWINTRACE_INTERPOSE(_dt_posix_spawn,posix_spawn);
  • readlink.c

     
    4646 * Deny \c readlink(2) if the file is not within the sandbox bounds.
    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))
    5454        __darwintrace_setup();
     
    6969        return result;
    7070#undef readlink
    7171}
     72DARWINTRACE_INTERPOSE(_dt_readlink,readlink);
  • rename.c

     
    4646 * Wrapper around \c rename(2) to prevent moving a file outside, or out of the
    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();
    5252
     
    6767        return result;
    6868#undef rename
    6969}
     70DARWINTRACE_INTERPOSE(_dt_rename,rename);
  • rmdir.c

     
    4646 * Wrapper around \c rmdir(2) to deny deleting directories outside of the
    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();
    5252
     
    6464        return result;
    6565#undef rmdir
    6666}
     67DARWINTRACE_INTERPOSE(_dt_rmdir,rmdir);
  • stat.c

     
    4747 * Wrapper around \c stat(2) to hide information about files outside the
    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();
    5353
     
    6666#undef stat
    6767}
    6868
     69int stat(const char *path, void *sb);
     70DARWINTRACE_INTERPOSE(_dt_stat,stat);
     71
    6972// Don't provide stat64 on systems that have no stat64 syscall
    7073#ifdef SYS_stat64
    71 int stat64(const char *path, void *sb) {
     74int _dt_stat64(const char *path, void *sb) {
    7275#define stat64(path, sb) syscall(SYS_stat64, path, sb)
    7376        __darwintrace_setup();
    7477
     
    8790#undef stat64
    8891}
    8992
    90 int stat$INODE64(const char *path, void *sb) {
    91         return stat64(path, sb);
    92 }
     93int stat64(const char *path, void *sb);
     94DARWINTRACE_INTERPOSE(_dt_stat64,stat64);
     95
     96
     97int stat$INODE64(const char *path, void *sb);
     98
     99DARWINTRACE_INTERPOSE(_dt_stat64,stat$INODE64);
     100
    93101#endif /* defined(SYS_stat64) */
    94102
    95 int lstat(const char *path, void *sb) {
     103
     104int _dt_lstat(const char *path, void *sb) {
    96105#define lstat(path, sb) syscall(SYS_lstat, path, sb)
    97106        __darwintrace_setup();
    98107
     
    112121#undef lstat
    113122}
    114123
     124int lstat(const char *path, void *sb);
     125DARWINTRACE_INTERPOSE(_dt_lstat,lstat);
     126
    115127// Don't provide lstat64 on systems that have no lstat64 syscall
    116128#ifdef SYS_lstat64
    117 int lstat64(const char *path, void *sb) {
     129int _dt_lstat64(const char *path, void *sb) {
    118130#define lstat64(path, sb) syscall(SYS_lstat64, path, sb)
    119131        __darwintrace_setup();
    120132
     
    134146#undef lstat64
    135147}
    136148
    137 int lstat$INODE64(const char *path, void *sb) {
    138         return lstat64(path, sb);
    139 }
     149int lstat64(const char *path, void *sb);
     150DARWINTRACE_INTERPOSE(_dt_lstat64,lstat64);
     151
     152int lstat$INODE64(const char *path, void *sb);
     153
     154DARWINTRACE_INTERPOSE(_dt_lstat64,lstat$INODE64);
     155
    140156#endif /* defined(SYS_lstat64) */
     157
  • unlink.c

     
    4646 * Wrapper around \c unlink(2) that will deny attempts to delete files outside
    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();
    5252
     
    6464        return result;
    6565#undef unlink
    6666}
     67DARWINTRACE_INTERPOSE(_dt_unlink,unlink);