changeset 43b882cada33 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=43b882cada33
description:
        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:

 src/arch/alpha/linux/process.cc      |    2 +-
 src/arch/alpha/process.cc            |   25 +-
 src/arch/arm/linux/process.cc        |    2 +-
 src/arch/arm/process.cc              |   41 ++--
 src/arch/generic/types.hh            |    6 +
 src/arch/mips/process.cc             |   25 +-
 src/arch/power/process.cc            |   28 +-
 src/arch/riscv/process.cc            |   29 +-
 src/arch/sparc/linux/syscalls.cc     |    4 +-
 src/arch/sparc/process.cc            |   28 +-
 src/arch/sparc/process.hh            |    8 +-
 src/arch/x86/linux/process.cc        |   24 ++-
 src/arch/x86/linux/process.hh        |    7 +
 src/arch/x86/process.cc              |   64 +++++--
 src/arch/x86/process.hh              |   47 ++++++
 src/arch/x86/types.hh                |    7 +
 src/cpu/checker/thread_context.hh    |    8 +
 src/cpu/o3/thread_context.hh         |    2 +
 src/cpu/simple_thread.hh             |    6 +
 src/cpu/thread_context.hh            |   12 +
 src/cpu/thread_state.hh              |   15 +
 src/gpu-compute/shader.cc            |   11 +-
 src/mem/page_table.cc                |    7 +
 src/mem/page_table.hh                |    5 +
 src/mem/se_translating_port_proxy.hh |    2 +
 src/sim/Process.py                   |    2 +-
 src/sim/fd_array.cc                  |    7 +
 src/sim/fd_array.hh                  |    8 +
 src/sim/process.cc                   |  201 +++++++++++++++++++++----
 src/sim/process.hh                   |   71 +++++++-
 src/sim/syscall_desc.hh              |    4 +
 src/sim/syscall_emul.cc              |  141 +++++------------
 src/sim/syscall_emul.hh              |  269 ++++++++++++++++++++++++++++++++--
 33 files changed, 833 insertions(+), 285 deletions(-)

diffs (truncated from 2152 to 300 lines):

diff -r 79af314e9f0d -r 43b882cada33 src/arch/alpha/linux/process.cc
--- a/src/arch/alpha/linux/process.cc   Mon Feb 27 14:10:02 2017 -0500
+++ b/src/arch/alpha/linux/process.cc   Mon Feb 27 14:10:15 2017 -0500
@@ -440,7 +440,7 @@
     /* 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 -r 79af314e9f0d -r 43b882cada33 src/arch/alpha/process.cc
--- a/src/arch/alpha/process.cc Mon Feb 27 14:10:02 2017 -0500
+++ b/src/arch/alpha/process.cc Mon Feb 27 14:10:15 2017 -0500
@@ -50,19 +50,20 @@
 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 @@
         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 @@
     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 @@
 
     setSyscallArg(tc, 0, argc);
     setSyscallArg(tc, 1, argv_array_base);
-    tc->setIntReg(StackPointerReg, stack_min);
+    tc->setIntReg(StackPointerReg, memState->stackMin);
 
     tc->pcState(getStartPC());
 }
diff -r 79af314e9f0d -r 43b882cada33 src/arch/arm/linux/process.cc
--- a/src/arch/arm/linux/process.cc     Mon Feb 27 14:10:02 2017 -0500
+++ b/src/arch/arm/linux/process.cc     Mon Feb 27 14:10:15 2017 -0500
@@ -241,7 +241,7 @@
     /* 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 -r 79af314e9f0d -r 43b882cada33 src/arch/arm/process.cc
--- a/src/arch/arm/process.cc   Mon Feb 27 14:10:02 2017 -0500
+++ b/src/arch/arm/process.cc   Mon Feb 27 14:10:15 2017 -0500
@@ -70,34 +70,36 @@
                            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 @@
 
     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 @@
     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 @@
 
     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 @@
     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 -r 79af314e9f0d -r 43b882cada33 src/arch/generic/types.hh
--- a/src/arch/generic/types.hh Mon Feb 27 14:10:02 2017 -0500
+++ b/src/arch/generic/types.hh Mon Feb 27 14:10:15 2017 -0500
@@ -148,6 +148,12 @@
         npc(val + sizeof(MachInst));
     };
 
+    void
+    setNPC(Addr val)
+    {
+        npc(val);
+    }
+
     SimplePCState() {}
     SimplePCState(Addr val) { set(val); }
 
diff -r 79af314e9f0d -r 43b882cada33 src/arch/mips/process.cc
--- a/src/arch/mips/process.cc  Mon Feb 27 14:10:02 2017 -0500
+++ b/src/arch/mips/process.cc  Mon Feb 27 14:10:15 2017 -0500
@@ -53,17 +53,18 @@
 {
     // 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 @@
         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 @@
 
     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 @@
 
     setSyscallArg(tc, 0, argc);
     setSyscallArg(tc, 1, argv_array_base);
-    tc->setIntReg(StackPointerReg, stack_min);
+    tc->setIntReg(StackPointerReg, memState->stackMin);
 
     tc->pcState(getStartPC());
 }
diff -r 79af314e9f0d -r 43b882cada33 src/arch/power/process.cc
--- a/src/arch/power/process.cc Mon Feb 27 14:10:02 2017 -0500
+++ b/src/arch/power/process.cc Mon Feb 27 14:10:15 2017 -0500
@@ -51,17 +51,18 @@
 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;
 }
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to