@@ -122,7 +122,29 @@ 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
+ return MemMap.remap (CommitBase, TaggedSize, " scudo:secondary" ,
136
+ MAP_MEMTAG | Flags) &&
137
+ MemMap.remap (AllocPos, CommitSize - TaggedSize, " scudo:secondary" ,
138
+ Flags);
139
+ } else {
140
+ const uptr RemapFlags =
141
+ (useMemoryTagging<Config>(Options) ? MAP_MEMTAG : 0 ) | Flags;
142
+ return MemMap.remap (CommitBase, CommitSize, " scudo:secondary" ,
143
+ RemapFlags);
144
+ }
145
+ }
146
+
147
+ const uptr MaxUnusedCacheBytes = MaxUnusedCachePages * PageSize;
126
148
if (useMemoryTagging<Config>(Options) && CommitSize > MaxUnusedCacheBytes) {
127
149
const uptr UntaggedPos = Max (AllocPos, CommitBase + MaxUnusedCacheBytes);
128
150
return MemMap.remap (CommitBase, UntaggedPos - CommitBase, " scudo:secondary" ,
0 commit comments