syscall_emul.cc (5282:2dba627b6646) syscall_emul.cc (5513:8631b29873a2)
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;

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

235 strncpy((char *)name.bufferPtr(), hostname, name_len);
236
237 name.copyOut(tc->getMemPort());
238
239 return 0;
240}
241
242SyscallReturn
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;

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

235 strncpy((char *)name.bufferPtr(), hostname, name_len);
236
237 name.copyOut(tc->getMemPort());
238
239 return 0;
240}
241
242SyscallReturn
243getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
244{
245 int result = 0;
246 unsigned long size = tc->getSyscallArg(1);
247 BufferArg buf(tc->getSyscallArg(0), size);
248
249 // Is current working directory defined?
250 string cwd = p->getcwd();
251 if (!cwd.empty()) {
252 if (cwd.length() >= size) {
253 // Buffer too small
254 return -ERANGE;
255 }
256 strncpy((char *)buf.bufferPtr(), cwd.c_str(), size);
257 result = cwd.length();
258 }
259 else {
260 if (getcwd((char *)buf.bufferPtr(), size) != NULL) {
261 result = strlen((char *)buf.bufferPtr());
262 }
263 else {
264 result = -1;
265 }
266 }
267
268 buf.copyOut(tc->getMemPort());
269
270 return (result == -1) ? -errno : result;
271}
272
273
274SyscallReturn
275readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
276{
277 string path;
278
279 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
280 return (TheISA::IntReg)-EFAULT;
281
282 // Adjust path for current working directory
283 path = p->fullPath(path);
284
285 size_t bufsiz = tc->getSyscallArg(2);
286 BufferArg buf(tc->getSyscallArg(1), bufsiz);
287
288 int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz);
289
290 buf.copyOut(tc->getMemPort());
291
292 return (result == -1) ? -errno : result;
293}
294
295SyscallReturn
243unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
244{
245 string path;
246
247 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
248 return (TheISA::IntReg)-EFAULT;
249
250 // Adjust path for current working directory
251 path = p->fullPath(path);
252
253 int result = unlink(path.c_str());
254 return (result == -1) ? -errno : result;
255}
256
296unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
297{
298 string path;
299
300 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
301 return (TheISA::IntReg)-EFAULT;
302
303 // Adjust path for current working directory
304 path = p->fullPath(path);
305
306 int result = unlink(path.c_str());
307 return (result == -1) ? -errno : result;
308}
309
310
257SyscallReturn
311SyscallReturn
312mkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
313{
314 string path;
315
316 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
317 return (TheISA::IntReg)-EFAULT;
318
319 // Adjust path for current working directory
320 path = p->fullPath(path);
321
322 mode_t mode = tc->getSyscallArg(1);
323
324 int result = mkdir(path.c_str(), mode);
325 return (result == -1) ? -errno : result;
326}
327
328SyscallReturn
258renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
259{
260 string old_name;
261
262 if (!tc->getMemPort()->tryReadString(old_name, tc->getSyscallArg(0)))
263 return -EFAULT;
264
265 string new_name;

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

302
303 off_t length = tc->getSyscallArg(1);
304
305 int result = ftruncate(fd, length);
306 return (result == -1) ? -errno : result;
307}
308
309SyscallReturn
329renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
330{
331 string old_name;
332
333 if (!tc->getMemPort()->tryReadString(old_name, tc->getSyscallArg(0)))
334 return -EFAULT;
335
336 string new_name;

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

373
374 off_t length = tc->getSyscallArg(1);
375
376 int result = ftruncate(fd, length);
377 return (result == -1) ? -errno : result;
378}
379
380SyscallReturn
381umaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
382{
383 // Letting the simulated program change the simulator's umask seems like
384 // a bad idea. Compromise by just returning the current umask but not
385 // changing anything.
386 mode_t oldMask = umask(0);
387 umask(oldMask);
388 return oldMask;
389}
390
391SyscallReturn
310chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
311{
312 string path;
313
314 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
315 return -EFAULT;
316
317 /* XXX endianess */

--- 232 unchanged lines hidden ---
392chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
393{
394 string path;
395
396 if (!tc->getMemPort()->tryReadString(path, tc->getSyscallArg(0)))
397 return -EFAULT;
398
399 /* XXX endianess */

--- 232 unchanged lines hidden ---