1
- #define HAVE_MMAP 0
2
- #define HAVE_MORECORE 1
3
- #define MORECORE_CONTIGUOUS 0
4
- #define MORECORE_CANNOT_TRIM 1
1
+ #define HAVE_MMAP 1
2
+ #define LACKS_SYS_MMAN_H 1
3
+ #define MMAP_CLEARS 0
4
+ #define HAVE_MORECORE 0
5
5
#define NO_MALLOC_STATS 1
6
- #define LACKS_TIME_H /* time(0) calls malloc... */
6
+ #define LACKS_TIME_H 1 /* time(0) calls malloc... */
7
+ #define DEFAULT_GRANULARITY 0
8
+ #define MALLOC_ALIGNMENT 16
7
9
8
10
/*
9
11
Copyright 2023 Doug Lea
@@ -1653,7 +1655,7 @@ unsigned char _BitScanReverse(unsigned long *index, unsigned long mask);
1653
1655
1654
1656
#if HAVE_MMAP
1655
1657
1656
- #ifndef WIN32
1658
+ #if !defined( WIN32 ) && !defined( __MINT__ )
1657
1659
#define MUNMAP_DEFAULT (a , s ) munmap((a), (s))
1658
1660
#define MMAP_PROT (PROT_READ|PROT_WRITE)
1659
1661
#if !defined(MAP_ANONYMOUS ) && defined(MAP_ANON )
@@ -1677,7 +1679,7 @@ static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */
1677
1679
1678
1680
#define DIRECT_MMAP_DEFAULT (s ) MMAP_DEFAULT(s)
1679
1681
1680
- #else /* WIN32 */
1682
+ #elif defined( WIN32 )
1681
1683
1682
1684
/* Win32 MMAP via VirtualAlloc */
1683
1685
static FORCEINLINE void * win32mmap (size_t size ) {
@@ -1713,6 +1715,71 @@ static FORCEINLINE int win32munmap(void* ptr, size_t size) {
1713
1715
#define MMAP_DEFAULT (s ) win32mmap(s)
1714
1716
#define MUNMAP_DEFAULT (a , s ) win32munmap((a), (s))
1715
1717
#define DIRECT_MMAP_DEFAULT (s ) win32direct_mmap(s)
1718
+
1719
+ #else /* __MINT__ */
1720
+
1721
+ #include <mint/osbind.h>
1722
+
1723
+ #define MAX_POOL_ENTRIES 256
1724
+ static int next_os_pool ;
1725
+ static struct {
1726
+ void * ptr ;
1727
+ size_t size ;
1728
+ } os_pools [MAX_POOL_ENTRIES ];
1729
+
1730
+ /* Atari MMAP via Malloc */
1731
+ static FORCEINLINE void * atarimmap (size_t size ) {
1732
+ void * ptr ;
1733
+
1734
+ if (next_os_pool == MAX_POOL_ENTRIES )
1735
+ return MFAIL ;
1736
+
1737
+ ptr = (void * )Malloc (size );
1738
+
1739
+ if (ptr != 0 ) {
1740
+ os_pools [next_os_pool ].ptr = ptr ;
1741
+ os_pools [next_os_pool ].size = size ;
1742
+ next_os_pool ++ ;
1743
+ return ptr ;
1744
+ }
1745
+
1746
+ return MFAIL ;
1747
+ }
1748
+
1749
+ /* This function supports releasing coalesed segments */
1750
+ static FORCEINLINE int atarimunmap (void * ptr , size_t size ) {
1751
+ char * cptr = (char * )ptr ;
1752
+ while (size ) {
1753
+ int found = -1 ;
1754
+
1755
+ for (int i = 0 ; i < next_os_pool ; ++ i ) {
1756
+ if (os_pools [i ].ptr == cptr ) {
1757
+ if (os_pools [i ].size <= size )
1758
+ found = i ;
1759
+ break ;
1760
+ }
1761
+ }
1762
+
1763
+ if (found != -1 ) {
1764
+ cptr += os_pools [found ].size ;
1765
+ size -= os_pools [found ].size ;
1766
+
1767
+ if (-- next_os_pool > 0 )
1768
+ os_pools [found ] = os_pools [next_os_pool ];
1769
+
1770
+ Mfree (cptr );
1771
+ }
1772
+ else
1773
+ return -1 ;
1774
+ }
1775
+
1776
+ return 0 ;
1777
+ }
1778
+
1779
+ #define MMAP_DEFAULT (s ) atarimmap(s)
1780
+ #define MUNMAP_DEFAULT (a , s ) atarimunmap((a), (s))
1781
+ #define DIRECT_MMAP_DEFAULT (s ) MMAP_DEFAULT(s)
1782
+
1716
1783
#endif /* WIN32 */
1717
1784
#endif /* HAVE_MMAP */
1718
1785
@@ -4169,8 +4236,7 @@ static void* sys_alloc(mstate m, size_t nb) {
4169
4236
char * end = CMFAIL ;
4170
4237
ACQUIRE_MALLOC_GLOBAL_LOCK ();
4171
4238
br = (char * )(CALL_MORECORE (asize ));
4172
- /* end = (char*)(CALL_MORECORE(0)); */
4173
- end = br + asize ;
4239
+ end = (char * )(CALL_MORECORE (0 ));
4174
4240
RELEASE_MALLOC_GLOBAL_LOCK ();
4175
4241
if (br != CMFAIL && end != CMFAIL && br < end ) {
4176
4242
size_t ssize = end - br ;
0 commit comments