User Mode versus Kernel Mode
In Windows (and most OSs), there is a distinction between code that is running in user mode, and code that is running in kernel mode, because if all programs ran in kernel mode, they would be able to overwrite each others' memory and possibly bring down the entire system when they crashed.
This distinction has roots in lower levels; for example Intel CPUs have modes of operation called rings which specify the type of instructions and memory available to the running code:
• Ring 0 (kernel mode) full access to every resource, used by the Windows kernel
• Rings 1 and 2: customized levels of access, generally used by VMs
• Ring 3 (user mode) restricted access to resources
Virtual Memory
Each process has its own "virtual" memory space and resources. Its memory is "virtual" because the process thinks it has a large range of contiguous addresses; but in reality this is implemented by dividing RAM into chunks called pages (4 KB on x86 systems) and having its active pages scattered around RAM and inactive pages stored on disk. The CPU has a transparent mechanism for translating virtual addresses to physical addresses through a page table which the OS sets up. Virtual memory is useful because:
• A process cannot access the memory of other processes
• Each page can have different protection settings (read-only, read-write, kernel-mode-only, etc.)
• Inactive pages can be paged out to disk and retrieved when needed. This is also done when the system is low on RAM.
User Mode
In this mode, programs cannot modify pages directly and so have no way of affecting other processes except through their API. Programs in thismode also cannot interfere with interrupts and context switching.
Kernel Mode
When Windows is first loaded, the Windows kernel is started. It runs in kernel mode and sets up paging, virtual memory, interrupt handlers. Except System which runs in kernel mode, every other process runs in user mode. The kernel then creates some system processes in user mode, but switches back to kernel mode when it is interrupted by interrupts (events such as timers, keyboard, hard disk I/O). Whenever an interrupt occurs, the CPU stops executing the currently running program, switches to kernel mode, and executes the interrupt handler. The handler saves the state of the CPU, performs some processing relevant to that event, and restores the state of the CPU (possibly switching back to user mode) so the CPU can resume execution of the program.
Interrupts
When a program calls a Windows API function, that itself calls a different API: the Native API. Then it either triggers an interrupt or executes instructions such as
Context Switching
Programs may let the OS to switch to another program because they are waiting for something (human input, hard disk). These programs are known as unrunnable programs, and since they make calls to the kernel to wait for something, the kernel knows to perform context switching to allow another program to run. This is done by:
1. saving the state of the current program (including registers)
2. deciding which program to run next
3. restoring the state of that program
Preemption
It is setting a timed interrupt that will invoke context switching so that if a process (or thread) runs for more than a certain period of time (a process time slice or thread quantum), the OS will switch the context to another program. The time slice that is used may be different for each process.
📚 Summary of: Windows Programming » User Mode versus Kernel Mode
#Windows #Windows_Programming
In Windows (and most OSs), there is a distinction between code that is running in user mode, and code that is running in kernel mode, because if all programs ran in kernel mode, they would be able to overwrite each others' memory and possibly bring down the entire system when they crashed.
This distinction has roots in lower levels; for example Intel CPUs have modes of operation called rings which specify the type of instructions and memory available to the running code:
• Ring 0 (kernel mode) full access to every resource, used by the Windows kernel
• Rings 1 and 2: customized levels of access, generally used by VMs
• Ring 3 (user mode) restricted access to resources
Virtual Memory
Each process has its own "virtual" memory space and resources. Its memory is "virtual" because the process thinks it has a large range of contiguous addresses; but in reality this is implemented by dividing RAM into chunks called pages (4 KB on x86 systems) and having its active pages scattered around RAM and inactive pages stored on disk. The CPU has a transparent mechanism for translating virtual addresses to physical addresses through a page table which the OS sets up. Virtual memory is useful because:
• A process cannot access the memory of other processes
• Each page can have different protection settings (read-only, read-write, kernel-mode-only, etc.)
• Inactive pages can be paged out to disk and retrieved when needed. This is also done when the system is low on RAM.
User Mode
In this mode, programs cannot modify pages directly and so have no way of affecting other processes except through their API. Programs in thismode also cannot interfere with interrupts and context switching.
Kernel Mode
When Windows is first loaded, the Windows kernel is started. It runs in kernel mode and sets up paging, virtual memory, interrupt handlers. Except System which runs in kernel mode, every other process runs in user mode. The kernel then creates some system processes in user mode, but switches back to kernel mode when it is interrupted by interrupts (events such as timers, keyboard, hard disk I/O). Whenever an interrupt occurs, the CPU stops executing the currently running program, switches to kernel mode, and executes the interrupt handler. The handler saves the state of the CPU, performs some processing relevant to that event, and restores the state of the CPU (possibly switching back to user mode) so the CPU can resume execution of the program.
Interrupts
When a program calls a Windows API function, that itself calls a different API: the Native API. Then it either triggers an interrupt or executes instructions such as
sysenter and sysexit (x86). Both cause the CPU to switch to ring 0 (kernel mode) and begin executing the desired API function which is the interrupt handler set up by the OS. When the API function has finished processing, it switches back to user mode and resumes execution of the program. This is because API functions like ReadProcessMemory cannot work in user mode; the program can't access other programs' memory. In kernel mode, however, the API function can read any memory region without restriction.Context Switching
Programs may let the OS to switch to another program because they are waiting for something (human input, hard disk). These programs are known as unrunnable programs, and since they make calls to the kernel to wait for something, the kernel knows to perform context switching to allow another program to run. This is done by:
1. saving the state of the current program (including registers)
2. deciding which program to run next
3. restoring the state of that program
Preemption
It is setting a timed interrupt that will invoke context switching so that if a process (or thread) runs for more than a certain period of time (a process time slice or thread quantum), the OS will switch the context to another program. The time slice that is used may be different for each process.
📚 Summary of: Windows Programming » User Mode versus Kernel Mode
#Windows #Windows_Programming
#C #Windows
“For those who care about such things: Many have asked whether Windows is written in C or C++. The answer is that – despite NT’s Object-Based design – like most OS’, Windows is almost entirely written in ‘C’. Why? C++ introduces a cost in terms of memory footprint, and code execution overhead. Even today, the hidden costs of code written in C++ can be surprising, but back in the late 1990’s, when memory cost ~$60/MB (yes … $60 per MEGABYTE!), the hidden memory cost of vtables etc. was significant. In addition, the cost of virtual-method call indirection and object-dereferencing could result in very significant performance & scale penalties for C++ code at that time. While one still needs to be careful, the performance overhead of modern C++ on modern computers is much less of a concern, and is often an acceptable trade-off considering its security, readability, and maintainability benefits … which is why we’re steadily upgrading the Console’s code to modern C++.”
— Inside the Windows Console
“For those who care about such things: Many have asked whether Windows is written in C or C++. The answer is that – despite NT’s Object-Based design – like most OS’, Windows is almost entirely written in ‘C’. Why? C++ introduces a cost in terms of memory footprint, and code execution overhead. Even today, the hidden costs of code written in C++ can be surprising, but back in the late 1990’s, when memory cost ~$60/MB (yes … $60 per MEGABYTE!), the hidden memory cost of vtables etc. was significant. In addition, the cost of virtual-method call indirection and object-dereferencing could result in very significant performance & scale penalties for C++ code at that time. While one still needs to be careful, the performance overhead of modern C++ on modern computers is much less of a concern, and is often an acceptable trade-off considering its security, readability, and maintainability benefits … which is why we’re steadily upgrading the Console’s code to modern C++.”
— Inside the Windows Console
#Windows
The Windows API
- is Microsoft's core set of APIs available in the Windows OS, designed for interactions between apps and the OS.
Though its exposed functions and data structures are described in #C, any compiler or assembler able to handle the low-level data structures and the prescribed calling conventions for calls and callbacks may use it.
The functions provided by the Windows API can be grouped into eight categories:
1. Services
Base Services:
• file systems
• devices
• processes and threads
• error handling
—
Advanced Services:
• the Windows registry
• shutdown/restart the system
• start/stop/create a Windows service
• manage user accounts
—
2. Graphics Device Interface
• to output graphics to monitors, printers, etc.
— user-mode:
— kernel-mode:
3. GUI
• to create and manage screen windows
• receive mouse and keyboard input
—
Common Dialog Box Library:
• to open and save files
• choose color
• choose font
• ...
—
Common Control Library:
• buttons
• scrollbars
• status bars
• progress bars
• toolbars
• tabs
• ...
—
4. Windows Shell
• access and manipulate functions provided by the shell —
• The Shell Lightweight Utility Functions —
5. Network Services
• NetBIOS
• Winsock
• NetDDE
• remote procedure call (RPC)
• ...
—
6. Web
Internet Explorer also exposes an API. IE has been included with the OS since Windows 95 OSR2 and has provided web-related services to apps since Windows 98.
• An embeddable web browser control
• ...
—
7. Multimedia
MCI:
• play sound files
• send/receive MIDI messages
• access joysticks
—
Media encoding and playback:
• DirectShow: builds and runs generic multimedia pipelines, used to render in-game videos and build media players, Windows Media Player was based on it, no longer recommended for game development
• Media Foundation: a newer digital media API intended to replace DirectShow
8. DirectX
• Direct2D: hardware-accelerated 2D vector graphics
• Direct3D: hardware-accelerated 3D graphics
• DirectSound: low-level hardware-accelerated sound card access
• DirectInput: communication with input devices such as joysticks and gamepads
• DirectPlay: a multiplayer gaming infrastructure, deprecated
• DirectDraw: for 2D graphics, deprecated and replaced with Direct2D
• WinG: 16-bit 2D graphics, deprecated
The Windows API
- is Microsoft's core set of APIs available in the Windows OS, designed for interactions between apps and the OS.
Though its exposed functions and data structures are described in #C, any compiler or assembler able to handle the low-level data structures and the prescribed calling conventions for calls and callbacks may use it.
The functions provided by the Windows API can be grouped into eight categories:
1. Services
Base Services:
• file systems
• devices
• processes and threads
• error handling
—
kernel32.dll, KernelBase.dllAdvanced Services:
• the Windows registry
• shutdown/restart the system
• start/stop/create a Windows service
• manage user accounts
—
advapi32.dll, advapires32.dll2. Graphics Device Interface
• to output graphics to monitors, printers, etc.
— user-mode:
gdi32.dll— kernel-mode:
win32k.sys (communicates directly with the graphics driver)3. GUI
• to create and manage screen windows
• receive mouse and keyboard input
—
user32.dllCommon Dialog Box Library:
• to open and save files
• choose color
• choose font
• ...
—
comdlg32.dllCommon Control Library:
• buttons
• scrollbars
• status bars
• progress bars
• toolbars
• tabs
• ...
—
comctl32.dll4. Windows Shell
• access and manipulate functions provided by the shell —
shell32.dll• The Shell Lightweight Utility Functions —
shlwapi.dll5. Network Services
• NetBIOS
• Winsock
• NetDDE
• remote procedure call (RPC)
• ...
—
netapi32.dll6. Web
Internet Explorer also exposes an API. IE has been included with the OS since Windows 95 OSR2 and has provided web-related services to apps since Windows 98.
• An embeddable web browser control
• ...
—
shdocvw.dll, mshtml.dll7. Multimedia
MCI:
• play sound files
• send/receive MIDI messages
• access joysticks
—
winmm.dllMedia encoding and playback:
• DirectShow: builds and runs generic multimedia pipelines, used to render in-game videos and build media players, Windows Media Player was based on it, no longer recommended for game development
• Media Foundation: a newer digital media API intended to replace DirectShow
8. DirectX
• Direct2D: hardware-accelerated 2D vector graphics
• Direct3D: hardware-accelerated 3D graphics
• DirectSound: low-level hardware-accelerated sound card access
• DirectInput: communication with input devices such as joysticks and gamepads
• DirectPlay: a multiplayer gaming infrastructure, deprecated
• DirectDraw: for 2D graphics, deprecated and replaced with Direct2D
• WinG: 16-bit 2D graphics, deprecated
History of GameMaker: "GameMaker: Studio"
2012, May: GameMaker: Studio was launched as a completely new series that targeted commercial developers instead of hobbyists, and supported: #Windows, #Mac_OS (in development since 2007), #HTML5 (in development since 2011), #Android, #iOS, and many other platforms and OSs.
It also completely changed the projects structure: each project is a folder with all resources as individual
Since the launch of Studio, the product has been fully developed by YoYo Games. This makes Game Maker 8.x a closed chapter.
2015, February: GameMaker was acquired by Playtech together with YoYo Games. Announcements reassured improvements and plans to appeal to more advanced developers. They also promised GameMaker Studio 2.0. Nothing was changed for developers.
2016, November: GameMaker Studio 2 beta was released.
2017, March: GameMaker Studio 2, with a completely redesigned IDE rewritten in #CSharp, was released.
Present
Currently, a single code base can run natively across multiple platforms including Android, iOS, HTML5, PS4, Xbox One, Windows Desktop, OS X, Ubuntu, Windows UWP.
Future
GameMaker Studio 2 Roadmap
2012, May: GameMaker: Studio was launched as a completely new series that targeted commercial developers instead of hobbyists, and supported: #Windows, #Mac_OS (in development since 2007), #HTML5 (in development since 2011), #Android, #iOS, and many other platforms and OSs.
It also completely changed the projects structure: each project is a folder with all resources as individual
.gmx files in #XML format. This allows version control, and thus collaboration. Another new feature is a built-in Box2D physics engine.Since the launch of Studio, the product has been fully developed by YoYo Games. This makes Game Maker 8.x a closed chapter.
2015, February: GameMaker was acquired by Playtech together with YoYo Games. Announcements reassured improvements and plans to appeal to more advanced developers. They also promised GameMaker Studio 2.0. Nothing was changed for developers.
2016, November: GameMaker Studio 2 beta was released.
2017, March: GameMaker Studio 2, with a completely redesigned IDE rewritten in #CSharp, was released.
Present
Currently, a single code base can run natively across multiple platforms including Android, iOS, HTML5, PS4, Xbox One, Windows Desktop, OS X, Ubuntu, Windows UWP.
Future
GameMaker Studio 2 Roadmap