Ignore:
Timestamp:
Oct 10, 2008, 12:24:51 AM (14 years ago)
Author:
Pascal Terjan
Message:
  • Cleanup my term after a grab
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/mytrace.c

    r2786 r2906  
    165165#define MYCALL_FORK     7
    166166#define MYCALL_EXIT     8
     167#define MYCALL_IOCTL    9
    167168
    168169#if defined __x86_64__
    169170/* from unistd_32.h on an amd64 system */
    170 int syscalls32[] = { 5, 6, 4, 63, 57, 66, 37, 2, 1 };
     171int syscalls32[] = { 5, 6, 4, 63, 57, 66, 37, 2, 1, 54 };
    171172int syscalls64[] =
    172173#else
     
    174175#endif
    175176    { SYS_open, SYS_close, SYS_write, SYS_dup2, SYS_setpgid, SYS_setsid,
    176       SYS_kill, SYS_fork, SYS_exit };
     177      SYS_kill, SYS_fork, SYS_exit, SYS_ioctl };
    177178
    178179char const *syscallnames[] =
    179180    { "open", "close", "write", "dup2", "setpgid", "setsid", "kill", "fork",
    180       "exit" };
     181      "exit", "ioctl" };
    181182
    182183struct mytrace
     
    394395    ptrace(PTRACE_SETOPTIONS, t->pid, NULL, PTRACE_O_TRACEEXIT);
    395396    return remote_syscall(t, MYCALL_EXIT, status, 0, 0);
     397#else
     398    errno = ENOSYS;
     399    return -1;
     400#endif
     401}
     402
     403int mytrace_tcgets(struct mytrace *t, int fd, struct termios *tos)
     404{
     405#if defined USE_GRAB
     406    struct user_regs_struct regs;
     407    struct termios mytos;
     408    int ret;
     409
     410    if(ptrace(PTRACE_GETREGS, t->pid, NULL, &regs) < 0)
     411    {
     412        fprintf(stderr, "PTRACE_GETREGS failed\n");
     413        return errno;
     414    }
     415
     416    /* Backup the data that we will use */
     417    if(memcpy_from_target(t, (char *)&mytos, regs.RSP, sizeof(struct termios)) < 0)
     418        return -1;
     419
     420    ret = remote_syscall(t, MYCALL_IOCTL, fd, TCGETS, regs.RSP);
     421
     422    memcpy_from_target(t, (char *)tos, regs.RSP, sizeof(struct termios));
     423
     424    /* Restore the data */
     425    memcpy_into_target(t, regs.RSP, (char *)&mytos, sizeof(struct termios));
     426
     427    if(ret < 0)
     428    {
     429        errno = ret;
     430        return -1;
     431    }
     432
     433    return ret;
     434#else
     435    errno = ENOSYS;
     436    return -1;
     437#endif
     438}
     439
     440int mytrace_tcsets(struct mytrace *t, int fd, struct termios *tos)
     441{
     442#if defined USE_GRAB
     443    struct user_regs_struct regs;
     444    struct termios mytos;
     445    int ret;
     446
     447    if(ptrace(PTRACE_GETREGS, t->pid, NULL, &regs) < 0)
     448    {
     449        fprintf(stderr, "PTRACE_GETREGS failed\n");
     450        return errno;
     451    }
     452
     453    /* Backup the data that we will use */
     454    if(memcpy_from_target(t, (char *)&mytos, regs.RSP, sizeof(struct termios)) < 0)
     455        return -1;
     456
     457    memcpy_into_target(t, regs.RSP, (char *)tos, sizeof(struct termios));
     458
     459    ret = remote_syscall(t, MYCALL_IOCTL, fd, TCSETS, regs.RSP);
     460
     461    /* Restore the data */
     462    memcpy_into_target(t, regs.RSP, (char *)&mytos, sizeof(struct termios));
     463
     464    if(ret < 0)
     465    {
     466        errno = ret;
     467        return -1;
     468    }
     469
     470    return ret;
    396471#else
    397472    errno = ENOSYS;
Note: See TracChangeset for help on using the changeset viewer.