1 #ifndef JEMALLOC_INTERNAL_MALLOC_IO_H
2 #define JEMALLOC_INTERNAL_MALLOC_IO_H
6 # define FMT64_PREFIX "ll"
7 # define FMTPTR_PREFIX "ll"
9 # define FMT64_PREFIX "ll"
10 # define FMTPTR_PREFIX ""
15 # define FMTd64 FMT64_PREFIX "d"
16 # define FMTu64 FMT64_PREFIX "u"
17 # define FMTx64 FMT64_PREFIX "x"
18 # define FMTdPTR FMTPTR_PREFIX "d"
19 # define FMTuPTR FMTPTR_PREFIX "u"
20 # define FMTxPTR FMTPTR_PREFIX "x"
22 # include <inttypes.h>
23 # define FMTd32 PRId32
24 # define FMTu32 PRIu32
25 # define FMTx32 PRIx32
26 # define FMTd64 PRId64
27 # define FMTu64 PRIu64
28 # define FMTx64 PRIx64
29 # define FMTdPTR PRIdPTR
30 # define FMTuPTR PRIuPTR
31 # define FMTxPTR PRIxPTR
34 /* Size of stack-allocated buffer passed to buferror(). */
35 #define BUFERROR_BUF 64
38 * Size of stack-allocated buffer used by malloc_{,v,vc}printf(). This must be
39 * large enough for all possible uses within jemalloc.
41 #define MALLOC_PRINTF_BUFSIZE 4096
43 int buferror(int err, char *buf, size_t buflen);
44 uintmax_t malloc_strtoumax(const char *restrict nptr, char **restrict endptr,
46 void malloc_write(const char *s);
49 * malloc_vsnprintf() supports a subset of snprintf(3) that avoids floating
52 size_t malloc_vsnprintf(char *str, size_t size, const char *format,
54 size_t malloc_snprintf(char *str, size_t size, const char *format, ...)
55 JEMALLOC_FORMAT_PRINTF(3, 4);
57 * The caller can set write_cb and cbopaque to null to choose to print with the
58 * je_malloc_message hook.
60 void malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
61 const char *format, va_list ap);
62 void malloc_cprintf(void (*write_cb)(void *, const char *), void *cbopaque,
63 const char *format, ...) JEMALLOC_FORMAT_PRINTF(3, 4);
64 void malloc_printf(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);
67 malloc_write_fd(int fd, const void *buf, size_t count) {
68 #if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_write)
70 * Use syscall(2) rather than write(2) when possible in order to avoid
71 * the possibility of memory allocation within libc. This is necessary
72 * on FreeBSD; most operating systems do not have this problem though.
74 * syscall() returns long or int, depending on platform, so capture the
75 * result in the widest plausible type to avoid compiler warnings.
77 long result = syscall(SYS_write, fd, buf, count);
79 ssize_t result = (ssize_t)write(fd, buf,
85 return (ssize_t)result;
89 malloc_read_fd(int fd, void *buf, size_t count) {
90 #if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_read)
91 long result = syscall(SYS_read, fd, buf, count);
93 ssize_t result = read(fd, buf,
99 return (ssize_t)result;
102 #endif /* JEMALLOC_INTERNAL_MALLOC_IO_H */