2 * Server-side ptrace support
4 * Copyright (C) 1999 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include <sys/types.h>
31 #ifdef HAVE_SYS_PTRACE_H
32 # include <sys/ptrace.h>
34 #ifdef HAVE_SYS_PARAM_H
35 # include <sys/param.h>
37 #ifdef HAVE_SYS_SYSCALL_H
38 # include <sys/syscall.h>
40 #ifdef HAVE_SYS_UCONTEXT_H
41 # include <sys/ucontext.h>
49 #define WIN32_NO_STATUS
59 #define PTRACE_CONT PT_CONTINUE
61 #ifndef PTRACE_SINGLESTEP
62 #define PTRACE_SINGLESTEP PT_STEP
65 #define PTRACE_ATTACH PT_ATTACH
68 #define PTRACE_DETACH PT_DETACH
70 #ifndef PTRACE_PEEKDATA
71 #define PTRACE_PEEKDATA PT_READ_D
73 #ifndef PTRACE_POKEDATA
74 #define PTRACE_POKEDATA PT_WRITE_D
76 #ifndef PTRACE_PEEKUSER
77 #define PTRACE_PEEKUSER PT_READ_U
79 #ifndef PTRACE_POKEUSER
80 #define PTRACE_POKEUSER PT_WRITE_U
84 #define PTRACE_GETDBREGS PT_GETDBREGS
87 #define PTRACE_SETDBREGS PT_SETDBREGS
90 #ifndef HAVE_SYS_PTRACE_H
97 static inline int ptrace(int req
, ...) { errno
= EPERM
; return -1; /*FAIL*/ }
98 #endif /* HAVE_SYS_PTRACE_H */
104 /* handle a status returned by waitpid */
105 static int handle_child_status( struct thread
*thread
, int pid
, int status
, int want_sig
)
107 if (WIFSTOPPED(status
))
109 int sig
= WSTOPSIG(status
);
110 if (debug_level
&& thread
)
111 fprintf( stderr
, "%04x: *signal* signal=%d\n", thread
->id
, sig
);
114 /* ignore other signals for now */
115 ptrace( PTRACE_CONT
, pid
, (caddr_t
)1, sig
);
119 if (thread
&& (WIFSIGNALED(status
) || WIFEXITED(status
)))
121 thread
->unix_pid
= -1;
122 thread
->unix_tid
= -1;
125 if (WIFSIGNALED(status
))
126 fprintf( stderr
, "%04x: *exited* signal=%d\n",
127 thread
->id
, WTERMSIG(status
) );
129 fprintf( stderr
, "%04x: *exited* status=%d\n",
130 thread
->id
, WEXITSTATUS(status
) );
136 /* handle a SIGCHLD signal */
137 void sigchld_callback(void)
143 if (!(pid
= waitpid( -1, &status
, WUNTRACED
| WNOHANG
| __WALL
))) break;
146 struct thread
*thread
= get_thread_from_tid( pid
);
147 if (!thread
) thread
= get_thread_from_pid( pid
);
148 handle_child_status( thread
, pid
, status
, -1 );
154 /* return the Unix pid to use in ptrace calls for a given process */
155 static int get_ptrace_pid( struct thread
*thread
)
157 #ifdef linux /* linux always uses thread id */
158 if (thread
->unix_tid
!= -1) return thread
->unix_tid
;
160 return thread
->unix_pid
;
163 /* return the Unix tid to use in ptrace calls for a given thread */
164 static int get_ptrace_tid( struct thread
*thread
)
166 if (thread
->unix_tid
!= -1) return thread
->unix_tid
;
167 return thread
->unix_pid
;
170 /* wait for a ptraced child to get a certain signal */
171 static int waitpid_thread( struct thread
*thread
, int signal
)
178 if ((res
= waitpid( get_ptrace_pid(thread
), &status
, WUNTRACED
| __WALL
)) == -1)
182 if (!watchdog_triggered()) continue;
183 if (debug_level
) fprintf( stderr
, "%04x: *watchdog* waitpid aborted\n", thread
->id
);
185 else if (errno
== ECHILD
) /* must have died */
187 thread
->unix_pid
= -1;
188 thread
->unix_tid
= -1;
190 else perror( "waitpid" );
194 res
= handle_child_status( thread
, res
, status
, signal
);
195 if (!res
|| res
== signal
) break;
198 return (thread
->unix_pid
!= -1);
201 /* send a signal to a specific thread */
202 static inline int tkill( int tgid
, int pid
, int sig
)
205 int ret
= syscall( __NR_tgkill
, tgid
, pid
, sig
);
206 if (ret
< 0 && errno
== ENOSYS
) ret
= syscall( __NR_tkill
, pid
, sig
);
208 #elif (defined(__FreeBSD__) || defined (__FreeBSD_kernel__)) && defined(HAVE_THR_KILL2)
209 return thr_kill2( tgid
, pid
, sig
);
216 /* initialize the process tracing mechanism */
217 void init_tracing_mechanism(void)
219 /* no initialization needed for ptrace */
222 /* initialize the per-process tracing mechanism */
223 void init_process_tracing( struct process
*process
)
225 /* ptrace setup is done on-demand */
228 /* terminate the per-process tracing mechanism */
229 void finish_process_tracing( struct process
*process
)
233 /* send a Unix signal to a specific thread */
234 int send_thread_signal( struct thread
*thread
, int sig
)
238 if (thread
->unix_pid
!= -1)
240 if (thread
->unix_tid
!= -1)
242 ret
= tkill( thread
->unix_pid
, thread
->unix_tid
, sig
);
243 if (ret
== -1 && errno
== ENOSYS
) ret
= kill( thread
->unix_pid
, sig
);
245 else ret
= kill( thread
->unix_pid
, sig
);
247 if (ret
== -1 && errno
== ESRCH
) /* thread got killed */
249 thread
->unix_pid
= -1;
250 thread
->unix_tid
= -1;
253 if (debug_level
&& ret
!= -1)
254 fprintf( stderr
, "%04x: *sent signal* signal=%d\n", thread
->id
, sig
);
258 /* resume a thread after we have used ptrace on it */
259 static void resume_after_ptrace( struct thread
*thread
)
261 if (thread
->unix_pid
== -1) return;
262 if (ptrace( PTRACE_DETACH
, get_ptrace_pid(thread
), (caddr_t
)1, 0 ) == -1)
264 if (errno
== ESRCH
) thread
->unix_pid
= thread
->unix_tid
= -1; /* thread got killed */
268 /* suspend a thread to allow using ptrace on it */
269 /* you must do a resume_after_ptrace when finished with the thread */
270 static int suspend_for_ptrace( struct thread
*thread
)
272 /* can't stop a thread while initialisation is in progress */
273 if (thread
->unix_pid
== -1 || !is_process_init_done(thread
->process
)) goto error
;
275 /* this may fail if the client is already being debugged */
276 if (ptrace( PTRACE_ATTACH
, get_ptrace_pid(thread
), 0, 0 ) == -1)
278 if (errno
== ESRCH
) thread
->unix_pid
= thread
->unix_tid
= -1; /* thread got killed */
281 if (waitpid_thread( thread
, SIGSTOP
)) return 1;
282 resume_after_ptrace( thread
);
284 set_error( STATUS_ACCESS_DENIED
);
288 /* read a long from a thread address space */
289 static int read_thread_long( struct thread
*thread
, void *addr
, unsigned long *data
)
292 *data
= ptrace( PTRACE_PEEKDATA
, get_ptrace_pid(thread
), (caddr_t
)addr
, 0 );
293 if ( *data
== -1 && errno
)
301 static int read_thread_int( struct thread
*thread
, void *addr
, unsigned int *data
)
303 unsigned long long_data
;
306 ret
= read_thread_long( thread
, addr
, &long_data
);
311 /* write a long to a thread address space */
312 static long write_thread_long( struct thread
*thread
, void *addr
, unsigned long data
, unsigned long mask
)
314 unsigned long old_data
;
319 if (read_thread_long( thread
, addr
, &old_data
) == -1) return -1;
320 data
= (data
& mask
) | (old_data
& ~mask
);
322 if ((res
= ptrace( PTRACE_POKEDATA
, get_ptrace_pid(thread
), (caddr_t
)addr
, data
)) == -1)
327 /* return a thread of the process suitable for ptracing */
328 static struct thread
*get_ptrace_thread( struct process
*process
)
330 struct thread
*thread
;
332 LIST_FOR_EACH_ENTRY( thread
, &process
->thread_list
, struct thread
, proc_entry
)
334 if (thread
->unix_pid
!= -1) return thread
;
336 set_error( STATUS_PROCESS_IS_TERMINATING
); /* process is dead */
340 /* read data from a process memory space */
341 int read_process_memory( struct process
*process
, client_ptr_t ptr
, data_size_t size
, char *dest
)
343 struct thread
*thread
= get_ptrace_thread( process
);
344 unsigned int first_offset
, last_offset
, len
;
345 unsigned long data
, *addr
;
347 if (!thread
) return 0;
349 if ((unsigned long)ptr
!= ptr
)
351 set_error( STATUS_ACCESS_DENIED
);
355 first_offset
= ptr
% sizeof(long);
356 last_offset
= (size
+ first_offset
) % sizeof(long);
357 if (!last_offset
) last_offset
= sizeof(long);
359 addr
= (unsigned long *)(unsigned long)(ptr
- first_offset
);
360 len
= (size
+ first_offset
+ sizeof(long) - 1) / sizeof(long);
362 if (suspend_for_ptrace( thread
))
364 if (len
> 3) /* /proc/pid/mem should be faster for large sizes */
369 snprintf( procmem
, sizeof(procmem
), "/proc/%u/mem", process
->unix_pid
);
370 if ((fd
= open( procmem
, O_RDONLY
)) != -1)
372 ssize_t ret
= pread( fd
, dest
, size
, ptr
);
384 if (read_thread_long( thread
, addr
++, &data
) == -1) goto done
;
385 memcpy( dest
, (char *)&data
+ first_offset
, sizeof(long) - first_offset
);
386 dest
+= sizeof(long) - first_offset
;
393 if (read_thread_long( thread
, addr
++, &data
) == -1) goto done
;
394 memcpy( dest
, &data
, sizeof(long) );
395 dest
+= sizeof(long);
399 if (read_thread_long( thread
, addr
++, &data
) == -1) goto done
;
400 memcpy( dest
, (char *)&data
+ first_offset
, last_offset
- first_offset
);
404 resume_after_ptrace( thread
);
409 /* make sure we can write to the whole address range */
410 /* len is the total size (in longs) */
411 static int check_process_write_access( struct thread
*thread
, long *addr
, data_size_t len
)
413 int page
= get_page_size() / sizeof(long);
417 if (write_thread_long( thread
, addr
, 0, 0 ) == -1) return 0;
418 if (len
<= page
) break;
422 return (write_thread_long( thread
, addr
+ len
- 1, 0, 0 ) != -1);
425 /* write data to a process memory space */
426 int write_process_memory( struct process
*process
, client_ptr_t ptr
, data_size_t size
, const char *src
)
428 struct thread
*thread
= get_ptrace_thread( process
);
433 unsigned long first_mask
, first_offset
, last_mask
, last_offset
;
435 if (!thread
) return 0;
437 if ((unsigned long)ptr
!= ptr
)
439 set_error( STATUS_ACCESS_DENIED
);
443 /* compute the mask for the first long */
445 first_offset
= ptr
% sizeof(long);
446 memset( &first_mask
, 0, first_offset
);
448 /* compute the mask for the last long */
449 last_offset
= (size
+ first_offset
) % sizeof(long);
450 if (!last_offset
) last_offset
= sizeof(long);
452 memset( &last_mask
, 0xff, last_offset
);
454 addr
= (long *)(unsigned long)(ptr
- first_offset
);
455 len
= (size
+ first_offset
+ sizeof(long) - 1) / sizeof(long);
457 if (suspend_for_ptrace( thread
))
459 if (!check_process_write_access( thread
, addr
, len
))
461 set_error( STATUS_ACCESS_DENIED
);
470 snprintf( procmem
, sizeof(procmem
), "/proc/%u/mem", process
->unix_pid
);
471 if ((fd
= open( procmem
, O_WRONLY
)) != -1)
473 ssize_t r
= pwrite( fd
, src
, size
, ptr
);
483 /* first word is special */
486 memcpy( (char *)&data
+ first_offset
, src
, sizeof(long) - first_offset
);
487 src
+= sizeof(long) - first_offset
;
488 if (write_thread_long( thread
, addr
++, data
, first_mask
) == -1) goto done
;
492 else last_mask
&= first_mask
;
496 memcpy( &data
, src
, sizeof(long) );
498 if (write_thread_long( thread
, addr
++, data
, ~0ul ) == -1) goto done
;
502 /* last word is special too */
503 memcpy( (char *)&data
+ first_offset
, src
, last_offset
- first_offset
);
504 if (write_thread_long( thread
, addr
, data
, last_mask
) == -1) goto done
;
508 resume_after_ptrace( thread
);
513 /* retrieve an LDT selector entry */
514 void get_selector_entry( struct thread
*thread
, int entry
, unsigned int *base
,
515 unsigned int *limit
, unsigned char *flags
)
517 if (!thread
->process
->ldt_copy
)
519 set_error( STATUS_ACCESS_DENIED
);
524 set_error( STATUS_ACCESS_VIOLATION
);
527 if (suspend_for_ptrace( thread
))
529 unsigned int flags_buf
;
530 unsigned long addr
= (unsigned long)thread
->process
->ldt_copy
+ (entry
* 4);
532 if (read_thread_int( thread
, (void *)addr
, base
) == -1) goto done
;
533 if (read_thread_int( thread
, (void *)(addr
+ (8192 * 4)), limit
) == -1) goto done
;
534 addr
= (unsigned long)thread
->process
->ldt_copy
+ (2 * 8192 * 4) + (entry
& ~3);
535 if (read_thread_int( thread
, (void *)addr
, &flags_buf
) == -1) goto done
;
536 *flags
= flags_buf
>> (entry
& 3) * 8;
538 resume_after_ptrace( thread
);
543 #if defined(linux) && (defined(HAVE_SYS_USER_H) || defined(HAVE_ASM_USER_H)) \
544 && (defined(__i386__) || defined(__x86_64__))
546 #ifdef HAVE_SYS_USER_H
547 #include <sys/user.h>
548 #elif defined(HAVE_ASM_USER_H)
549 #include <asm/user.h>
552 /* debug register offset in struct user */
553 #define DR_OFFSET(dr) ((((struct user *)0)->u_debugreg) + (dr))
555 /* initialize registers in new thread if necessary */
556 void init_thread_context( struct thread
*thread
)
558 /* Linux doesn't clear all registers, but hopefully enough to avoid spurious breakpoints */
559 thread
->system_regs
= 0;
562 /* retrieve the thread x86 registers */
563 void get_thread_context( struct thread
*thread
, context_t
*context
, unsigned int flags
)
565 int i
, pid
= get_ptrace_tid(thread
);
568 /* all other regs are handled on the client side */
569 assert( flags
== SERVER_CTX_DEBUG_REGISTERS
);
571 if (!(thread
->system_regs
& SERVER_CTX_DEBUG_REGISTERS
))
573 /* caller has initialized everything to 0 already, just return */
574 context
->flags
|= SERVER_CTX_DEBUG_REGISTERS
;
578 if (!suspend_for_ptrace( thread
)) return;
580 for (i
= 0; i
< 8; i
++)
582 if (i
== 4 || i
== 5) continue;
584 data
[i
] = ptrace( PTRACE_PEEKUSER
, pid
, DR_OFFSET(i
), 0 );
585 if ((data
[i
] == -1) && errno
)
591 switch (context
->machine
)
593 case IMAGE_FILE_MACHINE_I386
:
594 context
->debug
.i386_regs
.dr0
= data
[0];
595 context
->debug
.i386_regs
.dr1
= data
[1];
596 context
->debug
.i386_regs
.dr2
= data
[2];
597 context
->debug
.i386_regs
.dr3
= data
[3];
598 context
->debug
.i386_regs
.dr6
= data
[6];
599 context
->debug
.i386_regs
.dr7
= data
[7];
601 case IMAGE_FILE_MACHINE_AMD64
:
602 context
->debug
.x86_64_regs
.dr0
= data
[0];
603 context
->debug
.x86_64_regs
.dr1
= data
[1];
604 context
->debug
.x86_64_regs
.dr2
= data
[2];
605 context
->debug
.x86_64_regs
.dr3
= data
[3];
606 context
->debug
.x86_64_regs
.dr6
= data
[6];
607 context
->debug
.x86_64_regs
.dr7
= data
[7];
610 set_error( STATUS_INVALID_PARAMETER
);
613 context
->flags
|= SERVER_CTX_DEBUG_REGISTERS
;
615 resume_after_ptrace( thread
);
618 /* set the thread x86 registers */
619 void set_thread_context( struct thread
*thread
, const context_t
*context
, unsigned int flags
)
621 int pid
= get_ptrace_tid( thread
);
623 /* all other regs are handled on the client side */
624 assert( flags
== SERVER_CTX_DEBUG_REGISTERS
);
626 if (!suspend_for_ptrace( thread
)) return;
628 switch (context
->machine
)
630 case IMAGE_FILE_MACHINE_I386
:
631 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(7), 0 ) == -1) goto error
;
632 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(0), context
->debug
.i386_regs
.dr0
) == -1) goto error
;
633 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(1), context
->debug
.i386_regs
.dr1
) == -1) goto error
;
634 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(2), context
->debug
.i386_regs
.dr2
) == -1) goto error
;
635 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(3), context
->debug
.i386_regs
.dr3
) == -1) goto error
;
636 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(6), context
->debug
.i386_regs
.dr6
) == -1) goto error
;
637 /* Linux 2.6.33+ needs enable bits set briefly to update value returned by PEEKUSER later */
638 ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(7), context
->debug
.i386_regs
.dr7
| 0x55 );
639 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(7), context
->debug
.i386_regs
.dr7
) == -1) goto error
;
640 thread
->system_regs
|= SERVER_CTX_DEBUG_REGISTERS
;
642 case IMAGE_FILE_MACHINE_AMD64
:
643 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(7), 0 ) == -1) goto error
;
644 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(0), context
->debug
.x86_64_regs
.dr0
) == -1) goto error
;
645 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(1), context
->debug
.x86_64_regs
.dr1
) == -1) goto error
;
646 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(2), context
->debug
.x86_64_regs
.dr2
) == -1) goto error
;
647 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(3), context
->debug
.x86_64_regs
.dr3
) == -1) goto error
;
648 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(6), context
->debug
.x86_64_regs
.dr6
) == -1) goto error
;
649 ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(7), context
->debug
.x86_64_regs
.dr7
| 0x55 );
650 if (ptrace( PTRACE_POKEUSER
, pid
, DR_OFFSET(7), context
->debug
.x86_64_regs
.dr7
) == -1) goto error
;
651 thread
->system_regs
|= SERVER_CTX_DEBUG_REGISTERS
;
654 set_error( STATUS_INVALID_PARAMETER
);
656 resume_after_ptrace( thread
);
660 resume_after_ptrace( thread
);
663 #elif defined(__i386__) && defined(PTRACE_GETDBREGS) && defined(PTRACE_SETDBREGS) && \
664 (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__))
666 #include <machine/reg.h>
668 /* initialize registers in new thread if necessary */
669 void init_thread_context( struct thread
*thread
)
671 if (!(thread
->system_regs
& SERVER_CTX_DEBUG_REGISTERS
)) return;
673 /* FreeBSD doesn't clear the debug registers in new threads */
674 if (suspend_for_ptrace( thread
))
678 memset( &dbregs
, 0, sizeof(dbregs
) );
679 ptrace( PTRACE_SETDBREGS
, get_ptrace_tid( thread
), (caddr_t
)&dbregs
, 0 );
680 resume_after_ptrace( thread
);
682 thread
->system_regs
= 0;
685 /* retrieve the thread x86 registers */
686 void get_thread_context( struct thread
*thread
, context_t
*context
, unsigned int flags
)
688 int pid
= get_ptrace_tid(thread
);
691 /* all other regs are handled on the client side */
692 assert( flags
== SERVER_CTX_DEBUG_REGISTERS
);
694 if (!suspend_for_ptrace( thread
)) return;
696 if (ptrace( PTRACE_GETDBREGS
, pid
, (caddr_t
) &dbregs
, 0 ) == -1) file_set_error();
700 /* needed for FreeBSD, the structure fields have changed under 5.x */
701 context
->debug
.i386_regs
.dr0
= DBREG_DRX((&dbregs
), 0);
702 context
->debug
.i386_regs
.dr1
= DBREG_DRX((&dbregs
), 1);
703 context
->debug
.i386_regs
.dr2
= DBREG_DRX((&dbregs
), 2);
704 context
->debug
.i386_regs
.dr3
= DBREG_DRX((&dbregs
), 3);
705 context
->debug
.i386_regs
.dr6
= DBREG_DRX((&dbregs
), 6);
706 context
->debug
.i386_regs
.dr7
= DBREG_DRX((&dbregs
), 7);
707 #elif defined(__NetBSD__)
708 context
->debug
.i386_regs
.dr0
= dbregs
.dr
[0];
709 context
->debug
.i386_regs
.dr1
= dbregs
.dr
[1];
710 context
->debug
.i386_regs
.dr2
= dbregs
.dr
[2];
711 context
->debug
.i386_regs
.dr3
= dbregs
.dr
[3];
712 context
->debug
.i386_regs
.dr6
= dbregs
.dr
[6];
713 context
->debug
.i386_regs
.dr7
= dbregs
.dr
[7];
715 context
->debug
.i386_regs
.dr0
= dbregs
.dr0
;
716 context
->debug
.i386_regs
.dr1
= dbregs
.dr1
;
717 context
->debug
.i386_regs
.dr2
= dbregs
.dr2
;
718 context
->debug
.i386_regs
.dr3
= dbregs
.dr3
;
719 context
->debug
.i386_regs
.dr6
= dbregs
.dr6
;
720 context
->debug
.i386_regs
.dr7
= dbregs
.dr7
;
722 context
->flags
|= SERVER_CTX_DEBUG_REGISTERS
;
724 resume_after_ptrace( thread
);
727 /* set the thread x86 registers */
728 void set_thread_context( struct thread
*thread
, const context_t
*context
, unsigned int flags
)
730 int pid
= get_ptrace_tid(thread
);
733 /* all other regs are handled on the client side */
734 assert( flags
== SERVER_CTX_DEBUG_REGISTERS
);
736 if (!suspend_for_ptrace( thread
)) return;
739 /* needed for FreeBSD, the structure fields have changed under 5.x */
740 DBREG_DRX((&dbregs
), 0) = context
->debug
.i386_regs
.dr0
;
741 DBREG_DRX((&dbregs
), 1) = context
->debug
.i386_regs
.dr1
;
742 DBREG_DRX((&dbregs
), 2) = context
->debug
.i386_regs
.dr2
;
743 DBREG_DRX((&dbregs
), 3) = context
->debug
.i386_regs
.dr3
;
744 DBREG_DRX((&dbregs
), 4) = 0;
745 DBREG_DRX((&dbregs
), 5) = 0;
746 DBREG_DRX((&dbregs
), 6) = context
->debug
.i386_regs
.dr6
;
747 DBREG_DRX((&dbregs
), 7) = context
->debug
.i386_regs
.dr7
;
748 #elif defined(__NetBSD__)
749 dbregs
.dr
[0] = context
->debug
.i386_regs
.dr0
;
750 dbregs
.dr
[1] = context
->debug
.i386_regs
.dr1
;
751 dbregs
.dr
[2] = context
->debug
.i386_regs
.dr2
;
752 dbregs
.dr
[3] = context
->debug
.i386_regs
.dr3
;
755 dbregs
.dr
[6] = context
->debug
.i386_regs
.dr6
;
756 dbregs
.dr
[7] = context
->debug
.i386_regs
.dr7
;
758 dbregs
.dr0
= context
->debug
.i386_regs
.dr0
;
759 dbregs
.dr1
= context
->debug
.i386_regs
.dr1
;
760 dbregs
.dr2
= context
->debug
.i386_regs
.dr2
;
761 dbregs
.dr3
= context
->debug
.i386_regs
.dr3
;
764 dbregs
.dr6
= context
->debug
.i386_regs
.dr6
;
765 dbregs
.dr7
= context
->debug
.i386_regs
.dr7
;
767 if (ptrace( PTRACE_SETDBREGS
, pid
, (caddr_t
)&dbregs
, 0 ) != -1)
769 thread
->system_regs
|= SERVER_CTX_DEBUG_REGISTERS
;
771 else file_set_error();
773 resume_after_ptrace( thread
);
776 #else /* linux || __FreeBSD__ */
778 /* initialize registers in new thread if necessary */
779 void init_thread_context( struct thread
*thread
)
783 /* retrieve the thread x86 registers */
784 void get_thread_context( struct thread
*thread
, context_t
*context
, unsigned int flags
)
788 /* set the thread x86 debug registers */
789 void set_thread_context( struct thread
*thread
, const context_t
*context
, unsigned int flags
)
793 #endif /* linux || __FreeBSD__ */
795 #endif /* USE_PTRACE */