summaryrefslogtreecommitdiff
path: root/mallocx.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-10-28 09:23:51 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-10-28 21:21:45 +0300
commitd4c81638d9087f5c344b0e86de6b2b3827c84f58 (patch)
tree5a18846c33701c8346d98fcd4066916f92876f66 /mallocx.c
parenta37cdaa3b7a0c1ac4acc9213bb0a5fa4b4f852e9 (diff)
downloadbdwgc-d4c81638d9087f5c344b0e86de6b2b3827c84f58.tar.gz
Define public GC_[p]valloc() and redirect to them in leak_detector.h
Issue #495 (bdwgc). * doc/README.macros (GC_NO_VALLOC): Document. * doc/leak.md: Mention GNU valloc and pvalloc functions. * include/gc/gc.h (GC_memalign): Remove comment that it is not tested; add comment describing the functionality and a note. * include/gc/gc.h [!GC_NO_VALLOC] (GC_valloc, GC_pvalloc): Declare new API function. * include/gc/leak_detector.h [!GC_NO_VALLOC] (valloc, pvalloc): Redefine to the corresponding GC_ function. * include/private/gc_priv.h (GC_page_size): Add comment. * include/private/gc_priv.h (GC_real_page_size): Declare new variable (or as a macro). * include/private/gcconfig.h [NACL] (GETPAGESIZE): Add TODO item. * mallocx.c (GC_memalign): Likewise. * tests/gctest.c (run_one_test): Likewise. * include/private/gcconfig.h [CYGWIN32 && (MPROTECT_VDB || USE_MUNMAP) || !MSWIN32 && !MSWINCE && !CYGWIN32 && (GC_DISABLE_INCREMENTAL || DEFAULT_VDB) && !USE_MMAP] (ALT_PAGESIZE_USED): Define macro. * include/private/gcconfig.h [CYGWIN32 && (MPROTECT_VDB || USE_MUNMAP) || !MSWIN32 && !MSWINCE && !CYGWIN32 && (GC_DISABLE_INCREMENTAL || DEFAULT_VDB) && !USE_MMAP && !GC_NO_VALLOC] (REAL_PAGESIZE_NEEDED): Likewise. * mallocx.c (GC_strdup): Reformat comment. * mallocx.c [!GC_NO_VALLOC] (GC_valloc, GC_pvalloc): Implement. * os_dep.c [REAL_PAGESIZE_NEEDED] (GC_real_page_size): Define variable. * os_dep.c [MSWIN32 || MSWINCE || CYGWIN32] (GC_setpagesize): Replace CYGWIN32&&(MPROTECT_VDB||USE_MUNMAP) to ALT_PAGESIZE_USED; remove comment that a separate variable could be added; reformat comment; assert about GC_pagesize only if REAL_PAGESIZE_NEEDED. * os_dep.c [ALT_PAGESIZE_USED && REAL_PAGESIZE_NEEDED] (GC_setpagesize): Set GC_real_page_size. * os_dep.c [!MSWIN32 && !MSWINCE && !CYGWIN32] (GC_setpagesize): Replace MPROTECT_VDB||PROC_VDB||SOFT_VDB||USE_MMAP to !ALT_PAGESIZE_USED. * tests/gctest.c [!GC_NO_VALLOC] (run_one_test): Call GC_valloc() and GC_pvalloc().
Diffstat (limited to 'mallocx.c')
-rw-r--r--mallocx.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/mallocx.c b/mallocx.c
index cb6dec07..aa441d2b 100644
--- a/mallocx.c
+++ b/mallocx.c
@@ -513,6 +513,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_memalign(size_t align, size_t lb)
}
/* We could also try to make sure that the real rounded-up object size */
/* is a multiple of align. That would be correct up to HBLKSIZE. */
+ /* TODO: Not space efficient for big align values. */
new_lb = SIZET_SAT_ADD(lb, align - 1);
result = (ptr_t)GC_malloc(new_lb);
/* It is OK not to check result for NULL as in that case */
@@ -554,8 +555,25 @@ GC_API int GC_CALL GC_posix_memalign(void **memptr, size_t align, size_t lb)
return 0;
}
-/* provide a version of strdup() that uses the collector to allocate the
- copy of the string */
+#ifndef GC_NO_VALLOC
+ GC_API GC_ATTR_MALLOC void * GC_CALL GC_valloc(size_t lb)
+ {
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
+ GC_ASSERT(GC_real_page_size != 0);
+ return GC_memalign(GC_real_page_size, lb);
+ }
+
+ GC_API GC_ATTR_MALLOC void * GC_CALL GC_pvalloc(size_t lb)
+ {
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
+ GC_ASSERT(GC_real_page_size != 0);
+ lb = SIZET_SAT_ADD(lb, GC_real_page_size - 1) & ~(GC_real_page_size - 1);
+ return GC_memalign(GC_real_page_size, lb);
+ }
+#endif /* !GC_NO_VALLOC */
+
+/* Provide a version of strdup() that uses the collector to allocate */
+/* the copy of the string. */
GC_API GC_ATTR_MALLOC char * GC_CALL GC_strdup(const char *s)
{
char *copy;