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