syscall_emul.cc (12796:16dffc0e6c7f) syscall_emul.cc (13031:47510ddc366d)
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 18 unchanged lines hidden (view full) ---

27 *
28 * Authors: Steve Reinhardt
29 * Ali Saidi
30 */
31
32#include "sim/syscall_emul.hh"
33
34#include <fcntl.h>
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 18 unchanged lines hidden (view full) ---

27 *
28 * Authors: Steve Reinhardt
29 * Ali Saidi
30 */
31
32#include "sim/syscall_emul.hh"
33
34#include <fcntl.h>
35#include <syscall.h>
35#include <unistd.h>
36
37#include <csignal>
38#include <iostream>
36#include <unistd.h>
37
38#include <csignal>
39#include <iostream>
40#include <mutex>
39#include <string>
40
41#include "arch/utility.hh"
42#include "base/chunk_generator.hh"
43#include "base/trace.hh"
44#include "config/the_isa.hh"
45#include "cpu/thread_context.hh"
46#include "dev/net/dist_iface.hh"
47#include "mem/page_table.hh"
41#include <string>
42
43#include "arch/utility.hh"
44#include "base/chunk_generator.hh"
45#include "base/trace.hh"
46#include "config/the_isa.hh"
47#include "cpu/thread_context.hh"
48#include "dev/net/dist_iface.hh"
49#include "mem/page_table.hh"
50#include "sim/byteswap.hh"
48#include "sim/process.hh"
49#include "sim/sim_exit.hh"
50#include "sim/syscall_debug_macros.hh"
51#include "sim/syscall_desc.hh"
52#include "sim/system.hh"
53
54using namespace std;
55using namespace TheISA;

--- 451 unchanged lines hidden (view full) ---

507unlinkHelper(SyscallDesc *desc, int num, Process *p, ThreadContext *tc,
508 int index)
509{
510 string path;
511
512 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
513 return -EFAULT;
514
51#include "sim/process.hh"
52#include "sim/sim_exit.hh"
53#include "sim/syscall_debug_macros.hh"
54#include "sim/syscall_desc.hh"
55#include "sim/system.hh"
56
57using namespace std;
58using namespace TheISA;

--- 451 unchanged lines hidden (view full) ---

510unlinkHelper(SyscallDesc *desc, int num, Process *p, ThreadContext *tc,
511 int index)
512{
513 string path;
514
515 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
516 return -EFAULT;
517
515 // Adjust path for current working directory
516 path = p->fullPath(path);
517
518 int result = unlink(path.c_str());
519 return (result == -1) ? -errno : result;
520}
521
522SyscallReturn
523linkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)

--- 576 unchanged lines hidden (view full) ---

1100}
1101
1102SyscallReturn
1103accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
1104{
1105 return accessFunc(desc, callnum, p, tc, 0);
1106}
1107
518 path = p->fullPath(path);
519
520 int result = unlink(path.c_str());
521 return (result == -1) ? -errno : result;
522}
523
524SyscallReturn
525linkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)

--- 576 unchanged lines hidden (view full) ---

1102}
1103
1104SyscallReturn
1105accessFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
1106{
1107 return accessFunc(desc, callnum, p, tc, 0);
1108}
1109
1110SyscallReturn
1111mknodFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
1112{
1113 int index = 0;
1114 std::string path;
1115 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
1116 return -EFAULT;
1117
1118 path = p->fullPath(path);
1119 mode_t mode = p->getSyscallArg(tc, index);
1120 dev_t dev = p->getSyscallArg(tc, index);
1121
1122 auto result = mknod(path.c_str(), mode, dev);
1123 return (result == -1) ? -errno : result;
1124}
1125
1126SyscallReturn
1127chdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
1128{
1129 int index = 0;
1130 std::string path;
1131 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
1132 return -EFAULT;
1133
1134 path = p->fullPath(path);
1135
1136 auto result = chdir(path.c_str());
1137 return (result == -1) ? -errno : result;
1138}
1139
1140SyscallReturn
1141rmdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
1142{
1143 int index = 0;
1144 std::string path;
1145 if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
1146 return -EFAULT;
1147
1148 path = p->fullPath(path);
1149
1150 auto result = rmdir(path.c_str());
1151 return (result == -1) ? -errno : result;
1152}
1153
1154SyscallReturn
1155getdentsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
1156{
1157 int index = 0;
1158 int tgt_fd = p->getSyscallArg(tc, index);
1159 Addr buf_ptr = p->getSyscallArg(tc, index);
1160 unsigned count = p->getSyscallArg(tc, index);
1161
1162 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
1163 if (!hbfdp)
1164 return -EBADF;
1165 int sim_fd = hbfdp->getSimFD();
1166
1167 BufferArg buf_arg(buf_ptr, count);
1168 auto status = syscall(SYS_getdents, sim_fd, buf_arg.bufferPtr(), count);
1169
1170 if (status == -1)
1171 return -errno;
1172
1173 typedef struct linux_dirent {
1174 unsigned long d_ino;
1175 unsigned long d_off;
1176 unsigned short d_reclen;
1177 char dname[];
1178 } LinDent;
1179
1180 unsigned traversed = 0;
1181 while (traversed < status) {
1182 LinDent *buffer = (LinDent*)((Addr)buf_arg.bufferPtr() + traversed);
1183
1184 auto host_reclen = buffer->d_reclen;
1185
1186 /**
1187 * Convert the byte ordering from the host to the target before
1188 * passing the data back into the target's address space to preserve
1189 * endianness.
1190 */
1191 buffer->d_ino = htog(buffer->d_ino);
1192 buffer->d_off = htog(buffer->d_off);
1193 buffer->d_reclen = htog(buffer->d_reclen);
1194
1195 traversed += host_reclen;
1196 }
1197
1198 buf_arg.copyOut(tc->getMemProxy());
1199 return status;
1200}
1201