/* 38 */ SyscallDesc("osf_old_stat", unimplementedFunc),
/* 39 */ SyscallDesc("setpgid", unimplementedFunc),
/* 40 */ SyscallDesc("osf_old_lstat", unimplementedFunc),
- /* 41 */ SyscallDesc("dup", unimplementedFunc),
+ /* 41 */ SyscallDesc("dup", dupFunc),
/* 42 */ SyscallDesc("pipe", pipePseudoFunc),
/* 43 */ SyscallDesc("osf_set_program_attributes", unimplementedFunc),
/* 44 */ SyscallDesc("osf_profil", unimplementedFunc),
}
+SyscallReturn
+dupFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
+{
+ int fd = process->sim_fd(tc->getSyscallArg(0));
+
+ if (fd < 0)
+ return -EBADF;
+
+ int result = dup(fd);
+ return (result == -1) ? -errno : process->alloc_fd(result);
+}
+
+
SyscallReturn
fcntlFunc(SyscallDesc *desc, int num, Process *process,
ThreadContext *tc)
SyscallReturn fchownFunc(SyscallDesc *desc, int num,
Process *p, ThreadContext *tc);
+/// Target dup() handler.
+SyscallReturn dupFunc(SyscallDesc *desc, int num,
+ Process *process, ThreadContext *tc);
+
/// Target fnctl() handler.
SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
Process *process, ThreadContext *tc);