diff options
author | Brandon Potter <brandon.potter@amd.com> | 2017-02-27 14:10:15 -0500 |
---|---|---|
committer | Brandon Potter <brandon.potter@amd.com> | 2017-02-27 14:10:15 -0500 |
commit | 2367198921765848a4f5b3d020a7cc5776209f80 (patch) | |
tree | 00cff9357d9e5f2bec277cf937e8a73944ce1c98 /src/arch | |
parent | 073cb266079edddec64ea8cd5169dd2cbef8f812 (diff) | |
download | gem5-2367198921765848a4f5b3d020a7cc5776209f80.tar.xz |
syscall_emul: [PATCH 15/22] add clone/execve for threading and multiprocess simulations
Modifies the clone system call and adds execve system call. Requires allowing
processes to steal thread contexts from other processes in the same system
object and the ability to detach pieces of process state (such as MemState)
to allow dynamic sharing.
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/alpha/linux/process.cc | 2 | ||||
-rw-r--r-- | src/arch/alpha/process.cc | 25 | ||||
-rw-r--r-- | src/arch/arm/linux/process.cc | 2 | ||||
-rw-r--r-- | src/arch/arm/process.cc | 41 | ||||
-rw-r--r-- | src/arch/generic/types.hh | 6 | ||||
-rw-r--r-- | src/arch/mips/process.cc | 25 | ||||
-rw-r--r-- | src/arch/power/process.cc | 28 | ||||
-rw-r--r-- | src/arch/riscv/process.cc | 29 | ||||
-rw-r--r-- | src/arch/sparc/linux/syscalls.cc | 4 | ||||
-rw-r--r-- | src/arch/sparc/process.cc | 28 | ||||
-rw-r--r-- | src/arch/sparc/process.hh | 8 | ||||
-rw-r--r-- | src/arch/x86/linux/process.cc | 24 | ||||
-rw-r--r-- | src/arch/x86/linux/process.hh | 7 | ||||
-rw-r--r-- | src/arch/x86/process.cc | 64 | ||||
-rw-r--r-- | src/arch/x86/process.hh | 47 | ||||
-rw-r--r-- | src/arch/x86/types.hh | 7 |
16 files changed, 232 insertions, 115 deletions
diff --git a/src/arch/alpha/linux/process.cc b/src/arch/alpha/linux/process.cc index 4a5dbd24f..dbfbcaf6a 100644 --- a/src/arch/alpha/linux/process.cc +++ b/src/arch/alpha/linux/process.cc @@ -440,7 +440,7 @@ SyscallDesc AlphaLinuxProcess::syscallDescs[] = { /* 309 */ SyscallDesc("get_kernel_syms", unimplementedFunc), /* 310 */ SyscallDesc("syslog", unimplementedFunc), /* 311 */ SyscallDesc("reboot", unimplementedFunc), - /* 312 */ SyscallDesc("clone", cloneFunc), + /* 312 */ SyscallDesc("clone", cloneFunc<AlphaLinux>), /* 313 */ SyscallDesc("uselib", unimplementedFunc), /* 314 */ SyscallDesc("mlock", unimplementedFunc), /* 315 */ SyscallDesc("munlock", unimplementedFunc), diff --git a/src/arch/alpha/process.cc b/src/arch/alpha/process.cc index 582dbb57d..64d0b54a9 100644 --- a/src/arch/alpha/process.cc +++ b/src/arch/alpha/process.cc @@ -50,19 +50,20 @@ using namespace std; AlphaProcess::AlphaProcess(ProcessParams *params, ObjectFile *objFile) : Process(params, objFile) { - brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); - brk_point = roundUp(brk_point, PageBytes); + memState->brkPoint = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + memState->brkPoint = roundUp(memState->brkPoint, PageBytes); // Set up stack. On Alpha, stack goes below text section. This // code should get moved to some architecture-specific spot. - stack_base = objFile->textBase() - (409600+4096); + memState->stackBase = objFile->textBase() - (409600+4096); // Set up region for mmaps. Tru64 seems to start just above 0 and // grow up from there. - mmap_end = 0x10000; + memState->mmapEnd = 0x10000; // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); } @@ -130,15 +131,15 @@ AlphaProcess::argsInit(int intSize, int pageSize) space_needed = 32*1024; // set bottom of stack - stack_min = stack_base - space_needed; + memState->stackMin = memState->stackBase - space_needed; // align it - stack_min = roundDown(stack_min, pageSize); - stack_size = stack_base - stack_min; + memState->stackMin = roundDown(memState->stackMin, pageSize); + memState->stackSize = memState->stackBase - memState->stackMin; // map memory - allocateMem(stack_min, roundUp(stack_size, pageSize)); + allocateMem(memState->stackMin, roundUp(memState->stackSize, pageSize)); // map out initial stack contents - Addr argv_array_base = stack_min + intSize; // room for argc + Addr argv_array_base = memState->stackMin + intSize; // room for argc Addr envp_array_base = argv_array_base + argv_array_size; Addr auxv_array_base = envp_array_base + envp_array_size; Addr arg_data_base = auxv_array_base + auxv_array_size; @@ -153,7 +154,7 @@ AlphaProcess::argsInit(int intSize, int pageSize) else panic("Unknown int size"); - initVirtMem.writeBlob(stack_min, (uint8_t*)&argc, intSize); + initVirtMem.writeBlob(memState->stackMin, (uint8_t*)&argc, intSize); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); @@ -170,7 +171,7 @@ AlphaProcess::argsInit(int intSize, int pageSize) setSyscallArg(tc, 0, argc); setSyscallArg(tc, 1, argv_array_base); - tc->setIntReg(StackPointerReg, stack_min); + tc->setIntReg(StackPointerReg, memState->stackMin); tc->pcState(getStartPC()); } diff --git a/src/arch/arm/linux/process.cc b/src/arch/arm/linux/process.cc index b8f40be81..9bca571e5 100644 --- a/src/arch/arm/linux/process.cc +++ b/src/arch/arm/linux/process.cc @@ -241,7 +241,7 @@ static SyscallDesc syscallDescs32[] = { /* 117 */ SyscallDesc("ipc", unimplementedFunc), /* 118 */ SyscallDesc("fsync", unimplementedFunc), /* 119 */ SyscallDesc("sigreturn", unimplementedFunc), - /* 120 */ SyscallDesc("clone", cloneFunc), + /* 120 */ SyscallDesc("clone", cloneFunc<ArmLinux32>), /* 121 */ SyscallDesc("setdomainname", unimplementedFunc), /* 122 */ SyscallDesc("uname", unameFunc32), /* 123 */ SyscallDesc("unused#123", unimplementedFunc), diff --git a/src/arch/arm/process.cc b/src/arch/arm/process.cc index 2fd5cc935..fd0243c44 100644 --- a/src/arch/arm/process.cc +++ b/src/arch/arm/process.cc @@ -70,34 +70,36 @@ ArmProcess32::ArmProcess32(ProcessParams *params, ObjectFile *objFile, ObjectFile::Arch _arch) : ArmProcess(params, objFile, _arch) { - stack_base = 0xbf000000L; + memState->stackBase = 0xbf000000L; // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); // Set up break point (Top of Heap) - brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); - brk_point = roundUp(brk_point, PageBytes); + memState->brkPoint = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + memState->brkPoint = roundUp(memState->brkPoint, PageBytes); // Set up region for mmaps. For now, start at bottom of kuseg space. - mmap_end = 0x40000000L; + memState->mmapEnd = 0x40000000L; } ArmProcess64::ArmProcess64(ProcessParams *params, ObjectFile *objFile, ObjectFile::Arch _arch) : ArmProcess(params, objFile, _arch) { - stack_base = 0x7fffff0000L; + memState->stackBase = 0x7fffff0000L; // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); // Set up break point (Top of Heap) - brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); - brk_point = roundUp(brk_point, PageBytes); + memState->brkPoint = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + memState->brkPoint = roundUp(memState->brkPoint, PageBytes); // Set up region for mmaps. For now, start at bottom of kuseg space. - mmap_end = 0x4000000000L; + memState->mmapEnd = 0x4000000000L; } void @@ -300,15 +302,16 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) int space_needed = frame_size + aux_padding; - stack_min = stack_base - space_needed; - stack_min = roundDown(stack_min, align); - stack_size = stack_base - stack_min; + memState->stackMin = memState->stackBase - space_needed; + memState->stackMin = roundDown(memState->stackMin, align); + memState->stackSize = memState->stackBase - memState->stackMin; // map memory - allocateMem(roundDown(stack_min, pageSize), roundUp(stack_size, pageSize)); + allocateMem(roundDown(memState->stackMin, pageSize), + roundUp(memState->stackSize, pageSize)); // map out initial stack contents - IntType sentry_base = stack_base - sentry_size; + IntType sentry_base = memState->stackBase - sentry_size; IntType aux_data_base = sentry_base - aux_data_size; IntType env_data_base = aux_data_base - env_data_size; IntType arg_data_base = env_data_base - arg_data_size; @@ -329,7 +332,7 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) DPRINTF(Stack, "0x%x - envp array\n", envp_array_base); DPRINTF(Stack, "0x%x - argv array\n", argv_array_base); DPRINTF(Stack, "0x%x - argc \n", argc_base); - DPRINTF(Stack, "0x%x - stack min\n", stack_min); + DPRINTF(Stack, "0x%x - stack min\n", memState->stackMin); // write contents to stack @@ -375,7 +378,7 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) ThreadContext *tc = system->getThreadContext(contextIds[0]); //Set the stack pointer register - tc->setIntReg(spIndex, stack_min); + tc->setIntReg(spIndex, memState->stackMin); //A pointer to a function to run when the program exits. We'll set this //to zero explicitly to make sure this isn't used. tc->setIntReg(ArgumentReg0, 0); @@ -401,8 +404,8 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) pc.set(getStartPC() & ~mask(1)); tc->pcState(pc); - //Align the "stack_min" to a page boundary. - stack_min = roundDown(stack_min, pageSize); + //Align the "stackMin" to a page boundary. + memState->stackMin = roundDown(memState->stackMin, pageSize); } ArmISA::IntReg diff --git a/src/arch/generic/types.hh b/src/arch/generic/types.hh index 2de8ca7b4..78ead6832 100644 --- a/src/arch/generic/types.hh +++ b/src/arch/generic/types.hh @@ -148,6 +148,12 @@ class SimplePCState : public PCStateBase npc(val + sizeof(MachInst)); }; + void + setNPC(Addr val) + { + npc(val); + } + SimplePCState() {} SimplePCState(Addr val) { set(val); } diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc index c1943bf39..4993b3c68 100644 --- a/src/arch/mips/process.cc +++ b/src/arch/mips/process.cc @@ -53,17 +53,18 @@ MipsProcess::MipsProcess(ProcessParams * params, ObjectFile *objFile) { // Set up stack. On MIPS, stack starts at the top of kuseg // user address space. MIPS stack grows down from here - stack_base = 0x7FFFFFFF; + memState->stackBase = 0x7FFFFFFF; // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); // Set up break point (Top of Heap) - brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); - brk_point = roundUp(brk_point, PageBytes); + memState->brkPoint = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + memState->brkPoint = roundUp(memState->brkPoint, PageBytes); // Set up region for mmaps. Start it 1GB above the top of the heap. - mmap_end = brk_point + 0x40000000L; + memState->mmapEnd = memState->brkPoint + 0x40000000L; } void @@ -140,15 +141,15 @@ MipsProcess::argsInit(int pageSize) env_data_size; // set bottom of stack - stack_min = stack_base - space_needed; + memState->stackMin = memState->stackBase - space_needed; // align it - stack_min = roundDown(stack_min, pageSize); - stack_size = stack_base - stack_min; + memState->stackMin = roundDown(memState->stackMin, pageSize); + memState->stackSize = memState->stackBase - memState->stackMin; // map memory - allocateMem(stack_min, roundUp(stack_size, pageSize)); + allocateMem(memState->stackMin, roundUp(memState->stackSize, pageSize)); // map out initial stack contents - IntType argv_array_base = stack_min + intSize; // room for argc + IntType argv_array_base = memState->stackMin + intSize; // room for argc IntType envp_array_base = argv_array_base + argv_array_size; IntType auxv_array_base = envp_array_base + envp_array_size; IntType arg_data_base = auxv_array_base + auxv_array_size; @@ -159,7 +160,7 @@ MipsProcess::argsInit(int pageSize) argc = htog((IntType)argc); - initVirtMem.writeBlob(stack_min, (uint8_t*)&argc, intSize); + initVirtMem.writeBlob(memState->stackMin, (uint8_t*)&argc, intSize); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); @@ -184,7 +185,7 @@ MipsProcess::argsInit(int pageSize) setSyscallArg(tc, 0, argc); setSyscallArg(tc, 1, argv_array_base); - tc->setIntReg(StackPointerReg, stack_min); + tc->setIntReg(StackPointerReg, memState->stackMin); tc->pcState(getStartPC()); } diff --git a/src/arch/power/process.cc b/src/arch/power/process.cc index 7359fbf9a..5a32218ef 100644 --- a/src/arch/power/process.cc +++ b/src/arch/power/process.cc @@ -51,17 +51,18 @@ using namespace PowerISA; PowerProcess::PowerProcess(ProcessParams *params, ObjectFile *objFile) : Process(params, objFile) { - stack_base = 0xbf000000L; + memState->stackBase = 0xbf000000L; // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); // Set up break point (Top of Heap) - brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); - brk_point = roundUp(brk_point, PageBytes); + memState->brkPoint = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + memState->brkPoint = roundUp(memState->brkPoint, PageBytes); // Set up region for mmaps. For now, start at bottom of kuseg space. - mmap_end = 0x70000000L; + memState->mmapEnd = 0x70000000L; } void @@ -185,15 +186,16 @@ PowerProcess::argsInit(int intSize, int pageSize) int space_needed = frame_size + aux_padding; - stack_min = stack_base - space_needed; - stack_min = roundDown(stack_min, align); - stack_size = stack_base - stack_min; + memState->stackMin = memState->stackBase - space_needed; + memState->stackMin = roundDown(memState->stackMin, align); + memState->stackSize = memState->stackBase - memState->stackMin; // map memory - allocateMem(roundDown(stack_min, pageSize), roundUp(stack_size, pageSize)); + allocateMem(roundDown(memState->stackMin, pageSize), + roundUp(memState->stackSize, pageSize)); // map out initial stack contents - uint32_t sentry_base = stack_base - sentry_size; + uint32_t sentry_base = memState->stackBase - sentry_size; uint32_t aux_data_base = sentry_base - aux_data_size; uint32_t env_data_base = aux_data_base - env_data_size; uint32_t arg_data_base = env_data_base - arg_data_size; @@ -212,7 +214,7 @@ PowerProcess::argsInit(int intSize, int pageSize) DPRINTF(Stack, "0x%x - envp array\n", envp_array_base); DPRINTF(Stack, "0x%x - argv array\n", argv_array_base); DPRINTF(Stack, "0x%x - argc \n", argc_base); - DPRINTF(Stack, "0x%x - stack min\n", stack_min); + DPRINTF(Stack, "0x%x - stack min\n", memState->stackMin); // write contents to stack @@ -257,12 +259,12 @@ PowerProcess::argsInit(int intSize, int pageSize) ThreadContext *tc = system->getThreadContext(contextIds[0]); //Set the stack pointer register - tc->setIntReg(StackPointerReg, stack_min); + tc->setIntReg(StackPointerReg, memState->stackMin); tc->pcState(getStartPC()); //Align the "stack_min" to a page boundary. - stack_min = roundDown(stack_min, pageSize); + memState->stackMin = roundDown(memState->stackMin, pageSize); } PowerISA::IntReg diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc index 6bc328325..8b168cb35 100644 --- a/src/arch/riscv/process.cc +++ b/src/arch/riscv/process.cc @@ -56,16 +56,16 @@ RiscvProcess::RiscvProcess(ProcessParams * params, { // Set up stack. On RISC-V, stack starts at the top of kuseg // user address space. RISC-V stack grows down from here - stack_base = 0x7FFFFFFF; + memState->stackBase = (Addr)0x7FFFFFFF; // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); // Set up break point (Top of Heap) - brk_point = objFile->bssBase() + objFile->bssSize(); + memState->brkPoint = objFile->bssBase() + objFile->bssSize(); // Set up region for mmaps. Start it 1GB above the top of the heap. - mmap_end = brk_point + 0x40000000L; + memState->mmapEnd = memState->brkPoint + 0x40000000L; } void @@ -124,18 +124,19 @@ RiscvProcess::argsInit(int pageSize) env_data_size += env.size() + 1; int auxv_array_size = 2 * sizeof(IntType)*auxv.size(); - stack_size = sizeof(IntType) + argv_array_size + 2 * sizeof(Addr) + - arg_data_size + 2 * sizeof(Addr); + memState->stackSize = sizeof(IntType) + argv_array_size + 2 * + sizeof(Addr) + arg_data_size + 2 * sizeof(Addr); if (!envp.empty()) { - stack_size += 2 * sizeof(Addr) + envp_array_size + 2 * sizeof(Addr) + - env_data_size; + memState->stackSize += 2 * sizeof(Addr) + envp_array_size + 2 * + sizeof(Addr) + env_data_size; } if (!auxv.empty()) - stack_size += 2 * sizeof(Addr) + auxv_array_size; - stack_min = roundDown(stack_base - stack_size, pageSize); - allocateMem(stack_min, roundUp(stack_size, pageSize)); + memState->stackSize += 2 * sizeof(Addr) + auxv_array_size; + memState->stackMin = roundDown(memState->stackBase - memState->stackSize, + pageSize); + allocateMem(memState->stackMin, roundUp(memState->stackSize, pageSize)); - Addr argv_array_base = stack_min + sizeof(IntType); + Addr argv_array_base = memState->stackMin + sizeof(IntType); Addr arg_data_base = argv_array_base + argv_array_size + 2 * sizeof(Addr); Addr envp_array_base = arg_data_base + arg_data_size; if (!envp.empty()) @@ -160,7 +161,7 @@ RiscvProcess::argsInit(int pageSize) } } - Addr sp = stack_min; + Addr sp = memState->stackMin; initVirtMem.writeBlob(sp, (uint8_t *)&argc, sizeof(IntType)); sp += sizeof(IntType); for (Addr arg_pointer: arg_pointers) { @@ -211,7 +212,7 @@ RiscvProcess::argsInit(int pageSize) } ThreadContext *tc = system->getThreadContext(contextIds[0]); - tc->setIntReg(StackPointerReg, stack_min); + tc->setIntReg(StackPointerReg, memState->stackMin); tc->pcState(getStartPC()); } diff --git a/src/arch/sparc/linux/syscalls.cc b/src/arch/sparc/linux/syscalls.cc index 6825b2abb..7fdc922ef 100644 --- a/src/arch/sparc/linux/syscalls.cc +++ b/src/arch/sparc/linux/syscalls.cc @@ -305,7 +305,7 @@ SyscallDesc SparcLinuxProcess::syscall32Descs[] = { /* 214 */ SyscallDesc("sysinfo", sysinfoFunc<Sparc32Linux>), // 32 bit /* 215 */ SyscallDesc("ipc", unimplementedFunc), // 32 bit /* 216 */ SyscallDesc("sigreturn", unimplementedFunc), // 32 bit - /* 217 */ SyscallDesc("clone", cloneFunc), + /* 217 */ SyscallDesc("clone", cloneFunc<Sparc32Linux>), /* 218 */ SyscallDesc("ioprio_get", unimplementedFunc), // 32 bit /* 219 */ SyscallDesc("adjtimex", unimplementedFunc), // 32 bit /* 220 */ SyscallDesc("sigprocmask", unimplementedFunc), // 32 bit @@ -611,7 +611,7 @@ SyscallDesc SparcLinuxProcess::syscallDescs[] = { /* 214 */ SyscallDesc("sysinfo", sysinfoFunc<SparcLinux>), /* 215 */ SyscallDesc("ipc", unimplementedFunc), /* 216 */ SyscallDesc("sigreturn", unimplementedFunc), - /* 217 */ SyscallDesc("clone", cloneFunc), + /* 217 */ SyscallDesc("clone", cloneFunc<SparcLinux>), /* 218 */ SyscallDesc("ioprio_get", unimplementedFunc), /* 219 */ SyscallDesc("adjtimex", unimplementedFunc), /* 220 */ SyscallDesc("sigprocmask", unimplementedFunc), diff --git a/src/arch/sparc/process.cc b/src/arch/sparc/process.cc index a8359a9ce..a64bc587f 100644 --- a/src/arch/sparc/process.cc +++ b/src/arch/sparc/process.cc @@ -59,11 +59,12 @@ SparcProcess::SparcProcess(ProcessParams * params, ObjectFile *objFile, { // XXX all the below need to be updated for SPARC - Ali - brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); - brk_point = roundUp(brk_point, PageBytes); + memState->brkPoint = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + memState->brkPoint = roundUp(memState->brkPoint, PageBytes); // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); // Initialize these to 0s fillStart = 0; @@ -324,15 +325,16 @@ SparcProcess::argsInit(int pageSize) aux_padding + frame_size; - stack_min = stack_base - space_needed; - stack_min = roundDown(stack_min, align); - stack_size = stack_base - stack_min; + memState->stackMin = memState->stackBase - space_needed; + memState->stackMin = roundDown(memState->stackMin, align); + memState->stackSize = memState->stackBase - memState->stackMin; // Allocate space for the stack - allocateMem(roundDown(stack_min, pageSize), roundUp(stack_size, pageSize)); + allocateMem(roundDown(memState->stackMin, pageSize), + roundUp(memState->stackSize, pageSize)); // map out initial stack contents - IntType sentry_base = stack_base - sentry_size; + IntType sentry_base = memState->stackBase - sentry_size; IntType file_name_base = sentry_base - file_name_size; IntType env_data_base = file_name_base - env_data_size; IntType arg_data_base = env_data_base - arg_data_size; @@ -356,9 +358,9 @@ SparcProcess::argsInit(int pageSize) DPRINTF(Stack, "%#x - argv array\n", argv_array_base); DPRINTF(Stack, "%#x - argc \n", argc_base); DPRINTF(Stack, "%#x - window save\n", window_save_base); - DPRINTF(Stack, "%#x - stack min\n", stack_min); + DPRINTF(Stack, "%#x - stack min\n", memState->stackMin); - assert(window_save_base == stack_min); + assert(window_save_base == memState->stackMin); // write contents to stack @@ -397,7 +399,7 @@ SparcProcess::argsInit(int pageSize) // Set up space for the trap handlers into the processes address space. // Since the stack grows down and there is reserved address space abov // it, we can put stuff above it and stay out of the way. - fillStart = stack_base; + fillStart = memState->stackBase; spillStart = fillStart + sizeof(MachInst) * numFillInsts; ThreadContext *tc = system->getThreadContext(contextIds[0]); @@ -405,7 +407,7 @@ SparcProcess::argsInit(int pageSize) // assert(NumArgumentRegs >= 2); // tc->setIntReg(ArgumentReg[0], argc); // tc->setIntReg(ArgumentReg[1], argv_array_base); - tc->setIntReg(StackPointerReg, stack_min - StackBias); + tc->setIntReg(StackPointerReg, memState->stackMin - StackBias); // %g1 is a pointer to a function that should be run at exit. Since we // don't have anything like that, it should be set to 0. @@ -414,7 +416,7 @@ SparcProcess::argsInit(int pageSize) tc->pcState(getStartPC()); // Align the "stack_min" to a page boundary. - stack_min = roundDown(stack_min, pageSize); + memState->stackMin = roundDown(memState->stackMin, pageSize); } void diff --git a/src/arch/sparc/process.hh b/src/arch/sparc/process.hh index efdc0f443..96901fde3 100644 --- a/src/arch/sparc/process.hh +++ b/src/arch/sparc/process.hh @@ -79,10 +79,10 @@ class Sparc32Process : public SparcProcess { // Set up stack. On SPARC Linux, stack goes from the top of memory // downward, less the hole for the kernel address space. - stack_base = (Addr)0xf0000000ULL; + memState->stackBase = (Addr)0xf0000000ULL; // Set up region for mmaps. - mmap_end = 0x70000000; + memState->mmapEnd = 0x70000000; } void initState(); @@ -109,10 +109,10 @@ class Sparc64Process : public SparcProcess { // Set up stack. On SPARC Linux, stack goes from the top of memory // downward, less the hole for the kernel address space. - stack_base = (Addr)0x80000000000ULL; + memState->stackBase = (Addr)0x80000000000ULL; // Set up region for mmaps. - mmap_end = 0xfffff80000000000ULL; + memState->mmapEnd = 0xfffff80000000000ULL; } void initState(); diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc index 56688fc89..c2d67eb81 100644 --- a/src/arch/x86/linux/process.cc +++ b/src/arch/x86/linux/process.cc @@ -276,10 +276,10 @@ static SyscallDesc syscallDescs64[] = { /* 53 */ SyscallDesc("socketpair", unimplementedFunc), /* 54 */ SyscallDesc("setsockopt", unimplementedFunc), /* 55 */ SyscallDesc("getsockopt", unimplementedFunc), - /* 56 */ SyscallDesc("clone", cloneFunc), + /* 56 */ SyscallDesc("clone", cloneFunc<X86Linux64>), /* 57 */ SyscallDesc("fork", unimplementedFunc), /* 58 */ SyscallDesc("vfork", unimplementedFunc), - /* 59 */ SyscallDesc("execve", unimplementedFunc), + /* 59 */ SyscallDesc("execve", execveFunc<X86Linux64>), /* 60 */ SyscallDesc("exit", exitFunc), /* 61 */ SyscallDesc("wait4", unimplementedFunc), /* 62 */ SyscallDesc("kill", unimplementedFunc), @@ -438,7 +438,7 @@ static SyscallDesc syscallDescs64[] = { /* 215 */ SyscallDesc("epoll_wait_old", unimplementedFunc), /* 216 */ SyscallDesc("remap_file_pages", unimplementedFunc), /* 217 */ SyscallDesc("getdents64", unimplementedFunc), - /* 218 */ SyscallDesc("set_tid_address", unimplementedFunc), + /* 218 */ SyscallDesc("set_tid_address", setTidAddressFunc), /* 219 */ SyscallDesc("restart_syscall", unimplementedFunc), /* 220 */ SyscallDesc("semtimedop", unimplementedFunc), /* 221 */ SyscallDesc("fadvise64", unimplementedFunc), @@ -542,6 +542,12 @@ X86_64LinuxProcess::X86_64LinuxProcess(ProcessParams * params, sizeof(syscallDescs64) / sizeof(SyscallDesc)) {} +void X86_64LinuxProcess::clone(ThreadContext *old_tc, ThreadContext *new_tc, + Process *process, TheISA::IntReg flags) +{ + X86_64Process::clone(old_tc, new_tc, (X86_64Process*)process, flags); +} + static SyscallDesc syscallDescs32[] = { /* 0 */ SyscallDesc("restart_syscall", unimplementedFunc), /* 1 */ SyscallDesc("exit", exitFunc), @@ -554,7 +560,7 @@ static SyscallDesc syscallDescs32[] = { /* 8 */ SyscallDesc("creat", unimplementedFunc), /* 9 */ SyscallDesc("link", unimplementedFunc), /* 10 */ SyscallDesc("unlink", unimplementedFunc), - /* 11 */ SyscallDesc("execve", unimplementedFunc), + /* 11 */ SyscallDesc("execve", execveFunc<X86Linux32>), /* 12 */ SyscallDesc("chdir", unimplementedFunc), /* 13 */ SyscallDesc("time", timeFunc<X86Linux32>), /* 14 */ SyscallDesc("mknod", unimplementedFunc), @@ -663,7 +669,7 @@ static SyscallDesc syscallDescs32[] = { /* 117 */ SyscallDesc("ipc", unimplementedFunc), /* 118 */ SyscallDesc("fsync", unimplementedFunc), /* 119 */ SyscallDesc("sigreturn", unimplementedFunc), - /* 120 */ SyscallDesc("clone", unimplementedFunc), + /* 120 */ SyscallDesc("clone", cloneFunc<X86Linux32>), /* 121 */ SyscallDesc("setdomainname", unimplementedFunc), /* 122 */ SyscallDesc("uname", unameFunc), /* 123 */ SyscallDesc("modify_ldt", unimplementedFunc), @@ -801,7 +807,7 @@ static SyscallDesc syscallDescs32[] = { /* 255 */ SyscallDesc("epoll_ctl", unimplementedFunc), /* 256 */ SyscallDesc("epoll_wait", unimplementedFunc), /* 257 */ SyscallDesc("remap_file_pages", unimplementedFunc), - /* 258 */ SyscallDesc("set_tid_address", unimplementedFunc), + /* 258 */ SyscallDesc("set_tid_address", setTidAddressFunc), /* 259 */ SyscallDesc("timer_create", unimplementedFunc), /* 260 */ SyscallDesc("timer_settime", unimplementedFunc), /* 261 */ SyscallDesc("timer_gettime", unimplementedFunc), @@ -873,3 +879,9 @@ I386LinuxProcess::I386LinuxProcess(ProcessParams * params, ObjectFile *objFile) : I386Process(params, objFile, syscallDescs32, sizeof(syscallDescs32) / sizeof(SyscallDesc)) {} + +void I386LinuxProcess::clone(ThreadContext *old_tc, ThreadContext *new_tc, + Process *process, TheISA::IntReg flags) +{ + I386Process::clone(old_tc, new_tc, (I386Process*)process, flags); +} diff --git a/src/arch/x86/linux/process.hh b/src/arch/x86/linux/process.hh index 70370960b..bafa9cc6c 100644 --- a/src/arch/x86/linux/process.hh +++ b/src/arch/x86/linux/process.hh @@ -44,6 +44,9 @@ #include "arch/x86/process.hh" #include "sim/process.hh" +struct ProcessParams; +struct ThreadContext; + namespace X86ISA { class X86_64LinuxProcess : public X86_64Process @@ -51,6 +54,8 @@ class X86_64LinuxProcess : public X86_64Process public: /// Constructor. X86_64LinuxProcess(ProcessParams * params, ObjectFile *objFile); + void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *process, + TheISA::IntReg flags); }; class I386LinuxProcess : public I386Process @@ -58,6 +63,8 @@ class I386LinuxProcess : public I386Process public: /// Constructor. I386LinuxProcess(ProcessParams * params, ObjectFile *objFile); + void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *process, + TheISA::IntReg flags); }; } // namespace X86ISA diff --git a/src/arch/x86/process.cc b/src/arch/x86/process.cc index 35ea70430..a929897ca 100644 --- a/src/arch/x86/process.cc +++ b/src/arch/x86/process.cc @@ -100,8 +100,17 @@ X86Process::X86Process(ProcessParams * params, ObjectFile *objFile, : Process(params, objFile), syscallDescs(_syscallDescs), numSyscallDescs(_numSyscallDescs) { - brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); - brk_point = roundUp(brk_point, PageBytes); + memState->brkPoint = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + memState->brkPoint = roundUp(memState->brkPoint, PageBytes); +} + +void X86Process::clone(ThreadContext *old_tc, ThreadContext *new_tc, + Process *p, TheISA::IntReg flags) +{ + Process::clone(old_tc, new_tc, p, flags); + X86Process *process = (X86Process*)p; + *process = *this; } X86_64Process::X86_64Process(ProcessParams *params, ObjectFile *objFile, @@ -117,10 +126,10 @@ X86_64Process::X86_64Process(ProcessParams *params, ObjectFile *objFile, // Set up stack. On X86_64 Linux, stack goes from the top of memory // downward, less the hole for the kernel address space plus one page // for undertermined purposes. - stack_base = (Addr)0x7FFFFFFFF000ULL; + memState->stackBase = (Addr)0x7FFFFFFFF000ULL; // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); // "mmap_base" is a function which defines where mmap region starts in // the process address space. @@ -130,7 +139,7 @@ X86_64Process::X86_64Process(ProcessParams *params, ObjectFile *objFile, // We do not use any address space layout randomization in gem5 // therefore the random fields become zero; the smallest gap space was // chosen but gap could potentially be much larger. - mmap_end = (Addr)0x7FFFF7FFF000ULL; + memState->mmapEnd = (Addr)0x7FFFF7FFF000ULL; } void @@ -159,10 +168,10 @@ I386Process::I386Process(ProcessParams *params, ObjectFile *objFile, vsyscallPage.vsyscallOffset = 0x400; vsyscallPage.vsysexitOffset = 0x410; - stack_base = _gdtStart; + memState->stackBase = _gdtStart; // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); // "mmap_base" is a function which defines where mmap region starts in // the process address space. @@ -172,7 +181,7 @@ I386Process::I386Process(ProcessParams *params, ObjectFile *objFile, // We do not use any address space layout randomization in gem5 // therefore the random fields become zero; the smallest gap space was // chosen but gap could potentially be much larger. - mmap_end = (Addr)0xB7FFF000ULL; + memState->mmapEnd = (Addr)0xB7FFF000ULL; } SyscallDesc* @@ -946,18 +955,21 @@ X86Process::argsInit(int pageSize, aux_padding + frame_size; - stack_min = stack_base - space_needed; - stack_min = roundDown(stack_min, align); - stack_size = roundUp(stack_base - stack_min, pageSize); + memState->stackMin = memState->stackBase - space_needed; + memState->stackMin = roundDown(memState->stackMin, align); + memState->stackSize = roundUp(memState->stackBase - memState->stackMin, + pageSize); // map memory - Addr stack_end = roundDown(stack_base - stack_size, pageSize); + Addr stack_end = roundDown(memState->stackBase - memState->stackSize, + pageSize); - DPRINTF(Stack, "Mapping the stack: 0x%x %dB\n", stack_end, stack_size); - allocateMem(stack_end, stack_size); + DPRINTF(Stack, "Mapping the stack: 0x%x %dB\n", + stack_end, memState->stackSize); + allocateMem(stack_end, memState->stackSize); // map out initial stack contents - IntType sentry_base = stack_base - sentry_size; + IntType sentry_base = memState->stackBase - sentry_size; IntType file_name_base = sentry_base - file_name_size; IntType env_data_base = file_name_base - env_data_size; IntType arg_data_base = env_data_base - arg_data_size; @@ -976,7 +988,7 @@ X86Process::argsInit(int pageSize, DPRINTF(Stack, "0x%x - envp array\n", envp_array_base); DPRINTF(Stack, "0x%x - argv array\n", argv_array_base); DPRINTF(Stack, "0x%x - argc \n", argc_base); - DPRINTF(Stack, "0x%x - stack min\n", stack_min); + DPRINTF(Stack, "0x%x - stack min\n", memState->stackMin); // write contents to stack @@ -1023,14 +1035,14 @@ X86Process::argsInit(int pageSize, ThreadContext *tc = system->getThreadContext(contextIds[0]); //Set the stack pointer register - tc->setIntReg(StackPointerReg, stack_min); + tc->setIntReg(StackPointerReg, memState->stackMin); // There doesn't need to be any segment base added in since we're dealing // with the flat segmentation model. tc->pcState(getStartPC()); //Align the "stack_min" to a page boundary. - stack_min = roundDown(stack_min, pageSize); + memState->stackMin = roundDown(memState->stackMin, pageSize); } void @@ -1074,6 +1086,14 @@ X86_64Process::setSyscallArg(ThreadContext *tc, int i, X86ISA::IntReg val) return tc->setIntReg(ArgumentReg[i], val); } +void +X86_64Process::clone(ThreadContext *old_tc, ThreadContext *new_tc, + Process *p, TheISA::IntReg flags) +{ + X86Process::clone(old_tc, new_tc, p, flags); + ((X86_64Process*)p)->vsyscallPage = vsyscallPage; +} + X86ISA::IntReg I386Process::getSyscallArg(ThreadContext *tc, int &i) { @@ -1098,3 +1118,11 @@ I386Process::setSyscallArg(ThreadContext *tc, int i, X86ISA::IntReg val) assert(i < NumArgumentRegs); return tc->setIntReg(ArgumentReg[i], val); } + +void +I386Process::clone(ThreadContext *old_tc, ThreadContext *new_tc, + Process *p, TheISA::IntReg flags) +{ + X86Process::clone(old_tc, new_tc, p, flags); + ((I386Process*)p)->vsyscallPage = vsyscallPage; +} diff --git a/src/arch/x86/process.hh b/src/arch/x86/process.hh index 9e3fafbdd..4240ee625 100644 --- a/src/arch/x86/process.hh +++ b/src/arch/x86/process.hh @@ -82,6 +82,21 @@ namespace X86ISA SyscallDesc* getDesc(int callnum); void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value); + void clone(ThreadContext *old_tc, ThreadContext *new_tc, + Process *process, TheISA::IntReg flags); + + X86Process & + operator=(const X86Process &in) + { + if (this == &in) + return *this; + + _gdtStart = in._gdtStart; + _gdtSize = in._gdtSize; + syscallDescs = in.syscallDescs; + + return *this; + } }; class X86_64Process : public X86Process @@ -97,6 +112,20 @@ namespace X86ISA Addr size; Addr vtimeOffset; Addr vgettimeofdayOffset; + + VSyscallPage & + operator=(const VSyscallPage &in) + { + if (this == &in) + return *this; + + base = in.base; + size = in.size; + vtimeOffset = in.vtimeOffset; + vgettimeofdayOffset = in.vgettimeofdayOffset; + + return *this; + } }; VSyscallPage vsyscallPage; @@ -108,6 +137,8 @@ namespace X86ISA /// Explicitly import the otherwise hidden getSyscallArg using Process::getSyscallArg; void setSyscallArg(ThreadContext *tc, int i, X86ISA::IntReg val); + void clone(ThreadContext *old_tc, ThreadContext *new_tc, + Process *process, TheISA::IntReg flags); }; class I386Process : public X86Process @@ -123,6 +154,20 @@ namespace X86ISA Addr size; Addr vsyscallOffset; Addr vsysexitOffset; + + VSyscallPage & + operator=(const VSyscallPage &in) + { + if (this == &in) + return *this; + + base = in.base; + size = in.size; + vsyscallOffset = in.vsyscallOffset; + vsysexitOffset = in.vsysexitOffset; + + return *this; + } }; VSyscallPage vsyscallPage; @@ -134,6 +179,8 @@ namespace X86ISA X86ISA::IntReg getSyscallArg(ThreadContext *tc, int &i); X86ISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width); void setSyscallArg(ThreadContext *tc, int i, X86ISA::IntReg val); + void clone(ThreadContext *old_tc, ThreadContext *new_tc, + Process *process, TheISA::IntReg flags); }; /** diff --git a/src/arch/x86/types.hh b/src/arch/x86/types.hh index 6451056ee..954f9f16e 100644 --- a/src/arch/x86/types.hh +++ b/src/arch/x86/types.hh @@ -305,6 +305,13 @@ namespace X86ISA PCState() {} PCState(Addr val) { set(val); } + void + setNPC(Addr val) + { + Base::setNPC(val); + _size = 0; + } + uint8_t size() const { return _size; } void size(uint8_t newSize) { _size = newSize; } |