2003-12-02 04:34:38 +01:00
|
|
|
/*
|
2005-03-10 20:20:12 +01:00
|
|
|
* Copyright (c) 2003-2005 The Regents of The University of Michigan
|
2003-12-02 04:34:38 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Authors: Steve Reinhardt
|
|
|
|
* Ali Saidi
|
2003-12-02 04:34:38 +01:00
|
|
|
*/
|
|
|
|
|
2006-02-19 05:44:22 +01:00
|
|
|
#include <fcntl.h>
|
2003-12-02 04:34:38 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "sim/syscall_emul.hh"
|
2006-03-15 23:04:50 +01:00
|
|
|
#include "base/chunk_generator.hh"
|
2003-12-02 04:34:38 +01:00
|
|
|
#include "base/trace.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "config/the_isa.hh"
|
2006-06-06 23:32:21 +02:00
|
|
|
#include "cpu/thread_context.hh"
|
2005-06-05 02:50:10 +02:00
|
|
|
#include "cpu/base.hh"
|
2006-03-15 23:04:50 +01:00
|
|
|
#include "mem/page_table.hh"
|
2003-12-02 04:34:38 +01:00
|
|
|
#include "sim/process.hh"
|
2009-04-15 22:13:47 +02:00
|
|
|
#include "sim/system.hh"
|
2006-06-10 05:01:31 +02:00
|
|
|
#include "sim/sim_exit.hh"
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
using namespace std;
|
Changes to untemplate StaticInst and StaticInstPtr, change the isa to a namespace instead of a class, an improvement to the architecture specific header file selection system, and fixed up a few include paths.
arch/alpha/alpha_linux_process.cc:
Added using directive for AlphaISA namespace
arch/alpha/alpha_memory.hh:
arch/alpha/isa/branch.isa:
cpu/pc_event.hh:
Added typedefs for Addr
arch/alpha/alpha_tru64_process.cc:
arch/alpha/arguments.cc:
Added using directive for AlphaISA
arch/alpha/ev5.hh:
Added an include of arch/alpha/isa_traits.hh, and a using directive for the AlphaISA namespace.
arch/alpha/faults.hh:
Added a typedef for the Addr type, and changed the formatting of the faults slightly.
arch/alpha/isa/main.isa:
Untemplatized StaticInst, added a using for namespace AlphaISA to show up in decoder.cc and the exec.ccs, relocated makeNop to decoder.hh
arch/alpha/isa/mem.isa:
Untemplatized StaticInst and StaticInstPtr
arch/alpha/isa/pal.isa:
cpu/base_dyn_inst.cc:
Untemplatized StaticInstPtr
arch/alpha/isa_traits.hh:
Changed variables to be externs instead of static since they are part of a namespace and not a class.
arch/alpha/stacktrace.cc:
Untemplatized StaticInstPtr, and added a using directive for AlphaISA.
arch/alpha/stacktrace.hh:
Added some typedefs for Addr and MachInst, and untemplatized StaticInstPtr
arch/alpha/vtophys.cc:
Added a using directive for AlphaISA
arch/alpha/vtophys.hh:
Added the AlphaISA namespace specifier where needed
arch/isa_parser.py:
Changed the placement of the definition of the decodeInst function to be outside the namespaceInst namespace.
base/loader/object_file.hh:
cpu/o3/bpred_unit.hh:
Added a typedef for Addr
base/loader/symtab.hh:
Added a typedef for Addr, and added a TheISA to Addr in another typedef
base/remote_gdb.cc:
Added a using namespace TheISA, and untemplatized StaticInstPtr
base/remote_gdb.hh:
Added typedefs for Addr and MachInst
cpu/base.cc:
Added TheISA specifier to some variables exported from the isa.
cpu/base.hh:
Added a typedef for Addr, and TheISA to some variables from the ISA
cpu/base_dyn_inst.hh:
Untemplatized StaticInstPtr, and added TheISA specifier to some variables from the ISA.
cpu/exec_context.hh:
Added some typedefs for types from the isa, and added TheISA specifier to some variables from the isa
cpu/exetrace.hh:
Added typedefs for some types from the ISA, and untemplatized StaticInstPtr
cpu/memtest/memtest.cc:
cpu/o3/btb.cc:
dev/baddev.cc:
dev/ide_ctrl.cc:
dev/ide_disk.cc:
dev/isa_fake.cc:
dev/ns_gige.cc:
dev/pciconfigall.cc:
dev/platform.cc:
dev/sinic.cc:
dev/uart8250.cc:
kern/freebsd/freebsd_system.cc:
kern/linux/linux_system.cc:
kern/system_events.cc:
kern/tru64/dump_mbuf.cc:
kern/tru64/tru64_events.cc:
sim/process.cc:
sim/pseudo_inst.cc:
sim/system.cc:
Added using namespace TheISA
cpu/memtest/memtest.hh:
cpu/trace/opt_cpu.hh:
cpu/trace/reader/itx_reader.hh:
dev/ide_disk.hh:
dev/pcidev.hh:
dev/platform.hh:
dev/tsunami.hh:
sim/system.hh:
sim/vptr.hh:
Added typedef for Addr
cpu/o3/2bit_local_pred.hh:
Changed the include to use arch/isa_traits.hh instead of arch/alpha/isa_traits.hh. Added typedef for Addr
cpu/o3/alpha_cpu.hh:
Added typedefs for Addr and IntReg
cpu/o3/alpha_cpu_impl.hh:
Added this-> to setNextPC to fix a problem since it didn't depend on template parameters any more. Removed "typename" where it was no longer needed.
cpu/o3/alpha_dyn_inst.hh:
Cleaned up some typedefs, and untemplatized StaticInst
cpu/o3/alpha_dyn_inst_impl.hh:
untemplatized StaticInstPtr
cpu/o3/alpha_impl.hh:
Fixed up a typedef of MachInst
cpu/o3/bpred_unit_impl.hh:
Added a using TheISA::MachInst to a function
cpu/o3/btb.hh:
Changed an include from arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef for Addr
cpu/o3/commit.hh:
Removed a typedef of Impl::ISA as ISA, since TheISA takes care of this now.
cpu/o3/cpu.cc:
Cleaned up namespace issues
cpu/o3/cpu.hh:
Cleaned up namespace usage
cpu/o3/decode.hh:
Removed typedef of ISA, and changed it to TheISA
cpu/o3/fetch.hh:
Fized up typedefs, and changed ISA to TheISA
cpu/o3/free_list.hh:
Changed include of arch/alpha/isa_traits.hh to arch/isa_traits.hh
cpu/o3/iew.hh:
Removed typedef of ISA
cpu/o3/iew_impl.hh:
Added TheISA namespace specifier to MachInst
cpu/o3/ras.hh:
Changed include from arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef for Addr.
cpu/o3/regfile.hh:
Changed ISA to TheISA, and added some typedefs for Addr, IntReg, FloatReg, and MiscRegFile
cpu/o3/rename.hh:
Changed ISA to TheISA, and added a typedef for RegIndex
cpu/o3/rename_map.hh:
Added an include for arch/isa_traits.hh, and a typedef for RegIndex
cpu/o3/rob.hh:
Added a typedef for RegIndex
cpu/o3/store_set.hh:
cpu/o3/tournament_pred.hh:
Changed an include of arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef of Addr
cpu/ozone/cpu.hh:
Changed ISA into TheISA, and untemplatized StaticInst
cpu/pc_event.cc:
Added namespace specifier TheISA to Addr types
cpu/profile.hh:
kern/kernel_stats.hh:
Added typedef for Addr, and untemplatized StaticInstPtr
cpu/simple/cpu.cc:
Changed using directive from LittleEndianGuest to AlphaISA, which will contain both namespaces. Added TheISA where needed, and untemplatized StaticInst
cpu/simple/cpu.hh:
Added a typedef for MachInst, and untemplatized StaticInst
cpu/static_inst.cc:
Untemplatized StaticInst
cpu/static_inst.hh:
Untemplatized StaticInst by using the TheISA namespace
dev/alpha_console.cc:
Added using namespace AlphaISA
dev/simple_disk.hh:
Added typedef for Addr and fixed up some formatting
dev/sinicreg.hh:
Added TheISA namespace specifier where needed
dev/tsunami.cc:
dev/tsunami_io.cc:
dev/tsunami_pchip.cc:
Added using namespace TheISA. It might be better for it to be AlphaISA
dev/tsunami_cchip.cc:
Added typedef for TheISA. It might be better for it to be AlphaISA
kern/linux/aligned.hh:
sim/pseudo_inst.hh:
Added TheISA namespace specifier to Addr
kern/linux/linux_threadinfo.hh:
Added typedef for Addr, and TheISA namespace specifier to StackPointerReg
kern/tru64/mbuf.hh:
Added TheISA to Addr type in structs
sim/process.hh:
Added typedefs of Addr, RegFile, and MachInst
sim/syscall_emul.cc:
Added using namespace TheISA, and a cast of VMPageSize to the int type
sim/syscall_emul.hh:
Added typecast for Addr, and TheISA namespace specifier for where needed
--HG--
extra : convert_revision : 91d4f6ca33a73b21c1f1771d74bfdea3b80eff45
2006-02-19 08:34:37 +01:00
|
|
|
using namespace TheISA;
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
void
|
2006-09-17 09:00:55 +02:00
|
|
|
SyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-04-21 17:17:36 +02:00
|
|
|
DPRINTFR(SyscallVerbose,
|
|
|
|
"%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n",
|
|
|
|
curTick, tc->getCpuPtr()->name(), name,
|
2009-02-27 18:22:14 +01:00
|
|
|
process->getSyscallArg(tc, 0), process->getSyscallArg(tc, 1),
|
|
|
|
process->getSyscallArg(tc, 2), process->getSyscallArg(tc, 3));
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-06-06 23:32:21 +02:00
|
|
|
SyscallReturn retval = (*funcPtr)(this, callnum, process, tc);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-04-10 18:23:17 +02:00
|
|
|
DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n",
|
2006-06-06 23:32:21 +02:00
|
|
|
curTick,tc->getCpuPtr()->name(), name, retval.value());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
if (!(flags & SyscallDesc::SuppressReturnValue))
|
2009-02-27 18:22:14 +01:00
|
|
|
process->setSyscallReturn(tc, retval);
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
unimplementedFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2005-11-11 03:05:31 +01:00
|
|
|
fatal("syscall %s (#%d) unimplemented.", desc->name, callnum);
|
2006-03-18 16:51:28 +01:00
|
|
|
|
|
|
|
return 1;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
ignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2005-11-11 03:05:31 +01:00
|
|
|
warn("ignoring syscall %s(%d, %d, ...)", desc->name,
|
2009-02-27 18:22:14 +01:00
|
|
|
process->getSyscallArg(tc, 0), process->getSyscallArg(tc, 1));
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
exitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-04-15 22:13:47 +02:00
|
|
|
if (process->system->numRunningContexts() == 1) {
|
|
|
|
// Last running context... exit simulator
|
2009-02-27 18:22:14 +01:00
|
|
|
exitSimLoop("target called exit()",
|
2009-04-15 22:13:47 +02:00
|
|
|
process->getSyscallArg(tc, 0) & 0xff);
|
|
|
|
} else {
|
|
|
|
// other running threads... just halt this one
|
|
|
|
tc->halt();
|
2006-07-03 18:19:35 +02:00
|
|
|
}
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 1;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
SyscallReturn
|
|
|
|
exitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
|
|
|
// really should just halt all thread contexts belonging to this
|
|
|
|
// process in case there's another process running...
|
|
|
|
exitSimLoop("target called exit()",
|
|
|
|
process->getSyscallArg(tc, 0) & 0xff);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
Changes to untemplate StaticInst and StaticInstPtr, change the isa to a namespace instead of a class, an improvement to the architecture specific header file selection system, and fixed up a few include paths.
arch/alpha/alpha_linux_process.cc:
Added using directive for AlphaISA namespace
arch/alpha/alpha_memory.hh:
arch/alpha/isa/branch.isa:
cpu/pc_event.hh:
Added typedefs for Addr
arch/alpha/alpha_tru64_process.cc:
arch/alpha/arguments.cc:
Added using directive for AlphaISA
arch/alpha/ev5.hh:
Added an include of arch/alpha/isa_traits.hh, and a using directive for the AlphaISA namespace.
arch/alpha/faults.hh:
Added a typedef for the Addr type, and changed the formatting of the faults slightly.
arch/alpha/isa/main.isa:
Untemplatized StaticInst, added a using for namespace AlphaISA to show up in decoder.cc and the exec.ccs, relocated makeNop to decoder.hh
arch/alpha/isa/mem.isa:
Untemplatized StaticInst and StaticInstPtr
arch/alpha/isa/pal.isa:
cpu/base_dyn_inst.cc:
Untemplatized StaticInstPtr
arch/alpha/isa_traits.hh:
Changed variables to be externs instead of static since they are part of a namespace and not a class.
arch/alpha/stacktrace.cc:
Untemplatized StaticInstPtr, and added a using directive for AlphaISA.
arch/alpha/stacktrace.hh:
Added some typedefs for Addr and MachInst, and untemplatized StaticInstPtr
arch/alpha/vtophys.cc:
Added a using directive for AlphaISA
arch/alpha/vtophys.hh:
Added the AlphaISA namespace specifier where needed
arch/isa_parser.py:
Changed the placement of the definition of the decodeInst function to be outside the namespaceInst namespace.
base/loader/object_file.hh:
cpu/o3/bpred_unit.hh:
Added a typedef for Addr
base/loader/symtab.hh:
Added a typedef for Addr, and added a TheISA to Addr in another typedef
base/remote_gdb.cc:
Added a using namespace TheISA, and untemplatized StaticInstPtr
base/remote_gdb.hh:
Added typedefs for Addr and MachInst
cpu/base.cc:
Added TheISA specifier to some variables exported from the isa.
cpu/base.hh:
Added a typedef for Addr, and TheISA to some variables from the ISA
cpu/base_dyn_inst.hh:
Untemplatized StaticInstPtr, and added TheISA specifier to some variables from the ISA.
cpu/exec_context.hh:
Added some typedefs for types from the isa, and added TheISA specifier to some variables from the isa
cpu/exetrace.hh:
Added typedefs for some types from the ISA, and untemplatized StaticInstPtr
cpu/memtest/memtest.cc:
cpu/o3/btb.cc:
dev/baddev.cc:
dev/ide_ctrl.cc:
dev/ide_disk.cc:
dev/isa_fake.cc:
dev/ns_gige.cc:
dev/pciconfigall.cc:
dev/platform.cc:
dev/sinic.cc:
dev/uart8250.cc:
kern/freebsd/freebsd_system.cc:
kern/linux/linux_system.cc:
kern/system_events.cc:
kern/tru64/dump_mbuf.cc:
kern/tru64/tru64_events.cc:
sim/process.cc:
sim/pseudo_inst.cc:
sim/system.cc:
Added using namespace TheISA
cpu/memtest/memtest.hh:
cpu/trace/opt_cpu.hh:
cpu/trace/reader/itx_reader.hh:
dev/ide_disk.hh:
dev/pcidev.hh:
dev/platform.hh:
dev/tsunami.hh:
sim/system.hh:
sim/vptr.hh:
Added typedef for Addr
cpu/o3/2bit_local_pred.hh:
Changed the include to use arch/isa_traits.hh instead of arch/alpha/isa_traits.hh. Added typedef for Addr
cpu/o3/alpha_cpu.hh:
Added typedefs for Addr and IntReg
cpu/o3/alpha_cpu_impl.hh:
Added this-> to setNextPC to fix a problem since it didn't depend on template parameters any more. Removed "typename" where it was no longer needed.
cpu/o3/alpha_dyn_inst.hh:
Cleaned up some typedefs, and untemplatized StaticInst
cpu/o3/alpha_dyn_inst_impl.hh:
untemplatized StaticInstPtr
cpu/o3/alpha_impl.hh:
Fixed up a typedef of MachInst
cpu/o3/bpred_unit_impl.hh:
Added a using TheISA::MachInst to a function
cpu/o3/btb.hh:
Changed an include from arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef for Addr
cpu/o3/commit.hh:
Removed a typedef of Impl::ISA as ISA, since TheISA takes care of this now.
cpu/o3/cpu.cc:
Cleaned up namespace issues
cpu/o3/cpu.hh:
Cleaned up namespace usage
cpu/o3/decode.hh:
Removed typedef of ISA, and changed it to TheISA
cpu/o3/fetch.hh:
Fized up typedefs, and changed ISA to TheISA
cpu/o3/free_list.hh:
Changed include of arch/alpha/isa_traits.hh to arch/isa_traits.hh
cpu/o3/iew.hh:
Removed typedef of ISA
cpu/o3/iew_impl.hh:
Added TheISA namespace specifier to MachInst
cpu/o3/ras.hh:
Changed include from arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef for Addr.
cpu/o3/regfile.hh:
Changed ISA to TheISA, and added some typedefs for Addr, IntReg, FloatReg, and MiscRegFile
cpu/o3/rename.hh:
Changed ISA to TheISA, and added a typedef for RegIndex
cpu/o3/rename_map.hh:
Added an include for arch/isa_traits.hh, and a typedef for RegIndex
cpu/o3/rob.hh:
Added a typedef for RegIndex
cpu/o3/store_set.hh:
cpu/o3/tournament_pred.hh:
Changed an include of arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef of Addr
cpu/ozone/cpu.hh:
Changed ISA into TheISA, and untemplatized StaticInst
cpu/pc_event.cc:
Added namespace specifier TheISA to Addr types
cpu/profile.hh:
kern/kernel_stats.hh:
Added typedef for Addr, and untemplatized StaticInstPtr
cpu/simple/cpu.cc:
Changed using directive from LittleEndianGuest to AlphaISA, which will contain both namespaces. Added TheISA where needed, and untemplatized StaticInst
cpu/simple/cpu.hh:
Added a typedef for MachInst, and untemplatized StaticInst
cpu/static_inst.cc:
Untemplatized StaticInst
cpu/static_inst.hh:
Untemplatized StaticInst by using the TheISA namespace
dev/alpha_console.cc:
Added using namespace AlphaISA
dev/simple_disk.hh:
Added typedef for Addr and fixed up some formatting
dev/sinicreg.hh:
Added TheISA namespace specifier where needed
dev/tsunami.cc:
dev/tsunami_io.cc:
dev/tsunami_pchip.cc:
Added using namespace TheISA. It might be better for it to be AlphaISA
dev/tsunami_cchip.cc:
Added typedef for TheISA. It might be better for it to be AlphaISA
kern/linux/aligned.hh:
sim/pseudo_inst.hh:
Added TheISA namespace specifier to Addr
kern/linux/linux_threadinfo.hh:
Added typedef for Addr, and TheISA namespace specifier to StackPointerReg
kern/tru64/mbuf.hh:
Added TheISA to Addr type in structs
sim/process.hh:
Added typedefs of Addr, RegFile, and MachInst
sim/syscall_emul.cc:
Added using namespace TheISA, and a cast of VMPageSize to the int type
sim/syscall_emul.hh:
Added typecast for Addr, and TheISA namespace specifier for where needed
--HG--
extra : convert_revision : 91d4f6ca33a73b21c1f1771d74bfdea3b80eff45
2006-02-19 08:34:37 +01:00
|
|
|
return (int)VMPageSize;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2008-11-15 18:30:10 +01:00
|
|
|
brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
|
|
|
// change brk addr to first arg
|
2009-02-27 18:22:14 +01:00
|
|
|
Addr new_brk = p->getSyscallArg(tc, 0);
|
2008-11-15 18:30:10 +01:00
|
|
|
|
|
|
|
// in Linux at least, brk(0) returns the current break value
|
|
|
|
// (note that the syscall and the glibc function have different behavior)
|
|
|
|
if (new_brk == 0)
|
|
|
|
return p->brk_point;
|
|
|
|
|
|
|
|
if (new_brk > p->brk_point) {
|
|
|
|
// might need to allocate some new pages
|
2006-03-15 23:04:50 +01:00
|
|
|
for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point,
|
|
|
|
VMPageSize); !gen.done(); gen.next()) {
|
2008-11-15 18:30:10 +01:00
|
|
|
if (!p->pTable->translate(gen.addr()))
|
2006-03-15 23:04:50 +01:00
|
|
|
p->pTable->allocate(roundDown(gen.addr(), VMPageSize),
|
|
|
|
VMPageSize);
|
2009-10-24 19:53:58 +02:00
|
|
|
|
|
|
|
// if the address is already there, zero it out
|
|
|
|
else {
|
|
|
|
uint8_t zero = 0;
|
|
|
|
TranslatingPort *tp = tc->getMemPort();
|
|
|
|
|
|
|
|
// split non-page aligned accesses
|
|
|
|
Addr next_page = roundUp(gen.addr(), VMPageSize);
|
|
|
|
uint32_t size_needed = next_page - gen.addr();
|
|
|
|
tp->memsetBlob(gen.addr(), zero, size_needed);
|
|
|
|
if (gen.addr() + VMPageSize > next_page &&
|
|
|
|
next_page < new_brk &&
|
|
|
|
p->pTable->translate(next_page))
|
|
|
|
{
|
|
|
|
size_needed = VMPageSize - size_needed;
|
|
|
|
tp->memsetBlob(next_page, zero, size_needed);
|
|
|
|
}
|
|
|
|
}
|
2006-03-15 23:04:50 +01:00
|
|
|
}
|
2005-03-09 21:52:10 +01:00
|
|
|
}
|
2008-11-15 18:30:10 +01:00
|
|
|
|
|
|
|
p->brk_point = new_brk;
|
2005-03-10 20:20:12 +01:00
|
|
|
DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point);
|
|
|
|
return p->brk_point;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int target_fd = p->getSyscallArg(tc, 0);
|
2005-11-11 03:08:33 +01:00
|
|
|
int status = close(p->sim_fd(target_fd));
|
|
|
|
if (status >= 0)
|
|
|
|
p->free_fd(target_fd);
|
|
|
|
return status;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int fd = p->sim_fd(p->getSyscallArg(tc, 0));
|
|
|
|
int nbytes = p->getSyscallArg(tc, 2);
|
|
|
|
BufferArg bufArg(p->getSyscallArg(tc, 1), nbytes);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
int bytes_read = read(fd, bufArg.bufferPtr(), nbytes);
|
|
|
|
|
|
|
|
if (bytes_read != -1)
|
2006-06-06 23:32:21 +02:00
|
|
|
bufArg.copyOut(tc->getMemPort());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return bytes_read;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int fd = p->sim_fd(p->getSyscallArg(tc, 0));
|
|
|
|
int nbytes = p->getSyscallArg(tc, 2);
|
|
|
|
BufferArg bufArg(p->getSyscallArg(tc, 1), nbytes);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-06-06 23:32:21 +02:00
|
|
|
bufArg.copyIn(tc->getMemPort());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
int bytes_written = write(fd, bufArg.bufferPtr(), nbytes);
|
|
|
|
|
|
|
|
fsync(fd);
|
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return bytes_written;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int fd = p->sim_fd(p->getSyscallArg(tc, 0));
|
|
|
|
uint64_t offs = p->getSyscallArg(tc, 1);
|
|
|
|
int whence = p->getSyscallArg(tc, 2);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
off_t result = lseek(fd, offs, whence);
|
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return (result == (off_t)-1) ? -errno : result;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-03 04:34:55 +01:00
|
|
|
SyscallReturn
|
|
|
|
_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int fd = p->sim_fd(p->getSyscallArg(tc, 0));
|
|
|
|
uint64_t offset_high = p->getSyscallArg(tc, 1);
|
|
|
|
uint32_t offset_low = p->getSyscallArg(tc, 2);
|
|
|
|
Addr result_ptr = p->getSyscallArg(tc, 3);
|
|
|
|
int whence = p->getSyscallArg(tc, 4);
|
2007-03-03 04:34:55 +01:00
|
|
|
|
|
|
|
uint64_t offset = (offset_high << 32) | offset_low;
|
|
|
|
|
|
|
|
uint64_t result = lseek(fd, offset, whence);
|
|
|
|
result = TheISA::htog(result);
|
|
|
|
|
|
|
|
if (result == (off_t)-1) {
|
|
|
|
//The seek failed.
|
|
|
|
return -errno;
|
|
|
|
} else {
|
2009-04-21 17:17:36 +02:00
|
|
|
// The seek succeeded.
|
|
|
|
// Copy "result" to "result_ptr"
|
|
|
|
// XXX We'll assume that the size of loff_t is 64 bits on the
|
|
|
|
// target platform
|
2007-03-03 04:34:55 +01:00
|
|
|
BufferArg result_buf(result_ptr, sizeof(result));
|
|
|
|
memcpy(result_buf.bufferPtr(), &result, sizeof(result));
|
|
|
|
result_buf.copyOut(tc->getMemPort());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (result == (off_t)-1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
munmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
|
|
|
// given that we don't really implement mmap, munmap is really easy
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *hostname = "m5.eecs.umich.edu";
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
gethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int name_len = p->getSyscallArg(tc, 1);
|
|
|
|
BufferArg name(p->getSyscallArg(tc, 0), name_len);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
strncpy((char *)name.bufferPtr(), hostname, name_len);
|
|
|
|
|
2006-06-06 23:32:21 +02:00
|
|
|
name.copyOut(tc->getMemPort());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2008-07-23 23:41:33 +02:00
|
|
|
SyscallReturn
|
|
|
|
getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
int result = 0;
|
2009-02-27 18:22:14 +01:00
|
|
|
unsigned long size = p->getSyscallArg(tc, 1);
|
|
|
|
BufferArg buf(p->getSyscallArg(tc, 0), size);
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
// Is current working directory defined?
|
|
|
|
string cwd = p->getcwd();
|
|
|
|
if (!cwd.empty()) {
|
|
|
|
if (cwd.length() >= size) {
|
|
|
|
// Buffer too small
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
strncpy((char *)buf.bufferPtr(), cwd.c_str(), size);
|
|
|
|
result = cwd.length();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (getcwd((char *)buf.bufferPtr(), size) != NULL) {
|
|
|
|
result = strlen((char *)buf.bufferPtr());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.copyOut(tc->getMemPort());
|
|
|
|
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
|
|
|
readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
string path;
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
|
2008-07-23 23:41:33 +02:00
|
|
|
return (TheISA::IntReg)-EFAULT;
|
|
|
|
|
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
size_t bufsiz = p->getSyscallArg(tc, 2);
|
|
|
|
BufferArg buf(p->getSyscallArg(tc, 1), bufsiz);
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz);
|
|
|
|
|
|
|
|
buf.copyOut(tc->getMemPort());
|
|
|
|
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2004-02-05 18:16:17 +01:00
|
|
|
{
|
2005-06-03 22:19:34 +02:00
|
|
|
string path;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
|
2005-03-09 21:52:10 +01:00
|
|
|
return (TheISA::IntReg)-EFAULT;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2004-02-05 18:16:17 +01:00
|
|
|
int result = unlink(path.c_str());
|
2005-03-10 20:20:12 +01:00
|
|
|
return (result == -1) ? -errno : result;
|
2004-02-05 18:16:17 +01:00
|
|
|
}
|
|
|
|
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
SyscallReturn
|
|
|
|
mkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
string path;
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
|
2008-07-23 23:41:33 +02:00
|
|
|
return (TheISA::IntReg)-EFAULT;
|
|
|
|
|
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
mode_t mode = p->getSyscallArg(tc, 1);
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
int result = mkdir(path.c_str(), mode);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2004-02-05 18:16:17 +01:00
|
|
|
{
|
2005-06-03 22:19:34 +02:00
|
|
|
string old_name;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, 0)))
|
2005-03-10 20:20:12 +01:00
|
|
|
return -EFAULT;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
string new_name;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
if (!tc->getMemPort()->tryReadString(new_name, p->getSyscallArg(tc, 1)))
|
2005-03-10 20:20:12 +01:00
|
|
|
return -EFAULT;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
old_name = p->fullPath(old_name);
|
|
|
|
new_name = p->fullPath(new_name);
|
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
int64_t result = rename(old_name.c_str(), new_name.c_str());
|
2005-03-10 20:20:12 +01:00
|
|
|
return (result == -1) ? -errno : result;
|
2004-02-05 18:16:17 +01:00
|
|
|
}
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
truncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2005-06-03 22:19:34 +02:00
|
|
|
{
|
|
|
|
string path;
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
|
2005-06-03 22:19:34 +02:00
|
|
|
return -EFAULT;
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
off_t length = p->getSyscallArg(tc, 1);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
int result = truncate(path.c_str(), length);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2009-04-21 17:17:36 +02:00
|
|
|
ftruncateFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *process, ThreadContext *tc)
|
2005-06-03 22:19:34 +02:00
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
|
2005-06-03 22:19:34 +02:00
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
off_t length = process->getSyscallArg(tc, 1);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
|
|
|
int result = ftruncate(fd, length);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
2005-11-22 18:08:08 +01:00
|
|
|
|
2009-10-24 19:53:58 +02:00
|
|
|
SyscallReturn
|
|
|
|
ftruncate64Func(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *process, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
|
|
|
// I'm not sure why, but the length argument is in arg reg 3
|
|
|
|
loff_t length = process->getSyscallArg(tc, 3);
|
|
|
|
|
|
|
|
int result = ftruncate64(fd, length);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
2008-07-23 23:41:33 +02:00
|
|
|
SyscallReturn
|
|
|
|
umaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
// Letting the simulated program change the simulator's umask seems like
|
|
|
|
// a bad idea. Compromise by just returning the current umask but not
|
|
|
|
// changing anything.
|
|
|
|
mode_t oldMask = umask(0);
|
|
|
|
umask(oldMask);
|
2008-08-04 03:19:53 +02:00
|
|
|
return (int)oldMask;
|
2008-07-23 23:41:33 +02:00
|
|
|
}
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
|
|
|
string path;
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
|
2005-11-22 18:08:08 +01:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
/* XXX endianess */
|
2009-02-27 18:22:14 +01:00
|
|
|
uint32_t owner = p->getSyscallArg(tc, 1);
|
2005-11-22 18:08:08 +01:00
|
|
|
uid_t hostOwner = owner;
|
2009-02-27 18:22:14 +01:00
|
|
|
uint32_t group = p->getSyscallArg(tc, 2);
|
2005-11-22 18:08:08 +01:00
|
|
|
gid_t hostGroup = group;
|
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
int result = chown(path.c_str(), hostOwner, hostGroup);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
|
|
|
/* XXX endianess */
|
2009-02-27 18:22:14 +01:00
|
|
|
uint32_t owner = process->getSyscallArg(tc, 1);
|
2005-11-22 18:08:08 +01:00
|
|
|
uid_t hostOwner = owner;
|
2009-02-27 18:22:14 +01:00
|
|
|
uint32_t group = process->getSyscallArg(tc, 2);
|
2005-11-22 18:08:08 +01:00
|
|
|
gid_t hostGroup = group;
|
|
|
|
|
|
|
|
int result = fchown(fd, hostOwner, hostGroup);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
2006-02-19 05:44:22 +01:00
|
|
|
|
|
|
|
|
2006-08-28 16:39:56 +02:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
|
2006-08-28 16:39:56 +02:00
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
|
2006-08-28 16:39:56 +02:00
|
|
|
if (fd < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
Process::FdMap *fdo = process->sim_fd_obj(process->getSyscallArg(tc, 0));
|
2007-11-29 06:22:46 +01:00
|
|
|
|
2006-08-28 16:39:56 +02:00
|
|
|
int result = dup(fd);
|
2009-04-21 17:17:36 +02:00
|
|
|
return (result == -1) ? -errno :
|
|
|
|
process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false);
|
2006-08-28 16:39:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-19 05:44:22 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-02-19 05:44:22 +01:00
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int fd = process->getSyscallArg(tc, 0);
|
2006-02-19 05:44:22 +01:00
|
|
|
|
|
|
|
if (fd < 0 || process->sim_fd(fd) < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
int cmd = process->getSyscallArg(tc, 1);
|
2006-02-19 05:44:22 +01:00
|
|
|
switch (cmd) {
|
|
|
|
case 0: // F_DUPFD
|
|
|
|
// if we really wanted to support this, we'd need to do it
|
|
|
|
// in the target fd space.
|
|
|
|
warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd);
|
|
|
|
return -EMFILE;
|
|
|
|
|
|
|
|
case 1: // F_GETFD (get close-on-exec flag)
|
|
|
|
case 2: // F_SETFD (set close-on-exec flag)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 3: // F_GETFL (get file flags)
|
|
|
|
case 4: // F_SETFL (set file flags)
|
|
|
|
// not sure if this is totally valid, but we'll pass it through
|
|
|
|
// to the underlying OS
|
|
|
|
warn("fcntl(%d, %d) passed through to host\n", fd, cmd);
|
|
|
|
return fcntl(process->sim_fd(fd), cmd);
|
|
|
|
// return 0;
|
|
|
|
|
|
|
|
case 7: // F_GETLK (get lock)
|
|
|
|
case 8: // F_SETLK (set lock)
|
|
|
|
case 9: // F_SETLKW (set lock and wait)
|
|
|
|
// don't mess with file locking... just act like it's OK
|
|
|
|
warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
warn("Unknown fcntl command %d\n", cmd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-09 23:07:13 +02:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fcntl64Func(SyscallDesc *desc, int num, LiveProcess *process,
|
2006-06-09 23:07:13 +02:00
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
2009-02-27 18:22:14 +01:00
|
|
|
int fd = process->getSyscallArg(tc, 0);
|
2006-06-09 23:07:13 +02:00
|
|
|
|
|
|
|
if (fd < 0 || process->sim_fd(fd) < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2009-02-27 18:22:14 +01:00
|
|
|
int cmd = process->getSyscallArg(tc, 1);
|
2006-06-09 23:07:13 +02:00
|
|
|
switch (cmd) {
|
|
|
|
case 33: //F_GETLK64
|
|
|
|
warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd);
|
|
|
|
return -EMFILE;
|
|
|
|
|
|
|
|
case 34: // F_SETLK64
|
|
|
|
case 35: // F_SETLKW64
|
|
|
|
warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd);
|
|
|
|
return -EMFILE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// not sure if this is totally valid, but we'll pass it through
|
|
|
|
// to the underlying OS
|
|
|
|
warn("fcntl64(%d, %d) passed through to host\n", fd, cmd);
|
|
|
|
return fcntl(process->sim_fd(fd), cmd);
|
|
|
|
// return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-09 21:42:09 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
pipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
int fds[2], sim_fds[2];
|
|
|
|
int pipe_retval = pipe(fds);
|
|
|
|
|
|
|
|
if (pipe_retval < 0) {
|
|
|
|
// error
|
|
|
|
return pipe_retval;
|
|
|
|
}
|
|
|
|
|
2007-11-29 06:22:46 +01:00
|
|
|
sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true);
|
|
|
|
sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
2007-11-29 06:22:46 +01:00
|
|
|
process->setReadPipeSource(sim_fds[0], sim_fds[1]);
|
2006-03-09 21:42:09 +01:00
|
|
|
// Alpha Linux convention for pipe() is that fd[0] is returned as
|
|
|
|
// the return value of the function, and fd[1] is returned in r20.
|
2006-06-06 23:32:21 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]);
|
2006-03-09 21:42:09 +01:00
|
|
|
return sim_fds[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getpidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// Make up a PID. There's no interprocess communication in
|
|
|
|
// fake_syscall mode, so there's no way for a process to know it's
|
|
|
|
// not getting a unique value.
|
|
|
|
|
2006-09-17 09:00:55 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, process->ppid());
|
|
|
|
return process->pid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// Make up a UID and EUID... it shouldn't matter, and we want the
|
|
|
|
// simulation to be deterministic.
|
|
|
|
|
|
|
|
// EUID goes in r20.
|
2006-09-17 09:00:55 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID
|
2008-09-10 20:26:15 +02:00
|
|
|
return process->uid(); // UID
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// Get current group ID. EGID goes in r20.
|
2006-09-17 09:00:55 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID
|
|
|
|
return process->gid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
setuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// can't fathom why a benchmark would call this.
|
2009-02-27 18:22:14 +01:00
|
|
|
warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, 0));
|
2006-03-09 21:42:09 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// Make up a PID. There's no interprocess communication in
|
|
|
|
// fake_syscall mode, so there's no way for a process to know it's
|
|
|
|
// not getting a unique value.
|
|
|
|
|
2006-09-17 09:00:55 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID
|
|
|
|
return process->pid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2006-09-17 09:00:55 +02:00
|
|
|
return process->ppid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2008-09-10 20:26:15 +02:00
|
|
|
return process->uid(); // UID
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
geteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2008-09-10 20:26:15 +02:00
|
|
|
return process->euid(); // UID
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2006-09-17 09:00:55 +02:00
|
|
|
return process->gid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2006-09-17 09:00:55 +02:00
|
|
|
return process->egid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
2006-02-19 05:44:22 +01:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
SyscallReturn
|
|
|
|
cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
|
|
|
DPRINTF(SyscallVerbose, "In sys_clone:\n");
|
2009-04-21 17:17:36 +02:00
|
|
|
DPRINTF(SyscallVerbose, " Flags=%llx\n", process->getSyscallArg(tc, 0));
|
2009-04-21 17:17:36 +02:00
|
|
|
DPRINTF(SyscallVerbose, " Child stack=%llx\n",
|
|
|
|
process->getSyscallArg(tc, 1));
|
2009-04-21 17:17:36 +02:00
|
|
|
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
if (process->getSyscallArg(tc, 0) != 0x10f00) {
|
2009-04-21 17:17:36 +02:00
|
|
|
warn("This sys_clone implementation assumes flags "
|
|
|
|
"CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD "
|
|
|
|
"(0x10f00), and may not work correctly with given flags "
|
|
|
|
"0x%llx\n", process->getSyscallArg(tc, 0));
|
2009-04-21 17:17:36 +02:00
|
|
|
}
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
ThreadContext* ctc; // child thread context
|
2009-04-21 17:17:36 +02:00
|
|
|
if ( ( ctc = process->findFreeContext() ) != NULL ) {
|
|
|
|
DPRINTF(SyscallVerbose, " Found unallocated thread context\n");
|
|
|
|
|
|
|
|
ctc->clearArchRegs();
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// Arch-specific cloning code
|
2009-04-21 17:17:36 +02:00
|
|
|
#if THE_ISA == ALPHA_ISA or THE_ISA == X86_ISA
|
2009-04-21 17:17:36 +02:00
|
|
|
// Cloning the misc. regs for these archs is enough
|
2009-04-21 17:17:36 +02:00
|
|
|
TheISA::copyMiscRegs(tc, ctc);
|
|
|
|
#elif THE_ISA == SPARC_ISA
|
|
|
|
TheISA::copyRegs(tc, ctc);
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// TODO: Explain what this code actually does :-)
|
2009-04-21 17:17:36 +02:00
|
|
|
ctc->setIntReg(NumIntArchRegs + 6, 0);
|
|
|
|
ctc->setIntReg(NumIntArchRegs + 4, 0);
|
|
|
|
ctc->setIntReg(NumIntArchRegs + 3, NWindows - 2);
|
|
|
|
ctc->setIntReg(NumIntArchRegs + 5, NWindows);
|
2009-07-10 10:01:47 +02:00
|
|
|
ctc->setMiscReg(MISCREG_CWP, 0);
|
2009-04-21 17:17:36 +02:00
|
|
|
ctc->setIntReg(NumIntArchRegs + 7, 0);
|
|
|
|
ctc->setMiscRegNoEffect(MISCREG_TL, 0);
|
|
|
|
ctc->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY);
|
|
|
|
|
|
|
|
for (int y = 8; y < 32; y++)
|
|
|
|
ctc->setIntReg(y, tc->readIntReg(y));
|
|
|
|
#else
|
|
|
|
fatal("sys_clone is not implemented for this ISA\n");
|
|
|
|
#endif
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// Set up stack register
|
2009-04-21 17:17:36 +02:00
|
|
|
ctc->setIntReg(TheISA::StackPointerReg, process->getSyscallArg(tc, 1));
|
2009-04-21 17:17:36 +02:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// Set up syscall return values in parent and child
|
|
|
|
ctc->setIntReg(ReturnValueReg, 0); // return value, child
|
2009-04-21 17:17:36 +02:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// Alpha needs SyscallSuccessReg=0 in child
|
2009-04-21 17:17:36 +02:00
|
|
|
#if THE_ISA == ALPHA_ISA
|
2009-04-21 17:17:36 +02:00
|
|
|
ctc->setIntReg(TheISA::SyscallSuccessReg, 0);
|
2009-04-21 17:17:36 +02:00
|
|
|
#endif
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// In SPARC/Linux, clone returns 0 on pseudo-return register if
|
|
|
|
// parent, non-zero if child
|
2009-04-21 17:17:36 +02:00
|
|
|
#if THE_ISA == SPARC_ISA
|
|
|
|
tc->setIntReg(TheISA::SyscallPseudoReturnReg, 0);
|
|
|
|
ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ctc->setPC(tc->readNextPC());
|
|
|
|
ctc->setNextPC(tc->readNextPC() + sizeof(TheISA::MachInst));
|
2009-04-25 08:11:21 +02:00
|
|
|
ctc->setNextNPC(tc->readNextNPC() + sizeof(TheISA::MachInst));
|
2009-04-21 17:17:36 +02:00
|
|
|
|
|
|
|
ctc->activate();
|
|
|
|
|
|
|
|
// Should return nonzero child TID in parent's syscall return register,
|
|
|
|
// but for our pthread library any non-zero value will work
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
fatal("Called sys_clone, but no unallocated thread contexts found!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|