1References: 2----------- 3 4window -> desktop 5window -> class 6 7thread_input -> thread 8 9thread -> process 10process -> winsta 11thread -> desktop 12desktop -> winsta 13winsta -> session 14 15NOTE: Message queue has 1:1 relationship with (w32)thread and need no ref. count. 16 -If the (w32)thread is destroyed, so is the message queue. 17 -If the (w32)thread exist, so does the message queue. 18 So if you want the queue to hang around, you reference the thread instead. 19 20^ This is wrong, one can attach message queue to different thread using 21AttachThreadInput. The number of threads sharing a queue is stored in the 22message queue structure and can be considered a reference count. Also on 23Windows systems there is maintained a global list of thread attachments. 24 25Above references create following dependencies: 26----------------------------------------------- 27 28window -> desktop -> winsta -> session 29window -> class 30 31thread -> process -> winsta -> session 32thread -> desktop -> winsta -> session 33 34process -> winsta -> session 35 36NtUser/NtGdi/win32k syscalls 37---------------------------- 38 39A process and/or thread automatically gets converted to a GUI thread / 40process when the first syscall from the shadow service table is called (ie. 41any NtUser* or NtGdi* call). GUI threads have bigger kernel stack (FIXME: 42not the case on ReactOS yet) and have associated storage for the Win32 43structures. The conversion itself happens in the syscall handler and the 44win32k callbacks (registered with PsEstablishWin32Callouts) are called 45accordingly. 46 47A process automatically establishes a connection to a window station on the 48GUI thread conversion. The Win32 process initialization callback routine 49also creates and initializes the W32PROCESS structure and associates it with 50the process. 51 52Similary for thread the callback routine automatically assigns a desktop 53when the thread is converted to GUI thread. The thread also gets a W32THREAD 54structure, a message queue and a thread input structures. 55 56Beware that there is an exception to these rules and that's WinLogon. Since 57at the time the process starts no window stations or desktops exist, none 58are assigned to the the initial thread / process. The first Win32k calls 59the thread does are to create the window station and desktop and to associate 60them with itself. 61 62FIXME: At the time of this writing there's a second exception, a "primitive 63message queue" thread in CSRSS that is created before any window stations 64exist and is used to capture keyboard input in console mode. Eventually we 65should get rid of it and replace is with hidden window w/ focus or something 66similar. 67 68Generally this means that when you are in a Win32k syscall function (other 69than the window station or desktop functions) you can be 100% sure that the 70following exists: 71 72- Process window station 73- Win32 process structure 74- Win32 thread structure 75- Thread message queue 76- Thread input 77- Thread desktop 78 79There is no need to validate any of these values, because they MUST EXIST! 80