@@ -35,35 +35,54 @@ namespace snmalloc
3535 */
3636 static constexpr int default_mmap_flags = MAP_NORESERVE;
3737
38- static void * reserve (size_t size) noexcept
38+ /* *
39+ * Not generalizing this handler purposely as in other platforms
40+ * mechanisms could differ greatly.
41+ */
42+ template <StateMem state_mem>
43+ static void pageid (void * p, size_t size) noexcept
3944 {
40- void * p = PALPOSIX<PALLinux>::reserve (size);
41- if (p)
42- {
43- madvise (p, size, MADV_DONTDUMP);
4445# ifdef SNMALLOC_PAGEID
4546# ifndef PR_SET_VMA
4647# define PR_SET_VMA 0x53564d41
4748# define PR_SET_VMA_ANON_NAME 0
4849# endif
4950
50- /* *
51- *
52- * If the kernel is set with CONFIG_ANON_VMA_NAME
53- * the reserved pages would appear as follow
54- *
55- * 7fa5f0ceb000-7fa5f0e00000 rw-p 00000000 00:00 0 [anon:snmalloc]
56- * 7fa5f0e00000-7fa5f1800000 rw-p 00000000 00:00 0 [anon:snmalloc]
57- *
58- */
59-
60- prctl (
61- PR_SET_VMA,
62- PR_SET_VMA_ANON_NAME,
63- (unsigned long )p,
64- size,
65- (unsigned long )" snmalloc" );
51+ /* *
52+ *
53+ * If the kernel is set with CONFIG_ANON_VMA_NAME
54+ * the reserved pages would appear as follow
55+ *
56+ * 7fa5f0ceb000-7fa5f0e00000 rw-p 00000000 00:00 0 [anon:snmalloc
57+ * (<type>)] 7fa5f0e00000-7fa5f1800000 rw-p 00000000 00:00 0
58+ * [anon:snmalloc (<type>)]
59+ *
60+ * The 80 buffer limit is specific to this syscall.
61+ */
62+
63+ char buf[80 ] = {0 };
64+ pagetype<state_mem>(buf, sizeof (buf));
65+
66+ prctl (
67+ PR_SET_VMA,
68+ PR_SET_VMA_ANON_NAME,
69+ (unsigned long )p,
70+ size,
71+ (unsigned long )buf);
72+ # else
73+ UNUSED (p);
74+ UNUSED (size);
6675# endif
76+ }
77+
78+ template <StateMem state_mem = Unused>
79+ static void * reserve (size_t size) noexcept
80+ {
81+ void * p = PALPOSIX<PALLinux>::reserve<state_mem>(size);
82+ if (p)
83+ {
84+ madvise (p, size, MADV_DONTDUMP);
85+ pageid<state_mem>(p, size);
6786 }
6887 return p;
6988 }
@@ -131,11 +150,12 @@ namespace snmalloc
131150 /* *
132151 * Notify platform that we will be using these pages.
133152 */
134- template <ZeroMem zero_mem>
153+ template <ZeroMem zero_mem, StateMem state_mem = Allocated >
135154 static void notify_using (void * p, size_t size) noexcept
136155 {
137156 PALPOSIX<PALLinux>::notify_using<zero_mem>(p, size);
138157 madvise (p, size, MADV_DODUMP);
158+ pageid<state_mem>(p, size);
139159 }
140160
141161 static uint64_t get_entropy64 ()
0 commit comments