syscall_emul.cc (13479:5a1924882c60) | syscall_emul.cc (13539:22b36f5a7a95) |
---|---|
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; --- 1137 unchanged lines hidden (view full) --- 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 | 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; --- 1137 unchanged lines hidden (view full) --- 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 |
1154#if defined(SYS_getdents) 1155SyscallReturn 1156getdentsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) | 1154#if defined(SYS_getdents) || defined(SYS_getdents64) 1155template<typename DE, int SYS_NUM> 1156static SyscallReturn 1157getdentsImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) |
1157{ 1158 int index = 0; 1159 int tgt_fd = p->getSyscallArg(tc, index); 1160 Addr buf_ptr = p->getSyscallArg(tc, index); 1161 unsigned count = p->getSyscallArg(tc, index); 1162 1163 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]); 1164 if (!hbfdp) 1165 return -EBADF; 1166 int sim_fd = hbfdp->getSimFD(); 1167 1168 BufferArg buf_arg(buf_ptr, count); | 1158{ 1159 int index = 0; 1160 int tgt_fd = p->getSyscallArg(tc, index); 1161 Addr buf_ptr = p->getSyscallArg(tc, index); 1162 unsigned count = p->getSyscallArg(tc, index); 1163 1164 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]); 1165 if (!hbfdp) 1166 return -EBADF; 1167 int sim_fd = hbfdp->getSimFD(); 1168 1169 BufferArg buf_arg(buf_ptr, count); |
1169 auto status = syscall(SYS_getdents, sim_fd, buf_arg.bufferPtr(), count); | 1170 auto status = syscall(SYS_NUM, sim_fd, buf_arg.bufferPtr(), count); |
1170 1171 if (status == -1) 1172 return -errno; 1173 | 1171 1172 if (status == -1) 1173 return -errno; 1174 |
1174 typedef struct linux_dirent { 1175 unsigned long d_ino; 1176 unsigned long d_off; 1177 unsigned short d_reclen; 1178 char dname[]; 1179 } LinDent; 1180 | |
1181 unsigned traversed = 0; 1182 while (traversed < status) { | 1175 unsigned traversed = 0; 1176 while (traversed < status) { |
1183 LinDent *buffer = (LinDent*)((Addr)buf_arg.bufferPtr() + traversed); | 1177 DE *buffer = (DE*)((Addr)buf_arg.bufferPtr() + traversed); |
1184 1185 auto host_reclen = buffer->d_reclen; 1186 1187 /** 1188 * Convert the byte ordering from the host to the target before 1189 * passing the data back into the target's address space to preserve 1190 * endianness. 1191 */ 1192 buffer->d_ino = htog(buffer->d_ino); 1193 buffer->d_off = htog(buffer->d_off); 1194 buffer->d_reclen = htog(buffer->d_reclen); 1195 1196 traversed += host_reclen; 1197 } 1198 1199 buf_arg.copyOut(tc->getMemProxy()); 1200 return status; 1201} 1202#endif | 1178 1179 auto host_reclen = buffer->d_reclen; 1180 1181 /** 1182 * Convert the byte ordering from the host to the target before 1183 * passing the data back into the target's address space to preserve 1184 * endianness. 1185 */ 1186 buffer->d_ino = htog(buffer->d_ino); 1187 buffer->d_off = htog(buffer->d_off); 1188 buffer->d_reclen = htog(buffer->d_reclen); 1189 1190 traversed += host_reclen; 1191 } 1192 1193 buf_arg.copyOut(tc->getMemProxy()); 1194 return status; 1195} 1196#endif |
1197 1198#if defined(SYS_getdents) 1199SyscallReturn 1200getdentsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) 1201{ 1202 typedef struct linux_dirent { 1203 unsigned long d_ino; 1204 unsigned long d_off; 1205 unsigned short d_reclen; 1206 char dname[]; 1207 } LinDent; 1208 1209 return getdentsImpl<LinDent, SYS_getdents>(desc, callnum, p, tc); 1210} 1211#endif 1212 1213#if defined(SYS_getdents64) 1214SyscallReturn 1215getdents64Func(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc) 1216{ 1217 typedef struct linux_dirent64 { 1218 ino64_t d_ino; 1219 off64_t d_off; 1220 unsigned short d_reclen; 1221 char dname[]; 1222 } LinDent64; 1223 1224 return getdentsImpl<LinDent64, SYS_getdents64>(desc, callnum, p, tc); 1225} 1226#endif |
|