thread.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Wine server threads
  3. *
  4. * Copyright (C) 1998 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_THREAD_H
  21. #define __WINE_SERVER_THREAD_H
  22. #include "object.h"
  23. /* thread structure */
  24. struct process;
  25. struct thread_wait;
  26. struct thread_apc;
  27. struct debug_obj;
  28. struct debug_event;
  29. struct msg_queue;
  30. enum run_state
  31. {
  32. RUNNING, /* running normally */
  33. TERMINATED /* terminated */
  34. };
  35. /* descriptor for fds currently in flight from client to server */
  36. struct inflight_fd
  37. {
  38. int client; /* fd on the client side (or -1 if entry is free) */
  39. int server; /* fd on the server side */
  40. };
  41. #define MAX_INFLIGHT_FDS 16 /* max number of fds in flight per thread */
  42. struct thread
  43. {
  44. struct object obj; /* object header */
  45. struct list entry; /* entry in system-wide thread list */
  46. struct list proc_entry; /* entry in per-process thread list */
  47. struct process *process;
  48. thread_id_t id; /* thread id */
  49. struct list mutex_list; /* list of currently owned mutexes */
  50. unsigned int system_regs; /* which system regs have been set */
  51. struct msg_queue *queue; /* message queue */
  52. struct thread_wait *wait; /* current wait condition if sleeping */
  53. struct list system_apc; /* queue of system async procedure calls */
  54. struct list user_apc; /* queue of user async procedure calls */
  55. struct inflight_fd inflight[MAX_INFLIGHT_FDS]; /* fds currently in flight */
  56. unsigned int error; /* current error code */
  57. union generic_request req; /* current request */
  58. void *req_data; /* variable-size data for request */
  59. unsigned int req_toread; /* amount of data still to read in request */
  60. void *reply_data; /* variable-size data for reply */
  61. unsigned int reply_size; /* size of reply data */
  62. unsigned int reply_towrite; /* amount of data still to write in reply */
  63. struct fd *request_fd; /* fd for receiving client requests */
  64. struct fd *reply_fd; /* fd to send a reply to a client */
  65. struct fd *wait_fd; /* fd to use to wake a sleeping client */
  66. enum run_state state; /* running state */
  67. int exit_code; /* thread exit code */
  68. int unix_pid; /* Unix pid of client */
  69. int unix_tid; /* Unix tid of client */
  70. struct context *context; /* current context */
  71. client_ptr_t suspend_cookie;/* wait cookie of suspending select */
  72. client_ptr_t teb; /* TEB address (in client address space) */
  73. client_ptr_t entry_point; /* entry point (in client address space) */
  74. affinity_t affinity; /* affinity mask */
  75. int priority; /* priority level */
  76. int suspend; /* suspend count */
  77. int dbg_hidden; /* hidden from debugger */
  78. obj_handle_t desktop; /* desktop handle */
  79. int desktop_users; /* number of objects using the thread desktop */
  80. timeout_t creation_time; /* Thread creation time */
  81. timeout_t exit_time; /* Thread exit time */
  82. struct token *token; /* security token associated with this thread */
  83. struct list kernel_object; /* list of kernel object pointers */
  84. data_size_t desc_len; /* thread description length in bytes */
  85. WCHAR *desc; /* thread description string */
  86. };
  87. extern struct thread *current;
  88. /* thread functions */
  89. extern struct thread *create_thread( int fd, struct process *process,
  90. const struct security_descriptor *sd );
  91. extern struct thread *get_thread_from_id( thread_id_t id );
  92. extern struct thread *get_thread_from_handle( obj_handle_t handle, unsigned int access );
  93. extern struct thread *get_thread_from_tid( int tid );
  94. extern struct thread *get_thread_from_pid( int pid );
  95. extern struct thread *get_wait_queue_thread( struct wait_queue_entry *entry );
  96. extern enum select_op get_wait_queue_select_op( struct wait_queue_entry *entry );
  97. extern client_ptr_t get_wait_queue_key( struct wait_queue_entry *entry );
  98. extern void make_wait_abandoned( struct wait_queue_entry *entry );
  99. extern void stop_thread( struct thread *thread );
  100. extern int wake_thread( struct thread *thread );
  101. extern int wake_thread_queue_entry( struct wait_queue_entry *entry );
  102. extern int add_queue( struct object *obj, struct wait_queue_entry *entry );
  103. extern void remove_queue( struct object *obj, struct wait_queue_entry *entry );
  104. extern void kill_thread( struct thread *thread, int violent_death );
  105. extern void wake_up( struct object *obj, int max );
  106. extern int thread_queue_apc( struct process *process, struct thread *thread, struct object *owner, const apc_call_t *call_data );
  107. extern void thread_cancel_apc( struct thread *thread, struct object *owner, enum apc_type type );
  108. extern int thread_add_inflight_fd( struct thread *thread, int client, int server );
  109. extern int thread_get_inflight_fd( struct thread *thread, int client );
  110. extern struct token *thread_get_impersonation_token( struct thread *thread );
  111. extern int set_thread_affinity( struct thread *thread, affinity_t affinity );
  112. extern int is_cpu_supported( enum cpu_type cpu );
  113. extern unsigned int get_supported_cpu_mask(void);
  114. extern int suspend_thread( struct thread *thread );
  115. extern int resume_thread( struct thread *thread );
  116. /* ptrace functions */
  117. extern void sigchld_callback(void);
  118. extern void init_thread_context( struct thread *thread );
  119. extern void get_thread_context( struct thread *thread, context_t *context, unsigned int flags );
  120. extern void set_thread_context( struct thread *thread, const context_t *context, unsigned int flags );
  121. extern int send_thread_signal( struct thread *thread, int sig );
  122. extern void get_selector_entry( struct thread *thread, int entry, unsigned int *base,
  123. unsigned int *limit, unsigned char *flags );
  124. extern unsigned int global_error; /* global error code for when no thread is current */
  125. static inline unsigned int get_error(void) { return current ? current->error : global_error; }
  126. static inline void set_error( unsigned int err ) { global_error = err; if (current) current->error = err; }
  127. static inline void clear_error(void) { set_error(0); }
  128. static inline void set_win32_error( unsigned int err ) { set_error( 0xc0010000 | err ); }
  129. static inline thread_id_t get_thread_id( struct thread *thread ) { return thread->id; }
  130. #endif /* __WINE_SERVER_THREAD_H */