• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2007-2008 The Android Open Source Project
2 **
3 ** This software is licensed under the terms of the GNU General Public
4 ** License version 2, as published by the Free Software Foundation, and
5 ** may be copied, distributed, and modified under those terms.
6 **
7 ** This program is distributed in the hope that it will be useful,
8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 ** GNU General Public License for more details.
11 */
12 #ifndef _TRACE_DEV_H_
13 #define _TRACE_DEV_H_
14 
15 #include "hw/android/goldfish/device.h"
16 #include "cpu.h"
17 
18 #define CLIENT_PAGE_SIZE        4096
19 
20 /* trace device registers */
21 
22 /* The indices below all corresponds to slots that can only be accessed
23  * by the guest kernel. See below for indices reachable from the guest
24  * user-land.
25  */
26 #define TRACE_DEV_REG_SWITCH            0
27 #define TRACE_DEV_REG_FORK              1
28 #define TRACE_DEV_REG_EXECVE_PID        2
29 #define TRACE_DEV_REG_EXECVE_VMSTART    3
30 #define TRACE_DEV_REG_EXECVE_VMEND      4
31 #define TRACE_DEV_REG_EXECVE_OFFSET     5
32 #define TRACE_DEV_REG_EXECVE_EXEPATH    6
33 #define TRACE_DEV_REG_EXIT              7
34 #define TRACE_DEV_REG_CMDLINE           8
35 #define TRACE_DEV_REG_CMDLINE_LEN       9
36 #define TRACE_DEV_REG_MMAP_EXEPATH      10
37 #define TRACE_DEV_REG_INIT_PID          11
38 #define TRACE_DEV_REG_INIT_NAME         12
39 #define TRACE_DEV_REG_CLONE             13
40 #define TRACE_DEV_REG_UNMAP_START       14
41 #define TRACE_DEV_REG_UNMAP_END         15
42 #define TRACE_DEV_REG_NAME              16
43 #define TRACE_DEV_REG_TGID              17
44 #define TRACE_DEV_REG_DYN_SYM           50
45 #define TRACE_DEV_REG_DYN_SYM_ADDR      51
46 #define TRACE_DEV_REG_REMOVE_ADDR       52
47 #define TRACE_DEV_REG_PRINT_STR         60
48 #define TRACE_DEV_REG_PRINT_NUM_DEC     61
49 #define TRACE_DEV_REG_PRINT_NUM_HEX     62
50 #define TRACE_DEV_REG_STOP_EMU          90
51 #define TRACE_DEV_REG_ENABLE            100
52 
53 /* NOTE: The device's second physical page is mapped to /dev/qemu_trace
54  *        This means that if you do the following:
55  *
56  *           magicPage = my_mmap("/dev/qemu_trace", ...);
57  *           *(uint32_t*)magicPage[index] = value;
58  *
59  *        The write at address magicPage+index*4 here will be seen
60  *        by the device as a write to the i/o offset 4096 + index*4,
61  *        i.e. (1024 + index)*4.
62  *
63  *        As a consequence, any index defined below corresponds to
64  *        location (index-1024)*4 in the mmapped page in the guest.
65  */
66 
67 /* The first 64 entries are reserved for VM instrumentation */
68 #define TRACE_DEV_REG_METHOD_ENTRY      1024
69 #define TRACE_DEV_REG_METHOD_EXIT       1025
70 #define TRACE_DEV_REG_METHOD_EXCEPTION  1026
71 #define TRACE_DEV_REG_NATIVE_ENTRY      1028
72 #define TRACE_DEV_REG_NATIVE_EXIT       1029
73 #define TRACE_DEV_REG_NATIVE_EXCEPTION  1030
74 
75 /* Next, QEMUD fast pipes */
76 #define TRACE_DEV_PIPE_BASE             1280    /* 1024 + (64*4) */
77 #define TRACE_DEV_PIPE_COMMAND          (TRACE_DEV_PIPE_BASE + 0)
78 #define TRACE_DEV_PIPE_STATUS           (TRACE_DEV_PIPE_BASE + 0)
79 #define TRACE_DEV_PIPE_ADDRESS          (TRACE_DEV_PIPE_BASE + 1)
80 #define TRACE_DEV_PIPE_SIZE             (TRACE_DEV_PIPE_BASE + 2)
81 #define TRACE_DEV_PIPE_CHANNEL          (TRACE_DEV_PIPE_BASE + 3)
82 
83 /* These entries are reserved for libc instrumentation, i.e. memcheck */
84 #if 0  /* see memcheck_common.h */
85 #define TRACE_DEV_REG_MEMCHECK              1536  /* 1024 + (128*4) */
86 #define TRACE_DEV_REG_LIBC_INIT             (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_LIBC_INIT)
87 #define TRACE_DEV_REG_MALLOC                (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_MALLOC)
88 #define TRACE_DEV_REG_FREE_PTR              (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_FREE_PTR)
89 #define TRACE_DEV_REG_QUERY_MALLOC          (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_QUERY_MALLOC)
90 #define TRACE_DEV_REG_PRINT_USER_STR        (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_PRINT_USER_STR)
91 #endif
92 
93 /* the virtual trace device state */
94 typedef struct {
95     struct goldfish_device dev;
96 } trace_dev_state;
97 
98 /*
99  * interfaces for copy from virtual space
100  * from target-arm/op_helper.c
101  */
102 extern void vstrcpy(target_ulong ptr, char *buf, int max);
103 
104 /*
105  * interfaces to trace module to signal kernel events
106  */
107 extern void trace_switch(int pid);
108 extern void trace_fork(int tgid, int pid);
109 extern void trace_clone(int tgid, int pid);
110 extern void trace_execve(const char *arg, int len);
111 extern void trace_exit(int exitcode);
112 extern void trace_mmap(unsigned long vstart, unsigned long vend,
113                        unsigned long offset, const char *path);
114 extern void trace_munmap(unsigned long vstart, unsigned long vend);
115 extern void trace_dynamic_symbol_add(unsigned long vaddr, const char *name);
116 extern void trace_dynamic_symbol_remove(unsigned long vaddr);
117 extern void trace_init_name(int tgid, int pid, const char *name);
118 extern void trace_init_exec(unsigned long start, unsigned long end,
119                             unsigned long offset, const char *exe);
120 extern void start_tracing(void);
121 extern void stop_tracing(void);
122 extern void trace_exception(uint32 target_pc);
123 
124 #endif
125