Mercurial > sdl-ios-xcode
annotate include/SDL_rwops.h @ 1176:dd2a8deeb26d
Date: Mon, 17 Oct 2005 20:09:03 -0400
From: Mark Schreiber <mark7@alumni.cmu.edu>
To: ryan@clutteredmind.org
Subject: [PATCH]SDL mprotect() crash fix
(I'm going to throw this patch your way at the suggestion of #SDL --
for some reason, I had some difficulty sending it to the main list
last time, and I go bonkers subscribing to send each email or
patch...)
Currently, when I run SDL applications as non-root using
SDL_VIDEODRIVER=dga, the fbdev fallback mprotect()s read/write the
proper size of mmapped /dev/fb0 (7.5MB), but on framebuffer release
mprotect()s read-only the range by the entire size of my video memory
(128MB), which causes a segfault:
#0 0x002a9a27 in ?? () from /lib/libc.so.6
#1 0x04a63eb6 in SDL_XDGAUnmapFramebuffer (screen=3D0) at XF86DGA2.c:978
#2 0x04a63efc in SDL_XDGACloseFramebuffer (dpy=3D0x9d3f008, screen=3D0)
at XF86DGA2.c:268
#3 0x04a68b57 in DGA_Available () at SDL_dgavideo.c:98
#4 0x04a53677 in SDL_VideoInit (driver_name=3D0xbfb0bfc7 "dga", flags=3D0)
at SDL_video.c:180
#5 0x04a2613f in SDL_InitSubSystem (flags=3D32) at SDL.c:74
#6 0x04a2617c in SDL_Init (flags=3D32) at SDL.c:166
#7 0x08049722 in main (argc=3D1, argv=3D0x0) at testwin.c:32
This is SDL 1.2.8 on Fedora Core 4, radeon driver for a Radeon 9250,
xorg-x11-6.8.2-37.
I've attached a one-line patch against SDL CVS that updates the size
of the framebuffer at framebuffer map time so that the mprotect() on
unmap will be the same size. I'm not sure if this is the best
approach (i.e. one might want to retain the original value), but it
does make my SDL applications work without segfaulting.
-- Best of luck, Mark Schreiber
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 19 Nov 2005 18:57:00 +0000 |
parents | 02759105b989 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
764
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
251
b8688cfdc232
Updated the headers with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* This file provides a general interface for SDL to read and write | |
29 data sources. It can easily be extended to files, memory, etc. | |
30 */ | |
31 | |
32 #ifndef _SDL_RWops_h | |
33 #define _SDL_RWops_h | |
34 | |
35 #include <stdio.h> | |
36 | |
37 #include "SDL_types.h" | |
38 | |
39 #include "begin_code.h" | |
40 /* Set up for C function definitions, even when using C++ */ | |
41 #ifdef __cplusplus | |
42 extern "C" { | |
43 #endif | |
44 | |
45 /* This is the read/write operation structure -- very basic */ | |
46 | |
47 typedef struct SDL_RWops { | |
48 /* Seek to 'offset' relative to whence, one of stdio's whence values: | |
49 SEEK_SET, SEEK_CUR, SEEK_END | |
50 Returns the final offset in the data source. | |
51 */ | |
930
02759105b989
Date: Fri, 20 Aug 2004 08:31:20 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
52 int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence); |
0 | 53 |
54 /* Read up to 'num' objects each of size 'objsize' from the data | |
55 source to the area pointed at by 'ptr'. | |
56 Returns the number of objects read, or -1 if the read failed. | |
57 */ | |
930
02759105b989
Date: Fri, 20 Aug 2004 08:31:20 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
58 int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum); |
0 | 59 |
60 /* Write exactly 'num' objects each of size 'objsize' from the area | |
61 pointed at by 'ptr' to data source. | |
62 Returns 'num', or -1 if the write failed. | |
63 */ | |
930
02759105b989
Date: Fri, 20 Aug 2004 08:31:20 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
64 int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num); |
0 | 65 |
66 /* Close and free an allocated SDL_FSops structure */ | |
930
02759105b989
Date: Fri, 20 Aug 2004 08:31:20 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
67 int (SDLCALL *close)(struct SDL_RWops *context); |
0 | 68 |
69 Uint32 type; | |
70 union { | |
71 struct { | |
72 int autoclose; | |
73 FILE *fp; | |
74 } stdio; | |
75 struct { | |
76 Uint8 *base; | |
77 Uint8 *here; | |
78 Uint8 *stop; | |
79 } mem; | |
80 struct { | |
81 void *data1; | |
82 } unknown; | |
83 } hidden; | |
84 | |
85 } SDL_RWops; | |
86 | |
87 | |
88 /* Functions to create SDL_RWops structures from various data sources */ | |
89 | |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
90 extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char *mode); |
0 | 91 |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
92 extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose); |
0 | 93 |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
94 extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size); |
764
974c0fb74bf8
Added function to create RWops from const memory: SDL_RWFromConstMem()
Sam Lantinga <slouken@libsdl.org>
parents:
337
diff
changeset
|
95 extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size); |
0 | 96 |
337
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
97 extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void); |
9154ec9ca3d2
Explicitly specify the SDL API calling convention (C by default)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
98 extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area); |
0 | 99 |
100 /* Macros to easily read and write from an SDL_RWops structure */ | |
101 #define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence) | |
102 #define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, SEEK_CUR) | |
103 #define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n) | |
104 #define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n) | |
105 #define SDL_RWclose(ctx) (ctx)->close(ctx) | |
106 | |
107 | |
108 /* Ends C function definitions when using C++ */ | |
109 #ifdef __cplusplus | |
110 } | |
111 #endif | |
112 #include "close_code.h" | |
113 | |
114 #endif /* _SDL_RWops_h */ |