home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / mach-o / dyld_debug.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-14  |  7.4 KB  |  246 lines

  1. /*
  2.  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  * 
  6.  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
  7.  * Reserved.  This file contains Original Code and/or Modifications of
  8.  * Original Code as defined in and that are subject to the Apple Public
  9.  * Source License Version 1.1 (the "License").  You may not use this file
  10.  * except in compliance with the License.  Please obtain a copy of the
  11.  * License at http://www.apple.com/publicsource and read it before using
  12.  * this file.
  13.  * 
  14.  * The Original Code and all software distributed under the License are
  15.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  16.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  17.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
  19.  * License for the specific language governing rights and limitations
  20.  * under the License.
  21.  * 
  22.  * @APPLE_LICENSE_HEADER_END@
  23.  */
  24. #ifndef _DYLD_DEBUG_
  25. #define _DYLD_DEBUG_
  26.  
  27. #import <mach/mach.h>
  28. #ifndef DYLD_BUILD /* do not include this when building dyld itself */
  29. #import <mach-o/dyld.h>
  30. #endif /* !defined(DYLD_BUILD) */
  31. /*
  32.  * The dyld debugging API.
  33.  */
  34. enum dyld_debug_return {
  35.     DYLD_SUCCESS,
  36.     DYLD_INCONSISTENT_DATA,
  37.     DYLD_INVALID_ARGUMENTS,
  38.     DYLD_FAILURE
  39. };
  40.  
  41. struct dyld_debug_module {
  42.     struct mach_header *header;
  43.     unsigned long vmaddr_slide;
  44.     unsigned long module_index;
  45. };
  46.  
  47. enum dyld_event_type {
  48.     DYLD_IMAGE_ADDED,
  49.     DYLD_MODULE_BOUND,
  50.     DYLD_MODULE_REMOVED,
  51.     DYLD_MODULE_REPLACED,
  52.     DYLD_PAST_EVENTS_END,
  53.     DYLD_IMAGE_REMOVED
  54. };
  55.  
  56. struct dyld_event {
  57.     enum dyld_event_type type;
  58.     struct dyld_debug_module arg[2];
  59. };
  60.  
  61. extern enum dyld_debug_return _dyld_debug_defining_module(
  62.     mach_port_t target_task,
  63.     unsigned long send_timeout,
  64.     unsigned long rcv_timeout,
  65.     boolean_t inconsistent_data_ok,
  66.     char *name,
  67.     struct dyld_debug_module *module);
  68.  
  69. extern enum dyld_debug_return _dyld_debug_is_module_bound(
  70.     mach_port_t target_task,
  71.     unsigned long send_timeout,
  72.     unsigned long rcv_timeout,
  73.     boolean_t inconsistent_data_ok,
  74.     struct dyld_debug_module module,
  75.     boolean_t *bound);
  76.  
  77. extern enum dyld_debug_return _dyld_debug_bind_module(
  78.     mach_port_t target_task,
  79.     unsigned long send_timeout,
  80.     unsigned long rcv_timeout,
  81.     boolean_t inconsistent_data_ok,
  82.     struct dyld_debug_module module);
  83.  
  84. extern enum dyld_debug_return _dyld_debug_module_name(
  85.     mach_port_t target_task,
  86.     unsigned long send_timeout,
  87.     unsigned long rcv_timeout,
  88.     boolean_t inconsistent_data_ok,
  89.     struct dyld_debug_module module,
  90.     char **image_name,
  91.     unsigned long *image_nameCnt,
  92.     char **module_name,
  93.     unsigned long *module_nameCnt);
  94.  
  95. extern enum dyld_debug_return _dyld_debug_subscribe_to_events(
  96.     mach_port_t target_task,
  97.     unsigned long send_timeout,
  98.     unsigned long rcv_timeout,
  99.     boolean_t inconsistent_data_ok,
  100.     void (*dyld_event_routine)(struct dyld_event event));
  101.  
  102. /*
  103.  * _dyld_debug_add_event_subscriber() uses the mig interface functions below
  104.  * to dispatch the dyld event messages from the subscriber port specified.
  105.  */
  106. extern enum dyld_debug_return _dyld_debug_add_event_subscriber(
  107.     mach_port_t target_task,
  108.     unsigned long send_timeout,
  109.     unsigned long rcv_timeout,
  110.     boolean_t inconsistent_data_ok,
  111.     mach_port_t subscriber);
  112.  
  113. /*
  114.  * These structures should be produced by mig(1) from the mig generated files
  115.  * but they are not.  These are really only needed so the correct size of the
  116.  * request and reply messages can be allocated.
  117.  */
  118. struct _dyld_event_message_request {
  119. #ifdef __MACH30__
  120.     mach_msg_header_t head;
  121.     NDR_record_t NDR;
  122.     struct dyld_event event;
  123.     mach_msg_trailer_t trailer;
  124. #else
  125.     msg_header_t head;
  126.     msg_type_t eventType;
  127.     struct dyld_event event;
  128. #endif
  129. };
  130. struct _dyld_event_message_reply {
  131. #ifdef __MACH30__
  132.     mach_msg_header_t head;
  133.     NDR_record_t NDR;
  134.     struct dyld_event event;
  135. #else
  136.     msg_header_t head;
  137.     msg_type_t RetCodeType;
  138.     kern_return_t RetCode;
  139. #endif
  140. };
  141. #ifndef    mig_internal
  142. /*
  143.  * _dyld_event_server() is the mig generated routine to dispatch dyld event
  144.  * messages.
  145.  */
  146. extern boolean_t _dyld_event_server(
  147. #ifdef __MACH30__
  148.     mach_msg_header_t *request,
  149.     mach_msg_header_t *reply);
  150. #else
  151.     struct _dyld_event_message_request *request,
  152.     struct _dyld_event_message_reply *reply);
  153. #endif
  154. #endif /* mig_internal */
  155.  
  156. #ifndef SHLIB
  157. /*
  158.  * _dyld_event_server_callback() is the routine called by _dyld_event_server()
  159.  * that must be written by users of _dyld_event_server().
  160.  */
  161. extern
  162. #ifdef __MACH30__
  163. kern_return_t
  164. #else
  165. void
  166. #endif
  167. _dyld_event_server_callback(
  168. #ifdef __MACH30__
  169.     mach_port_t subscriber,
  170. #else
  171.     port_t subscriber,
  172. #endif
  173.     struct dyld_event event);
  174. #endif /* SHLIB */
  175.  
  176. /*
  177.  * This is the state of the target task while we are sending a message to it.
  178.  */
  179. struct _dyld_debug_task_state {
  180.     mach_port_t       debug_port;
  181.     mach_port_t    debug_thread;
  182.     unsigned int   debug_thread_resume_count;
  183.     unsigned int   task_resume_count;
  184.     mach_port_t   *threads;
  185.     unsigned int   thread_count;
  186. };
  187.  
  188. /*
  189.  * _dyld_debug_make_runnable() is called before sending messages to the
  190.  * dynamic link editor.  Basically it assures that the debugging
  191.  * thread is the only runnable thread in the task to receive the
  192.  * message.  It also assures that the debugging thread is indeed
  193.  * runnable if it was suspended.  The function will make sure each 
  194.  * thread in the remote task is suspended and resumed the same number
  195.  * of times, so in the end the suspend count of each individual thread
  196.  * is the same.
  197.  */
  198. extern enum dyld_debug_return _dyld_debug_make_runnable(
  199.     mach_port_t target_task,
  200.     struct _dyld_debug_task_state *state);
  201.  
  202. /*
  203.  * _dyld_debug_restore_runnable() is called after sending messages to the
  204.  * dynamic link editor.  It undoes what _dyld_debug_make_runnable() did to the
  205.  * task and put it back the way it was.
  206.  */
  207. extern enum dyld_debug_return _dyld_debug_restore_runnable(
  208.     mach_port_t target_task,
  209.     struct _dyld_debug_task_state *state);
  210.  
  211. /*
  212.  * To provide more detailed information when the APIs of the dyld debug
  213.  * interfaces fail (return DYLD_FAILURE) the following structure is filled in.
  214.  * After it is filled in the function registered with
  215.  * set_dyld_debug_error_func() is called with a pointer to that struct.
  216.  *
  217.  * The local_error field is a unique number for each possible error condition
  218.  * in the source code in that makes up the dyld debug APIs.  The source file
  219.  * and line number in the cctools libdyld directory where the dyld debug APIs
  220.  * are implemented are set into the file_name and line_number fields.  The
  221.  * field dyld_debug_return is filled in with that would be returned by the
  222.  * API (usually DYLD_FAILURE).  The other fields will be zero or filled in by
  223.  * the error code from the mach system call, or UNIX system call that failed.
  224.  */
  225. struct dyld_debug_error_data {
  226.     enum dyld_debug_return dyld_debug_return;
  227.     kern_return_t mach_error;
  228.     int dyld_debug_errno;
  229.     unsigned long local_error;
  230.     char *file_name;
  231.     unsigned long line_number;
  232. };
  233.  
  234. extern void _dyld_debug_set_error_func(
  235.     void (*func)(struct dyld_debug_error_data *e));
  236.  
  237. #ifndef DYLD_BUILD /* do not include this when building dyld itself */
  238.  
  239. extern enum dyld_debug_return _dyld_debug_task_from_core(
  240.     NSObjectFileImage coreFileImage,
  241.     mach_port_t *core_task);
  242.  
  243. #endif /* !defined(DYLD_BUILD) */
  244.  
  245. #endif /* _DYLD_DEBUG_ */
  246.