@shd101wyy/yo 0.1.24 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/skills/yo-async-effects/async-effects-recipes.md +6 -6
- package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +34 -0
- package/.github/skills/yo-syntax/syntax-cheatsheet.md +441 -2
- package/out/cjs/index.cjs +563 -567
- package/out/cjs/yo-cli.cjs +656 -651
- package/out/cjs/yo-lsp.cjs +614 -618
- package/out/esm/index.mjs +582 -586
- package/out/types/src/codegen/codegen-c.d.ts +2 -2
- package/out/types/src/codegen/functions/collection.d.ts +2 -2
- package/out/types/src/codegen/functions/context.d.ts +3 -2
- package/out/types/src/codegen/types/collection.d.ts +2 -2
- package/out/types/src/codegen/utils/index.d.ts +4 -1
- package/out/types/src/doc/builder.d.ts +2 -2
- package/out/types/src/evaluator/calls/closure-type.d.ts +2 -2
- package/out/types/src/evaluator/calls/record-type.d.ts +11 -0
- package/out/types/src/evaluator/context.d.ts +8 -9
- package/out/types/src/evaluator/index.d.ts +3 -3
- package/out/types/src/evaluator/types/record.d.ts +14 -0
- package/out/types/src/evaluator/types/validation.d.ts +2 -2
- package/out/types/src/evaluator/values/anonymous-module.d.ts +5 -5
- package/out/types/src/evaluator/values/impl.d.ts +1 -1
- package/out/types/src/expr.d.ts +2 -4
- package/out/types/src/function-value.d.ts +1 -1
- package/out/types/src/lsp/document-manager.d.ts +1 -1
- package/out/types/src/module-manager.d.ts +3 -3
- package/out/types/src/test-runner.d.ts +1 -0
- package/out/types/src/types/creators.d.ts +3 -4
- package/out/types/src/types/definitions.d.ts +8 -19
- package/out/types/src/types/guards.d.ts +3 -3
- package/out/types/src/types/tags.d.ts +0 -1
- package/out/types/src/types/utils.d.ts +1 -1
- package/out/types/src/value-tag.d.ts +0 -1
- package/out/types/src/value.d.ts +6 -13
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/error.yo +6 -6
- package/std/prelude.yo +1 -7
- package/vendor/mimalloc/.github/workflows/release.yaml +55 -0
- package/vendor/mimalloc/.github/workflows/stale.yaml +27 -0
- package/vendor/mimalloc/.github/workflows/test.yaml +163 -0
- package/vendor/mimalloc/CMakeLists.txt +52 -33
- package/vendor/mimalloc/azure-pipelines.yml +4 -3
- package/vendor/mimalloc/bin/bundle.bat +74 -0
- package/vendor/mimalloc/bin/bundle.sh +232 -0
- package/vendor/mimalloc/cmake/mimalloc-config-version.cmake +2 -2
- package/vendor/mimalloc/contrib/docker/alpine/Dockerfile +1 -1
- package/vendor/mimalloc/contrib/docker/alpine-arm32v7/Dockerfile +2 -2
- package/vendor/mimalloc/contrib/docker/alpine-x86/Dockerfile +1 -1
- package/vendor/mimalloc/contrib/docker/manylinux-x64/Dockerfile +1 -1
- package/vendor/mimalloc/contrib/vcpkg/portfile.cmake +4 -3
- package/vendor/mimalloc/contrib/vcpkg/vcpkg.json +1 -1
- package/vendor/mimalloc/doc/mimalloc-doc.h +42 -4
- package/vendor/mimalloc/doc/release-notes.md +15 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj +3 -3
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-static-lib.vcxproj +511 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-override-static-lib.vcxproj.filters +117 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test-dep.vcxproj +360 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc-test-override-static.vcxproj +310 -0
- package/vendor/mimalloc/ide/vs2022/mimalloc.sln +92 -35
- package/vendor/mimalloc/include/mimalloc/atomic.h +178 -182
- package/vendor/mimalloc/include/mimalloc/bits.h +8 -10
- package/vendor/mimalloc/include/mimalloc/internal.h +76 -32
- package/vendor/mimalloc/include/mimalloc/prim.h +25 -18
- package/vendor/mimalloc/include/mimalloc/track.h +7 -2
- package/vendor/mimalloc/include/mimalloc/types.h +57 -29
- package/vendor/mimalloc/include/mimalloc-override.h +10 -10
- package/vendor/mimalloc/include/mimalloc-stats.h +18 -6
- package/vendor/mimalloc/include/mimalloc.h +22 -12
- package/vendor/mimalloc/readme.md +42 -17
- package/vendor/mimalloc/src/alloc-aligned.c +13 -11
- package/vendor/mimalloc/src/alloc-override.c +97 -17
- package/vendor/mimalloc/src/alloc-posix.c +44 -27
- package/vendor/mimalloc/src/alloc.c +73 -23
- package/vendor/mimalloc/src/arena-meta.c +3 -3
- package/vendor/mimalloc/src/arena.c +380 -192
- package/vendor/mimalloc/src/bitmap.c +68 -18
- package/vendor/mimalloc/src/bitmap.h +8 -4
- package/vendor/mimalloc/src/free.c +83 -47
- package/vendor/mimalloc/src/heap.c +94 -40
- package/vendor/mimalloc/src/init.c +273 -102
- package/vendor/mimalloc/src/libc.c +53 -8
- package/vendor/mimalloc/src/options.c +43 -40
- package/vendor/mimalloc/src/os.c +110 -45
- package/vendor/mimalloc/src/page-map.c +14 -8
- package/vendor/mimalloc/src/page-queue.c +9 -6
- package/vendor/mimalloc/src/page.c +26 -16
- package/vendor/mimalloc/src/prim/emscripten/prim.c +10 -1
- package/vendor/mimalloc/src/prim/osx/alloc-override-zone.c +35 -16
- package/vendor/mimalloc/src/prim/unix/prim.c +26 -22
- package/vendor/mimalloc/src/prim/wasi/prim.c +7 -4
- package/vendor/mimalloc/src/prim/windows/prim.c +247 -44
- package/vendor/mimalloc/src/random.c +8 -3
- package/vendor/mimalloc/src/stats.c +59 -48
- package/vendor/mimalloc/src/theap.c +85 -44
- package/vendor/mimalloc/src/threadlocal.c +102 -41
- package/vendor/mimalloc/test/main-override-static.c +31 -2
- package/vendor/mimalloc/test/main-override.c +27 -14
- package/vendor/mimalloc/test/main-static-dep.cpp +46 -0
- package/vendor/mimalloc/test/main-static-dep.h +11 -0
- package/vendor/mimalloc/test/test-api-fill.c +2 -2
- package/vendor/mimalloc/test/test-stress.c +3 -3
- package/vendor/mimalloc/test/test-wrong.c +11 -7
- package/out/types/src/evaluator/calls/module-type.d.ts +0 -11
- package/out/types/src/evaluator/types/module.d.ts +0 -19
|
@@ -61,14 +61,14 @@ int mi_posix_memalign(void** p, size_t alignment, size_t size) mi_attr_noexcept
|
|
|
61
61
|
if (alignment==0 || !_mi_is_power_of_two(alignment)) return EINVAL; // not a power of 2
|
|
62
62
|
void* q = mi_malloc_aligned(size, alignment);
|
|
63
63
|
if (q==NULL && size != 0) return ENOMEM;
|
|
64
|
-
mi_assert_internal((
|
|
64
|
+
mi_assert_internal(_mi_is_aligned(q,alignment));
|
|
65
65
|
*p = q;
|
|
66
66
|
return 0;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
mi_decl_nodiscard mi_decl_restrict void* mi_memalign(size_t alignment, size_t size) mi_attr_noexcept {
|
|
70
70
|
void* p = mi_malloc_aligned(size, alignment);
|
|
71
|
-
mi_assert_internal((
|
|
71
|
+
mi_assert_internal(_mi_is_aligned(p,alignment));
|
|
72
72
|
return p;
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -95,27 +95,43 @@ mi_decl_nodiscard mi_decl_restrict void* mi_aligned_alloc(size_t alignment, size
|
|
|
95
95
|
*/
|
|
96
96
|
// C11 also requires alignment to be a power-of-two (and > 0) which is checked in mi_malloc_aligned
|
|
97
97
|
void* p = mi_malloc_aligned(size, alignment);
|
|
98
|
-
mi_assert_internal((
|
|
98
|
+
mi_assert_internal(_mi_is_aligned(p,alignment));
|
|
99
99
|
return p;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
mi_decl_nodiscard void* mi_reallocarray( void* p, size_t count, size_t size ) mi_attr_noexcept { // BSD
|
|
103
|
-
|
|
102
|
+
mi_decl_nodiscard void* mi_reallocarray( void* p, size_t count, size_t size ) mi_attr_noexcept { // BSD <https://man.freebsd.org/cgi/man.cgi?query=reallocarray>
|
|
103
|
+
size_t total;
|
|
104
|
+
if mi_unlikely(mi_count_size_overflow(count, size, &total)) {
|
|
105
|
+
errno = EOVERFLOW;
|
|
106
|
+
return NULL;
|
|
107
|
+
}
|
|
108
|
+
void* newp = mi_realloc(p,total);
|
|
104
109
|
if (newp==NULL) { errno = ENOMEM; }
|
|
105
110
|
return newp;
|
|
106
111
|
}
|
|
107
112
|
|
|
108
|
-
mi_decl_nodiscard int mi_reallocarr( void*
|
|
109
|
-
mi_assert(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return EINVAL;
|
|
113
|
+
mi_decl_nodiscard int mi_reallocarr( void* ptrp, size_t count, size_t size ) mi_attr_noexcept { // NetBSD <https://man.netbsd.org/reallocarr.3>
|
|
114
|
+
mi_assert(size != 0);
|
|
115
|
+
mi_assert(ptrp != NULL);
|
|
116
|
+
if (ptrp == NULL || size == 0) {
|
|
117
|
+
return (errno = EINVAL);
|
|
118
|
+
}
|
|
119
|
+
size_t total;
|
|
120
|
+
if mi_unlikely(mi_count_size_overflow(count, size, &total)) {
|
|
121
|
+
return (errno = EOVERFLOW);
|
|
122
|
+
}
|
|
123
|
+
void** op = (void**)ptrp;
|
|
124
|
+
if (total == 0) {
|
|
125
|
+
free(*op);
|
|
126
|
+
*op = NULL;
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
void* newp = mi_realloc(*op,total);
|
|
131
|
+
if (newp == NULL) { return (errno = ENOMEM); }
|
|
132
|
+
*op = newp;
|
|
133
|
+
return 0;
|
|
113
134
|
}
|
|
114
|
-
void** op = (void**)p;
|
|
115
|
-
void* newp = mi_reallocarray(*op, count, size);
|
|
116
|
-
if mi_unlikely(newp == NULL) { return errno; }
|
|
117
|
-
*op = newp;
|
|
118
|
-
return 0;
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
void* mi__expand(void* p, size_t newsize) mi_attr_noexcept { // Microsoft
|
|
@@ -124,12 +140,13 @@ void* mi__expand(void* p, size_t newsize) mi_attr_noexcept { // Microsoft
|
|
|
124
140
|
return res;
|
|
125
141
|
}
|
|
126
142
|
|
|
127
|
-
mi_decl_nodiscard mi_decl_restrict
|
|
143
|
+
mi_decl_nodiscard mi_decl_restrict wchar_t* mi_wcsdup(const wchar_t* s) mi_attr_noexcept {
|
|
128
144
|
if (s==NULL) return NULL;
|
|
129
|
-
size_t
|
|
130
|
-
for(
|
|
131
|
-
size_t size
|
|
132
|
-
|
|
145
|
+
size_t wlen;
|
|
146
|
+
for(wlen = 0; s[wlen] != 0 && wlen < PTRDIFF_MAX; wlen++) { } // prevent overflow on wlen+1
|
|
147
|
+
size_t size;
|
|
148
|
+
if (mi_mul_overflow(wlen+1, sizeof(wchar_t), &size) || size > PTRDIFF_MAX) return NULL;
|
|
149
|
+
wchar_t* p = (wchar_t*)mi_malloc(size);
|
|
133
150
|
if (p != NULL) {
|
|
134
151
|
_mi_memcpy(p,s,size);
|
|
135
152
|
}
|
|
@@ -141,36 +158,36 @@ mi_decl_nodiscard mi_decl_restrict unsigned char* mi_mbsdup(const unsigned char*
|
|
|
141
158
|
}
|
|
142
159
|
|
|
143
160
|
int mi_dupenv_s(char** buf, size_t* size, const char* name) mi_attr_noexcept {
|
|
144
|
-
if (buf==NULL || name==NULL) return EINVAL;
|
|
145
161
|
if (size != NULL) *size = 0;
|
|
146
|
-
|
|
162
|
+
if (buf==NULL || name==NULL) return EINVAL;
|
|
163
|
+
char* p = getenv(name);
|
|
147
164
|
if (p==NULL) {
|
|
148
165
|
*buf = NULL;
|
|
149
166
|
}
|
|
150
167
|
else {
|
|
151
168
|
*buf = mi_strdup(p);
|
|
152
169
|
if (*buf==NULL) return ENOMEM;
|
|
153
|
-
if (size != NULL) *size = _mi_strlen(p);
|
|
170
|
+
if (size != NULL) { *size = _mi_strlen(p) + 1; } // cannot overflow as mi_strdup is limited to PTRDIFF_MAX
|
|
154
171
|
}
|
|
155
172
|
return 0;
|
|
156
173
|
}
|
|
157
174
|
|
|
158
|
-
int mi_wdupenv_s(
|
|
159
|
-
if (buf==NULL || name==NULL) return EINVAL;
|
|
175
|
+
int mi_wdupenv_s(wchar_t** buf, size_t* size, const wchar_t* name) mi_attr_noexcept {
|
|
160
176
|
if (size != NULL) *size = 0;
|
|
177
|
+
if (buf==NULL || name==NULL) return EINVAL;
|
|
161
178
|
#if !defined(_WIN32) || (defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP))
|
|
162
179
|
// not supported
|
|
163
180
|
*buf = NULL;
|
|
164
181
|
return EINVAL;
|
|
165
182
|
#else
|
|
166
|
-
|
|
183
|
+
wchar_t* p = (wchar_t*)_wgetenv(name);
|
|
167
184
|
if (p==NULL) {
|
|
168
185
|
*buf = NULL;
|
|
169
186
|
}
|
|
170
187
|
else {
|
|
171
188
|
*buf = mi_wcsdup(p);
|
|
172
189
|
if (*buf==NULL) return ENOMEM;
|
|
173
|
-
if (size != NULL) *size = wcslen(
|
|
190
|
+
if (size != NULL) { *size = wcslen(p) + 1; } // cannot overflow as wcsdup is limited to PTRDIFF_MAX
|
|
174
191
|
}
|
|
175
192
|
return 0;
|
|
176
193
|
#endif
|
|
@@ -33,8 +33,8 @@ static mi_decl_forceinline void* mi_page_malloc_zero(mi_theap_t* theap, mi_page_
|
|
|
33
33
|
{
|
|
34
34
|
if (page->block_size != 0) { // not the empty theap
|
|
35
35
|
mi_assert_internal(mi_page_block_size(page) >= size);
|
|
36
|
-
mi_assert_internal(_mi_is_aligned(page, MI_PAGE_ALIGN));
|
|
37
|
-
mi_assert_internal(_mi_ptr_page(page)==page);
|
|
36
|
+
mi_assert_internal(_mi_is_aligned(mi_page_slice_start(page), MI_PAGE_ALIGN));
|
|
37
|
+
mi_assert_internal(_mi_ptr_page(mi_page_start(page))==page);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// check the free list
|
|
@@ -91,7 +91,7 @@ static mi_decl_forceinline void* mi_page_malloc_zero(mi_theap_t* theap, mi_page_
|
|
|
91
91
|
else {
|
|
92
92
|
block->next = 0;
|
|
93
93
|
mi_track_mem_defined(block, bsize);
|
|
94
|
-
}
|
|
94
|
+
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
#if MI_PADDING // && !MI_TRACK_ENABLED
|
|
@@ -265,6 +265,15 @@ mi_decl_nodiscard mi_decl_restrict void* mi_zalloc_small(size_t size) mi_attr_no
|
|
|
265
265
|
return mi_theap_malloc_small_zero(_mi_theap_default(), size, true, NULL);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
mi_decl_nodiscard extern inline mi_decl_restrict void* mi_theap_zalloc_small(mi_theap_t* theap, size_t size) mi_attr_noexcept {
|
|
269
|
+
return mi_theap_malloc_small_zero(theap, size, true, NULL);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
mi_decl_nodiscard mi_decl_restrict void* mi_heap_zalloc_small(mi_heap_t* heap, size_t size) mi_attr_noexcept {
|
|
273
|
+
return mi_theap_malloc_small_zero_nonnull(_mi_heap_theap(heap), size, true, NULL);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
268
277
|
mi_decl_nodiscard extern inline mi_decl_restrict void* mi_theap_zalloc(mi_theap_t* theap, size_t size) mi_attr_noexcept {
|
|
269
278
|
return _mi_theap_malloc_zero(theap, size, true, NULL);
|
|
270
279
|
}
|
|
@@ -366,7 +375,7 @@ void* _mi_theap_realloc_zero(mi_theap_t* theap, void* p, size_t newsize, bool ze
|
|
|
366
375
|
if (usable_pre!=NULL) { *usable_pre = mi_page_usable_block_size(page); }
|
|
367
376
|
}
|
|
368
377
|
if mi_unlikely(newsize<=size && newsize>=(size/2) && newsize>0 // note: newsize must be > 0 or otherwise we return NULL for realloc(NULL,0)
|
|
369
|
-
&& mi_page_heap(page)==theap
|
|
378
|
+
&& mi_page_heap(page)==_mi_theap_heap(theap)) // and within the same heap
|
|
370
379
|
{
|
|
371
380
|
mi_assert_internal(p!=NULL);
|
|
372
381
|
// todo: do not track as the usable size is still the same in the free; adjust potential padding?
|
|
@@ -481,6 +490,7 @@ mi_decl_nodiscard void* mi_heap_recalloc(mi_heap_t* heap, void* p, size_t count,
|
|
|
481
490
|
mi_decl_nodiscard static mi_decl_restrict char* mi_theap_strdup(mi_theap_t* theap, const char* s) mi_attr_noexcept {
|
|
482
491
|
if (s == NULL) return NULL;
|
|
483
492
|
size_t len = _mi_strlen(s);
|
|
493
|
+
if (len > MI_MAX_ALLOC_SIZE - 1) return NULL; // prevent overflow on len+1
|
|
484
494
|
char* t = (char*)mi_theap_malloc(theap,len+1);
|
|
485
495
|
if (t == NULL) return NULL;
|
|
486
496
|
_mi_memcpy(t, s, len);
|
|
@@ -500,6 +510,7 @@ mi_decl_nodiscard mi_decl_restrict char* mi_heap_strdup(mi_heap_t* heap, const c
|
|
|
500
510
|
mi_decl_nodiscard static mi_decl_restrict char* mi_theap_strndup(mi_theap_t* theap, const char* s, size_t n) mi_attr_noexcept {
|
|
501
511
|
if (s == NULL) return NULL;
|
|
502
512
|
const size_t len = _mi_strnlen(s,n); // len <= n
|
|
513
|
+
if (len > MI_MAX_ALLOC_SIZE - 1) return NULL; // prevent overflow on len+1
|
|
503
514
|
char* t = (char*)mi_theap_malloc(theap, len+1);
|
|
504
515
|
if (t == NULL) return NULL;
|
|
505
516
|
_mi_memcpy(t, s, len);
|
|
@@ -539,17 +550,51 @@ mi_decl_nodiscard static mi_decl_restrict char* mi_theap_realpath(mi_theap_t* th
|
|
|
539
550
|
return mi_theap_strndup(theap, buf, PATH_MAX);
|
|
540
551
|
}
|
|
541
552
|
}
|
|
553
|
+
|
|
542
554
|
#else
|
|
555
|
+
|
|
556
|
+
#include <unistd.h> // pathconf
|
|
557
|
+
|
|
558
|
+
static size_t mi_path_max(void) {
|
|
559
|
+
static _Atomic(size_t) path_max = 0;
|
|
560
|
+
size_t pmax = mi_atomic_load_acquire(&path_max);
|
|
561
|
+
if (pmax == 0) {
|
|
562
|
+
long m = 0;
|
|
563
|
+
#ifdef _PC_PATH_MAX
|
|
564
|
+
m = pathconf("/",_PC_PATH_MAX);
|
|
565
|
+
#endif
|
|
566
|
+
if (m <= 0) pmax = 4096; // guess
|
|
567
|
+
else if (m < 256) pmax = 256; // at least 256
|
|
568
|
+
else if (m > 64*1024) pmax = 64*1024; // at most 64 KiB
|
|
569
|
+
else pmax = m;
|
|
570
|
+
size_t expected = 0;
|
|
571
|
+
mi_atomic_cas_strong_acq_rel(&path_max, &expected, pmax);
|
|
572
|
+
}
|
|
573
|
+
return pmax;
|
|
574
|
+
}
|
|
575
|
+
|
|
543
576
|
char* mi_theap_realpath(mi_theap_t* theap, const char* fname, char* resolved_name) mi_attr_noexcept {
|
|
544
577
|
if (resolved_name != NULL) {
|
|
545
578
|
return realpath(fname,resolved_name);
|
|
546
579
|
}
|
|
547
580
|
else {
|
|
581
|
+
/*
|
|
548
582
|
char* rname = realpath(fname, NULL);
|
|
549
583
|
if (rname == NULL) return NULL;
|
|
550
|
-
char* result =
|
|
551
|
-
mi_cfree(rname); //
|
|
584
|
+
char* result = mi_heap_strdup(heap, rname);
|
|
585
|
+
mi_cfree(rname); // note: may leak the original pointer if allocated internally with the system allocator
|
|
552
586
|
// note: with ASAN realpath is intercepted and mi_cfree may leak the returned pointer :-(
|
|
587
|
+
return result;
|
|
588
|
+
*/
|
|
589
|
+
const size_t n = mi_path_max();
|
|
590
|
+
char* const buf = (char*)mi_zalloc(n+1);
|
|
591
|
+
if (buf == NULL) {
|
|
592
|
+
errno = ENOMEM;
|
|
593
|
+
return NULL;
|
|
594
|
+
}
|
|
595
|
+
char* rname = realpath(fname,buf);
|
|
596
|
+
char* result = mi_theap_strndup(theap,rname,n); // ok if `rname==NULL`
|
|
597
|
+
mi_free(buf);
|
|
553
598
|
return result;
|
|
554
599
|
}
|
|
555
600
|
}
|
|
@@ -750,7 +795,7 @@ static void* mi_block_ptr_set_guarded(mi_block_t* block, size_t obj_size) {
|
|
|
750
795
|
}
|
|
751
796
|
uint8_t* guard_page = (uint8_t*)block + block_size - os_page_size;
|
|
752
797
|
// note: the alignment of the guard page relies on blocks being os_page_size aligned which
|
|
753
|
-
// is ensured in `mi_arena_page_alloc_fresh`.
|
|
798
|
+
// is ensured in `mi_arena_page_alloc_fresh`.
|
|
754
799
|
mi_assert_internal(_mi_is_aligned(block, os_page_size));
|
|
755
800
|
mi_assert_internal(_mi_is_aligned(guard_page, os_page_size));
|
|
756
801
|
if (!page->memid.is_pinned && _mi_is_aligned(guard_page, os_page_size)) {
|
|
@@ -770,7 +815,8 @@ static void* mi_block_ptr_set_guarded(mi_block_t* block, size_t obj_size) {
|
|
|
770
815
|
// give up to place it right in front of the guard page if the offset is too large for unalignment
|
|
771
816
|
offset = MI_PAGE_MAX_OVERALLOC_ALIGN;
|
|
772
817
|
}
|
|
773
|
-
|
|
818
|
+
uint8_t* const p = (uint8_t*)block + offset;
|
|
819
|
+
mi_assert_internal(p == guard_page - obj_size);
|
|
774
820
|
mi_track_align(block, p, offset, obj_size);
|
|
775
821
|
mi_track_mem_defined(block, sizeof(mi_block_t));
|
|
776
822
|
return p;
|
|
@@ -778,31 +824,35 @@ static void* mi_block_ptr_set_guarded(mi_block_t* block, size_t obj_size) {
|
|
|
778
824
|
|
|
779
825
|
mi_decl_restrict void* _mi_theap_malloc_guarded(mi_theap_t* theap, size_t size, bool zero) mi_attr_noexcept
|
|
780
826
|
{
|
|
781
|
-
#if defined(MI_PADDING_SIZE)
|
|
782
|
-
mi_assert(MI_PADDING_SIZE==0);
|
|
783
|
-
#endif
|
|
784
827
|
// allocate multiple of page size ending in a guard page
|
|
785
828
|
// ensure minimal alignment requirement?
|
|
829
|
+
if mi_unlikely(size >= MI_MAX_ALLOC_SIZE - MI_PADDING_SIZE) { // check up front so the `req_size` won't overflow
|
|
830
|
+
_mi_error_message(EOVERFLOW, "(guarded) allocation request is too large (%zu bytes)\n", size);
|
|
831
|
+
return NULL;
|
|
832
|
+
}
|
|
786
833
|
const size_t os_page_size = _mi_os_page_size();
|
|
787
834
|
const size_t obj_size = (mi_option_is_enabled(mi_option_guarded_precise) ? size : _mi_align_up(size, MI_MAX_ALIGN_SIZE));
|
|
788
835
|
const size_t bsize = _mi_align_up(_mi_align_up(obj_size, MI_MAX_ALIGN_SIZE) + sizeof(mi_block_t), MI_MAX_ALIGN_SIZE);
|
|
789
|
-
const size_t req_size = _mi_align_up(bsize + os_page_size, os_page_size);
|
|
790
|
-
mi_block_t* const block = (mi_block_t*)_mi_malloc_generic(theap, req_size,
|
|
836
|
+
const size_t req_size = _mi_align_up(bsize + os_page_size, os_page_size);
|
|
837
|
+
mi_block_t* const block = (mi_block_t*)_mi_malloc_generic(theap, req_size, 0 /* don't zero */, NULL);
|
|
791
838
|
if (block==NULL) return NULL;
|
|
792
839
|
void* const p = mi_block_ptr_set_guarded(block, obj_size);
|
|
840
|
+
if (p == NULL) return p;
|
|
841
|
+
if (zero) {
|
|
842
|
+
_mi_memzero_aligned(p,obj_size); // we have to zero here as padding might have written here (if the blocksize > reqsize + os_page_size)
|
|
843
|
+
}
|
|
793
844
|
|
|
794
845
|
// stats
|
|
795
|
-
mi_track_malloc(p,
|
|
796
|
-
if (
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
}
|
|
846
|
+
mi_track_malloc(p, obj_size, zero);
|
|
847
|
+
if (!mi_theap_is_initialized(theap)) { theap = _mi_theap_default(); }
|
|
848
|
+
mi_theap_stat_counter_increase(theap, malloc_guarded_count, 1);
|
|
849
|
+
#if MI_STAT>1
|
|
850
|
+
// adjust stats to only count the allocated size of the block (and not the guard page)
|
|
851
|
+
mi_theap_stat_adjust_decrease(theap, malloc_requested, req_size);
|
|
852
|
+
mi_theap_stat_increase(theap, malloc_requested, size);
|
|
853
|
+
#endif
|
|
804
854
|
#if MI_DEBUG>3
|
|
805
|
-
if (
|
|
855
|
+
if (zero) {
|
|
806
856
|
mi_assert_expensive(mi_mem_is_zero(p, size));
|
|
807
857
|
}
|
|
808
858
|
#endif
|
|
@@ -46,7 +46,7 @@ static mi_decl_cache_align _Atomic(mi_meta_page_t*) mi_meta_pages = MI_ATOMIC_V
|
|
|
46
46
|
|
|
47
47
|
#if MI_DEBUG > 1
|
|
48
48
|
static mi_meta_page_t* mi_meta_page_of_ptr(void* p, size_t* block_idx) {
|
|
49
|
-
mi_meta_page_t* mpage = (mi_meta_page_t*)((uint8_t*)
|
|
49
|
+
mi_meta_page_t* mpage = (mi_meta_page_t*)((uint8_t*)_mi_align_down_ptr(p,MI_META_PAGE_ALIGN) + _mi_os_secure_guard_page_size());
|
|
50
50
|
if (block_idx != NULL) {
|
|
51
51
|
*block_idx = ((uint8_t*)p - (uint8_t*)mpage) / MI_META_BLOCK_SIZE;
|
|
52
52
|
}
|
|
@@ -118,7 +118,7 @@ mi_decl_noinline void* _mi_meta_zalloc( size_t size, mi_memid_t* pmemid )
|
|
|
118
118
|
mi_meta_page_t* mpage = mpage0;
|
|
119
119
|
while (mpage != NULL) {
|
|
120
120
|
size_t block_idx;
|
|
121
|
-
if (mi_bbitmap_try_find_and_clearN(&mpage->blocks_free,
|
|
121
|
+
if (mi_bbitmap_try_find_and_clearN(&mpage->blocks_free, 0, block_count, &block_idx)) {
|
|
122
122
|
// found and claimed `block_count` blocks
|
|
123
123
|
*pmemid = _mi_memid_create_meta(mpage, block_idx, block_count);
|
|
124
124
|
return mi_meta_block_start(mpage,block_idx);
|
|
@@ -136,7 +136,7 @@ mi_decl_noinline void* _mi_meta_zalloc( size_t size, mi_memid_t* pmemid )
|
|
|
136
136
|
mpage = mi_meta_page_zalloc();
|
|
137
137
|
if (mpage != NULL) {
|
|
138
138
|
size_t block_idx;
|
|
139
|
-
if (mi_bbitmap_try_find_and_clearN(&mpage->blocks_free,
|
|
139
|
+
if (mi_bbitmap_try_find_and_clearN(&mpage->blocks_free, 0, block_count, &block_idx)) {
|
|
140
140
|
// found and claimed `block_count` blocks
|
|
141
141
|
*pmemid = _mi_memid_create_meta(mpage, block_idx, block_count);
|
|
142
142
|
return mi_meta_block_start(mpage,block_idx);
|