Skip to content

Commit 6d8992e

Browse files
benzeajmberg-intel
authored andcommitted
um: compress memory related stub syscalls while adding them
To keep the number of syscalls that the stub has to do lower, compress two consecutive syscalls of the same type if the second is just a continuation of the first. Signed-off-by: Benjamin Berg <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent 76ed915 commit 6d8992e

File tree

1 file changed

+39
-0
lines changed
  • arch/um/os-Linux/skas

1 file changed

+39
-0
lines changed

arch/um/os-Linux/skas/mem.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,37 @@ struct stub_syscall *syscall_stub_alloc(struct mm_id *mm_idp)
151151
return sc;
152152
}
153153

154+
static struct stub_syscall *syscall_stub_get_previous(struct mm_id *mm_idp,
155+
int syscall_type,
156+
unsigned long virt)
157+
{
158+
if (mm_idp->syscall_data_len > 0) {
159+
struct stub_data *proc_data = (void *) mm_idp->stack;
160+
struct stub_syscall *sc;
161+
162+
sc = &proc_data->syscall_data[mm_idp->syscall_data_len - 1];
163+
164+
if (sc->syscall == syscall_type &&
165+
sc->mem.addr + sc->mem.length == virt)
166+
return sc;
167+
}
168+
169+
return NULL;
170+
}
154171

155172
void map(struct mm_id *mm_idp, unsigned long virt, unsigned long len, int prot,
156173
int phys_fd, unsigned long long offset)
157174
{
158175
struct stub_syscall *sc;
159176

177+
/* Compress with previous syscall if that is possible */
178+
sc = syscall_stub_get_previous(mm_idp, STUB_SYSCALL_MMAP, virt);
179+
if (sc && sc->mem.prot == prot && sc->mem.fd == phys_fd &&
180+
sc->mem.offset == MMAP_OFFSET(offset - sc->mem.length)) {
181+
sc->mem.length += len;
182+
return;
183+
}
184+
160185
sc = syscall_stub_alloc(mm_idp);
161186
sc->syscall = STUB_SYSCALL_MMAP;
162187
sc->mem.addr = virt;
@@ -170,6 +195,13 @@ void unmap(struct mm_id *mm_idp, unsigned long addr, unsigned long len)
170195
{
171196
struct stub_syscall *sc;
172197

198+
/* Compress with previous syscall if that is possible */
199+
sc = syscall_stub_get_previous(mm_idp, STUB_SYSCALL_MUNMAP, addr);
200+
if (sc) {
201+
sc->mem.length += len;
202+
return;
203+
}
204+
173205
sc = syscall_stub_alloc(mm_idp);
174206
sc->syscall = STUB_SYSCALL_MUNMAP;
175207
sc->mem.addr = addr;
@@ -181,6 +213,13 @@ void protect(struct mm_id *mm_idp, unsigned long addr, unsigned long len,
181213
{
182214
struct stub_syscall *sc;
183215

216+
/* Compress with previous syscall if that is possible */
217+
sc = syscall_stub_get_previous(mm_idp, STUB_SYSCALL_MPROTECT, addr);
218+
if (sc && sc->mem.prot == prot) {
219+
sc->mem.length += len;
220+
return;
221+
}
222+
184223
sc = syscall_stub_alloc(mm_idp);
185224
sc->syscall = STUB_SYSCALL_MPROTECT;
186225
sc->mem.addr = addr;

0 commit comments

Comments
 (0)