/xbmc/cores/DllLoader/exports/wrapper.c

http://github.com/xbmc/xbmc · C · 494 lines · 397 code · 81 blank · 16 comment · 2 complexity · a000f23f341fd192d440c137616f7bf3 MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2018 Team Kodi
  3. * This file is part of Kodi - https://kodi.tv
  4. *
  5. * SPDX-License-Identifier: GPL-2.0-or-later
  6. * See LICENSES/README.md for more information.
  7. */
  8. //
  9. // To recreate wrapper.def:
  10. //
  11. // bash# (echo -n "-Wl"; grep __wrap wrapper.c | grep -v bash | sed "s/.*__wrap_//g" | sed "s/(.*//g" | awk '{printf(",-wrap,%s",$0);}') > wrapper.def
  12. //
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #if !defined(TARGET_ANDROID)
  16. #include <sys/statvfs.h>
  17. #endif
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <stdarg.h>
  22. #include <dirent.h>
  23. #include <dlfcn.h>
  24. #if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_ANDROID)
  25. typedef off_t __off_t;
  26. typedef int64_t off64_t;
  27. typedef off64_t __off64_t;
  28. typedef fpos_t fpos64_t;
  29. #define stat64 stat
  30. #endif
  31. #ifdef TARGET_POSIX
  32. #define _stat stat
  33. #endif
  34. struct mntent;
  35. void* dllmalloc(size_t );
  36. void* dllcalloc( size_t , size_t );
  37. void* dllrealloc(void*, size_t);
  38. void dllfree(void*);
  39. int dll_open(const char* szFileName, int iMode);
  40. int dll_write(int fd, const void* buffer, unsigned int uiSize);
  41. int dll_read(int fd, void* buffer, unsigned int uiSize);
  42. off_t dll_lseek(int fd, __off_t lPos, int iWhence);
  43. __off64_t dll_lseeki64(int fd, __off64_t lPos, int iWhence);
  44. int dll_close(int fd);
  45. FILE * dll_fopen (const char * filename, const char * mode);
  46. FILE* dll_freopen(const char *path, const char *mode, FILE *stream);
  47. FILE* dll_fdopen(int i, const char* file);
  48. int dll_fclose (FILE * stream);
  49. int dll_ferror (FILE * stream);
  50. int dll_feof (FILE * stream);
  51. int dll_fileno(FILE* stream);
  52. void dll_clearerr(FILE* stream);
  53. int dll_fread (void * buffer, size_t size, size_t count, FILE * stream);
  54. size_t dll_fwrite ( const void * buffer, size_t size, size_t count, FILE * stream );
  55. int dll_fflush (FILE * stream);
  56. int dll_fputc (int character, FILE * stream);
  57. int dll_fputs (const char * szLine , FILE* stream);
  58. int dll_putc(int c, FILE *stream);
  59. int dll_fseek ( FILE * stream , long offset , int origin );
  60. int dll_fseek64(FILE *stream, off64_t offset, int origin);
  61. long dll_ftell(FILE *stream);
  62. off64_t dll_ftell64(FILE *stream);
  63. void dll_rewind(FILE* stream);
  64. int dll_fgetpos(FILE* stream, fpos_t* pos);
  65. int dll_fgetpos64(FILE *stream, fpos64_t *pos);
  66. int dll_fsetpos(FILE* stream, const fpos_t* pos);
  67. int dll_fsetpos64(FILE* stream, const fpos64_t* pos);
  68. DIR* dll_opendir(const char* name);
  69. struct dirent* dll_readdir(DIR* dirp);
  70. int dll_closedir(DIR* dirp);
  71. void dll_rewinddir(DIR* dirp);
  72. int dll_fprintf(FILE* stream , const char * format, ...);
  73. int dllprintf(const char *format, ...);
  74. int dll_vfprintf(FILE *stream, const char *format, va_list va);
  75. int dll_fgetc (FILE* stream);
  76. char * dll_fgets (char* pszString, int num , FILE * stream);
  77. int dll_getc (FILE * stream);
  78. int dll_ungetc (int c, FILE * stream);
  79. int dll_ioctl(int d, unsigned long int request, va_list va);
  80. int dll_stat(const char *path, struct _stat *buffer);
  81. int dll_stat64(const char *path, struct stat64 *buffer);
  82. void dll_flockfile(FILE *file);
  83. int dll_ftrylockfile(FILE *file);
  84. void dll_funlockfile(FILE *file);
  85. int dll_fstat64(int fd, struct stat64 *buf);
  86. int dll_fstat(int fd, struct _stat *buf);
  87. FILE* dll_popen(const char *command, const char *mode);
  88. void* dll_dlopen(const char *filename, int flag);
  89. int dll_setvbuf(FILE *stream, char *buf, int type, size_t size);
  90. struct mntent *dll_getmntent(FILE *fp);
  91. void *__wrap_dlopen(const char *filename, int flag)
  92. {
  93. return dlopen(filename, flag);
  94. }
  95. FILE *__wrap_popen(const char *command, const char *mode)
  96. {
  97. return dll_popen(command, mode);
  98. }
  99. void* __wrap_calloc( size_t num, size_t size )
  100. {
  101. return dllcalloc(num, size);
  102. }
  103. void* __wrap_malloc(size_t size)
  104. {
  105. return dllmalloc(size);
  106. }
  107. void* __wrap_realloc( void *memblock, size_t size )
  108. {
  109. return dllrealloc(memblock, size);
  110. }
  111. void __wrap_free( void* pPtr )
  112. {
  113. dllfree(pPtr);
  114. }
  115. int __wrap_open(const char *file, int oflag, ...)
  116. {
  117. return dll_open(file, oflag);
  118. }
  119. int __wrap_open64(const char *file, int oflag, ...)
  120. {
  121. return dll_open(file, oflag);
  122. }
  123. int __wrap_close(int fd)
  124. {
  125. return dll_close(fd);
  126. }
  127. ssize_t __wrap_write(int fd, const void *buf, size_t count)
  128. {
  129. return dll_write(fd, buf, count);
  130. }
  131. ssize_t __wrap_read(int fd, void *buf, size_t count)
  132. {
  133. return dll_read(fd, buf, count);
  134. }
  135. __off_t __wrap_lseek(int filedes, __off_t offset, int whence)
  136. {
  137. return dll_lseek(filedes, offset, whence);
  138. }
  139. __off64_t __wrap_lseek64(int filedes, __off64_t offset, int whence)
  140. {
  141. __off64_t seekRes = dll_lseeki64(filedes, offset, whence);
  142. return seekRes;
  143. }
  144. int __wrap_fclose(FILE *fp)
  145. {
  146. return dll_fclose(fp);
  147. }
  148. int __wrap_ferror(FILE *stream)
  149. {
  150. return dll_ferror(stream);
  151. }
  152. void __wrap_clearerr(FILE *stream)
  153. {
  154. dll_clearerr(stream);
  155. }
  156. int __wrap_feof(FILE *stream)
  157. {
  158. return dll_feof(stream);
  159. }
  160. int __wrap_fileno(FILE *stream)
  161. {
  162. return dll_fileno(stream);
  163. }
  164. FILE *__wrap_fopen(const char *path, const char *mode)
  165. {
  166. return dll_fopen(path, mode);
  167. }
  168. FILE *__wrap_fopen64(const char *path, const char *mode)
  169. {
  170. return dll_fopen(path, mode);
  171. }
  172. FILE *__wrap_fdopen(int filedes, const char *mode)
  173. {
  174. return dll_fdopen(filedes, mode);
  175. }
  176. FILE *__wrap_freopen(const char *path, const char *mode, FILE *stream)
  177. {
  178. return dll_freopen(path, mode, stream);
  179. }
  180. size_t __wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
  181. {
  182. return dll_fread(ptr, size, nmemb, stream);
  183. }
  184. size_t __wrap_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  185. {
  186. return dll_fwrite(ptr, size, nmemb, stream);
  187. }
  188. int __wrap_fflush(FILE *stream)
  189. {
  190. return dll_fflush(stream);
  191. }
  192. int __wrap_fputc(int c, FILE *stream)
  193. {
  194. return dll_fputc(c, stream);
  195. }
  196. int __wrap_fputs(const char *s, FILE *stream)
  197. {
  198. return dll_fputs(s, stream);
  199. }
  200. int __wrap__IO_putc(int c, FILE *stream)
  201. {
  202. return dll_putc(c, stream);
  203. }
  204. int __wrap_fseek(FILE *stream, long offset, int whence)
  205. {
  206. return dll_fseek(stream, offset, whence);
  207. }
  208. int __wrap_fseeko64(FILE *stream, off64_t offset, int whence)
  209. {
  210. return dll_fseek64(stream, offset, whence);
  211. }
  212. long __wrap_ftell(FILE *stream)
  213. {
  214. return dll_ftell(stream);
  215. }
  216. off64_t __wrap_ftello64(FILE *stream)
  217. {
  218. return dll_ftell64(stream);
  219. }
  220. void __wrap_rewind(FILE *stream)
  221. {
  222. dll_rewind(stream);
  223. }
  224. int __wrap_fgetpos(FILE *stream, fpos_t *pos)
  225. {
  226. return dll_fgetpos(stream, pos);
  227. }
  228. int __wrap_fgetpos64(FILE *stream, fpos64_t *pos)
  229. {
  230. return dll_fgetpos64(stream, pos);
  231. }
  232. int __wrap_fsetpos(FILE *stream, fpos_t *pos)
  233. {
  234. return dll_fsetpos(stream, pos);
  235. }
  236. int __wrap_fsetpos64(FILE *stream, fpos64_t *pos)
  237. {
  238. return dll_fsetpos64(stream, pos);
  239. }
  240. DIR * __wrap_opendir(const char *name)
  241. {
  242. return dll_opendir(name);
  243. }
  244. struct dirent * __wrap_readdir(DIR* dirp)
  245. {
  246. return dll_readdir(dirp);
  247. }
  248. struct dirent * __wrap_readdir64(DIR* dirp)
  249. {
  250. return dll_readdir(dirp);
  251. }
  252. int __wrap_closedir(DIR* dirp)
  253. {
  254. return dll_closedir(dirp);
  255. }
  256. void __wrap_rewinddir(DIR* dirp)
  257. {
  258. dll_rewinddir(dirp);
  259. }
  260. int __wrap_fprintf(FILE *stream, const char *format, ...)
  261. {
  262. int res;
  263. va_list va;
  264. va_start(va, format);
  265. res = dll_vfprintf(stream, format, va);
  266. va_end(va);
  267. return res;
  268. }
  269. int __wrap_vfprintf(FILE *stream, const char *format, va_list ap)
  270. {
  271. return dll_vfprintf(stream, format, ap);
  272. }
  273. int __wrap_printf(const char *format, ...)
  274. {
  275. int res;
  276. va_list va;
  277. va_start(va, format);
  278. res = dll_vfprintf(stdout, format, va);
  279. va_end(va);
  280. return res;
  281. }
  282. int __wrap_fgetc(FILE *stream)
  283. {
  284. return dll_fgetc(stream);
  285. }
  286. char *__wrap_fgets(char *s, int size, FILE *stream)
  287. {
  288. return dll_fgets(s, size, stream);
  289. }
  290. int __wrap__IO_getc(FILE *stream)
  291. {
  292. return dll_getc(stream);
  293. }
  294. int __wrap__IO_getc_unlocked(FILE *stream)
  295. {
  296. return dll_getc(stream);
  297. }
  298. int __wrap_getc_unlocked(FILE *stream)
  299. {
  300. return dll_getc(stream);
  301. }
  302. int __wrap_ungetc(int c, FILE *stream)
  303. {
  304. return dll_ungetc(c, stream);
  305. }
  306. int __wrap_getc(FILE *stream)
  307. {
  308. return dll_getc(stream);
  309. }
  310. int __wrap_ioctl(int d, unsigned long int request, ...)
  311. {
  312. int res;
  313. va_list va;
  314. va_start(va, request);
  315. res = dll_ioctl(d, request, va);
  316. va_end(va);
  317. return res;
  318. }
  319. int __wrap__stat(const char *path, struct _stat *buffer)
  320. {
  321. return dll_stat(path, buffer);
  322. }
  323. int __wrap_stat(const char *path, struct _stat *buffer)
  324. {
  325. return dll_stat(path, buffer);
  326. }
  327. int __wrap___xstat(int __ver, const char *__filename, struct stat *__stat_buf)
  328. {
  329. return dll_stat(__filename, __stat_buf);
  330. }
  331. int __wrap___xstat64(int __ver, const char *__filename, struct stat64 *__stat_buf)
  332. {
  333. return dll_stat64(__filename, __stat_buf);
  334. }
  335. int __wrap___lxstat64(int __ver, const char *__filename, struct stat64 *__stat_buf)
  336. {
  337. return dll_stat64(__filename, __stat_buf);
  338. }
  339. void __wrap_flockfile(FILE *file)
  340. {
  341. dll_flockfile(file);
  342. }
  343. int __wrap_ftrylockfile(FILE *file)
  344. {
  345. return dll_ftrylockfile(file);
  346. }
  347. void __wrap_funlockfile(FILE *file)
  348. {
  349. dll_funlockfile(file);
  350. }
  351. int __wrap___fxstat64(int ver, int fd, struct stat64 *buf)
  352. {
  353. return dll_fstat64(fd, buf);
  354. }
  355. int __wrap___fxstat(int ver, int fd, struct stat *buf)
  356. {
  357. return dll_fstat(fd, buf);
  358. }
  359. int __wrap_fstat(int fd, struct _stat *buf)
  360. {
  361. return dll_fstat(fd, buf);
  362. }
  363. int __wrap_setvbuf(FILE *stream, char *buf, int type, size_t size)
  364. {
  365. return dll_setvbuf(stream, buf, type, size);
  366. }
  367. struct mntent *__wrap_getmntent(FILE *fp)
  368. {
  369. #ifdef TARGET_POSIX
  370. return dll_getmntent(fp);
  371. #endif
  372. return NULL;
  373. }
  374. // GCC 4.3 in Ubuntu 8.10 defines _FORTIFY_SOURCE=2 which means, that fread, read etc
  375. // are actually #defines which are inlined when compiled with -O. Those defines
  376. // actually call __*chk (for example, __fread_chk). We need to bypass this whole
  377. // thing to actually call our wrapped functions.
  378. #if _FORTIFY_SOURCE > 1
  379. size_t __wrap___fread_chk(void * ptr, size_t ptrlen, size_t size, size_t n, FILE * stream)
  380. {
  381. return dll_fread(ptr, size, n, stream);
  382. }
  383. int __wrap___printf_chk(int flag, const char *format, ...)
  384. {
  385. int res;
  386. va_list va;
  387. va_start(va, format);
  388. res = dll_vfprintf(stdout, format, va);
  389. va_end(va);
  390. return res;
  391. }
  392. int __wrap___vfprintf_chk(FILE* stream, int flag, const char *format, va_list ap)
  393. {
  394. return dll_vfprintf(stream, format, ap);
  395. }
  396. int __wrap___fprintf_chk(FILE * stream, int flag, const char *format, ...)
  397. {
  398. int res;
  399. va_list va;
  400. va_start(va, format);
  401. res = dll_vfprintf(stream, format, va);
  402. va_end(va);
  403. return res;
  404. }
  405. char *__wrap___fgets_chk(char *s, size_t size, int n, FILE *stream)
  406. {
  407. return dll_fgets(s, n, stream);
  408. }
  409. size_t __wrap___read_chk(int fd, void *buf, size_t nbytes, size_t buflen)
  410. {
  411. return dll_read(fd, buf, nbytes);
  412. }
  413. #endif