syscall_emul: move mmapGrowsDown() to LiveProcess
The mmapGrowsDown() method was a static method on the OperatingSystem class (and derived classes), which worked OK for the templated syscall emulation methods, but made it hard to access elsewhere. This patch moves the method to be a virtual function on the LiveProcess method, where it can be overridden for specific platforms (for now, Alpha). This patch also changes the value of mmapGrowsDown() from being false by default and true only on X86Linux32 to being true by default and false only on Alpha, which seems closer to reality (though in reality most people use ASLR and this doesn't really matter anymore). In the process, also got rid of the unused mmap_start field on LiveProcess and OperatingSystem mmapGrowsUp variable.
This commit is contained in:
parent
7eaa5952f9
commit
f6cd7a4bb7
|
@ -57,7 +57,7 @@ AlphaLiveProcess::AlphaLiveProcess(LiveProcessParams *params,
|
|||
|
||||
// Set up region for mmaps. Tru64 seems to start just above 0 and
|
||||
// grow up from there.
|
||||
mmap_start = mmap_end = 0x10000;
|
||||
mmap_end = 0x10000;
|
||||
|
||||
// Set pointer for next thread stack. Reserve 8M for main stack.
|
||||
next_thread_stack_base = stack_base - (8 * 1024 * 1024);
|
||||
|
|
|
@ -54,6 +54,10 @@ class AlphaLiveProcess : public LiveProcess
|
|||
void setSyscallArg(ThreadContext *tc, int i, AlphaISA::IntReg val) override;
|
||||
void setSyscallReturn(ThreadContext *tc,
|
||||
SyscallReturn return_value) override;
|
||||
|
||||
// override default implementation in LiveProcess as the mmap
|
||||
// region for Alpha platforms grows upward
|
||||
virtual bool mmapGrowsDown() const override { return false; }
|
||||
};
|
||||
|
||||
/* No architectural page table defined for this ISA */
|
||||
|
|
|
@ -77,7 +77,7 @@ ArmLiveProcess32::ArmLiveProcess32(LiveProcessParams *params,
|
|||
brk_point = roundUp(brk_point, PageBytes);
|
||||
|
||||
// Set up region for mmaps. For now, start at bottom of kuseg space.
|
||||
mmap_start = mmap_end = 0x40000000L;
|
||||
mmap_end = 0x40000000L;
|
||||
}
|
||||
|
||||
ArmLiveProcess64::ArmLiveProcess64(LiveProcessParams *params,
|
||||
|
@ -94,7 +94,7 @@ ArmLiveProcess64::ArmLiveProcess64(LiveProcessParams *params,
|
|||
brk_point = roundUp(brk_point, PageBytes);
|
||||
|
||||
// Set up region for mmaps. For now, start at bottom of kuseg space.
|
||||
mmap_start = mmap_end = 0x4000000000L;
|
||||
mmap_end = 0x4000000000L;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -61,7 +61,7 @@ MipsLiveProcess::MipsLiveProcess(LiveProcessParams * params,
|
|||
brk_point = roundUp(brk_point, PageBytes);
|
||||
|
||||
// Set up region for mmaps. Start it 1GB above the top of the heap.
|
||||
mmap_start = mmap_end = brk_point + 0x40000000L;
|
||||
mmap_end = brk_point + 0x40000000L;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -59,7 +59,7 @@ PowerLiveProcess::PowerLiveProcess(LiveProcessParams *params,
|
|||
brk_point = roundUp(brk_point, PageBytes);
|
||||
|
||||
// Set up region for mmaps. For now, start at bottom of kuseg space.
|
||||
mmap_start = mmap_end = 0x70000000L;
|
||||
mmap_end = 0x70000000L;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -82,7 +82,7 @@ class Sparc32LiveProcess : public SparcLiveProcess
|
|||
stack_base = (Addr)0xf0000000ULL;
|
||||
|
||||
// Set up region for mmaps.
|
||||
mmap_start = mmap_end = 0x70000000;
|
||||
mmap_end = 0x70000000;
|
||||
}
|
||||
|
||||
void initState();
|
||||
|
@ -111,9 +111,8 @@ class Sparc64LiveProcess : public SparcLiveProcess
|
|||
// downward, less the hole for the kernel address space.
|
||||
stack_base = (Addr)0x80000000000ULL;
|
||||
|
||||
// Set up region for mmaps. Tru64 seems to start just above 0 and
|
||||
// grow up from there.
|
||||
mmap_start = mmap_end = 0xfffff80000000000ULL;
|
||||
// Set up region for mmaps.
|
||||
mmap_end = 0xfffff80000000000ULL;
|
||||
}
|
||||
|
||||
void initState();
|
||||
|
|
|
@ -290,8 +290,6 @@ class X86Linux32 : public Linux
|
|||
uint32_t freehigh; /* Available high memory size */
|
||||
uint32_t mem_unit; /* Memory unit size in bytes */
|
||||
} tgt_sysinfo;
|
||||
|
||||
static bool mmapGrowsDown() { return true; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -114,7 +114,7 @@ X86_64LiveProcess::X86_64LiveProcess(LiveProcessParams *params,
|
|||
|
||||
// Set up region for mmaps. This was determined empirically and may not
|
||||
// always be correct.
|
||||
mmap_start = mmap_end = (Addr)0x2aaaaaaab000ULL;
|
||||
mmap_end = (Addr)0x2aaaaaaab000ULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -151,7 +151,7 @@ I386LiveProcess::I386LiveProcess(LiveProcessParams *params,
|
|||
|
||||
// Set up region for mmaps. This was determined empirically and may not
|
||||
// always be correct.
|
||||
mmap_start = mmap_end = (Addr)0xf7ffe000ULL;
|
||||
mmap_end = (Addr)0xf7ffe000ULL;
|
||||
}
|
||||
|
||||
SyscallDesc*
|
||||
|
|
|
@ -78,25 +78,24 @@ Shader::mmap(int length)
|
|||
// round up length to the next page
|
||||
length = roundUp(length, TheISA::PageBytes);
|
||||
|
||||
if (X86Linux64::mmapGrowsDown()) {
|
||||
Process *proc = gpuTc->getProcessPtr();
|
||||
|
||||
if (proc->mmapGrowsDown()) {
|
||||
DPRINTF(HSAIL, "GROWS DOWN");
|
||||
start = gpuTc->getProcessPtr()->mmap_end -length;
|
||||
gpuTc->getProcessPtr()->mmap_end = start;
|
||||
start = proc->mmap_end - length;
|
||||
proc->mmap_end = start;
|
||||
} else {
|
||||
DPRINTF(HSAIL, "GROWS UP");
|
||||
start = gpuTc->getProcessPtr()->mmap_end;
|
||||
gpuTc->getProcessPtr()->mmap_end += length;
|
||||
start = proc->mmap_end;
|
||||
proc->mmap_end += length;
|
||||
|
||||
// assertion to make sure we don't overwrite the stack (it grows down)
|
||||
assert(gpuTc->getProcessPtr()->mmap_end <
|
||||
gpuTc->getProcessPtr()->stack_base -
|
||||
gpuTc->getProcessPtr()->max_stack_size);
|
||||
|
||||
assert(proc->mmap_end < proc->stack_base - proc->max_stack_size);
|
||||
}
|
||||
|
||||
DPRINTF(HSAIL,"Shader::mmap start= %#x, %#x\n", start, length);
|
||||
|
||||
gpuTc->getProcessPtr()->allocateMem(start,length);
|
||||
proc->allocateMem(start, length);
|
||||
|
||||
return start;
|
||||
}
|
||||
|
|
|
@ -116,10 +116,6 @@ class OperatingSystem {
|
|||
|
||||
static int openSpecialFile(std::string path, LiveProcess *process, ThreadContext *tc);
|
||||
|
||||
static const bool mmapGrowsUp = true;
|
||||
|
||||
static bool mmapGrowsDown() { return false; }
|
||||
|
||||
}; // class OperatingSystem
|
||||
|
||||
#endif // __OPERATINGSYSTEM_HH__
|
||||
|
|
|
@ -182,7 +182,7 @@ Process::Process(ProcessParams * params)
|
|||
fde_stderr->set(sim_fd, params->errout, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
0664, false);
|
||||
|
||||
mmap_start = mmap_end = 0;
|
||||
mmap_end = 0;
|
||||
nxm_start = nxm_end = 0;
|
||||
// other parameters will be initialized when the program is loaded
|
||||
}
|
||||
|
@ -412,7 +412,6 @@ Process::serialize(CheckpointOut &cp) const
|
|||
SERIALIZE_SCALAR(stack_size);
|
||||
SERIALIZE_SCALAR(stack_min);
|
||||
SERIALIZE_SCALAR(next_thread_stack_base);
|
||||
SERIALIZE_SCALAR(mmap_start);
|
||||
SERIALIZE_SCALAR(mmap_end);
|
||||
SERIALIZE_SCALAR(nxm_start);
|
||||
SERIALIZE_SCALAR(nxm_end);
|
||||
|
@ -432,7 +431,6 @@ Process::unserialize(CheckpointIn &cp)
|
|||
UNSERIALIZE_SCALAR(stack_size);
|
||||
UNSERIALIZE_SCALAR(stack_min);
|
||||
UNSERIALIZE_SCALAR(next_thread_stack_base);
|
||||
UNSERIALIZE_SCALAR(mmap_start);
|
||||
UNSERIALIZE_SCALAR(mmap_end);
|
||||
UNSERIALIZE_SCALAR(nxm_start);
|
||||
UNSERIALIZE_SCALAR(nxm_end);
|
||||
|
|
|
@ -107,9 +107,13 @@ class Process : public SimObject
|
|||
Addr next_thread_stack_base;
|
||||
|
||||
// Base of region for mmaps (when user doesn't specify an address).
|
||||
Addr mmap_start;
|
||||
Addr mmap_end;
|
||||
|
||||
// Does mmap region grow upward or downward from mmap_end? Most
|
||||
// platforms grow downward, but a few (such as Alpha) grow upward
|
||||
// instead, so they can override thie method to return false.
|
||||
virtual bool mmapGrowsDown() const { return true; }
|
||||
|
||||
// Base of region for nxm data
|
||||
Addr nxm_start;
|
||||
Addr nxm_end;
|
||||
|
|
|
@ -1297,8 +1297,8 @@ mmapImpl(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc,
|
|||
// Extend global mmap region if necessary. Note that we ignore the
|
||||
// start address unless MAP_FIXED is specified.
|
||||
if (!(tgt_flags & OS::TGT_MAP_FIXED)) {
|
||||
start = (OS::mmapGrowsDown()) ? p->mmap_end - length : p->mmap_end;
|
||||
p->mmap_end = (OS::mmapGrowsDown()) ? start : p->mmap_end + length;
|
||||
start = p->mmapGrowsDown() ? p->mmap_end - length : p->mmap_end;
|
||||
p->mmap_end = p->mmapGrowsDown() ? start : p->mmap_end + length;
|
||||
}
|
||||
|
||||
DPRINTF_SYSCALL(Verbose, " mmap range is 0x%x - 0x%x\n",
|
||||
|
|
Loading…
Reference in a new issue