process.cc revision 11854:0e94e16e26ea
1/*
2 * Copyright (c) 2014 Advanced Micro Devices, Inc.
3 * Copyright (c) 2012 ARM Limited
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder.  You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2001-2005 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Nathan Binkert
42 *          Steve Reinhardt
43 *          Ali Saidi
44 */
45
46#include "sim/process.hh"
47
48#include <fcntl.h>
49#include <unistd.h>
50
51#include <array>
52#include <map>
53#include <string>
54#include <vector>
55
56#include "base/intmath.hh"
57#include "base/loader/object_file.hh"
58#include "base/loader/symtab.hh"
59#include "base/statistics.hh"
60#include "config/the_isa.hh"
61#include "cpu/thread_context.hh"
62#include "mem/page_table.hh"
63#include "mem/se_translating_port_proxy.hh"
64#include "params/Process.hh"
65#include "sim/emul_driver.hh"
66#include "sim/syscall_desc.hh"
67#include "sim/system.hh"
68
69#if THE_ISA == ALPHA_ISA
70#include "arch/alpha/linux/process.hh"
71#elif THE_ISA == SPARC_ISA
72#include "arch/sparc/linux/process.hh"
73#include "arch/sparc/solaris/process.hh"
74#elif THE_ISA == MIPS_ISA
75#include "arch/mips/linux/process.hh"
76#elif THE_ISA == ARM_ISA
77#include "arch/arm/linux/process.hh"
78#include "arch/arm/freebsd/process.hh"
79#elif THE_ISA == X86_ISA
80#include "arch/x86/linux/process.hh"
81#elif THE_ISA == POWER_ISA
82#include "arch/power/linux/process.hh"
83#elif THE_ISA == RISCV_ISA
84#include "arch/riscv/linux/process.hh"
85#else
86#error "THE_ISA not set"
87#endif
88
89
90using namespace std;
91using namespace TheISA;
92
93// current number of allocated processes
94int num_processes = 0;
95
96static int
97openFile(const string& filename, int flags, mode_t mode)
98{
99    int sim_fd = open(filename.c_str(), flags, mode);
100    if (sim_fd != -1)
101        return sim_fd;
102    fatal("Unable to open %s with mode %O", filename, mode);
103}
104
105static int
106openInputFile(const string &filename)
107{
108    return openFile(filename, O_RDONLY, 0);
109}
110
111static int
112openOutputFile(const string &filename)
113{
114    return openFile(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
115}
116
117Process::Process(ProcessParams * params, ObjectFile * obj_file)
118    : SimObject(params), system(params->system),
119      brk_point(0), stack_base(0), stack_size(0), stack_min(0),
120      max_stack_size(params->max_stack_size),
121      next_thread_stack_base(0),
122      useArchPT(params->useArchPT),
123      kvmInSE(params->kvmInSE),
124      pTable(useArchPT ?
125        static_cast<PageTableBase *>(new ArchPageTable(name(), params->pid,
126            system)) :
127        static_cast<PageTableBase *>(new FuncPageTable(name(), params->pid))),
128      initVirtMem(system->getSystemPort(), this,
129                  SETranslatingPortProxy::Always),
130      fd_array(make_shared<array<FDEntry, NUM_FDS>>()),
131      imap {{"",       -1},
132            {"cin",    STDIN_FILENO},
133            {"stdin",  STDIN_FILENO}},
134      oemap{{"",       -1},
135            {"cout",   STDOUT_FILENO},
136            {"stdout", STDOUT_FILENO},
137            {"cerr",   STDERR_FILENO},
138            {"stderr", STDERR_FILENO}},
139      objFile(obj_file),
140      argv(params->cmd), envp(params->env), cwd(params->cwd),
141      executable(params->executable),
142      _uid(params->uid), _euid(params->euid),
143      _gid(params->gid), _egid(params->egid),
144      _pid(params->pid), _ppid(params->ppid),
145      drivers(params->drivers)
146{
147    int sim_fd;
148    std::map<string,int>::iterator it;
149
150    // Search through the input options and set fd if match is found;
151    // otherwise, open an input file and seek to location.
152    FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
153    if ((it = imap.find(params->input)) != imap.end())
154        sim_fd = it->second;
155    else
156        sim_fd = openInputFile(params->input);
157    fde_stdin->set(sim_fd, params->input, O_RDONLY, -1, false);
158
159    // Search through the output/error options and set fd if match is found;
160    // otherwise, open an output file and seek to location.
161    FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO);
162    if ((it = oemap.find(params->output)) != oemap.end())
163        sim_fd = it->second;
164    else
165        sim_fd = openOutputFile(params->output);
166    fde_stdout->set(sim_fd, params->output, O_WRONLY | O_CREAT | O_TRUNC,
167                    0664, false);
168
169    FDEntry *fde_stderr = getFDEntry(STDERR_FILENO);
170    if (params->output == params->errout)
171        // Reuse the same file descriptor if these match.
172        sim_fd = fde_stdout->fd;
173    else if ((it = oemap.find(params->errout)) != oemap.end())
174        sim_fd = it->second;
175    else
176        sim_fd = openOutputFile(params->errout);
177    fde_stderr->set(sim_fd, params->errout, O_WRONLY | O_CREAT | O_TRUNC,
178                    0664, false);
179
180    mmap_end = 0;
181    // other parameters will be initialized when the program is loaded
182
183    // load up symbols, if any... these may be used for debugging or
184    // profiling.
185    if (!debugSymbolTable) {
186        debugSymbolTable = new SymbolTable();
187        if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
188            !objFile->loadLocalSymbols(debugSymbolTable) ||
189            !objFile->loadWeakSymbols(debugSymbolTable)) {
190            // didn't load any symbols
191            delete debugSymbolTable;
192            debugSymbolTable = NULL;
193        }
194    }
195}
196
197void
198Process::regStats()
199{
200    SimObject::regStats();
201
202    using namespace Stats;
203
204    num_syscalls
205        .name(name() + ".num_syscalls")
206        .desc("Number of system calls")
207        ;
208}
209
210void
211Process::inheritFDArray(Process *p)
212{
213    fd_array = p->fd_array;
214}
215
216ThreadContext *
217Process::findFreeContext()
218{
219    for (int id : contextIds) {
220        ThreadContext *tc = system->getThreadContext(id);
221        if (tc->status() == ThreadContext::Halted)
222            return tc;
223    }
224    return NULL;
225}
226
227void
228Process::initState()
229{
230    if (contextIds.empty())
231        fatal("Process %s is not associated with any HW contexts!\n", name());
232
233    // first thread context for this process... initialize & enable
234    ThreadContext *tc = system->getThreadContext(contextIds[0]);
235
236    // mark this context as active so it will start ticking.
237    tc->activate();
238
239    pTable->initState(tc);
240}
241
242DrainState
243Process::drain()
244{
245    findFileOffsets();
246    return DrainState::Drained;
247}
248
249int
250Process::allocFD(int sim_fd, const string& filename, int flags, int mode,
251                 bool pipe)
252{
253    for (int free_fd = 0; free_fd < fd_array->size(); free_fd++) {
254        FDEntry *fde = getFDEntry(free_fd);
255        if (fde->isFree()) {
256            fde->set(sim_fd, filename, flags, mode, pipe);
257            return free_fd;
258        }
259    }
260
261    fatal("Out of target file descriptors");
262}
263
264void
265Process::resetFDEntry(int tgt_fd)
266{
267    FDEntry *fde = getFDEntry(tgt_fd);
268    assert(fde->fd > -1);
269
270    fde->reset();
271}
272
273int
274Process::getSimFD(int tgt_fd)
275{
276    FDEntry *entry = getFDEntry(tgt_fd);
277    return entry ? entry->fd : -1;
278}
279
280FDEntry *
281Process::getFDEntry(int tgt_fd)
282{
283    assert(0 <= tgt_fd && tgt_fd < fd_array->size());
284    return &(*fd_array)[tgt_fd];
285}
286
287int
288Process::getTgtFD(int sim_fd)
289{
290    for (int index = 0; index < fd_array->size(); index++)
291        if ((*fd_array)[index].fd == sim_fd)
292            return index;
293    return -1;
294}
295
296void
297Process::allocateMem(Addr vaddr, int64_t size, bool clobber)
298{
299    int npages = divCeil(size, (int64_t)PageBytes);
300    Addr paddr = system->allocPhysPages(npages);
301    pTable->map(vaddr, paddr, size,
302                clobber ? PageTableBase::Clobber : PageTableBase::Zero);
303}
304
305bool
306Process::fixupStackFault(Addr vaddr)
307{
308    // Check if this is already on the stack and there's just no page there
309    // yet.
310    if (vaddr >= stack_min && vaddr < stack_base) {
311        allocateMem(roundDown(vaddr, PageBytes), PageBytes);
312        return true;
313    }
314
315    // We've accessed the next page of the stack, so extend it to include
316    // this address.
317    if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
318        while (vaddr < stack_min) {
319            stack_min -= TheISA::PageBytes;
320            if (stack_base - stack_min > max_stack_size)
321                fatal("Maximum stack size exceeded\n");
322            allocateMem(stack_min, TheISA::PageBytes);
323            inform("Increasing stack size by one page.");
324        };
325        return true;
326    }
327    return false;
328}
329
330void
331Process::fixFileOffsets()
332{
333    auto seek = [] (FDEntry *fde)
334    {
335        if (lseek(fde->fd, fde->fileOffset, SEEK_SET) < 0)
336            fatal("Unable to see to location in %s", fde->filename);
337    };
338
339    std::map<string,int>::iterator it;
340
341    // Search through the input options and set fd if match is found;
342    // otherwise, open an input file and seek to location.
343    FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
344
345    // Check if user has specified a different input file, and if so, use it
346    // instead of the file specified in the checkpoint. This also resets the
347    // file offset from the checkpointed value
348    string new_in = ((ProcessParams*)params())->input;
349    if (new_in != fde_stdin->filename) {
350        warn("Using new input file (%s) rather than checkpointed (%s)\n",
351             new_in, fde_stdin->filename);
352        fde_stdin->filename = new_in;
353        fde_stdin->fileOffset = 0;
354    }
355
356    if ((it = imap.find(fde_stdin->filename)) != imap.end()) {
357        fde_stdin->fd = it->second;
358    } else {
359        fde_stdin->fd = openInputFile(fde_stdin->filename);
360        seek(fde_stdin);
361    }
362
363    // Search through the output/error options and set fd if match is found;
364    // otherwise, open an output file and seek to location.
365    FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO);
366
367    // Check if user has specified a different output file, and if so, use it
368    // instead of the file specified in the checkpoint. This also resets the
369    // file offset from the checkpointed value
370    string new_out = ((ProcessParams*)params())->output;
371    if (new_out != fde_stdout->filename) {
372        warn("Using new output file (%s) rather than checkpointed (%s)\n",
373             new_out, fde_stdout->filename);
374        fde_stdout->filename = new_out;
375        fde_stdout->fileOffset = 0;
376    }
377
378    if ((it = oemap.find(fde_stdout->filename)) != oemap.end()) {
379        fde_stdout->fd = it->second;
380    } else {
381        fde_stdout->fd = openOutputFile(fde_stdout->filename);
382        seek(fde_stdout);
383    }
384
385    FDEntry *fde_stderr = getFDEntry(STDERR_FILENO);
386
387    // Check if user has specified a different error file, and if so, use it
388    // instead of the file specified in the checkpoint. This also resets the
389    // file offset from the checkpointed value
390    string new_err = ((ProcessParams*)params())->errout;
391    if (new_err != fde_stderr->filename) {
392        warn("Using new error file (%s) rather than checkpointed (%s)\n",
393             new_err, fde_stderr->filename);
394        fde_stderr->filename = new_err;
395        fde_stderr->fileOffset = 0;
396    }
397
398    if (fde_stdout->filename == fde_stderr->filename) {
399        // Reuse the same file descriptor if these match.
400        fde_stderr->fd = fde_stdout->fd;
401    } else if ((it = oemap.find(fde_stderr->filename)) != oemap.end()) {
402        fde_stderr->fd = it->second;
403    } else {
404        fde_stderr->fd = openOutputFile(fde_stderr->filename);
405        seek(fde_stderr);
406    }
407
408    for (int tgt_fd = 3; tgt_fd < fd_array->size(); tgt_fd++) {
409        FDEntry *fde = getFDEntry(tgt_fd);
410        if (fde->fd == -1)
411            continue;
412
413        if (fde->isPipe) {
414            if (fde->filename == "PIPE-WRITE")
415                continue;
416            assert(fde->filename == "PIPE-READ");
417
418            int fds[2];
419            if (pipe(fds) < 0)
420                fatal("Unable to create new pipe");
421
422            fde->fd = fds[0];
423
424            FDEntry *fde_write = getFDEntry(fde->readPipeSource);
425            assert(fde_write->filename == "PIPE-WRITE");
426            fde_write->fd = fds[1];
427        } else {
428            fde->fd = openFile(fde->filename.c_str(), fde->flags, fde->mode);
429            seek(fde);
430        }
431    }
432}
433
434void
435Process::findFileOffsets()
436{
437    for (auto& fde : *fd_array) {
438        if (fde.fd != -1)
439            fde.fileOffset = lseek(fde.fd, 0, SEEK_CUR);
440    }
441}
442
443void
444Process::setReadPipeSource(int read_pipe_fd, int source_fd)
445{
446    FDEntry *fde = getFDEntry(read_pipe_fd);
447    assert(source_fd >= -1);
448    fde->readPipeSource = source_fd;
449}
450
451void
452Process::serialize(CheckpointOut &cp) const
453{
454    SERIALIZE_SCALAR(brk_point);
455    SERIALIZE_SCALAR(stack_base);
456    SERIALIZE_SCALAR(stack_size);
457    SERIALIZE_SCALAR(stack_min);
458    SERIALIZE_SCALAR(next_thread_stack_base);
459    SERIALIZE_SCALAR(mmap_end);
460    pTable->serialize(cp);
461    for (int x = 0; x < fd_array->size(); x++) {
462        (*fd_array)[x].serializeSection(cp, csprintf("FDEntry%d", x));
463    }
464
465}
466
467void
468Process::unserialize(CheckpointIn &cp)
469{
470    UNSERIALIZE_SCALAR(brk_point);
471    UNSERIALIZE_SCALAR(stack_base);
472    UNSERIALIZE_SCALAR(stack_size);
473    UNSERIALIZE_SCALAR(stack_min);
474    UNSERIALIZE_SCALAR(next_thread_stack_base);
475    UNSERIALIZE_SCALAR(mmap_end);
476    pTable->unserialize(cp);
477    for (int x = 0; x < fd_array->size(); x++) {
478        FDEntry *fde = getFDEntry(x);
479        fde->unserializeSection(cp, csprintf("FDEntry%d", x));
480    }
481    fixFileOffsets();
482    // The above returns a bool so that you could do something if you don't
483    // find the param in the checkpoint if you wanted to, like set a default
484    // but in this case we'll just stick with the instantiated value if not
485    // found.
486}
487
488bool
489Process::map(Addr vaddr, Addr paddr, int size, bool cacheable)
490{
491    pTable->map(vaddr, paddr, size,
492                cacheable ? PageTableBase::Zero : PageTableBase::Uncacheable);
493    return true;
494}
495
496void
497Process::syscall(int64_t callnum, ThreadContext *tc)
498{
499    num_syscalls++;
500
501    SyscallDesc *desc = getDesc(callnum);
502    if (desc == NULL)
503        fatal("Syscall %d out of range", callnum);
504
505    desc->doSyscall(callnum, this, tc);
506}
507
508IntReg
509Process::getSyscallArg(ThreadContext *tc, int &i, int width)
510{
511    return getSyscallArg(tc, i);
512}
513
514EmulatedDriver *
515Process::findDriver(std::string filename)
516{
517    for (EmulatedDriver *d : drivers) {
518        if (d->match(filename))
519            return d;
520    }
521
522    return NULL;
523}
524
525void
526Process::updateBias()
527{
528    ObjectFile *interp = objFile->getInterpreter();
529
530    if (!interp || !interp->relocatable())
531        return;
532
533    // Determine how large the interpreters footprint will be in the process
534    // address space.
535    Addr interp_mapsize = roundUp(interp->mapSize(), TheISA::PageBytes);
536
537    // We are allocating the memory area; set the bias to the lowest address
538    // in the allocated memory region.
539    Addr ld_bias = mmapGrowsDown() ? mmap_end - interp_mapsize : mmap_end;
540
541    // Adjust the process mmap area to give the interpreter room; the real
542    // execve system call would just invoke the kernel's internal mmap
543    // functions to make these adjustments.
544    mmap_end = mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
545
546    interp->updateBias(ld_bias);
547}
548
549ObjectFile *
550Process::getInterpreter()
551{
552    return objFile->getInterpreter();
553}
554
555Addr
556Process::getBias()
557{
558    ObjectFile *interp = getInterpreter();
559
560    return interp ? interp->bias() : objFile->bias();
561}
562
563Addr
564Process::getStartPC()
565{
566    ObjectFile *interp = getInterpreter();
567
568    return interp ? interp->entryPoint() : objFile->entryPoint();
569}
570
571Process *
572ProcessParams::create()
573{
574    Process *process = NULL;
575
576    // If not specified, set the executable parameter equal to the
577    // simulated system's zeroth command line parameter
578    if (executable == "") {
579        executable = cmd[0];
580    }
581
582    ObjectFile *obj_file = createObjectFile(executable);
583    if (obj_file == NULL) {
584        fatal("Can't load object file %s", executable);
585    }
586
587#if THE_ISA == ALPHA_ISA
588    if (obj_file->getArch() != ObjectFile::Alpha)
589        fatal("Object file architecture does not match compiled ISA (Alpha).");
590
591    switch (obj_file->getOpSys()) {
592      case ObjectFile::UnknownOpSys:
593        warn("Unknown operating system; assuming Linux.");
594        // fall through
595      case ObjectFile::Linux:
596        process = new AlphaLinuxProcess(this, obj_file);
597        break;
598
599      default:
600        fatal("Unknown/unsupported operating system.");
601    }
602#elif THE_ISA == SPARC_ISA
603    if (obj_file->getArch() != ObjectFile::SPARC64 &&
604        obj_file->getArch() != ObjectFile::SPARC32)
605        fatal("Object file architecture does not match compiled ISA (SPARC).");
606    switch (obj_file->getOpSys()) {
607      case ObjectFile::UnknownOpSys:
608        warn("Unknown operating system; assuming Linux.");
609        // fall through
610      case ObjectFile::Linux:
611        if (obj_file->getArch() == ObjectFile::SPARC64) {
612            process = new Sparc64LinuxProcess(this, obj_file);
613        } else {
614            process = new Sparc32LinuxProcess(this, obj_file);
615        }
616        break;
617
618      case ObjectFile::Solaris:
619        process = new SparcSolarisProcess(this, obj_file);
620        break;
621
622      default:
623        fatal("Unknown/unsupported operating system.");
624    }
625#elif THE_ISA == X86_ISA
626    if (obj_file->getArch() != ObjectFile::X86_64 &&
627        obj_file->getArch() != ObjectFile::I386)
628        fatal("Object file architecture does not match compiled ISA (x86).");
629    switch (obj_file->getOpSys()) {
630      case ObjectFile::UnknownOpSys:
631        warn("Unknown operating system; assuming Linux.");
632        // fall through
633      case ObjectFile::Linux:
634        if (obj_file->getArch() == ObjectFile::X86_64) {
635            process = new X86_64LinuxProcess(this, obj_file);
636        } else {
637            process = new I386LinuxProcess(this, obj_file);
638        }
639        break;
640
641      default:
642        fatal("Unknown/unsupported operating system.");
643    }
644#elif THE_ISA == MIPS_ISA
645    if (obj_file->getArch() != ObjectFile::Mips)
646        fatal("Object file architecture does not match compiled ISA (MIPS).");
647    switch (obj_file->getOpSys()) {
648      case ObjectFile::UnknownOpSys:
649        warn("Unknown operating system; assuming Linux.");
650        // fall through
651      case ObjectFile::Linux:
652        process = new MipsLinuxProcess(this, obj_file);
653        break;
654
655      default:
656        fatal("Unknown/unsupported operating system.");
657    }
658#elif THE_ISA == ARM_ISA
659    ObjectFile::Arch arch = obj_file->getArch();
660    if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
661        arch != ObjectFile::Arm64)
662        fatal("Object file architecture does not match compiled ISA (ARM).");
663    switch (obj_file->getOpSys()) {
664      case ObjectFile::UnknownOpSys:
665        warn("Unknown operating system; assuming Linux.");
666        // fall through
667      case ObjectFile::Linux:
668        if (arch == ObjectFile::Arm64) {
669            process = new ArmLinuxProcess64(this, obj_file,
670                                            obj_file->getArch());
671        } else {
672            process = new ArmLinuxProcess32(this, obj_file,
673                                            obj_file->getArch());
674        }
675        break;
676      case ObjectFile::FreeBSD:
677        if (arch == ObjectFile::Arm64) {
678            process = new ArmFreebsdProcess64(this, obj_file,
679                                              obj_file->getArch());
680        } else {
681            process = new ArmFreebsdProcess32(this, obj_file,
682                                              obj_file->getArch());
683        }
684        break;
685      case ObjectFile::LinuxArmOABI:
686        fatal("M5 does not support ARM OABI binaries. Please recompile with an"
687              " EABI compiler.");
688      default:
689        fatal("Unknown/unsupported operating system.");
690    }
691#elif THE_ISA == POWER_ISA
692    if (obj_file->getArch() != ObjectFile::Power)
693        fatal("Object file architecture does not match compiled ISA (Power).");
694    switch (obj_file->getOpSys()) {
695      case ObjectFile::UnknownOpSys:
696        warn("Unknown operating system; assuming Linux.");
697        // fall through
698      case ObjectFile::Linux:
699        process = new PowerLinuxProcess(this, obj_file);
700        break;
701
702      default:
703        fatal("Unknown/unsupported operating system.");
704    }
705#elif THE_ISA == RISCV_ISA
706    if (obj_file->getArch() != ObjectFile::Riscv)
707        fatal("Object file architecture does not match compiled ISA (RISCV).");
708    switch (obj_file->getOpSys()) {
709      case ObjectFile::UnknownOpSys:
710        warn("Unknown operating system; assuming Linux.");
711        // fall through
712      case ObjectFile::Linux:
713        process = new RiscvLinuxProcess(this, obj_file);
714        break;
715      default:
716        fatal("Unknown/unsupported operating system.");
717    }
718#else
719#error "THE_ISA not set"
720#endif
721
722    if (process == NULL)
723        fatal("Unknown error creating process object.");
724    return process;
725}
726
727std::string
728Process::fullPath(const std::string &file_name)
729{
730    if (file_name[0] == '/' || cwd.empty())
731        return file_name;
732
733    std::string full = cwd;
734
735    if (cwd[cwd.size() - 1] != '/')
736        full += '/';
737
738    return full + file_name;
739}
740