mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	padsp: wrap __open_2 and __open64_2
These functions are used in OSS programs where the "flags" parameter for open() is not a build-time constant and the build has _FORTIFY_SOURCE enabled.
This commit is contained in:
		
							parent
							
								
									95ccbf7346
								
							
						
					
					
						commit
						4bb8a83c62
					
				
					 1 changed files with 52 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -118,6 +118,7 @@ static PA_LLIST_HEAD(fd_info, fd_infos) = NULL;
 | 
			
		|||
static int (*_ioctl)(int, int, void*) = NULL;
 | 
			
		||||
static int (*_close)(int) = NULL;
 | 
			
		||||
static int (*_open)(const char *, int, mode_t) = NULL;
 | 
			
		||||
static int (*___open_2)(const char *, int) = NULL;
 | 
			
		||||
static FILE* (*_fopen)(const char *path, const char *mode) = NULL;
 | 
			
		||||
static int (*_stat)(const char *, struct stat *) = NULL;
 | 
			
		||||
#ifdef _STAT_VER
 | 
			
		||||
| 
						 | 
				
			
			@ -125,6 +126,7 @@ static int (*___xstat)(int, const char *, struct stat *) = NULL;
 | 
			
		|||
#endif
 | 
			
		||||
#ifdef HAVE_OPEN64
 | 
			
		||||
static int (*_open64)(const char *, int, mode_t) = NULL;
 | 
			
		||||
static int (*___open64_2)(const char *, int) = NULL;
 | 
			
		||||
static FILE* (*_fopen64)(const char *path, const char *mode) = NULL;
 | 
			
		||||
static int (*_stat64)(const char *, struct stat64 *) = NULL;
 | 
			
		||||
#ifdef _STAT_VER
 | 
			
		||||
| 
						 | 
				
			
			@ -157,6 +159,14 @@ do { \
 | 
			
		|||
    pthread_mutex_unlock(&func_mutex); \
 | 
			
		||||
} while(0)
 | 
			
		||||
 | 
			
		||||
#define LOAD___OPEN_2_FUNC() \
 | 
			
		||||
do { \
 | 
			
		||||
    pthread_mutex_lock(&func_mutex); \
 | 
			
		||||
    if (!___open_2) \
 | 
			
		||||
        ___open_2 = (int (*)(const char *, int)) dlsym_fn(RTLD_NEXT, "__open_2"); \
 | 
			
		||||
    pthread_mutex_unlock(&func_mutex); \
 | 
			
		||||
} while(0)
 | 
			
		||||
 | 
			
		||||
#define LOAD_OPEN64_FUNC() \
 | 
			
		||||
do { \
 | 
			
		||||
    pthread_mutex_lock(&func_mutex); \
 | 
			
		||||
| 
						 | 
				
			
			@ -165,6 +175,14 @@ do { \
 | 
			
		|||
    pthread_mutex_unlock(&func_mutex); \
 | 
			
		||||
} while(0)
 | 
			
		||||
 | 
			
		||||
#define LOAD___OPEN64_2_FUNC() \
 | 
			
		||||
do { \
 | 
			
		||||
    pthread_mutex_lock(&func_mutex); \
 | 
			
		||||
    if (!___open64_2) \
 | 
			
		||||
        ___open64_2 = (int (*)(const char *, int)) dlsym_fn(RTLD_NEXT, "__open64_2"); \
 | 
			
		||||
    pthread_mutex_unlock(&func_mutex); \
 | 
			
		||||
} while(0)
 | 
			
		||||
 | 
			
		||||
#define LOAD_CLOSE_FUNC() \
 | 
			
		||||
do { \
 | 
			
		||||
    pthread_mutex_lock(&func_mutex); \
 | 
			
		||||
| 
						 | 
				
			
			@ -1494,6 +1512,27 @@ int open(const char *filename, int flags, ...) {
 | 
			
		|||
    return real_open(filename, flags, mode);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static pa_bool_t is_audio_device_node(const char *path) {
 | 
			
		||||
    return
 | 
			
		||||
        pa_streq(path, "/dev/dsp") ||
 | 
			
		||||
        pa_streq(path, "/dev/adsp") ||
 | 
			
		||||
        pa_streq(path, "/dev/audio") ||
 | 
			
		||||
        pa_streq(path, "/dev/sndstat") ||
 | 
			
		||||
        pa_streq(path, "/dev/mixer");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int __open_2(const char *filename, int flags) {
 | 
			
		||||
    debug(DEBUG_LEVEL_VERBOSE, __FILE__": __open_2(%s)\n", filename?filename:"NULL");
 | 
			
		||||
 | 
			
		||||
    if ((flags & O_CREAT) ||
 | 
			
		||||
        !filename ||
 | 
			
		||||
        !is_audio_device_node(filename)) {
 | 
			
		||||
        LOAD___OPEN_2_FUNC();
 | 
			
		||||
        return ___open_2(filename, flags);
 | 
			
		||||
    }
 | 
			
		||||
    return real_open(filename, flags, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int mixer_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno) {
 | 
			
		||||
    int ret = -1;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2383,15 +2422,6 @@ int close(int fd) {
 | 
			
		|||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static pa_bool_t is_audio_device_node(const char *path) {
 | 
			
		||||
    return
 | 
			
		||||
        pa_streq(path, "/dev/dsp") ||
 | 
			
		||||
        pa_streq(path, "/dev/adsp") ||
 | 
			
		||||
        pa_streq(path, "/dev/audio") ||
 | 
			
		||||
        pa_streq(path, "/dev/sndstat") ||
 | 
			
		||||
        pa_streq(path, "/dev/mixer");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int access(const char *pathname, int mode) {
 | 
			
		||||
 | 
			
		||||
    debug(DEBUG_LEVEL_VERBOSE, __FILE__": access(%s)\n", pathname?pathname:"NULL");
 | 
			
		||||
| 
						 | 
				
			
			@ -2527,6 +2557,19 @@ int open64(const char *filename, int flags, ...) {
 | 
			
		|||
    return real_open(filename, flags, mode);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int __open64_2(const char *filename, int flags) {
 | 
			
		||||
    debug(DEBUG_LEVEL_VERBOSE, __FILE__": __open64_2(%s)\n", filename?filename:"NULL");
 | 
			
		||||
 | 
			
		||||
    if ((flags & O_CREAT) ||
 | 
			
		||||
        !filename ||
 | 
			
		||||
        !is_audio_device_node(filename)) {
 | 
			
		||||
        LOAD___OPEN64_2_FUNC();
 | 
			
		||||
        return ___open64_2(filename, flags);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return real_open(filename, flags, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef _STAT_VER
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue