1 /*****************************************************************************
2 * override.c: overriden function calls for VLC media player
3 *****************************************************************************
4 * Copyright (C) 2010 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
27 void vlc_enable_override (void);
29 static bool override = false;
31 void vlc_enable_override (void)
36 #if defined (__GNUC__) /* typeof and statement-expression */ \
37 && (defined (__ELF__) && !defined (__sun__))
38 /* Solaris crashes on printf("%s", NULL); which is legal, but annoying. */
46 static void vlogbug (const char *level, const char *func, const char *fmt,
50 fprintf (stderr, "%s: call to %s(", level, func);
51 vfprintf (stderr, fmt, ap);
52 fputs (")\n", stderr);
56 static void logbug (const char *level, const char *func, const char *fmt, ...)
61 vlogbug (level, func, fmt, ap);
65 static void *getsym (const char *name)
67 void *sym = dlsym (RTLD_NEXT, name);
70 fprintf (stderr, "Cannot resolve symbol %s!\n", name);
76 #define LOG(level, ...) logbug(level, __func__, __VA_ARGS__)
77 #define CALL(func, ...) \
78 ({ typeof (func) *sym = getsym ( # func); sym (__VA_ARGS__); })
83 * "Conforming multi-threaded applications shall not use the environ variable
84 * to access or modify any environment variable while any other thread is
85 * concurrently modifying any environment variable." -- POSIX.
87 * Some evil libraries modify the environment. We currently ignore the calls as
88 * they could crash the process. This may cause funny behaviour though. */
89 int putenv (char *str)
93 LOG("Blocked", "\"%s\"", str);
96 return CALL(putenv, str);
99 int setenv (const char *name, const char *value, int overwrite)
103 LOG("Blocked", "\"%s\", \"%s\", %d", name, value, overwrite);
106 return CALL(setenv, name, value, overwrite);
109 int unsetenv (const char *name)
113 LOG("Blocked", "\"%s\"", name);
116 return CALL(unsetenv, name);
120 /*** Pseudo random numbers ***
122 * The C PRNG is not thread-safe (and generally sucks, the POSIX 48-bits PRNG
123 * is much better as a reproducible non-secure PRNG). To work around this, we
124 * force evil callers to serialize. This makes the call safe, but fails to
125 * preserve reproducibility of the number sequence (which usually does not
128 static pthread_mutex_t prng_lock = PTHREAD_MUTEX_INITIALIZER;
130 void srand (unsigned int seed)
132 pthread_mutex_lock (&prng_lock);
133 LOG("Warning", "%d", seed);
135 pthread_mutex_unlock (&prng_lock);
142 pthread_mutex_lock (&prng_lock);
145 pthread_mutex_unlock (&prng_lock);