annotate src/loadso/macosx/SDL_dlcompat.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 14717b52abc0
children 4da1ee79c9af
rev   line source
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #ifdef SDL_LOADSO_DLCOMPAT
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 /* Please note that dlcompat apparently ships in current Mac OS X versions
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 * as a system library that provides compatibility with the Unix "dlopen"
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 * interface. In order to allow SDL to work on older OS X releases and also
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 * not conflict with the system lib on newer versions, we include dlcompat
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 * in SDL and change the symbols to prevent symbol clash with any existing
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 * system libraries. --ryan.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 /* here is the dlcompat license: */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 /*
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 Copyright (c) 2002 Jorge Acereda <jacereda@users.sourceforge.net> &
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 Peter O'Gorman <ogorman@users.sourceforge.net>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 Portions may be copyright others, see the AUTHORS file included with this
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 distribution.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 Maintained by Peter O'Gorman <ogorman@users.sourceforge.net>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 Bug Reports and other queries should go to <ogorman@users.sourceforge.net>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 Permission is hereby granted, free of charge, to any person obtaining
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 a copy of this software and associated documentation files (the
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 "Software"), to deal in the Software without restriction, including
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 without limitation the rights to use, copy, modify, merge, publish,
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 distribute, sublicense, and/or sell copies of the Software, and to
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 permit persons to whom the Software is furnished to do so, subject to
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 the following conditions:
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 The above copyright notice and this permission notice shall be
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 included in all copies or substantial portions of the Software.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 #include <pthread.h>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 #include <sys/types.h>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 #include <sys/stat.h>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 #include <stdarg.h>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 #include <limits.h>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 #include <mach-o/dyld.h>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 #include <mach-o/nlist.h>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 #include <mach-o/getsect.h>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 #include "SDL_stdinc.h"
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 /* Just playing to see if it would compile with the freebsd headers, it does,
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 * but because of the different values for RTLD_LOCAL etc, it would break binary
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 * compat... oh well
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 #ifndef __BSD_VISIBLE
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 #define __BSD_VISIBLE 1
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 /*include "dlfcn.h"*/
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 #ifdef __cplusplus
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
88 extern "C"
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
89 {
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 #if defined (__GNUC__) && __GNUC__ > 3
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 #define dl_restrict __restrict
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 #else
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 #define dl_restrict
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 #if 0
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 #ifndef _POSIX_SOURCE
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 /*
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 * Structure filled in by dladdr().
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
103 typedef struct SDL_OSX_dl_info
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
104 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
105 const char *dli_fname; /* Pathname of shared object */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
106 void *dli_fbase; /* Base address of shared object */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
107 const char *dli_sname; /* Name of nearest symbol */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
108 void *dli_saddr; /* Address of nearest symbol */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
109 } SDL_OSX_Dl_info;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
111 static int SDL_OSX_dladdr (const void *dl_restrict,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
112 SDL_OSX_Dl_info * dl_restrict);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
113 #endif /* ! _POSIX_SOURCE */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
114 #endif /* 0 */
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
116 static int SDL_OSX_dlclose (void *handle);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
117 static const char *SDL_OSX_dlerror (void);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
118 static void *SDL_OSX_dlopen (const char *path, int mode);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
119 static void *SDL_OSX_dlsym (void *dl_restrict handle,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
120 const char *dl_restrict symbol);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 #define RTLD_LAZY 0x1
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 #define RTLD_NOW 0x2
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 #define RTLD_LOCAL 0x4
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 #define RTLD_GLOBAL 0x8
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 #ifndef _POSIX_SOURCE
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 #define RTLD_NOLOAD 0x10
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 #define RTLD_NODELETE 0x80
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 /*
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 * Special handle arguments for SDL_OSX_dlsym().
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
134 #define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
135 #define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
136 #endif /* ! _POSIX_SOURCE */
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 #ifdef __cplusplus
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 #ifndef dl_restrict
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 #define dl_restrict __restrict
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 /* This is not available on 10.1 */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 #ifndef LC_LOAD_WEAK_DYLIB
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 #define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 /* With this stuff here, this thing may actually compile/run on 10.0 systems
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 * Not that I have a 10.0 system to test it on anylonger
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 #ifndef LC_REQ_DYLD
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 #define LC_REQ_DYLD 0x80000000
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 #ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 #define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 #ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 #define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 #ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 #ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 #define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 /* These symbols will be looked for in dyld */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
169 static const struct mach_header *(*dyld_NSAddImage) (const char *,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
170 unsigned long) = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
171 static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
172 const char *) = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
173 static NSSymbol (*dyld_NSLookupSymbolInImage) (const struct mach_header *,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
174 const char *, unsigned long) =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
175 0;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 /* Define this to make dlcompat reuse data block. This way in theory we save
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 * a little bit of overhead. However we then couldn't correctly catch excess
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 * calls to SDL_OSX_dlclose(). Hence we don't use this feature
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 #undef REUSE_STATUS
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 /* Size of the internal error message buffer (used by dlerror()) */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 #define ERR_STR_LEN 251
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 /* Maximum number of search paths supported by getSearchPath */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 #define MAX_SEARCH_PATHS 32
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 #define MAGIC_DYLIB_OFI ((NSObjectFileImage) 'DYOF')
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 #define MAGIC_DYLIB_MOD ((NSModule) 'DYMO')
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 /* internal flags */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 #define DL_IN_LIST 0x01
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 /* our mutex */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 static pthread_mutex_t dlcompat_mutex;
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 /* Our thread specific storage
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 static pthread_key_t dlerror_key;
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 struct dlthread
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
204 int lockcnt;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
205 unsigned char errset;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
206 char errstr[ERR_STR_LEN];
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 };
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 /* This is our central data structure. Whenever a module is loaded via
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 * SDL_OSX_dlopen(), we create such a struct.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 struct dlstatus
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
214 struct dlstatus *next; /* pointer to next element in the linked list */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
215 NSModule module;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
216 const struct mach_header *lib;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
217 int refs; /* reference count */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
218 int mode; /* mode in which this module was loaded */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
219 dev_t device;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
220 ino_t inode;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
221 int flags; /* Any internal flags we may need */
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 };
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 /* Head node of the dlstatus list */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
225 static struct dlstatus mainStatus =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
226 { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 };
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 static struct dlstatus *stqueue = &mainStatus;
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 /* Storage for the last error message (used by dlerror()) */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 /* static char err_str[ERR_STR_LEN]; */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 /* static int err_filled = 0; */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 /* Prototypes to internal functions */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
235 static void debug (const char *fmt, ...);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
236 static void error (const char *str, ...);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
237 static const char *safegetenv (const char *s);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
238 static const char *searchList (void);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
239 static const char *getSearchPath (int i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
240 static const char *getFullPath (int i, const char *file);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
241 static const struct stat *findFile (const char *file, const char **fullPath);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
242 static int isValidStatus (struct dlstatus *status);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
243 static inline int isFlagSet (int mode, int flag);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
244 static struct dlstatus *lookupStatus (const struct stat *sbuf);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
245 static void insertStatus (struct dlstatus *dls, const struct stat *sbuf);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
246 static int promoteLocalToGlobal (struct dlstatus *dls);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
247 static void *reference (struct dlstatus *dls, int mode);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
248 static void *dlsymIntern (struct dlstatus *dls, const char *symbol,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
249 int canSetError);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
250 static struct dlstatus *allocStatus (void);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
251 static struct dlstatus *loadModule (const char *path, const struct stat *sbuf,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
252 int mode);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
253 static NSSymbol search_linked_libs (const struct mach_header *mh,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
254 const char *symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
255 static const char *get_lib_name (const struct mach_header *mh);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
256 static const struct mach_header *get_mach_header_from_NSModule (NSModule mod);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
257 static void dlcompat_init_func (void);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
258 static inline void dlcompat_init_check (void);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
259 static inline void dolock (void);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
260 static inline void dounlock (void);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
261 static void dlerrorfree (void *data);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
262 static void resetdlerror (void);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
263 static const struct mach_header *my_find_image (const char *name);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
264 static const struct mach_header *image_for_address (const void *address);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
265 static inline char *dyld_error_str (void);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 #if FINK_BUILD
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 /* Two Global Functions */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
269 static void *dlsym_prepend_underscore (void *handle, const char *symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
270 static void *dlsym_auto_underscore (void *handle, const char *symbol);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 /* And their _intern counterparts */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
273 static void *dlsym_prepend_underscore_intern (void *handle,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
274 const char *symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
275 static void *dlsym_auto_underscore_intern (void *handle, const char *symbol);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 /* Functions */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
280 static void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
281 debug (const char *fmt, ...)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 {
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 #if DEBUG > 1
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
284 va_list arg;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
285 va_start (arg, fmt);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
286 fprintf (stderr, "DLDEBUG: ");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
287 vfprintf (stderr, fmt, arg);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
288 fprintf (stderr, "\n");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
289 fflush (stderr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
290 va_end (arg);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
294 static void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
295 error (const char *str, ...)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
297 va_list arg;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
298 struct dlthread *tss;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
299 char *err_str;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
300 va_start (arg, str);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
301 tss = pthread_getspecific (dlerror_key);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
302 err_str = tss->errstr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
303 SDL_strlcpy (err_str, "dlcompat: ", ERR_STR_LEN);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
304 vsnprintf (err_str + 10, ERR_STR_LEN - 10, str, arg);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
305 va_end (arg);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
306 debug ("ERROR: %s\n", err_str);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
307 tss->errset = 1;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
310 static void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
311 warning (const char *str)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 {
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 #if DEBUG > 0
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
314 fprintf (stderr, "WARNING: dlcompat: %s\n", str);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
318 static const char *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
319 safegetenv (const char *s)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
321 const char *ss = SDL_getenv (s);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
322 return ss ? ss : "";
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 /* because this is only used for debugging and error reporting functions, we
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 * don't really care about how elegant it is... it could use the load
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 * commands to find the install name of the library, but...
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
329 static const char *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
330 get_lib_name (const struct mach_header *mh)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
332 unsigned long count = _dyld_image_count ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
333 unsigned long i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
334 const char *val = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
335 if (mh) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
336 for (i = 0; i < count; i++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
337 if (mh == _dyld_get_image_header (i)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
338 val = _dyld_get_image_name (i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
339 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
340 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
341 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
342 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
343 return val;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 /* Returns the mach_header for the module bu going through all the loaded images
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 * and finding the one with the same name as the module. There really ought to be
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 * an api for doing this, would be faster, but there isn't one right now
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
350 static const struct mach_header *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
351 get_mach_header_from_NSModule (NSModule mod)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
353 const char *mod_name = NSNameOfModule (mod);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
354 const struct mach_header *mh = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
355 unsigned long count = _dyld_image_count ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
356 unsigned long i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
357 debug ("Module name: %s", mod_name);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
358 for (i = 0; i < count; i++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
359 if (!SDL_strcmp (mod_name, _dyld_get_image_name (i))) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
360 mh = _dyld_get_image_header (i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
361 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
362 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
363 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
364 return mh;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 /* Compute and return a list of all directories that we should search when
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 * /usr/lib and /lib. Since both of the environments variables can contain a
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 * list of colon seperated paths, we simply concat them and the two other paths
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 * into one big string, which we then can easily parse.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 * Splitting this string into the actual path list is done by getSearchPath()
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
376 static const char *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
377 searchList ()
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
379 size_t buf_size;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
380 static char *buf = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
381 const char *ldlp = safegetenv ("LD_LIBRARY_PATH");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
382 const char *dyldlp = safegetenv ("DYLD_LIBRARY_PATH");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
383 const char *stdpath = SDL_getenv ("DYLD_FALLBACK_LIBRARY_PATH");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
384 if (!stdpath)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
385 stdpath = "/usr/local/lib:/lib:/usr/lib";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
386 if (!buf) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
387 buf_size =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
388 SDL_strlen (ldlp) + SDL_strlen (dyldlp) + SDL_strlen (stdpath) +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
389 4;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
390 buf = SDL_malloc (buf_size);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
391 SDL_snprintf (buf, buf_size, "%s%s%s%s%s%c", dyldlp,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
392 (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
393 stdpath, '\0');
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
394 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
395 return buf;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 /* Returns the ith search path from the list as computed by searchList() */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
399 static const char *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
400 getSearchPath (int i)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
402 static const char *list = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
403 static char **path = (char **) 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
404 static int end = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
405 static int numsize = MAX_SEARCH_PATHS;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
406 static char **tmp;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
407 /* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
408 if (i == -1) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
409 return (const char *) path;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
410 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
411 if (!path) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
412 path = (char **) SDL_calloc (MAX_SEARCH_PATHS, sizeof (char **));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
413 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
414 if (!list && !end)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
415 list = searchList ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
416 if (i >= (numsize)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
417 debug ("Increasing size for long PATH");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
418 tmp =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
419 (char **) SDL_calloc ((MAX_SEARCH_PATHS + numsize),
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
420 sizeof (char **));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
421 if (tmp) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
422 SDL_memcpy (tmp, path, sizeof (char **) * numsize);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
423 SDL_free (path);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
424 path = tmp;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
425 numsize += MAX_SEARCH_PATHS;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
426 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
427 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
428 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
429 }
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
431 while (!path[i] && !end) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
432 path[i] = strsep ((char **) &list, ":");
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
434 if (path[i][0] == 0)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
435 path[i] = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
436 end = (list == 0);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
437 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
438 return path[i];
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
441 static const char *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
442 getFullPath (int i, const char *file)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
444 static char buf[PATH_MAX];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
445 const char *path = getSearchPath (i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
446 if (path) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
447 SDL_snprintf (buf, PATH_MAX, "%s/%s", path, file);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
448 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
449 return path ? buf : 0;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 /* Given a file name, try to determine the full path for that file. Starts
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 * its search in the current directory, and then tries all paths in the
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 * search list in the order they are specified there.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
456 static const struct stat *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
457 findFile (const char *file, const char **fullPath)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
459 int i = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
460 static struct stat sbuf;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
461 char *fileName;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
462 debug ("finding file %s", file);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
463 *fullPath = file;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
464 if (0 == stat (file, &sbuf))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
465 return &sbuf;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
466 if (SDL_strchr (file, '/'))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
467 return 0; /* If the path had a / we don't look in env var places */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
468 fileName = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
469 if (!fileName)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
470 fileName = (char *) file;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
471 while ((*fullPath = getFullPath (i++, fileName))) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
472 if (0 == stat (*fullPath, &sbuf))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
473 return &sbuf;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
474 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
475 ;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
476 return 0;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 /* Determine whether a given dlstatus is valid or not */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
480 static int
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
481 isValidStatus (struct dlstatus *status)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
483 /* Walk the list to verify status is contained in it */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
484 struct dlstatus *dls = stqueue;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
485 while (dls && status != dls)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
486 dls = dls->next;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
487 if (dls == 0)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
488 error ("invalid handle");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
489 else if ((dls->module == 0) || (dls->refs == 0))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
490 error ("handle to closed library");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
491 else
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
492 return TRUE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
493 return FALSE;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
496 static inline int
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
497 isFlagSet (int mode, int flag)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
499 return (mode & flag) == flag;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
502 static struct dlstatus *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
503 lookupStatus (const struct stat *sbuf)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
505 struct dlstatus *dls = stqueue;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
506 debug ("looking for status");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
507 while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
508 || sbuf->st_dev != dls->device
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
509 || sbuf->st_ino != dls->inode))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
510 dls = dls->next;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
511 return dls;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
514 static void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
515 insertStatus (struct dlstatus *dls, const struct stat *sbuf)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
517 debug ("inserting status");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
518 dls->inode = sbuf->st_ino;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
519 dls->device = sbuf->st_dev;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
520 dls->refs = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
521 dls->mode = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
522 if ((dls->flags & DL_IN_LIST) == 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
523 dls->next = stqueue;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
524 stqueue = dls;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
525 dls->flags |= DL_IN_LIST;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
526 }
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
529 static struct dlstatus *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
530 allocStatus ()
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
532 struct dlstatus *dls;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 #ifdef REUSE_STATUS
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
534 dls = stqueue;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
535 while (dls && dls->module)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
536 dls = dls->next;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
537 if (!dls)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
539 dls = SDL_calloc (sizeof (*dls), 1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
540 return dls;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
543 static int
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
544 promoteLocalToGlobal (struct dlstatus *dls)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
546 static int (*p) (NSModule module) = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
547 debug ("promoting");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
548 if (!p)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
549 _dyld_func_lookup ("__dyld_NSMakePrivateModulePublic", (void **) &p);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
550 return (dls->module == MAGIC_DYLIB_MOD) || (p && p (dls->module));
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
553 static void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
554 reference (struct dlstatus *dls, int mode)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
556 if (dls) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
557 if (dls->module == MAGIC_DYLIB_MOD && isFlagSet (mode, RTLD_LOCAL)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
558 warning ("trying to open a .dylib with RTLD_LOCAL");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
559 error ("unable to open a .dylib with RTLD_LOCAL");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
560 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
561 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
562 if (isFlagSet (mode, RTLD_GLOBAL) &&
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
563 !isFlagSet (dls->mode, RTLD_GLOBAL)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
564 && !promoteLocalToGlobal (dls)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
565 error ("unable to promote local module to global");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
566 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
567 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
568 dls->mode |= mode;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
569 dls->refs++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
570 } else
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
571 debug ("reference called with NULL argument");
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
573 return dls;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
576 static const struct mach_header *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
577 my_find_image (const char *name)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
579 const struct mach_header *mh = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
580 const char *id = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
581 int i = _dyld_image_count ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
582 int j;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
583 mh = (struct mach_header *)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
584 dyld_NSAddImage (name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
585 NSADDIMAGE_OPTION_RETURN_ON_ERROR);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
586 if (!mh) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
587 for (j = 0; j < i; j++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
588 id = _dyld_get_image_name (j);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
589 if (!SDL_strcmp (id, name)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
590 mh = _dyld_get_image_header (j);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
591 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
592 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
593 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
594 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
595 return mh;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 /*
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 * dyld adds libraries by first adding the directly dependant libraries in link order, and
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 * then adding the dependencies for those libraries, so we should do the same... but we don't
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 * any of it's direct dependencies, then it probably isn't there.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
604 static NSSymbol
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
605 search_linked_libs (const struct mach_header *mh, const char *symbol)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
607 unsigned int n;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
608 struct load_command *lc = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
609 struct mach_header *wh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
610 NSSymbol nssym = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
611 if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
612 && dyld_NSLookupSymbolInImage) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
613 lc = (struct load_command *) ((char *) mh +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
614 sizeof (struct mach_header));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
615 for (n = 0; n < mh->ncmds;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
616 n++, lc = (struct load_command *) ((char *) lc + lc->cmdsize)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
617 if ((LC_LOAD_DYLIB == lc->cmd)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
618 || (LC_LOAD_WEAK_DYLIB == lc->cmd)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
619 if ((wh = (struct mach_header *)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
620 my_find_image ((char
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
621 *) (((struct dylib_command *) lc)->
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
622 dylib.name.offset + (char *) lc)))) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
623 if (dyld_NSIsSymbolNameDefinedInImage (wh, symbol)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
624 nssym = dyld_NSLookupSymbolInImage (wh,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
625 symbol,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
626 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
627 |
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
628 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
629 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
630 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
631 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
632 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
633 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
634 if ((!nssym) && NSIsSymbolNameDefined (symbol)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
635 /* I've never seen this debug message... */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
636 debug ("Symbol \"%s\" is defined but was not found", symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
637 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
638 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
639 return nssym;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
640 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
642 /* Up to the caller to SDL_free() returned string */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
643 static inline char *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
644 dyld_error_str ()
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
645 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
646 NSLinkEditErrors dylder;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
647 int dylderno;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
648 const char *dylderrstr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
649 const char *dyldfile;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
650 char *retStr = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
651 NSLinkEditError (&dylder, &dylderno, &dyldfile, &dylderrstr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
652 if (dylderrstr && *dylderrstr) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
653 retStr = SDL_strdup (dylderrstr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
654 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
655 return retStr;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
656 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
657
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
658 static void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
659 dlsymIntern (struct dlstatus *dls, const char *symbol, int canSetError)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
660 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
661 NSSymbol nssym = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
662 #ifdef __GCC__
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
663 void *caller = __builtin_return_address (1); /* Be *very* careful about inlining */
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
664 #else
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
665 void *caller = NULL;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
666 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
667 const struct mach_header *caller_mh = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
668 char *savedErrorStr = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
669 resetdlerror ();
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
670 #ifndef RTLD_SELF
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
671 #define RTLD_SELF ((void *) -3)
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
672 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
673 if (NULL == dls)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
674 dls = RTLD_SELF;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
675 if ((RTLD_NEXT == dls) || (RTLD_SELF == dls)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
676 if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
677 && caller) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
678 caller_mh = image_for_address (caller);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
679 if (RTLD_SELF == dls) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
680 /* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
681 * But it appears to work anyway, and looking at the code in dyld_libfuncs.c
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
682 * this is acceptable.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
683 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
684 if (dyld_NSIsSymbolNameDefinedInImage (caller_mh, symbol)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
685 nssym = dyld_NSLookupSymbolInImage (caller_mh,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
686 symbol,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
687 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
688 |
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
689 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
690 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
691 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
692 if (!nssym) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
693 if (RTLD_SELF == dls)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
694 savedErrorStr = dyld_error_str ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
695 nssym = search_linked_libs (caller_mh, symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
696 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
697 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
698 if (canSetError)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
699 error ("RTLD_SELF and RTLD_NEXT are not supported");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
700 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
701 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
702 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
703 if (!nssym) {
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
704
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
705 if (RTLD_DEFAULT == dls) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
706 dls = &mainStatus;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
707 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
708 if (!isValidStatus (dls))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
709 return NULL;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
710
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
711 if (dls->module != MAGIC_DYLIB_MOD) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
712 nssym = NSLookupSymbolInModule (dls->module, symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
713 if (!nssym && NSIsSymbolNameDefined (symbol)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
714 debug ("Searching dependencies");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
715 savedErrorStr = dyld_error_str ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
716 nssym =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
717 search_linked_libs (get_mach_header_from_NSModule
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
718 (dls->module), symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
719 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
720 } else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
721 && dyld_NSLookupSymbolInImage) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
722 if (dyld_NSIsSymbolNameDefinedInImage (dls->lib, symbol)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
723 nssym = dyld_NSLookupSymbolInImage (dls->lib,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
724 symbol,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
725 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
726 |
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
727 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
728 } else if (NSIsSymbolNameDefined (symbol)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
729 debug ("Searching dependencies");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
730 savedErrorStr = dyld_error_str ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
731 nssym = search_linked_libs (dls->lib, symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
732 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
733 } else if (dls->module == MAGIC_DYLIB_MOD) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
734 /* Global context, use NSLookupAndBindSymbol */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
735 if (NSIsSymbolNameDefined (symbol)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
736 /* There doesn't seem to be a return on error option for this call???
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
737 this is potentially broken, if binding fails, it will improperly
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
738 exit the application. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
739 nssym = NSLookupAndBindSymbol (symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
740 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
741 if (savedErrorStr)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
742 SDL_free (savedErrorStr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
743 savedErrorStr = SDL_malloc (256);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
744 SDL_snprintf (savedErrorStr, 256,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
745 "Symbol \"%s\" not in global context", symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
746 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
747 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
748 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
749 /* Error reporting */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
750 if (!nssym) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
751 if (!savedErrorStr || !SDL_strlen (savedErrorStr)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
752 if (savedErrorStr)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
753 SDL_free (savedErrorStr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
754 savedErrorStr = SDL_malloc (256);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
755 SDL_snprintf (savedErrorStr, 256, "Symbol \"%s\" not found",
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
756 symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
757 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
758 if (canSetError) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
759 error (savedErrorStr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
760 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
761 debug (savedErrorStr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
762 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
763 if (savedErrorStr)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
764 SDL_free (savedErrorStr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
765 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
766 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
767 return NSAddressOfSymbol (nssym);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
768 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
769
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
770 static struct dlstatus *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
771 loadModule (const char *path, const struct stat *sbuf, int mode)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
772 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
773 NSObjectFileImage ofi = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
774 NSObjectFileImageReturnCode ofirc;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
775 struct dlstatus *dls;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
776 NSLinkEditErrors ler;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
777 int lerno;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
778 const char *errstr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
779 const char *file;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
780 void (*init) (void);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
781
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
782 ofirc = NSCreateObjectFileImageFromFile (path, &ofi);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
783 switch (ofirc) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
784 case NSObjectFileImageSuccess:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
785 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
786 case NSObjectFileImageInappropriateFile:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
787 if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
788 && dyld_NSLookupSymbolInImage) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
789 if (isFlagSet (mode, RTLD_LOCAL)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
790 warning ("trying to open a .dylib with RTLD_LOCAL");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
791 error ("unable to open this file with RTLD_LOCAL");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
792 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
793 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
794 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
795 error ("opening this file is unsupported on this system");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
796 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
797 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
798 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
799 case NSObjectFileImageFailure:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
800 error ("object file setup failure");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
801 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
802 case NSObjectFileImageArch:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
803 error ("no object for this architecture");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
804 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
805 case NSObjectFileImageFormat:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
806 error ("bad object file format");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
807 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
808 case NSObjectFileImageAccess:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
809 error ("can't read object file");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
810 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
811 default:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
812 error ("unknown error from NSCreateObjectFileImageFromFile()");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
813 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
814 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
815 dls = lookupStatus (sbuf);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
816 if (!dls) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
817 dls = allocStatus ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
818 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
819 if (!dls) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
820 error ("unable to allocate memory");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
821 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
822 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
823 // dls->lib = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
824 if (ofirc == NSObjectFileImageInappropriateFile) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
825 if ((dls->lib =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
826 dyld_NSAddImage (path, NSADDIMAGE_OPTION_RETURN_ON_ERROR))) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
827 debug ("Dynamic lib loaded at %ld", dls->lib);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
828 ofi = MAGIC_DYLIB_OFI;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
829 dls->module = MAGIC_DYLIB_MOD;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
830 ofirc = NSObjectFileImageSuccess;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
831 /* Although it is possible with a bit of work to modify this so it works and
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
832 functions with RTLD_NOW, I don't deem it necessary at the moment */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
833 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
834 if (!(dls->module)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
835 NSLinkEditError (&ler, &lerno, &file, &errstr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
836 if (!errstr || (!SDL_strlen (errstr)))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
837 error ("Can't open this file type");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
838 else
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
839 error (errstr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
840 if ((dls->flags & DL_IN_LIST) == 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
841 SDL_free (dls);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
842 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
843 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
844 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
845 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
846 dls->module = NSLinkModule (ofi, path,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
847 NSLINKMODULE_OPTION_RETURN_ON_ERROR |
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
848 NSLINKMODULE_OPTION_PRIVATE |
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
849 (isFlagSet (mode, RTLD_NOW) ?
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
850 NSLINKMODULE_OPTION_BINDNOW : 0));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
851 NSDestroyObjectFileImage (ofi);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
852 if (dls->module) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
853 dls->lib = get_mach_header_from_NSModule (dls->module);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
854 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
855 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
856 if (!dls->module) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
857 NSLinkEditError (&ler, &lerno, &file, &errstr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
858 if ((dls->flags & DL_IN_LIST) == 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
859 SDL_free (dls);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
860 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
861 error (errstr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
862 return NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
863 }
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
864
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
865 insertStatus (dls, sbuf);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
866 dls = reference (dls, mode);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
867 if ((init = dlsymIntern (dls, "__init", 0))) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
868 debug ("calling _init()");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
869 init ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
870 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
871 return dls;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
872 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
873
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
874 inline static void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
875 dlcompat_init_check (void)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
876 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
877 static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
878 static int init_done = 0;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
879
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
880 pthread_mutex_lock (&l);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
881 if (!init_done) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
882 dlcompat_init_func ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
883 init_done = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
884 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
885 pthread_mutex_unlock (&l);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
886 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
887
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
888 static void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
889 dlcompat_init_func (void)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
890 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
891 _dyld_func_lookup ("__dyld_NSAddImage", (void **) &dyld_NSAddImage);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
892 _dyld_func_lookup ("__dyld_NSIsSymbolNameDefinedInImage",
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
893 (void **) &dyld_NSIsSymbolNameDefinedInImage);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
894 _dyld_func_lookup ("__dyld_NSLookupSymbolInImage",
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
895 (void **) &dyld_NSLookupSymbolInImage);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
896 if (pthread_mutex_init (&dlcompat_mutex, NULL))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
897 exit (1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
898 if (pthread_key_create (&dlerror_key, &dlerrorfree))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
899 exit (1);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
900 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
901
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
902 static void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
903 resetdlerror ()
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
904 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
905 struct dlthread *tss;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
906 tss = pthread_getspecific (dlerror_key);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
907 tss->errset = 0;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
908 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
909
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
910 static void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
911 dlerrorfree (void *data)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
912 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
913 SDL_free (data);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
914 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
915
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
916 /* We kind of want a recursive lock here, but meet a little trouble
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
917 * because they are not available pre OS X 10.2, so we fake it
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
918 * using thread specific storage to keep a lock count
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
919 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
920 static inline void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
921 dolock (void)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
922 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
923 int err = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
924 struct dlthread *tss;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
925 dlcompat_init_check ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
926 tss = pthread_getspecific (dlerror_key);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
927 if (!tss) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
928 tss = SDL_malloc (sizeof (struct dlthread));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
929 tss->lockcnt = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
930 tss->errset = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
931 if (pthread_setspecific (dlerror_key, tss)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
932 fprintf (stderr, "dlcompat: pthread_setspecific failed\n");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
933 exit (1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
934 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
935 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
936 if (!tss->lockcnt)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
937 err = pthread_mutex_lock (&dlcompat_mutex);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
938 tss->lockcnt = tss->lockcnt + 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
939 if (err)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
940 exit (err);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
941 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
942
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
943 static inline void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
944 dounlock (void)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
945 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
946 int err = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
947 struct dlthread *tss;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
948 tss = pthread_getspecific (dlerror_key);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
949 tss->lockcnt = tss->lockcnt - 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
950 if (!tss->lockcnt)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
951 err = pthread_mutex_unlock (&dlcompat_mutex);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
952 if (err)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
953 exit (err);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
954 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
955
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
956 static void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
957 SDL_OSX_dlopen (const char *path, int mode)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
958 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
959 const struct stat *sbuf;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
960 struct dlstatus *dls;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
961 const char *fullPath;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
962
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
963 dolock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
964 resetdlerror ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
965 if (!path) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
966 dls = &mainStatus;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
967 goto dlopenok;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
968 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
969 if (!(sbuf = findFile (path, &fullPath))) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
970 error ("file \"%s\" not found", path);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
971 goto dlopenerror;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
972 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
973 /* Now checks that it hasn't been closed already */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
974 if ((dls = lookupStatus (sbuf)) && (dls->refs > 0)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
975 /* debug("status found"); */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
976 dls = reference (dls, mode);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
977 goto dlopenok;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
978 }
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
979 #ifdef RTLD_NOLOAD
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
980 if (isFlagSet (mode, RTLD_NOLOAD)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
981 error ("no existing handle and RTLD_NOLOAD specified");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
982 goto dlopenerror;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
983 }
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
984 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
985 if (isFlagSet (mode, RTLD_LAZY) && isFlagSet (mode, RTLD_NOW)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
986 error ("how can I load something both RTLD_LAZY and RTLD_NOW?");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
987 goto dlopenerror;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
988 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
989 dls = loadModule (fullPath, sbuf, mode);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
990
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
991 dlopenok:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
992 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
993 return (void *) dls;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
994 dlopenerror:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
995 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
996 return NULL;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
997 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
998
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
999 #if !FINK_BUILD
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1000 static void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1001 SDL_OSX_dlsym (void *dl_restrict handle, const char *dl_restrict symbol)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1002 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1003 int sym_len = SDL_strlen (symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1004 void *value = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1005 char *malloc_sym = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1006 dolock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1007 malloc_sym = SDL_malloc (sym_len + 2);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1008 if (malloc_sym) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1009 SDL_snprintf (malloc_sym, sym_len + 2, "_%s", symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1010 value = dlsymIntern (handle, malloc_sym, 1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1011 SDL_free (malloc_sym);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1012 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1013 error ("Unable to allocate memory");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1014 goto dlsymerror;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1015 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1016 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1017 return value;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1018 dlsymerror:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1019 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1020 return NULL;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1021 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1022 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1023
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1024 #if FINK_BUILD
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1025
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1026 static void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1027 dlsym_prepend_underscore (void *handle, const char *symbol)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1028 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1029 void *answer;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1030 dolock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1031 answer = dlsym_prepend_underscore_intern (handle, symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1032 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1033 return answer;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1034 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1035
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1036 static void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1037 dlsym_prepend_underscore_intern (void *handle, const char *symbol)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1038 {
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1039 /*
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1040 * A quick and easy way for porting packages which call dlsym(handle,"sym")
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1041 * If the porter adds -Ddlsym=dlsym_prepend_underscore to the CFLAGS then
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1042 * this function will be called, and will add the required underscore.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1043 *
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1044 * Note that I haven't figured out yet which should be "standard", prepend
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1045 * the underscore always, or not at all. These global functions need to go away
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1046 * for opendarwin.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1047 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1048 int sym_len = SDL_strlen (symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1049 void *value = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1050 char *malloc_sym = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1051 malloc_sym = SDL_malloc (sym_len + 2);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1052 if (malloc_sym) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1053 SDL_snprintf (malloc_sym, sym_len + 2, "_%s", symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1054 value = dlsymIntern (handle, malloc_sym, 1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1055 SDL_free (malloc_sym);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1056 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1057 error ("Unable to allocate memory");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1058 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1059 return value;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1060 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1061
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1062 static void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1063 dlsym_auto_underscore (void *handle, const char *symbol)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1064 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1065 void *answer;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1066 dolock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1067 answer = dlsym_auto_underscore_intern (handle, symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1068 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1069 return answer;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1070
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1071 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1072 static void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1073 dlsym_auto_underscore_intern (void *handle, const char *symbol)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1074 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1075 struct dlstatus *dls = handle;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1076 void *addr = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1077 addr = dlsymIntern (dls, symbol, 0);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1078 if (!addr)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1079 addr = dlsym_prepend_underscore_intern (handle, symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1080 return addr;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1081 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1082
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1083
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1084 static void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1085 SDL_OSX_dlsym (void *dl_restrict handle, const char *dl_restrict symbol)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1086 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1087 struct dlstatus *dls = handle;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1088 void *addr = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1089 dolock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1090 addr = dlsymIntern (dls, symbol, 1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1091 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1092 return addr;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1093 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1094 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1095
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1096 static int
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1097 SDL_OSX_dlclose (void *handle)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1098 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1099 struct dlstatus *dls = handle;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1100 dolock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1101 resetdlerror ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1102 if (!isValidStatus (dls)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1103 goto dlcloseerror;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1104 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1105 if (dls->module == MAGIC_DYLIB_MOD) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1106 const char *name;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1107 if (!dls->lib) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1108 name = "global context";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1109 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1110 name = get_lib_name (dls->lib);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1111 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1112 warning ("trying to close a .dylib!");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1113 error ("Not closing \"%s\" - dynamic libraries cannot be closed",
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1114 name);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1115 goto dlcloseerror;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1116 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1117 if (!dls->module) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1118 error ("module already closed");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1119 goto dlcloseerror;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1120 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1121
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1122 if (dls->refs == 1) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1123 unsigned long options = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1124 void (*fini) (void);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1125 if ((fini = dlsymIntern (dls, "__fini", 0))) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1126 debug ("calling _fini()");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1127 fini ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1128 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1129 options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1130 #ifdef RTLD_NODELETE
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1131 if (isFlagSet (dls->mode, RTLD_NODELETE))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1132 options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1133 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1134 if (!NSUnLinkModule (dls->module, options)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1135 error ("unable to unlink module");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1136 goto dlcloseerror;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1137 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1138 dls->refs--;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1139 dls->module = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1140 /* Note: the dlstatus struct dls is neither removed from the list
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1141 * nor is the memory it occupies freed. This shouldn't pose a
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1142 * problem in mostly all cases, though.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1143 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1144 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1145 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1146 return 0;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1147 dlcloseerror:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1148 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1149 return 1;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1150 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1151
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1152 static const char *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1153 SDL_OSX_dlerror (void)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1154 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1155 struct dlthread *tss;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1156 const char *err_str = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1157 dlcompat_init_check ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1158 tss = pthread_getspecific (dlerror_key);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1159 if (tss != NULL && tss->errset != 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1160 tss->errset = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1161 err_str = tss->errstr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1162 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1163 return (err_str);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1164 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1165
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1166 /* Given an address, return the mach_header for the image containing it
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1167 * or zero if the given address is not contained in any loaded images.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1168 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1169 static const struct mach_header *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1170 image_for_address (const void *address)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1171 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1172 unsigned long i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1173 unsigned long j;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1174 unsigned long count = _dyld_image_count ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1175 const struct mach_header *mh = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1176 struct load_command *lc = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1177 unsigned long addr = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1178 for (i = 0; i < count; i++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1179 addr = (unsigned long) address - _dyld_get_image_vmaddr_slide (i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1180 mh = _dyld_get_image_header (i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1181 if (mh) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1182 lc = (struct load_command *) ((char *) mh +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1183 sizeof (struct mach_header));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1184 for (j = 0; j < mh->ncmds;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1185 j++, lc =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1186 (struct load_command *) ((char *) lc + lc->cmdsize)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1187 if (LC_SEGMENT == lc->cmd &&
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1188 addr >= ((struct segment_command *) lc)->vmaddr &&
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1189 addr <
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1190 ((struct segment_command *) lc)->vmaddr +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1191 ((struct segment_command *) lc)->vmsize) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1192 goto image_found;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1193 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1194 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1195 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1196 mh = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1197 }
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1198 image_found:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1199 return mh;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1200 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1201
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1202 #if 0 /* unused */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1203 static int
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1204 SDL_OSX_dladdr (const void *dl_restrict p, SDL_OSX_Dl_info * dl_restrict info)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1205 {
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1206 /*
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1207 FIXME: USe the routine image_for_address.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1208 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1209 unsigned long i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1210 unsigned long j;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1211 unsigned long count = _dyld_image_count ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1212 struct mach_header *mh = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1213 struct load_command *lc = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1214 unsigned long addr = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1215 unsigned long table_off = (unsigned long) 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1216 int found = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1217 if (!info)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1218 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1219 dolock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1220 resetdlerror ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1221 info->dli_fname = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1222 info->dli_fbase = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1223 info->dli_sname = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1224 info->dli_saddr = 0;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1225 /* Some of this was swiped from code posted by Douglas Davidson <ddavidso AT apple DOT com>
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1226 * to darwin-development AT lists DOT apple DOT com and slightly modified
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1227 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1228 for (i = 0; i < count; i++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1229 addr = (unsigned long) p - _dyld_get_image_vmaddr_slide (i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1230 mh = _dyld_get_image_header (i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1231 if (mh) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1232 lc = (struct load_command *) ((char *) mh +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1233 sizeof (struct mach_header));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1234 for (j = 0; j < mh->ncmds;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1235 j++, lc =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1236 (struct load_command *) ((char *) lc + lc->cmdsize)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1237 if (LC_SEGMENT == lc->cmd &&
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1238 addr >= ((struct segment_command *) lc)->vmaddr &&
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1239 addr <
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1240 ((struct segment_command *) lc)->vmaddr +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1241 ((struct segment_command *) lc)->vmsize) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1242 info->dli_fname = _dyld_get_image_name (i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1243 info->dli_fbase = (void *) mh;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1244 found = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1245 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1246 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1247 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1248 if (found)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1249 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1250 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1251 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1252 if (!found) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1253 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1254 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1255 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1256 lc = (struct load_command *) ((char *) mh + sizeof (struct mach_header));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1257 for (j = 0; j < mh->ncmds;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1258 j++, lc = (struct load_command *) ((char *) lc + lc->cmdsize)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1259 if (LC_SEGMENT == lc->cmd) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1260 if (!SDL_strcmp
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1261 (((struct segment_command *) lc)->segname, "__LINKEDIT"))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1262 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1263 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1264 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1265 table_off =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1266 ((unsigned long) ((struct segment_command *) lc)->vmaddr) -
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1267 ((unsigned long) ((struct segment_command *) lc)->fileoff) +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1268 _dyld_get_image_vmaddr_slide (i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1269 debug ("table off %x", table_off);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1270
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1271 lc = (struct load_command *) ((char *) mh + sizeof (struct mach_header));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1272 for (j = 0; j < mh->ncmds;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1273 j++, lc = (struct load_command *) ((char *) lc + lc->cmdsize)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1274 if (LC_SYMTAB == lc->cmd) {
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1275
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1276 struct nlist *symtable =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1277 (struct nlist *) (((struct symtab_command *) lc)->symoff +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1278 table_off);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1279 unsigned long numsyms = ((struct symtab_command *) lc)->nsyms;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1280 struct nlist *nearest = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1281 unsigned long diff = 0xffffffff;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1282 unsigned long strtable =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1283 (unsigned long) (((struct symtab_command *) lc)->stroff +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1284 table_off);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1285 debug ("symtable %x", symtable);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1286 for (i = 0; i < numsyms; i++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1287 /* Ignore the following kinds of Symbols */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1288 if ((!symtable->n_value) /* Undefined */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1289 ||(symtable->n_type >= N_PEXT) /* Debug symbol */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1290 ||(!(symtable->n_type & N_EXT)) /* Local Symbol */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1291 ) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1292 symtable++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1293 continue;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1294 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1295 if ((addr >= symtable->n_value)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1296 && (diff >= (symtable->n_value - addr))) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1297 diff = (unsigned long) symtable->n_value - addr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1298 nearest = symtable;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1299 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1300 symtable++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1301 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1302 if (nearest) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1303 info->dli_saddr = nearest->n_value + ((void *) p - addr);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1304 info->dli_sname = (char *) (strtable + nearest->n_un.n_strx);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1305 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1306 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1307 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1308 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1309 return 1;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1310 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1311 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1312
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1313 /*
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1314 * Implement the dlfunc() interface, which behaves exactly the same as
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1315 * dlsym() except that it returns a function pointer instead of a data
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1316 * pointer. This can be used by applications to avoid compiler warnings
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1317 * about undefined behavior, and is intended as prior art for future
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1318 * POSIX standardization. This function requires that all pointer types
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1319 * have the same representation, which is true on all platforms FreeBSD
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1320 * runs on, but is not guaranteed by the C standard.
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1321 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1322 #if 0
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1323 static dlfunc_t
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1324 SDL_OSX_dlfunc (void *dl_restrict handle, const char *dl_restrict symbol)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1325 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1326 union
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1327 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1328 void *d;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1329 dlfunc_t f;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1330 } rv;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1331 int sym_len = SDL_strlen (symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1332 char *malloc_sym = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1333 dolock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1334 malloc_sym = SDL_malloc (sym_len + 2);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1335 if (malloc_sym) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1336 SDL_snprintf (malloc_sym, sym_len + 2, "_%s", symbol);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1337 rv.d = dlsymIntern (handle, malloc_sym, 1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1338 SDL_free (malloc_sym);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1339 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1340 error ("Unable to allocate memory");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1341 goto dlfuncerror;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1342 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1343 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1344 return rv.f;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1345 dlfuncerror:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1346 dounlock ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1347 return NULL;
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1348 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1349 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1350
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1351
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1352
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1353 /* dlcompat ends, here's the SDL interface... --ryan. */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1354
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1355
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1356 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1357 /* System dependent library loading routines */
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1358
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1359 #include "SDL_loadso.h"
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1360
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1361 void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1362 SDL_LoadObject (const char *sofile)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1363 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1364 void *handle = SDL_OSX_dlopen (sofile, RTLD_NOW);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1365 const char *loaderror = SDL_OSX_dlerror ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1366 if (handle == NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1367 SDL_SetError ("Failed loading %s: %s", sofile, loaderror);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1368 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1369 return (handle);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1370 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1371
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1372 void *
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1373 SDL_LoadFunction (void *handle, const char *name)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1374 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1375 void *symbol = SDL_OSX_dlsym (handle, name);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1376 if (symbol == NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1377 SDL_SetError ("Failed loading %s: %s", name, SDL_OSX_dlerror ());
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1378 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1379 return (symbol);
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1380 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1381
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1382 void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1383 SDL_UnloadObject (void *handle)
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1384 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1385 if (handle != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1386 SDL_OSX_dlclose (handle);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1387 }
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1388 }
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1389
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1390 #endif /* SDL_LOADSO_DLCOMPAT */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
1391 /* vi: set ts=4 sw=4 expandtab: */