process.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Wine server processes
  3. *
  4. * Copyright (C) 1999 Alexandre Julliard
  5. *
  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.
  10. *
  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.
  15. *
  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
  19. */
  20. #ifndef __WINE_SERVER_PROCESS_H
  21. #define __WINE_SERVER_PROCESS_H
  22. #include "object.h"
  23. struct atom_table;
  24. struct handle_table;
  25. struct startup_info;
  26. struct job;
  27. /* process startup state */
  28. enum startup_state { STARTUP_IN_PROGRESS, STARTUP_DONE, STARTUP_ABORTED };
  29. /* process structures */
  30. struct process_dll
  31. {
  32. struct list entry; /* entry in per-process dll list */
  33. mod_handle_t base; /* dll base address (in process addr space) */
  34. client_ptr_t name; /* ptr to ptr to name (in process addr space) */
  35. int dbg_offset; /* debug info offset */
  36. int dbg_size; /* debug info size */
  37. data_size_t namelen; /* length of dll file name */
  38. WCHAR *filename; /* dll file name */
  39. };
  40. struct rawinput_device_entry
  41. {
  42. struct list entry;
  43. struct rawinput_device device;
  44. };
  45. struct process
  46. {
  47. struct object obj; /* object header */
  48. struct list entry; /* entry in system-wide process list */
  49. process_id_t parent_id; /* parent process id (at the time of creation) */
  50. struct list thread_list; /* thread list */
  51. struct thread *debugger; /* thread debugging this process */
  52. struct debug_event *debug_event; /* debug event being sent to debugger */
  53. struct handle_table *handles; /* handle entries */
  54. struct fd *msg_fd; /* fd for sendmsg/recvmsg */
  55. process_id_t id; /* id of the process */
  56. process_id_t group_id; /* group id of the process */
  57. struct timeout_user *sigkill_timeout; /* timeout for final SIGKILL */
  58. enum cpu_type cpu; /* client CPU type */
  59. int unix_pid; /* Unix pid for final SIGKILL */
  60. int exit_code; /* process exit code */
  61. int running_threads; /* number of threads running in this process */
  62. timeout_t start_time; /* absolute time at process start */
  63. timeout_t end_time; /* absolute time at process end */
  64. affinity_t affinity; /* process affinity mask */
  65. int priority; /* priority class */
  66. int suspend; /* global process suspend count */
  67. unsigned int is_system:1; /* is it a system process? */
  68. unsigned int debug_children:1;/* also debug all child processes */
  69. unsigned int is_terminating:1;/* is process terminating? */
  70. unsigned int is_kernel:1; /* winedevice process */
  71. struct job *job; /* job object ascoicated with this process */
  72. struct list job_entry; /* list entry for job object */
  73. struct list asyncs; /* list of async object owned by the process */
  74. struct list locks; /* list of file locks owned by the process */
  75. struct list classes; /* window classes owned by the process */
  76. struct console_input*console; /* console input */
  77. enum startup_state startup_state; /* startup state */
  78. struct startup_info *startup_info; /* startup info while init is in progress */
  79. struct event *idle_event; /* event for input idle */
  80. struct file *exe_file; /* file handle for main exe (during startup only) */
  81. obj_handle_t winstation; /* main handle to process window station */
  82. obj_handle_t desktop; /* handle to desktop to use for new threads */
  83. struct token *token; /* security token associated with this process */
  84. struct list views; /* list of memory views */
  85. struct list dlls; /* list of loaded dlls */
  86. client_ptr_t peb; /* PEB address in client address space */
  87. client_ptr_t ldt_copy; /* pointer to LDT copy in client addr space */
  88. struct dir_cache *dir_cache; /* map of client-side directory cache */
  89. unsigned int trace_data; /* opaque data used by the process tracing mechanism */
  90. struct list rawinput_devices;/* list of registered rawinput devices */
  91. const struct rawinput_device *rawinput_mouse; /* rawinput mouse device, if any */
  92. const struct rawinput_device *rawinput_kbd; /* rawinput keyboard device, if any */
  93. struct list kernel_object; /* list of kernel object pointers */
  94. struct object *callback_init_event;
  95. struct device_manager *dev_mgr;
  96. int esync_fd; /* esync file descriptor (signaled on exit) */
  97. };
  98. struct process_snapshot
  99. {
  100. struct process *process; /* process ptr */
  101. int count; /* process refcount */
  102. int threads; /* number of threads */
  103. int priority; /* priority class */
  104. int handles; /* number of handles */
  105. };
  106. #define CPU_FLAG(cpu) (1 << (cpu))
  107. #define CPU_64BIT_MASK (CPU_FLAG(CPU_x86_64) | CPU_FLAG(CPU_ARM64))
  108. /* process functions */
  109. extern unsigned int alloc_ptid( void *ptr );
  110. extern void free_ptid( unsigned int id );
  111. extern void *get_ptid_entry( unsigned int id );
  112. extern struct process *create_process( int fd, struct process *parent, int inherit_all,
  113. const struct security_descriptor *sd, struct token *token );
  114. extern data_size_t init_process( struct thread *thread );
  115. extern struct thread *get_process_first_thread( struct process *process );
  116. extern struct process *get_process_from_id( process_id_t id );
  117. extern struct process *get_process_from_handle( obj_handle_t handle, unsigned int access );
  118. extern int process_set_debugger( struct process *process, struct thread *thread );
  119. extern int debugger_detach( struct process* process, struct thread* debugger );
  120. extern int set_process_debug_flag( struct process *process, int flag );
  121. extern void add_process_thread( struct process *process,
  122. struct thread *thread );
  123. extern void remove_process_thread( struct process *process,
  124. struct thread *thread );
  125. extern void suspend_process( struct process *process );
  126. extern void resume_process( struct process *process );
  127. extern void kill_process( struct process *process, int violent_death );
  128. extern void kill_console_processes( struct thread *renderer, int exit_code );
  129. extern void kill_debugged_processes( struct thread *debugger, int exit_code );
  130. extern void detach_debugged_processes( struct thread *debugger );
  131. extern struct process_snapshot *process_snap( int *count );
  132. extern void enum_processes( int (*cb)(struct process*, void*), void *user);
  133. extern void replace_process_token( struct process *process, struct token *token );
  134. extern int is_process( struct object *obj );
  135. /* console functions */
  136. extern void inherit_console( struct thread *parent_thread, struct process *parent,
  137. struct process *process, obj_handle_t hconin );
  138. extern int free_console( struct process *process );
  139. extern struct thread *console_get_renderer( struct console_input *console );
  140. /* process tracing mechanism to use */
  141. #ifdef __APPLE__
  142. #define USE_MACH
  143. #elif defined(__sun)
  144. #define USE_PROCFS
  145. #else
  146. #define USE_PTRACE
  147. #endif
  148. extern void init_tracing_mechanism(void);
  149. extern void init_process_tracing( struct process *process );
  150. extern void finish_process_tracing( struct process *process );
  151. extern int read_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, char *dest );
  152. extern int write_process_memory( struct process *process, client_ptr_t ptr, data_size_t size, const char *src );
  153. static inline process_id_t get_process_id( struct process *process ) { return process->id; }
  154. static inline int is_process_init_done( struct process *process )
  155. {
  156. return process->startup_state == STARTUP_DONE;
  157. }
  158. static inline struct process_dll *get_process_exe_module( struct process *process )
  159. {
  160. struct list *ptr = list_head( &process->dlls );
  161. return ptr ? LIST_ENTRY( ptr, struct process_dll, entry ) : NULL;
  162. }
  163. #endif /* __WINE_SERVER_PROCESS_H */