@@ -122,7 +122,30 @@ bool mapSecondary(const Options &Options, uptr CommitBase, uptr CommitSize,
122
122
Flags |= MAP_RESIZABLE;
123
123
Flags |= MAP_ALLOWNOMEM;
124
124
125
- const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * getPageSizeCached ();
125
+ const uptr PageSize = getPageSizeCached ();
126
+ if (SCUDO_TRUSTY) {
127
+ /*
128
+ * On Trusty we need AllocPos to be usable for shared memory, which cannot
129
+ * cross multiple mappings. This means we need to split around AllocPos
130
+ * and not over it. We can only do this if the address is page-aligned.
131
+ */
132
+ const uptr TaggedSize = AllocPos - CommitBase;
133
+ if (useMemoryTagging<Config>(Options) && isAligned (TaggedSize, PageSize)) {
134
+ DCHECK_GT (TaggedSize, 0 );
135
+ DCHECK_LT (TaggedSize, CommitSize);
136
+ return MemMap.remap (CommitBase, TaggedSize, " scudo:secondary" ,
137
+ MAP_MEMTAG | Flags) &&
138
+ MemMap.remap (AllocPos, CommitSize - TaggedSize, " scudo:secondary" ,
139
+ Flags);
140
+ } else {
141
+ const uptr RemapFlags =
142
+ (useMemoryTagging<Config>(Options) ? MAP_MEMTAG : 0 ) | Flags;
143
+ return MemMap.remap (CommitBase, CommitSize, " scudo:secondary" ,
144
+ RemapFlags);
145
+ }
146
+ }
147
+
148
+ const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * PageSize;
126
149
if (useMemoryTagging<Config>(Options) && CommitSize > MaxUnusedCacheBytes) {
127
150
const uptr UntaggedPos = Max (AllocPos, CommitBase + MaxUnusedCacheBytes);
128
151
return MemMap.remap (CommitBase, UntaggedPos - CommitBase, " scudo:secondary" ,
0 commit comments