mmap.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * Wine memory mappings support
  3. *
  4. * Copyright 2000, 2004 Alexandre Julliard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include "config.h"
  21. #include <assert.h>
  22. #include <ctype.h>
  23. #include <errno.h>
  24. #include <fcntl.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <sys/types.h>
  29. #include <sys/wait.h>
  30. #include <sys/mman.h>
  31. #include <unistd.h>
  32. #ifdef HAVE_STDINT_H
  33. # include <stdint.h>
  34. #endif
  35. #include "wine/list.h"
  36. #include "wine/asm.h"
  37. #ifndef MAP_NORESERVE
  38. #define MAP_NORESERVE 0
  39. #endif
  40. #ifndef MAP_PRIVATE
  41. #define MAP_PRIVATE 0
  42. #endif
  43. #ifndef MAP_ANON
  44. #define MAP_ANON 0
  45. #endif
  46. static inline int get_fdzero(void)
  47. {
  48. static int fd = -1;
  49. if (MAP_ANON == 0 && fd == -1)
  50. {
  51. if ((fd = open( "/dev/zero", O_RDONLY )) == -1)
  52. {
  53. perror( "/dev/zero: open" );
  54. exit(1);
  55. }
  56. }
  57. return fd;
  58. }
  59. #if (defined(__svr4__) || defined(__NetBSD__)) && !defined(MAP_TRYFIXED)
  60. /***********************************************************************
  61. * try_mmap_fixed
  62. *
  63. * The purpose of this routine is to emulate the behaviour of
  64. * the Linux mmap() routine if a non-NULL address is passed,
  65. * but the MAP_FIXED flag is not set. Linux in this case tries
  66. * to place the mapping at the specified address, *unless* the
  67. * range is already in use. Solaris, however, completely ignores
  68. * the address argument in this case.
  69. *
  70. * As Wine code occasionally relies on the Linux behaviour, e.g. to
  71. * be able to map non-relocatable PE executables to their proper
  72. * start addresses, or to map the DOS memory to 0, this routine
  73. * emulates the Linux behaviour by checking whether the desired
  74. * address range is still available, and placing the mapping there
  75. * using MAP_FIXED if so.
  76. */
  77. static int try_mmap_fixed (void *addr, size_t len, int prot, int flags,
  78. int fildes, off_t off)
  79. {
  80. char * volatile result = NULL;
  81. const size_t pagesize = sysconf( _SC_PAGESIZE );
  82. pid_t pid, wret;
  83. /* We only try to map to a fixed address if
  84. addr is non-NULL and properly aligned,
  85. and MAP_FIXED isn't already specified. */
  86. if ( !addr )
  87. return 0;
  88. if ( (uintptr_t)addr & (pagesize-1) )
  89. return 0;
  90. if ( flags & MAP_FIXED )
  91. return 0;
  92. /* We use vfork() to freeze all threads of the
  93. current process. This allows us to check without
  94. race condition whether the desired memory range is
  95. already in use. Note that because vfork() shares
  96. the address spaces between parent and child, we
  97. can actually perform the mapping in the child. */
  98. if ( (pid = vfork()) == -1 )
  99. {
  100. perror("try_mmap_fixed: vfork");
  101. exit(1);
  102. }
  103. if ( pid == 0 )
  104. {
  105. int i;
  106. char vec;
  107. /* We call mincore() for every page in the desired range.
  108. If any of these calls succeeds, the page is already
  109. mapped and we must fail. */
  110. for ( i = 0; i < len; i += pagesize )
  111. if ( mincore( (caddr_t)addr + i, pagesize, &vec ) != -1 )
  112. _exit(1);
  113. /* Perform the mapping with MAP_FIXED set. This is safe
  114. now, as none of the pages is currently in use. */
  115. result = mmap( addr, len, prot, flags | MAP_FIXED, fildes, off );
  116. if ( result == addr )
  117. _exit(0);
  118. if ( result != (void *) -1 ) /* This should never happen ... */
  119. munmap( result, len );
  120. _exit(1);
  121. }
  122. /* reap child */
  123. do {
  124. wret = waitpid(pid, NULL, 0);
  125. } while (wret < 0 && errno == EINTR);
  126. return result == addr;
  127. }
  128. #elif defined(__APPLE__)
  129. #include <mach/mach_init.h>
  130. #include <mach/mach_vm.h>
  131. /*
  132. * On Darwin, we can use the Mach call mach_vm_map to allocate
  133. * anonymous memory at the specified address and then, if necessary, use
  134. * mmap with MAP_FIXED to replace the mapping.
  135. */
  136. static int try_mmap_fixed (void *addr, size_t len, int prot, int flags,
  137. int fildes, off_t off)
  138. {
  139. mach_vm_address_t result = (mach_vm_address_t)addr;
  140. int vm_flags = VM_FLAGS_FIXED;
  141. if (flags & MAP_NOCACHE)
  142. vm_flags |= VM_FLAGS_NO_CACHE;
  143. if (!mach_vm_map( mach_task_self(), &result, len, 0, vm_flags, MEMORY_OBJECT_NULL,
  144. 0, 0, prot, VM_PROT_ALL, VM_INHERIT_COPY ))
  145. {
  146. flags |= MAP_FIXED;
  147. if (((flags & ~(MAP_NORESERVE | MAP_NOCACHE)) == (MAP_ANON | MAP_FIXED | MAP_PRIVATE)) ||
  148. mmap( (void *)result, len, prot, flags, fildes, off ) != MAP_FAILED)
  149. return 1;
  150. mach_vm_deallocate(mach_task_self(),result,len);
  151. }
  152. return 0;
  153. }
  154. #endif /* (__svr4__ || __NetBSD__) && !MAP_TRYFIXED */
  155. /***********************************************************************
  156. * wine_anon_mmap
  157. *
  158. * Portable wrapper for anonymous mmaps
  159. */
  160. void *wine_anon_mmap( void *start, size_t size, int prot, int flags )
  161. {
  162. #ifdef MAP_SHARED
  163. flags &= ~MAP_SHARED;
  164. #endif
  165. /* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
  166. flags |= MAP_PRIVATE | MAP_ANON;
  167. if (!(flags & MAP_FIXED))
  168. {
  169. #ifdef MAP_TRYFIXED
  170. /* If available, this will attempt a fixed mapping in-kernel */
  171. flags |= MAP_TRYFIXED;
  172. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
  173. if ( start && mmap( start, size, prot, flags | MAP_FIXED | MAP_EXCL, get_fdzero(), 0 ) != MAP_FAILED )
  174. return start;
  175. #elif defined(__svr4__) || defined(__NetBSD__) || defined(__APPLE__)
  176. if ( try_mmap_fixed( start, size, prot, flags, get_fdzero(), 0 ) )
  177. return start;
  178. #endif
  179. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  180. /* Even FreeBSD 5.3 does not properly support NULL here. */
  181. if( start == NULL ) start = (void *)0x110000;
  182. #endif
  183. }
  184. return mmap( start, size, prot, flags, get_fdzero(), 0 );
  185. }
  186. #ifdef __ASM_OBSOLETE
  187. struct reserved_area
  188. {
  189. struct list entry;
  190. void *base;
  191. size_t size;
  192. };
  193. static struct list reserved_areas = LIST_INIT(reserved_areas);
  194. #ifndef __APPLE__
  195. static const unsigned int granularity_mask = 0xffff; /* reserved areas have 64k granularity */
  196. #endif
  197. void wine_mmap_add_reserved_area_obsolete( void *addr, size_t size );
  198. #ifdef __APPLE__
  199. /***********************************************************************
  200. * reserve_area
  201. *
  202. * Reserve as much memory as possible in the given area.
  203. */
  204. static inline void reserve_area( void *addr, void *end )
  205. {
  206. #ifdef __i386__
  207. static const mach_vm_address_t max_address = VM_MAX_ADDRESS;
  208. #else
  209. static const mach_vm_address_t max_address = MACH_VM_MAX_ADDRESS;
  210. #endif
  211. mach_vm_address_t address = (mach_vm_address_t)addr;
  212. mach_vm_address_t end_address = (mach_vm_address_t)end;
  213. if (!end_address || max_address < end_address)
  214. end_address = max_address;
  215. while (address < end_address)
  216. {
  217. mach_vm_address_t hole_address = address;
  218. kern_return_t ret;
  219. mach_vm_size_t size;
  220. vm_region_basic_info_data_64_t info;
  221. mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64;
  222. mach_port_t dummy_object_name = MACH_PORT_NULL;
  223. /* find the mapped region at or above the current address. */
  224. ret = mach_vm_region(mach_task_self(), &address, &size, VM_REGION_BASIC_INFO_64,
  225. (vm_region_info_t)&info, &count, &dummy_object_name);
  226. if (ret != KERN_SUCCESS)
  227. {
  228. address = max_address;
  229. size = 0;
  230. }
  231. if (end_address < address)
  232. address = end_address;
  233. if (hole_address < address)
  234. {
  235. /* found a hole, attempt to reserve it. */
  236. size_t hole_size = address - hole_address;
  237. mach_vm_address_t alloc_address = hole_address;
  238. ret = mach_vm_map( mach_task_self(), &alloc_address, hole_size, 0, VM_FLAGS_FIXED,
  239. MEMORY_OBJECT_NULL, 0, 0, PROT_NONE, VM_PROT_ALL, VM_INHERIT_COPY );
  240. if (!ret)
  241. wine_mmap_add_reserved_area_obsolete( (void*)hole_address, hole_size );
  242. else if (ret == KERN_NO_SPACE)
  243. {
  244. /* something filled (part of) the hole before we could.
  245. go back and look again. */
  246. address = hole_address;
  247. continue;
  248. }
  249. }
  250. address += size;
  251. }
  252. }
  253. #else
  254. /***********************************************************************
  255. * mmap_reserve
  256. *
  257. * mmap wrapper used for reservations, only maps the specified address
  258. */
  259. static inline int mmap_reserve( void *addr, size_t size )
  260. {
  261. void *ptr;
  262. int flags = MAP_PRIVATE | MAP_ANON | MAP_NORESERVE;
  263. #ifdef MAP_TRYFIXED
  264. flags |= MAP_TRYFIXED;
  265. #elif defined(__APPLE__)
  266. return try_mmap_fixed( addr, size, PROT_NONE, flags, get_fdzero(), 0 );
  267. #endif
  268. ptr = mmap( addr, size, PROT_NONE, flags, get_fdzero(), 0 );
  269. if (ptr != addr && ptr != (void *)-1) munmap( ptr, size );
  270. return (ptr == addr);
  271. }
  272. /***********************************************************************
  273. * reserve_area
  274. *
  275. * Reserve as much memory as possible in the given area.
  276. */
  277. static inline void reserve_area( void *addr, void *end )
  278. {
  279. size_t size = (char *)end - (char *)addr;
  280. #if (defined(__svr4__) || defined(__NetBSD__)) && !defined(MAP_TRYFIXED)
  281. /* try_mmap_fixed is inefficient when using vfork, so we need a different algorithm here */
  282. /* we assume no other thread is running at this point */
  283. size_t i, pagesize = sysconf( _SC_PAGESIZE );
  284. char vec;
  285. while (size)
  286. {
  287. for (i = 0; i < size; i += pagesize)
  288. if (mincore( (caddr_t)addr + i, pagesize, &vec ) != -1) break;
  289. i &= ~granularity_mask;
  290. if (i && mmap( addr, i, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
  291. get_fdzero(), 0 ) != (void *)-1)
  292. wine_mmap_add_reserved_area_obsolete( addr, i );
  293. i += granularity_mask + 1;
  294. if ((char *)addr + i < (char *)addr) break; /* overflow */
  295. addr = (char *)addr + i;
  296. if (addr >= end) break;
  297. size = (char *)end - (char *)addr;
  298. }
  299. #else
  300. if (!size) return;
  301. if (mmap_reserve( addr, size ))
  302. {
  303. wine_mmap_add_reserved_area_obsolete( addr, size );
  304. return;
  305. }
  306. size = (size / 2) & ~granularity_mask;
  307. if (size)
  308. {
  309. reserve_area( addr, (char *)addr + size );
  310. reserve_area( (char *)addr + size, end );
  311. }
  312. #endif
  313. }
  314. #endif /* __APPLE__ */
  315. #ifdef __i386__
  316. /***********************************************************************
  317. * reserve_malloc_space
  318. *
  319. * Solaris malloc is not smart enough to obtain space through mmap(), so try to make
  320. * sure that there is some available sbrk() space before we reserve other things.
  321. */
  322. static inline void reserve_malloc_space( size_t size )
  323. {
  324. #ifdef __sun
  325. size_t i, count = size / 1024;
  326. void **ptrs = malloc( count * sizeof(ptrs[0]) );
  327. if (!ptrs) return;
  328. for (i = 0; i < count; i++) if (!(ptrs[i] = malloc( 1024 ))) break;
  329. if (i--) /* free everything except the last one */
  330. while (i) free( ptrs[--i] );
  331. free( ptrs );
  332. #endif
  333. }
  334. /***********************************************************************
  335. * reserve_dos_area
  336. *
  337. * Reserve the DOS area (0x00000000-0x00110000).
  338. */
  339. static inline void reserve_dos_area(void)
  340. {
  341. const size_t first_page = 0x1000;
  342. const size_t dos_area_size = 0x110000;
  343. void *ptr;
  344. /* first page has to be handled specially */
  345. ptr = wine_anon_mmap( (void *)first_page, dos_area_size - first_page, PROT_NONE, MAP_NORESERVE );
  346. if (ptr != (void *)first_page)
  347. {
  348. if (ptr != (void *)-1) munmap( ptr, dos_area_size - first_page );
  349. return;
  350. }
  351. /* now add first page with MAP_FIXED */
  352. wine_anon_mmap( NULL, first_page, PROT_NONE, MAP_NORESERVE|MAP_FIXED );
  353. wine_mmap_add_reserved_area_obsolete( NULL, dos_area_size );
  354. }
  355. #endif
  356. /***********************************************************************
  357. * mmap_init
  358. */
  359. void mmap_init(void)
  360. {
  361. #ifdef __i386__
  362. struct reserved_area *area;
  363. struct list *ptr;
  364. #ifndef __APPLE__
  365. char stack;
  366. char * const stack_ptr = &stack;
  367. #endif
  368. char *user_space_limit = (char *)0x7ffe0000;
  369. reserve_malloc_space( 8 * 1024 * 1024 );
  370. if (!list_head( &reserved_areas ))
  371. {
  372. /* if we don't have a preloader, try to reserve some space below 2Gb */
  373. reserve_area( (void *)0x00110000, (void *)0x40000000 );
  374. }
  375. /* check for a reserved area starting at the user space limit */
  376. /* to avoid wasting time trying to allocate it again */
  377. LIST_FOR_EACH( ptr, &reserved_areas )
  378. {
  379. area = LIST_ENTRY( ptr, struct reserved_area, entry );
  380. if ((char *)area->base > user_space_limit) break;
  381. if ((char *)area->base + area->size > user_space_limit)
  382. {
  383. user_space_limit = (char *)area->base + area->size;
  384. break;
  385. }
  386. }
  387. #ifndef __APPLE__
  388. if (stack_ptr >= user_space_limit)
  389. {
  390. char *end = 0;
  391. char *base = stack_ptr - ((unsigned int)stack_ptr & granularity_mask) - (granularity_mask + 1);
  392. if (base > user_space_limit) reserve_area( user_space_limit, base );
  393. base = stack_ptr - ((unsigned int)stack_ptr & granularity_mask) + (granularity_mask + 1);
  394. #if defined(linux) || defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
  395. /* Heuristic: assume the stack is near the end of the address */
  396. /* space, this avoids a lot of futile allocation attempts */
  397. end = (char *)(((unsigned long)base + 0x0fffffff) & 0xf0000000);
  398. #endif
  399. reserve_area( base, end );
  400. }
  401. else
  402. #endif
  403. reserve_area( user_space_limit, 0 );
  404. /* reserve the DOS area if not already done */
  405. ptr = list_head( &reserved_areas );
  406. if (ptr)
  407. {
  408. area = LIST_ENTRY( ptr, struct reserved_area, entry );
  409. if (!area->base) return; /* already reserved */
  410. }
  411. reserve_dos_area();
  412. #elif defined(__x86_64__) || defined(__aarch64__)
  413. if (!list_head( &reserved_areas ))
  414. {
  415. /* if we don't have a preloader, try to reserve the space now */
  416. reserve_area( (void *)0x000000010000, (void *)0x000068000000 );
  417. reserve_area( (void *)0x00007ff00000, (void *)0x00007fff0000 );
  418. reserve_area( (void *)0x7ffffe000000, (void *)0x7fffffff0000 );
  419. }
  420. #endif
  421. }
  422. /***********************************************************************
  423. * wine_mmap_add_reserved_area
  424. *
  425. * Add an address range to the list of reserved areas.
  426. * Caller must have made sure the range is not used by anything else.
  427. *
  428. * Note: the reserved areas functions are not reentrant, caller is
  429. * responsible for proper locking.
  430. */
  431. void wine_mmap_add_reserved_area_obsolete( void *addr, size_t size )
  432. {
  433. struct reserved_area *area;
  434. struct list *ptr;
  435. if (!((char *)addr + size)) size--; /* avoid wrap-around */
  436. LIST_FOR_EACH( ptr, &reserved_areas )
  437. {
  438. area = LIST_ENTRY( ptr, struct reserved_area, entry );
  439. if (area->base > addr)
  440. {
  441. /* try to merge with the next one */
  442. if ((char *)addr + size == (char *)area->base)
  443. {
  444. area->base = addr;
  445. area->size += size;
  446. return;
  447. }
  448. break;
  449. }
  450. else if ((char *)area->base + area->size == (char *)addr)
  451. {
  452. /* merge with the previous one */
  453. area->size += size;
  454. /* try to merge with the next one too */
  455. if ((ptr = list_next( &reserved_areas, ptr )))
  456. {
  457. struct reserved_area *next = LIST_ENTRY( ptr, struct reserved_area, entry );
  458. if ((char *)addr + size == (char *)next->base)
  459. {
  460. area->size += next->size;
  461. list_remove( &next->entry );
  462. free( next );
  463. }
  464. }
  465. return;
  466. }
  467. }
  468. if ((area = malloc( sizeof(*area) )))
  469. {
  470. area->base = addr;
  471. area->size = size;
  472. list_add_before( ptr, &area->entry );
  473. }
  474. }
  475. /***********************************************************************
  476. * wine_mmap_remove_reserved_area
  477. *
  478. * Remove an address range from the list of reserved areas.
  479. * If 'unmap' is non-zero the range is unmapped too.
  480. *
  481. * Note: the reserved areas functions are not reentrant, caller is
  482. * responsible for proper locking.
  483. */
  484. void wine_mmap_remove_reserved_area_obsolete( void *addr, size_t size, int unmap )
  485. {
  486. struct reserved_area *area;
  487. struct list *ptr;
  488. if (!((char *)addr + size)) size--; /* avoid wrap-around */
  489. ptr = list_head( &reserved_areas );
  490. /* find the first area covering address */
  491. while (ptr)
  492. {
  493. area = LIST_ENTRY( ptr, struct reserved_area, entry );
  494. if ((char *)area->base >= (char *)addr + size) break; /* outside the range */
  495. if ((char *)area->base + area->size > (char *)addr) /* overlaps range */
  496. {
  497. if (area->base >= addr)
  498. {
  499. if ((char *)area->base + area->size > (char *)addr + size)
  500. {
  501. /* range overlaps beginning of area only -> shrink area */
  502. if (unmap) munmap( area->base, (char *)addr + size - (char *)area->base );
  503. area->size -= (char *)addr + size - (char *)area->base;
  504. area->base = (char *)addr + size;
  505. break;
  506. }
  507. else
  508. {
  509. /* range contains the whole area -> remove area completely */
  510. ptr = list_next( &reserved_areas, ptr );
  511. if (unmap) munmap( area->base, area->size );
  512. list_remove( &area->entry );
  513. free( area );
  514. continue;
  515. }
  516. }
  517. else
  518. {
  519. if ((char *)area->base + area->size > (char *)addr + size)
  520. {
  521. /* range is in the middle of area -> split area in two */
  522. struct reserved_area *new_area = malloc( sizeof(*new_area) );
  523. if (new_area)
  524. {
  525. new_area->base = (char *)addr + size;
  526. new_area->size = (char *)area->base + area->size - (char *)new_area->base;
  527. list_add_after( ptr, &new_area->entry );
  528. }
  529. else size = (char *)area->base + area->size - (char *)addr;
  530. area->size = (char *)addr - (char *)area->base;
  531. if (unmap) munmap( addr, size );
  532. break;
  533. }
  534. else
  535. {
  536. /* range overlaps end of area only -> shrink area */
  537. if (unmap) munmap( addr, (char *)area->base + area->size - (char *)addr );
  538. area->size = (char *)addr - (char *)area->base;
  539. }
  540. }
  541. }
  542. ptr = list_next( &reserved_areas, ptr );
  543. }
  544. }
  545. /***********************************************************************
  546. * wine_mmap_is_in_reserved_area
  547. *
  548. * Check if the specified range is included in a reserved area.
  549. * Returns 1 if range is fully included, 0 if range is not included
  550. * at all, and -1 if it is only partially included.
  551. *
  552. * Note: the reserved areas functions are not reentrant, caller is
  553. * responsible for proper locking.
  554. */
  555. int wine_mmap_is_in_reserved_area_obsolete( void *addr, size_t size )
  556. {
  557. struct reserved_area *area;
  558. struct list *ptr;
  559. LIST_FOR_EACH( ptr, &reserved_areas )
  560. {
  561. area = LIST_ENTRY( ptr, struct reserved_area, entry );
  562. if (area->base > addr) break;
  563. if ((char *)area->base + area->size <= (char *)addr) continue;
  564. /* area must contain block completely */
  565. if ((char *)area->base + area->size < (char *)addr + size) return -1;
  566. return 1;
  567. }
  568. return 0;
  569. }
  570. /***********************************************************************
  571. * wine_mmap_enum_reserved_areas
  572. *
  573. * Enumerate the list of reserved areas, sorted by addresses.
  574. * If enum_func returns a non-zero value, enumeration is stopped and the value is returned.
  575. *
  576. * Note: the reserved areas functions are not reentrant, caller is
  577. * responsible for proper locking.
  578. */
  579. int wine_mmap_enum_reserved_areas_obsolete( int (*enum_func)(void *base, size_t size, void *arg), void *arg,
  580. int top_down )
  581. {
  582. int ret = 0;
  583. struct list *ptr;
  584. if (top_down)
  585. {
  586. for (ptr = reserved_areas.prev; ptr != &reserved_areas; ptr = ptr->prev)
  587. {
  588. struct reserved_area *area = LIST_ENTRY( ptr, struct reserved_area, entry );
  589. if ((ret = enum_func( area->base, area->size, arg ))) break;
  590. }
  591. }
  592. else
  593. {
  594. for (ptr = reserved_areas.next; ptr != &reserved_areas; ptr = ptr->next)
  595. {
  596. struct reserved_area *area = LIST_ENTRY( ptr, struct reserved_area, entry );
  597. if ((ret = enum_func( area->base, area->size, arg ))) break;
  598. }
  599. }
  600. return ret;
  601. }
  602. __ASM_OBSOLETE(wine_mmap_add_reserved_area);
  603. __ASM_OBSOLETE(wine_mmap_remove_reserved_area);
  604. __ASM_OBSOLETE(wine_mmap_is_in_reserved_area);
  605. __ASM_OBSOLETE(wine_mmap_enum_reserved_areas);
  606. #endif /* __ASM_OBSOLETE */