1 /* 2 * Copyright 2007 The Android Open Source Project 3 * 4 * Sim wrapper global state. 5 */ 6 #ifndef _WRAPSIM_GLOBALS_H 7 #define _WRAPSIM_GLOBALS_H 8 9 #include <stdio.h> 10 #include <unistd.h> 11 #include <sys/types.h> 12 #include <sys/stat.h> 13 #include <sys/uio.h> 14 #include <sys/time.h> 15 #include <sys/vfs.h> 16 #include <utime.h> 17 #include <fcntl.h> 18 #include <dirent.h> 19 #include <pthread.h> 20 21 /* 22 * Type declarations for the functions we're replacing. 23 * 24 * For syscalls this matches the syscall definition, not the libc definition, 25 * e.g. no varargs for open() or ioctl(). 26 */ 27 typedef int (*Func_access)(const char*, int); 28 typedef int (*Func_open)(const char*, int, mode_t); 29 typedef int (*Func_open64)(const char*, int, mode_t); 30 31 typedef int (*Func_close)(int); 32 typedef int (*Func_dup)(int); 33 typedef ssize_t (*Func_read)(int, void*, size_t); 34 typedef ssize_t (*Func_readv)(int, const struct iovec*, int); 35 typedef ssize_t (*Func_write)(int, const void*, size_t); 36 typedef ssize_t (*Func_writev)(int, const struct iovec*, int); 37 typedef void* (*Func_mmap)(void*, size_t, int, int, int, __off_t); 38 typedef void* (*Func_mmap64)(void*, size_t, int, int, int, __off64_t); 39 typedef int (*Func_ioctl)(int, int, void*); 40 41 typedef int (*Func_chdir)(const char*); 42 typedef int (*Func_chmod)(const char*, mode_t); 43 typedef int (*Func_chown)(const char*, uid_t, uid_t); 44 typedef int (*Func_creat)(const char*, mode_t); 45 typedef int (*Func_execve)(const char*, char* const[], char* const[]); 46 typedef char* (*Func_getcwd)(char* buf, size_t size); 47 typedef int (*Func_lchown)(const char*, uid_t, uid_t); 48 typedef int (*Func_link)(const char*, const char*); 49 typedef int (*Func_lstat)(const char*, struct stat*); 50 typedef int (*Func_lstat64)(const char*, struct stat*); 51 typedef int (*Func___lxstat)(int version, const char*, struct stat*); 52 typedef int (*Func___lxstat64)(int version, const char*, struct stat*); 53 typedef int (*Func_mkdir)(const char*, mode_t mode); 54 typedef ssize_t (*Func_readlink)(const char*, char*, size_t); 55 typedef int (*Func_rename)(const char*, const char*); 56 typedef int (*Func_rmdir)(const char*); 57 typedef int (*Func_stat)(const char*, struct stat*); 58 typedef int (*Func_stat64)(const char*, struct stat*); 59 typedef int (*Func___xstat)(int version, const char*, struct stat*); 60 typedef int (*Func___xstat64)(int version, const char*, struct stat*); 61 typedef int (*Func_statfs)(const char*, struct statfs*); 62 typedef int (*Func_statfs64)(const char*, struct statfs*); 63 typedef int (*Func_symlink)(const char*, const char*); 64 typedef int (*Func_unlink)(const char*); 65 typedef int (*Func_utime)(const char*, const struct utimbuf*); 66 typedef int (*Func_utimes)(const char*, const struct timeval []); 67 68 typedef int (*Func_execl)(const char*, const char*, ...); 69 typedef int (*Func_execle)(const char*, const char*, ...); 70 typedef int (*Func_execlp)(const char*, const char*, ...); 71 typedef int (*Func_execv)(const char*, char* const []); 72 typedef int (*Func_execvp)(const char*, char* const []); 73 typedef FILE* (*Func_fopen)(const char*, const char*); 74 typedef FILE* (*Func_fopen64)(const char*, const char*); 75 typedef FILE* (*Func_freopen)(const char*, const char*, FILE*); 76 typedef int (*Func_ftw)(const char*, 77 int (*fn) (const char*, const struct stat*, int), 78 int); 79 typedef DIR* (*Func_opendir)(const char* path); 80 typedef void* (*Func_dlopen)(const char*, int); 81 82 typedef int (*Func_setpriority)(int, int, int); 83 //typedef int (*Func_pipe)(int [2]); 84 85 86 /* 87 * Pointers to the actual implementations. 88 */ 89 #ifndef CREATE_FUNC_STORAGE 90 # define EXTERN_FUNC extern 91 #else 92 # define EXTERN_FUNC 93 #endif 94 EXTERN_FUNC Func_access _ws_access; 95 EXTERN_FUNC Func_open _ws_open; 96 EXTERN_FUNC Func_open64 _ws_open64; 97 98 EXTERN_FUNC Func_close _ws_close; 99 EXTERN_FUNC Func_dup _ws_dup; 100 EXTERN_FUNC Func_read _ws_read; 101 EXTERN_FUNC Func_readv _ws_readv; 102 EXTERN_FUNC Func_write _ws_write; 103 EXTERN_FUNC Func_writev _ws_writev; 104 EXTERN_FUNC Func_mmap _ws_mmap; 105 EXTERN_FUNC Func_mmap64 _ws_mmap64; 106 EXTERN_FUNC Func_ioctl _ws_ioctl; 107 108 EXTERN_FUNC Func_chdir _ws_chdir; 109 EXTERN_FUNC Func_chmod _ws_chmod; 110 EXTERN_FUNC Func_chown _ws_chown; 111 EXTERN_FUNC Func_creat _ws_creat; 112 EXTERN_FUNC Func_execve _ws_execve; 113 EXTERN_FUNC Func_getcwd _ws_getcwd; 114 EXTERN_FUNC Func_lchown _ws_lchown; 115 EXTERN_FUNC Func_link _ws_link; 116 EXTERN_FUNC Func_lstat _ws_lstat; 117 EXTERN_FUNC Func_lstat64 _ws_lstat64; 118 EXTERN_FUNC Func___lxstat _ws___lxstat; 119 EXTERN_FUNC Func___lxstat64 _ws___lxstat64; 120 EXTERN_FUNC Func_mkdir _ws_mkdir; 121 EXTERN_FUNC Func_readlink _ws_readlink; 122 EXTERN_FUNC Func_rename _ws_rename; 123 EXTERN_FUNC Func_rmdir _ws_rmdir; 124 EXTERN_FUNC Func_stat _ws_stat; 125 EXTERN_FUNC Func_stat64 _ws_stat64; 126 EXTERN_FUNC Func___xstat _ws___xstat; 127 EXTERN_FUNC Func___xstat64 _ws___xstat64; 128 EXTERN_FUNC Func_statfs _ws_statfs; 129 EXTERN_FUNC Func_statfs64 _ws_statfs64; 130 EXTERN_FUNC Func_symlink _ws_symlink; 131 EXTERN_FUNC Func_unlink _ws_unlink; 132 EXTERN_FUNC Func_utime _ws_utime; 133 EXTERN_FUNC Func_utimes _ws_utimes; 134 135 EXTERN_FUNC Func_execl _ws_execl; 136 EXTERN_FUNC Func_execle _ws_execle; 137 EXTERN_FUNC Func_execlp _ws_execlp; 138 EXTERN_FUNC Func_execv _ws_execv; 139 EXTERN_FUNC Func_execvp _ws_execvp; 140 EXTERN_FUNC Func_fopen _ws_fopen; 141 EXTERN_FUNC Func_fopen64 _ws_fopen64; 142 EXTERN_FUNC Func_freopen _ws_freopen; 143 EXTERN_FUNC Func_ftw _ws_ftw; 144 EXTERN_FUNC Func_opendir _ws_opendir; 145 EXTERN_FUNC Func_dlopen _ws_dlopen; 146 147 EXTERN_FUNC Func_setpriority _ws_setpriority; 148 //EXTERN_FUNC Func_pipe _ws_pipe; 149 150 #define kMaxDisplays 4 151 152 /* 153 * Global values. Must be initialized in initGlobals(), which is executed 154 * the first time somebody calls dlopen on the wrapper lib. 155 */ 156 struct WrapSimGlobals { 157 volatile int initialized; 158 159 /* descriptor where we write log messages */ 160 int logFd; 161 162 /* socket for communicating with simulator front-end */ 163 int simulatorFd; 164 165 /* coordinate thread startup */ 166 pthread_mutex_t startLock; 167 pthread_cond_t startCond; 168 int startReady; 169 int simulatorInitFailed; 170 171 /* base directory for filename remapping */ 172 char* remapBaseDir; 173 int remapBaseDirLen; 174 175 /* 176 * Display characteristics. 177 * 178 * TODO: this is retrieved from the simulator during initial config. 179 * It needs to be visible to whatever process holds the surfaceflinger, 180 * which may or may not be the initial process in multi-process mode. 181 * We probably want to get the display config via a query, performed at 182 * intercepted-ioctl time, rather than a push from the sim at startup. 183 */ 184 struct { 185 int width; 186 int height; 187 188 int shmemKey; 189 int shmid; 190 void* addr; 191 long length; 192 int semid; 193 } display[kMaxDisplays]; 194 int numDisplays; 195 196 /* 197 * Input device. 198 */ 199 FakeDev* keyInputDevice; 200 const char *keyMap; 201 202 /* fake file descriptor allocation map */ 203 pthread_mutex_t fakeFdLock; 204 BitVector* fakeFdMap; 205 FakeDev* fakeFdList[kMaxFakeFdCount]; 206 207 /* used for wsAtomicAdd */ 208 pthread_mutex_t atomicLock; 209 }; 210 211 extern struct WrapSimGlobals gWrapSim; 212 213 #endif /*_WRAPSIM_GLOBALS_H*/ 214