Previous 199869 Revisions Next

r34273 Friday 9th January, 2015 at 02:01:20 UTC by Couriersud
- Moved OS specific low level code to osd/modules/lib.
- Removed duplicate code
- Should support LIB/BASELIB separation better going forward
[src/osd/modules/lib]osdlib.h*
[src/osd/modules/sync]osdsync.h sync_mini.c sync_ntc.c sync_sdl.c sync_tc.c sync_windows.c work_osd.c
[src/osd/osdmini]minimisc.c
[src/osd/sdl]drawogl.c sdl.mak sdldir.c sdlfile.c sdlfile.h sdlmain.c sdlos.h sdlos_macosx.c sdlos_os2.c sdlos_unix.c sdlos_win32.c video.c watchdog.c window.c
[src/osd/windows]windows.mak winmisc.c winos.c winos.h

trunk/src/osd/modules/lib/osdlib.h
r0r242785
1//============================================================
2//
3//  osdlib.h
4//
5//  Copyright (c) 1996-2014, Nicola Salmoria and the MAME Team.
6//  Visit http://mamedev.org for licensing and usage restrictions.
7//
8//  SDLMAME by Olivier Galibert and R. Belmont
9//
10//  - Common low level routines
11//  - Source files also provide the following from osdcore.h
12//
13//    - osd_ticks
14//    - osd_sleep
15//    - osd_malloc
16//    - osd_malloc_array
17//    - osd_free
18//============================================================
19
20#ifndef __OSDLIB__
21#define __OSDLIB__
22
23/*-----------------------------------------------------------------------------
24    osd_num_processors: return the number of processors
25
26    Parameters:
27
28        None.
29
30    Return value:
31
32        Number of processors
33-----------------------------------------------------------------------------*/
34int osd_get_num_processors(void);
35
36/*-----------------------------------------------------------------------------
37    osd_process_kill: kill the current process
38
39    Parameters:
40
41        None.
42
43    Return value:
44
45        None.
46-----------------------------------------------------------------------------*/
47void osd_process_kill(void);
48
49/*-----------------------------------------------------------------------------
50    osd_getenv: return pointer to environment variable
51
52    Parameters:
53
54        name  - name of environment variable
55
56    Return value:
57
58        pointer to value
59-----------------------------------------------------------------------------*/
60char *osd_getenv(const char *name);
61
62/*-----------------------------------------------------------------------------
63    osd_setenv: set environment variable
64
65    Parameters:
66
67        name  - name of environment variable
68        value - value to write
69        overwrite - overwrite if it exists
70
71    Return value:
72
73        0 on success
74-----------------------------------------------------------------------------*/
75
76int osd_setenv(const char *name, const char *value, int overwrite);
77
78#endif  /* __OSDLIB__ */
trunk/src/osd/modules/sync/osdsync.h
r242784r242785
172172-----------------------------------------------------------------------------*/
173173void osd_thread_wait_free(osd_thread *thread);
174174
175/*-----------------------------------------------------------------------------
176    osd_process_kill: kill the current process
177
178    Parameters:
179
180        None.
181
182    Return value:
183
184        None.
185-----------------------------------------------------------------------------*/
186void osd_process_kill(void);
187
188175//============================================================
189176//  Scalable Locks
190177//============================================================
trunk/src/osd/modules/sync/sync_mini.c
r242784r242785
161161{
162162}
163163
164
165//============================================================
166//  osd_process_kill
167//============================================================
168
169void osd_process_kill(void)
170{
171}
trunk/src/osd/modules/sync/sync_ntc.c
r242784r242785
524524   free(thread);
525525}
526526
527//============================================================
528//  osd_process_kill
529//============================================================
530
531void osd_process_kill(void)
532{
533   kill(getpid(), SIGKILL);
534}
trunk/src/osd/modules/sync/sync_sdl.c
r242784r242785
359359   free(thread);
360360}
361361
362//============================================================
363//  osd_process_kill
364//============================================================
365
366void osd_process_kill(void)
367{
368    kill(getpid(), SIGKILL);
369}
trunk/src/osd/modules/sync/sync_tc.c
r242784r242785
382382   free(thread);
383383}
384384
385//============================================================
386//  osd_process_kill
387//============================================================
388
389void osd_process_kill(void)
390{
391   kill(getpid(), SIGKILL);
392}
trunk/src/osd/modules/sync/sync_windows.c
r242784r242785
312312}
313313
314314//============================================================
315//  osd_process_kill
316//============================================================
317
318void osd_process_kill(void)
319{
320   TerminateProcess(GetCurrentProcess(), -1);
321}
322
323//============================================================
324315//  Scalable Locks
325316//============================================================
326317
trunk/src/osd/modules/sync/work_osd.c
r242784r242785
2626#include "osdcore.h"
2727
2828#include "modules/sync/osdsync.h"
29#include "modules/lib/osdlib.h"
2930
30#if defined(OSD_WINDOWS)
31#include "winos.h"
32#elif defined(OSD_SDL)
33#include "sdlos.h"
34typedef void *PVOID;
35#endif
36
3731#include "eminline.h"
3832
3933#if defined(SDLMAME_MACOSX)
4034#include "osxutils.h"
4135#endif
4236
37#if defined(OSD_SDL)
38typedef void *PVOID;
39#endif
4340
4441//============================================================
4542//  DEBUGGING
trunk/src/osd/osdmini/minimisc.c
r242784r242785
8282   return NULL;
8383}
8484
85
86//============================================================
87//  osd_get_slider_list
88//============================================================
89
90const void *osd_get_slider_list()
91{
92   // nothing to slide in mini OSD
93   return NULL;
94}
trunk/src/osd/sdl/drawogl.c
r242784r242785
2828
2929// OpenGL headers
3030#include "osd_opengl.h"
31#include "sdlos.h"
31#include "modules/lib/osdlib.h"
3232
3333
3434#include "gl_shader_tool.h"
trunk/src/osd/sdl/sdl.mak
r242784r242785
391391SDLSRC = $(SRC)/osd/$(OSD)
392392SDLOBJ = $(OBJ)/osd/$(OSD)
393393
394OBJDIRS += $(SDLOBJ) $(OSDOBJ)/modules/sync
394OBJDIRS += $(SDLOBJ) $(OSDOBJ)/modules/sync $(OSDOBJ)/modules/lib
395395
396396#-------------------------------------------------
397397# OSD core library
r242784r242785
405405   $(SDLOBJ)/sdlsocket.o   \
406406   $(SDLOBJ)/sdlmisc_$(BASE_TARGETOS).o    \
407407   $(SDLOBJ)/sdlos_$(SDLOS_TARGETOS).o \
408   $(OSDOBJ)/modules/lib/osdlib_$(SDLOS_TARGETOS).o \
408409   $(OSDOBJ)/modules/sync/sync_$(SYNC_IMPLEMENTATION).o
409410
410411ifdef NOASM
trunk/src/osd/sdl/sdldir.c
r242784r242785
3737#include <dirent.h>
3838
3939#include "osdcore.h"
40#include "sdlos.h"
40#include "modules/lib/osdlib.h"
4141
4242#if defined(SDLMAME_WIN32) || defined(SDLMAME_OS2)
4343#define PATHSEPCH '\\'
trunk/src/osd/sdl/sdlfile.c
r242784r242785
4141
4242// MAME headers
4343#include "sdlfile.h"
44#include "modules/lib/osdlib.h"
4445
45
4646//============================================================
4747//  GLOBAL IDENTIFIERS
4848//============================================================
trunk/src/osd/sdl/sdlfile.h
r242784r242785
1010//============================================================
1111
1212#include "osdcore.h"
13#include "sdlos.h"
1413
1514//============================================================
1615//  ENUM DEFINITIONS
trunk/src/osd/sdl/sdlmain.c
r242784r242785
5252#include "video.h"
5353#include "input.h"
5454#include "osdsdl.h"
55#include "sdlos.h"
55#include "modules/lib/osdlib.h"
5656#include "modules/sound/sdl_sound.h"
5757#if defined(SDLMAME_EMSCRIPTEN)
5858#include "modules/sound/js_sound.h"
r242784r242785
269269
270270// we do some special sauce on Win32...
271271
272#if !defined(SDLMAME_WIN32)
273int main(int argc, char **argv)
274{
275   int res = 0;
276
277#else
278
272#if defined(SDLMAME_WIN32)
279273/* gee */
280274extern "C" DECLSPEC void SDLCALL SDL_SetModuleHandle(void *hInst);
275#endif
281276
282277// translated to utf8_main
283278int main(int argc, char *argv[])
284279{
285280   int res = 0;
286281
282#if defined(SDLMAME_WIN32)
287283#if !(SDLMAME_SDL2)
288284   /* Load SDL dynamic link library */
289285   if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) {
r242784r242785
293289   SDL_SetModuleHandle(GetModuleHandle(NULL));
294290#endif
295291#endif
292
296293   // disable I/O buffering
297294   setvbuf(stdout, (char *) NULL, _IONBF, 0);
298295   setvbuf(stderr, (char *) NULL, _IONBF, 0);
r242784r242785
527524   {
528525      osd_printf_verbose("\t%-20s\n", SDL_GetAudioDriver(i));
529526   }
527
530528#endif
531529}
532530
trunk/src/osd/sdl/sdlos.h
r242784r242785
1//============================================================
2//
3//  sdlos.h - SDLMAME OS dependent functions
4//
5//  Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
6//  Visit http://mamedev.org for licensing and usage restrictions.
7//
8//  SDLMAME by Olivier Galibert and R. Belmont
9//
10//============================================================
11
12#ifndef __SDLOS__
13#define __SDLOS__
14
15/*-----------------------------------------------------------------------------
16    osd_num_processors: return the number of processors
17
18    Parameters:
19
20        None.
21
22    Return value:
23
24        Number of processors
25-----------------------------------------------------------------------------*/
26int osd_get_num_processors(void);
27
28
29/*-----------------------------------------------------------------------------
30    osd_getenv: return pointer to environment variable
31
32    Parameters:
33
34        name  - name of environment variable
35
36    Return value:
37
38        pointer to value
39-----------------------------------------------------------------------------*/
40char *osd_getenv(const char *name);
41
42/*-----------------------------------------------------------------------------
43    osd_setenv: set environment variable
44
45    Parameters:
46
47        name  - name of environment variable
48        value - value to write
49        overwrite - overwrite if it exists
50
51    Return value:
52
53        0 on success
54-----------------------------------------------------------------------------*/
55
56int osd_setenv(const char *name, const char *value, int overwrite);
57
58#endif  /* __SDLOS__ */
trunk/src/osd/sdl/sdlos_macosx.c
r242784r242785
139139   }
140140}
141141
142//============================================================
143//  osd_num_processors
144//============================================================
145142
146int osd_get_num_processors(void)
147{
148   int processors = 1;
149
150   struct host_basic_info host_basic_info;
151   unsigned int count;
152   kern_return_t r;
153   mach_port_t my_mach_host_self;
154
155   count = HOST_BASIC_INFO_COUNT;
156   my_mach_host_self = mach_host_self();
157   if ( ( r = host_info(my_mach_host_self, HOST_BASIC_INFO, (host_info_t)(&host_basic_info), &count)) == KERN_SUCCESS )
158   {
159      processors = host_basic_info.avail_cpus;
160   }
161   mach_port_deallocate(mach_task_self(), my_mach_host_self);
162
163   return processors;
164}
165
166143//============================================================
167//  osd_malloc
168//============================================================
169
170void *osd_malloc(size_t size)
171{
172#ifndef MALLOC_DEBUG
173   return malloc(size);
174#else
175#error "MALLOC_DEBUG not yet supported"
176#endif
177}
178
179
180//============================================================
181//  osd_malloc_array
182//============================================================
183
184void *osd_malloc_array(size_t size)
185{
186#ifndef MALLOC_DEBUG
187   return malloc(size);
188#else
189#error "MALLOC_DEBUG not yet supported"
190#endif
191}
192
193
194//============================================================
195//  osd_free
196//============================================================
197
198void osd_free(void *ptr)
199{
200#ifndef MALLOC_DEBUG
201   free(ptr);
202#else
203#error "MALLOC_DEBUG not yet supported"
204#endif
205}
206
207//============================================================
208//  osd_getenv
209//============================================================
210
211char *osd_getenv(const char *name)
212{
213   return getenv(name);
214}
215
216//============================================================
217//  osd_setenv
218//============================================================
219
220int osd_setenv(const char *name, const char *value, int overwrite)
221{
222   return setenv(name, value, overwrite);
223}
224
225//============================================================
226144//  osd_get_clipboard_text
227145//============================================================
228146
r242784r242785
365283}
366284
367285//============================================================
368//  osd_get_slider_list
369//============================================================
370
371const void *osd_get_slider_list()
372{
373   return NULL;
374}
375
376//============================================================
377286//  osd_get_full_path
378287//============================================================
379288
trunk/src/osd/sdl/sdlos_os2.c
r242784r242785
309309}
310310
311311//============================================================
312//  osd_get_slider_list
313//============================================================
314
315const void *osd_get_slider_list()
316{
317   return NULL;
318}
319
320//============================================================
321312//  osd_get_full_path
322313//============================================================
323314
trunk/src/osd/sdl/sdlos_unix.c
r242784r242785
7070   }
7171}
7272
73//============================================================
74//  osd_num_processors
75//============================================================
76
77int osd_get_num_processors(void)
78{
79   int processors = 1;
80
81#if defined(_SC_NPROCESSORS_ONLN)
82   processors = sysconf(_SC_NPROCESSORS_ONLN);
83#endif
84   return processors;
85}
86
87//============================================================
88//  osd_malloc
89//============================================================
90
91void *osd_malloc(size_t size)
92{
93#ifndef MALLOC_DEBUG
94   return malloc(size);
95#else
96#error "MALLOC_DEBUG not yet supported"
97#endif
98}
99
100
101//============================================================
102//  osd_malloc_array
103//============================================================
104
105void *osd_malloc_array(size_t size)
106{
107#ifndef MALLOC_DEBUG
108   return malloc(size);
109#else
110#error "MALLOC_DEBUG not yet supported"
111#endif
112}
113
114
115//============================================================
116//  osd_free
117//============================================================
118
119void osd_free(void *ptr)
120{
121#ifndef MALLOC_DEBUG
122   free(ptr);
123#else
124#error "MALLOC_DEBUG not yet supported"
125#endif
126}
127
128//============================================================
129//  osd_getenv
130//============================================================
131
132char *osd_getenv(const char *name)
133{
134   return getenv(name);
135}
136
137
138//============================================================
139//  osd_setenv
140//============================================================
141
142int osd_setenv(const char *name, const char *value, int overwrite)
143{
144   return setenv(name, value, overwrite);
145}
146
14773#if (SDLMAME_SDL2)
14874
14975//============================================================
r242784r242785
309235}
310236
311237//============================================================
312//  osd_get_slider_list
313//============================================================
314
315const void *osd_get_slider_list()
316{
317   return NULL;
318}
319
320//============================================================
321238//  osd_get_full_path
322239//============================================================
323240
trunk/src/osd/sdl/sdlos_win32.c
r242784r242785
2020#include "osdcore.h"
2121#include "strconv.h"
2222
23#include "../windows/winos.c"
24
2523//============================================================
2624//  PROTOTYPES
2725//============================================================
r242784r242785
160158}
161159
162160//============================================================
163//  osd_malloc
164//============================================================
165
166void *osd_malloc(size_t size)
167{
168#ifndef MALLOC_DEBUG
169   return HeapAlloc(GetProcessHeap(), 0, size);
170#else
171   // add in space for the size
172   size += sizeof(size_t);
173
174   // basic objects just come from the heap
175   void *result = HeapAlloc(GetProcessHeap(), 0, size);
176
177   // store the size and return and pointer to the data afterward
178   *reinterpret_cast<size_t *>(result) = size;
179   return reinterpret_cast<UINT8 *>(result) + sizeof(size_t);
180#endif
181}
182
183
184//============================================================
185//  osd_malloc_array
186//============================================================
187
188void *osd_malloc_array(size_t size)
189{
190#ifndef MALLOC_DEBUG
191   return HeapAlloc(GetProcessHeap(), 0, size);
192#else
193   // add in space for the size
194   size += sizeof(size_t);
195
196   // round the size up to a page boundary
197   size_t rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
198
199   // reserve that much memory, plus two guard pages
200   void *page_base = VirtualAlloc(NULL, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS);
201   if (page_base == NULL)
202      return NULL;
203
204   // now allow access to everything but the first and last pages
205   page_base = VirtualAlloc(reinterpret_cast<UINT8 *>(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE);
206   if (page_base == NULL)
207      return NULL;
208
209   // work backwards from the page base to get to the block base
210   void *result = GUARD_ALIGN_START ? page_base : (reinterpret_cast<UINT8 *>(page_base) + rounded_size - size);
211
212   // store the size at the start with a flag indicating it has a guard page
213   *reinterpret_cast<size_t *>(result) = size | 0x80000000;
214   return reinterpret_cast<UINT8 *>(result) + sizeof(size_t);
215#endif
216}
217
218
219//============================================================
220//  osd_free
221//============================================================
222
223void osd_free(void *ptr)
224{
225#ifndef MALLOC_DEBUG
226   HeapFree(GetProcessHeap(), 0, ptr);
227#else
228   size_t size = reinterpret_cast<size_t *>(ptr)[-1];
229
230   // if no guard page, just free the pointer
231   if ((size & 0x80000000) == 0)
232      HeapFree(GetProcessHeap(), 0, reinterpret_cast<UINT8 *>(ptr) - sizeof(size_t));
233
234   // large items need more care
235   else
236   {
237      ULONG_PTR page_base = (reinterpret_cast<ULONG_PTR>(ptr) - sizeof(size_t)) & ~(PAGE_SIZE - 1);
238      VirtualFree(reinterpret_cast<void *>(page_base - PAGE_SIZE), 0, MEM_RELEASE);
239   }
240#endif
241}
242
243//============================================================
244//  osd_setenv
245//============================================================
246
247int osd_setenv(const char *name, const char *value, int overwrite)
248{
249   char *buf;
250   int result;
251
252   if (!overwrite)
253   {
254      if (osd_getenv(name) != NULL)
255         return 0;
256   }
257   buf = (char *) osd_malloc_array(strlen(name)+strlen(value)+2);
258   sprintf(buf, "%s=%s", name, value);
259   result = putenv(buf);
260
261   /* will be referenced by environment
262    * Therefore it is not freed here
263    */
264
265   return result;
266}
267
268//============================================================
269161//  get_clipboard_text_by_format
270162//============================================================
271163
r242784r242785
460352}
461353
462354//============================================================
463//  osd_get_slider_list
464//============================================================
465
466const void *osd_get_slider_list()
467{
468   return NULL;
469}
470
471//============================================================
472355//  win_error_to_mame_file_error
473356//============================================================
474357
trunk/src/osd/sdl/video.c
r242784r242785
5050#include "window.h"
5151#include "input.h"
5252#include "osdsdl.h"
53#include "sdlos.h"
53#include "modules/lib/osdlib.h"
5454
5555//============================================================
5656//  CONSTANTS
trunk/src/osd/sdl/watchdog.c
r242784r242785
1818#endif
1919
2020#include "watchdog.h"
21#include "modules/lib/osdlib.h"
2122
2223static void *watchdog_thread(void *param)
2324{
trunk/src/osd/sdl/window.c
r242784r242785
235235      if (work_queue == NULL)
236236         return false;
237237      osd_work_item_queue(work_queue, &sdlwindow_thread_id, NULL, WORK_ITEM_FLAG_AUTO_RELEASE);
238      sdlwindow_sync();
238239   }
239240   else
240241   {
r242784r242785
264265         return false;
265266   }
266267
268#if SDLMAME_SDL2
269   /* We may want to set a number of the hints SDL2 provides.
270    * The code below will document which hints were set.
271    */
272    const char * hints[] = { SDL_HINT_RENDER_DRIVER,    SDL_HINT_RENDER_OPENGL_SHADERS,
273            SDL_HINT_RENDER_DIRECT3D_THREADSAFE, SDL_HINT_RENDER_SCALE_QUALITY,
274            SDL_HINT_RENDER_VSYNC, SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
275            SDL_HINT_VIDEO_X11_XVIDMODE, SDL_HINT_VIDEO_X11_XINERAMA,
276            SDL_HINT_VIDEO_X11_XRANDR, SDL_HINT_GRAB_KEYBOARD,
277            SDL_HINT_MOUSE_RELATIVE_MODE_WARP,
278            SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_HINT_IDLE_TIMER_DISABLED,
279            SDL_HINT_ORIENTATIONS, SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
280            SDL_HINT_XINPUT_ENABLED, SDL_HINT_GAMECONTROLLERCONFIG,
281            SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, SDL_HINT_ALLOW_TOPMOST,
282            SDL_HINT_TIMER_RESOLUTION, SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK,
283            SDL_HINT_VIDEO_WIN_D3DCOMPILER, SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
284            SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
285            NULL
286    };
287
288    osd_printf_verbose("\nHints:\n");
289    for (int i = 0; hints[i] != NULL; i++)
290        osd_printf_verbose("\t%-40s %s\n", hints[i], SDL_GetHint(hints[i]));
291#endif
292
267293   // set up the window list
268294   last_window_ptr = &sdl_window_list;
269295   osd_printf_verbose("Leave sdlwindow_init\n");
trunk/src/osd/windows/windows.mak
r242784r242785
8484OSDSRC = $(SRC)/osd
8585OSDOBJ = $(OBJ)/osd
8686
87OBJDIRS += $(WINOBJ) $(OSDOBJ)/modules/sync
87OBJDIRS += $(WINOBJ) $(OSDOBJ)/modules/sync $(OSDOBJ)/modules/lib
8888
8989ifdef USE_QTDEBUG
9090OBJDIRS += $(OSDOBJ)/modules/debugger/qt
r242784r242785
350350   $(WINOBJ)/winclip.o \
351351   $(WINOBJ)/winsocket.o \
352352   $(OSDOBJ)/modules/sync/work_osd.o \
353   $(OSDOBJ)/modules/lib/osdlib_win32.o \
353354   $(WINOBJ)/winptty.o \
354   $(WINOBJ)/winos.o \
355355
356356
357357#-------------------------------------------------
trunk/src/osd/windows/winmisc.c
r242784r242785
2121
2222
2323//============================================================
24//  MACROS
25//============================================================
26
27// presumed size of a page of memory
28#define PAGE_SIZE           4096
29
30// align allocations to start or end of the page?
31#define GUARD_ALIGN_START   0
32
33
34
35//============================================================
3624//  GLOBAL VARIABLES
3725//============================================================
3826
3927void (*s_debugger_stack_crawler)() = NULL;
4028
4129
42
4330//============================================================
44//  osd_malloc
45//============================================================
46
47void *osd_malloc(size_t size)
48{
49#ifndef MALLOC_DEBUG
50   return HeapAlloc(GetProcessHeap(), 0, size);
51#else
52   // add in space for the size
53   size += sizeof(size_t);
54
55   // basic objects just come from the heap
56   void *result = HeapAlloc(GetProcessHeap(), 0, size);
57
58   // store the size and return and pointer to the data afterward
59   *reinterpret_cast<size_t *>(result) = size;
60   return reinterpret_cast<UINT8 *>(result) + sizeof(size_t);
61#endif
62}
63
64
65//============================================================
66//  osd_malloc_array
67//============================================================
68
69void *osd_malloc_array(size_t size)
70{
71#ifndef MALLOC_DEBUG
72   return HeapAlloc(GetProcessHeap(), 0, size);
73#else
74   // add in space for the size
75   size += sizeof(size_t);
76
77   // round the size up to a page boundary
78   size_t rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
79
80   // reserve that much memory, plus two guard pages
81   void *page_base = VirtualAlloc(NULL, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS);
82   if (page_base == NULL)
83      return NULL;
84
85   // now allow access to everything but the first and last pages
86   page_base = VirtualAlloc(reinterpret_cast<UINT8 *>(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE);
87   if (page_base == NULL)
88      return NULL;
89
90   // work backwards from the page base to get to the block base
91   void *result = GUARD_ALIGN_START ? page_base : (reinterpret_cast<UINT8 *>(page_base) + rounded_size - size);
92
93   // store the size at the start with a flag indicating it has a guard page
94   *reinterpret_cast<size_t *>(result) = size | 0x80000000;
95   return reinterpret_cast<UINT8 *>(result) + sizeof(size_t);
96#endif
97}
98
99
100//============================================================
101//  osd_free
102//============================================================
103
104void osd_free(void *ptr)
105{
106#ifndef MALLOC_DEBUG
107   HeapFree(GetProcessHeap(), 0, ptr);
108#else
109   size_t size = reinterpret_cast<size_t *>(ptr)[-1];
110
111   // if no guard page, just free the pointer
112   if ((size & 0x80000000) == 0)
113      HeapFree(GetProcessHeap(), 0, reinterpret_cast<UINT8 *>(ptr) - sizeof(size_t));
114
115   // large items need more care
116   else
117   {
118      ULONG_PTR page_base = (reinterpret_cast<ULONG_PTR>(ptr) - sizeof(size_t)) & ~(PAGE_SIZE - 1);
119      VirtualFree(reinterpret_cast<void *>(page_base - PAGE_SIZE), 0, MEM_RELEASE);
120   }
121#endif
122}
123
124
125//============================================================
12631//  osd_alloc_executable
12732//============================================================
12833
trunk/src/osd/windows/winos.c
r242784r242785
1//============================================================
2//
3//  winos.c - Win32 OS specific low level code
4//
5//============================================================
6
7#define WIN32_LEAN_AND_MEAN
8#include <windows.h>
9#include <stdlib.h>
10
11// MAME headers
12#include "osdcore.h"
13
14//============================================================
15//  osd_num_processors
16//============================================================
17
18int osd_get_num_processors(void)
19{
20   SYSTEM_INFO info;
21
22   // otherwise, fetch the info from the system
23   GetSystemInfo(&info);
24
25   // max out at 4 for now since scaling above that seems to do poorly
26   return MIN(info.dwNumberOfProcessors, 4);
27}
28
29//============================================================
30//  osd_getenv
31//============================================================
32
33char *osd_getenv(const char *name)
34{
35   return getenv(name);
36}
trunk/src/osd/windows/winos.h
r242784r242785
1//============================================================
2//
3//  winos.h - Win32 OS specific low level code
4//
5//============================================================
6
7/*-----------------------------------------------------------------------------
8    osd_num_processors: return the number of processors
9
10    Parameters:
11
12        None.
13
14    Return value:
15
16        Number of processors
17-----------------------------------------------------------------------------*/
18int osd_get_num_processors(void);
19
20
21/*-----------------------------------------------------------------------------
22    osd_getenv: return pointer to environment variable
23
24    Parameters:
25
26        name  - name of environment variable
27
28    Return value:
29
30        pointer to value
31-----------------------------------------------------------------------------*/
32char *osd_getenv(const char *name);


Previous 199869 Revisions Next


© 1997-2024 The MAME Team