Windows operating system Flashcards
What is Kernel mode stack?
Its of size 12 KB and is part of 2 GB kernel space. Though the stack is allocated in kernel (system) space, it is associated with the running thread and will be swapped out when thread relinquishes its control
What is system services dispatcher function? (KiSystemService)
The main function in a device driver is Driver entry. In kernel mode each request is treated as an IRP (Interrupt request packet) so for every read, write and any other operation separate IRP’s are generated. For example - IRP_MJ/MN_READ, IRP_MJ/MN_WRITE etc. In the dispatcher function, code is written to invoke an action to perform when a particular IRP occurs i.e. suppose for IRP_MJ_READ operation the control goes from driver entry to dispatcher function , in that IRP_MJ_READ is handled.
what are different calling conventions
Below are important calling conversions
- _cdecl(caller frees the stack, parameters are passed from RL).
- __stdcall(callee frees up the stack, RL), Also known as pascal calling convention.
- __fastcall(callee frees up the stack, first in register and then on stack) .
- thiscall(callee, RL, the this pointer is passed in ECX register).
In debug mode, VC++ compiler adds stack-check function to check stack overrun or underrun. What is that? How it is useful?
For threads total stack region reserved is 1 MB, out of which 2 pages are committed to physical storage. Other pages are committed as stack grows in size. The second page is protected with PAGE_GUARD attribute and when thread tries to write on it (as an effect of stack growing), exception is thrown and a new page is committed. Sometimes the functions requires quite big stack (which needs more than 2 pages) in such case the statements in function might access area below page_guard page, which will result in access violation. (say function has a big array: int i[10000]). To avoid this, c run-time stack check function finds out total requirement of stack memory and commits that much memory in advance.
How to call 32 bit function from 16 bit code?
Using universal thunking. Universal thunking enables you to call a 32-bit function from 16-bit code. Universal thunking is supported by Windows NT and Windows 95/98 both.
What does .pdb file contains?
PDB (Program Database) is a symbol table file. Compiler switch \PDB:SEPT keeps type info in VC60.PDB file and symbol table in .PDB file. \PDB:CON puts both information in one .pdb file. These PDB files are very useful while debugging. If these files are not there then developer has to understand each and every assembly language instruction while debugging. PDB files makes debuggers life easy. If these files are available, debugger application can load these files while debugging and so user can see symbol names instead of hexadecimal values.
How will you post a message to a thread and not to any window created by that thread?
PostMessage(msg, NULL);
What is windows subclassing?
Subclassing is a procedure that allows an application to intercept and process messages sent or posted to a particular window before the window has a chance to process them. By subclassing a window an application can augment, modify or monitor the behavior of the window.
Hint: Change the address of wndproc using SetWindowLong() function
What is window superclassing
Superclassing is a technique that allows a application to create a new window class having basic functionality of the existing class plus enhancements provided by the application.
User mode synchronization objects means what? Does thread never goes in the kernel mode?
User mode synchronization objects don’t put thread in wait state and so executes in user mode only. Spin lock is the only true user mode synchronization object. Critical section tries to spin for certain number of time and then transitions to the kernel mode (during wait state). It internally uses event kernel object.
What is semaphore. Where it is used?
Semaphore is used where access to n number of resources need to controlled.
Semaphore uses two counters, max_resource_count specifies maximum number of resources that can be controlled and cur_resource_count specifies number of resources available for processing at present.
Semaphore is signaled if cur_resouce_count > 0.
CreateSemaphor() API creates a semaphore object. ReleaseSemaphor() is called when resource is available for other threads to use. Successful wait on the semaphor (WaitForSingleObject() is returning) decrements current resource count by 1 since one of the waiting thread has started using available resource.
What are the ways to debug ‘release’ mode application?
- Put debug info into release build as well.
2. Using MAP file and PDB file.
How to find crash location?
Use map file to find the crash address. The simple formula to find the line number and source file name is
what is structure of MAP file?
MAP file is the textual representation of your programs global symbols and source file and line number information. These files are very useful to find a crash location just by an address. The format of .map file is as follows. It has 5 different sections.
- States binary’s preferred base address location.
- Puts info about different sections (PE)
- lists all public ‘c’ functions with RVA+base address info.
- source file and line number info.
- exported functions.
The simple formula to find the line number and source file name is (Crash address - pref load address - 0x1000). To get the function name where crash occurred search for the function having RVA+base value greater than crash address. The preceding function is where the crash occurred.
How memory is partitioned?
On windows 2000, there are 4 main partitions -
- NULL pointer assignment
- user mode
- 64 KB off limits
- kernel mode.
Two additional partitions on win98 are
- 16 bit dos/windows application compatibility
- shared MMF.
What is the concept of 3GB user mode space?
The total process address space is divided as 2 GB user mode space and 2 GB kernel mode space. This 2 GB user mode space is not sufficient for some applications. So on Windows 2000 advance server, we can have setting such that 3 GB addess space is given to user mode application and kernel fits in only 1 GB. Applications must be compiled with /LARGEADRESSSPACE option to behave properly in 3 GB address space.
What is the advantage of having multiple paging files configured on a system, on different hard drives.
OS can write on multiple drives simulteniously. This will improve the performance.
What’s OS default behaviour for thread stack? How does it grows for OS 98/2000?
Each thread has 1 MB of stack region reserved for it. Out of which, initially only 2 pages are committed. Stack pointer points to the first page and second page has PAGE_GAURD protection attribute. So when stack grows to second page, exception is thrown and system commits one more page, and moves PAGE_GUARD attribute to this new page. This way stack grows. When stack reaches to end of third-last page of stack region, second last page is committed and here PAGE_GUARD attribute is not applied to new page i.e. last page. The system next throws STACK_OVERFLOW exception. The last page is never committed and if stack grows to this page, access violation exception is thrown.
Same happens in win98 with some exceptions, win98 protects for both stack overflow and underflow, PAGE_NOACCESS attribute is applied instead of PAGE_GUARD.
What is the use of ‘stack check’ function defined n c- run time library
This function checks the memory required for the function to execute is committed or not. If not committed, commits the required amount of memory. This is very useful if function has a very big stack.
What is hardware exception and software exception?
Exceptions raised by CPU are called as hardware exceptions (e.g. invalid memory access, divide by 0).
Exceptions raised by operating system or applications is called software exception (raiseexception() API).
What is heap?
Heaps are used to allocate small blocks of memory. It ignores allocation granularity boundary and page size. Internally it is a region of reserved address space. The pages are committed to this address space as and when required. System’s paging file backs these pages. Access to all heaps is serialized by default. One can opt for un-serialized heap using options flag parameter of function CreateHeap().
Design a single threaded application doing both background processing & UI handling
Hint: use fibre and peekmessage.
Write an edit control that takes only numeric input?
Use Subclassing in this case. The procedure should return an error message if the input is other than numeric value.
Hint: WM_CHAR massage
Why do we need to dispatch message? Why it is not processed when received in GetMassage() loop
Message loop is per thread. One thread may create two or more windows having different winproc to process messages corresponding to it. DispatchMessage() API dispatches messages to appropriate winproc for processing.