[NTOSKRNL]
Windows / ReactOS uses a software protection field called protection mask, which is stored inside invalid (Software) PTEs to provide information about the desired protection, when a page is made valid by the page fault handler. The mask consists of the values 0-7 specifying the read/write/execute rights, 0 being inaccessible aka MM_ZERO_ACCESS, plus 2 flag-like bits, for uncached and writecombine memory respectively. Both flags together don't make sense, so this combination is used to mark guard pages. Since all these flags only make sense when used together with a proper access (i.e. not MM_ZERO_ACCESS), the combination of these flags together with MM_ZERO_ACCESS was given special meaning: MM_DECOMMIT, which equals MM_GUARDPAGE | MM_ZERO_ACCESS is for decommitted pages, that are not yet erased to zero, MM_NOACCESS, which is the mask for pages that are mapped with PAGE_NOACCESS (this is to make sure that a software PTE of a committed page is never completely 0, which it could be, when MM_ZERO_ACCESS was used), and finally MM_OUTSWAPPED_KSTACK for outswapped kernel stacks. See also https://www.reactos.org/wiki/Techwiki:Memory_Protection_constants.
The next thing to know is that the number of PTEs that are not null is counted for each PDE. So once a page gets committed, a software PTE is written and the reference count is incremented. When the page is made valid by the fault handler, the count is not changed, when the page is decommitted, the MM_DECOMMIT software PTE is written and again the PTE stays non-null and nothing is changed. Only when the range is cleaned up totally, the PTEs get erased and the reference count is decremented. Now it happened that our page fault handler missed to validate the access rights of protection constants. The problem that came up with this is a major one: since a decommitted page is a software PTE with MM_DECOMMIT as the protection mask (which we remember has the MM_GUARDPAGE bit set), the fault handler considered faults on decommitted PTEs as faults on guard pages and simply removed the guard page flag, leaving a completely empty PTE behind! So the decommitted page got erased without decrementing the reference count. This lead to CORE-7445.
- Add protection flags (MM_GUARDPAGE, MM_WRITECOMBINE, MM_OUTSWAPPED_KSTACK)
- Instead of writing 0 to a PTE, use MI_WRITE_INVALID_PTE with MmZeroPte
- Implement MiIsAccessAllowed that checks for read/write/execute access and use it in MiAccessCheck
- Add some more ASSERTs
CORE-7445 #resolve

git-svn-id: svn://svn.reactos.org/reactos/trunk@61095 97493ccd-5924-5043-b1f5-66cb403b36ce
[CMAKE]
- Enable -Wtype-limits in GCC builds

git-svn-id: svn://svn.reactos.org/reactos/trunk@61096 97493ccd-5924-5043-b1f5-66cb403b36ce
[NETAPI32]
Refactor BuildUserInfoBuffer: Move the user info buffer inside of BuildUserInfoBuffer. This simplifies its callers.

git-svn-id: svn://svn.reactos.org/reactos/trunk@61097 97493ccd-5924-5043-b1f5-66cb403b36ce
[NTOS]
- FORCEINLINE belongs before the return type (-Wold-style-declaration)

git-svn-id: svn://svn.reactos.org/reactos/trunk@61098 97493ccd-5924-5043-b1f5-66cb403b36ce
[KMTESTS:RTL]
- Fix a warning

git-svn-id: svn://svn.reactos.org/reactos/trunk@61099 97493ccd-5924-5043-b1f5-66cb403b36ce
[POWRPROF]
- Fix a warning

git-svn-id: svn://svn.reactos.org/reactos/trunk@61100 97493ccd-5924-5043-b1f5-66cb403b36ce
[KERNEL32]
- Fix wrong check for realtime priority class in CreateProcessInternalW
- Fix double free in GetEnvironmentVariable[AW]
- Fix broken sizeof usage ('X' is of type int!)
- Remove redundant casts and comparisons

git-svn-id: svn://svn.reactos.org/reactos/trunk@61101 97493ccd-5924-5043-b1f5-66cb403b36ce
[NTOSKRNL]
- Create the Security directory and the LSA_AUTHENTICATION_INITIALIZED event in SepInitializationPhase1().
- Get rid of SeInitSRM().

git-svn-id: svn://svn.reactos.org/reactos/trunk@61102 97493ccd-5924-5043-b1f5-66cb403b36ce
[NETAPI32]
BuildUserInfoBuffer: Set the UF_PASSWD_CANT_CHANGE account control flag if the user does not have the USER_CHANGE_PASSWORD access right for his own account data.

git-svn-id: svn://svn.reactos.org/reactos/trunk@61103 97493ccd-5924-5043-b1f5-66cb403b36ce
[NTOSKRNL]
- Remove the BoundaryAddressMultiple parameter from MmCreateMemoryArea (wasn't used) and give it instead a Granularity parameter
- Use the Granularity parameter in MmMapViewOfSegment to make sure that full sections are allocated on a MM_ALLOCATION_GRANULARITY aligned address.
- Check for overflow and unaligned image base in MmMapViewOfSection when mapping image sections
- Return proper status code on failure


git-svn-id: svn://svn.reactos.org/reactos/trunk@61108 97493ccd-5924-5043-b1f5-66cb403b36ce
[NTOSKRNL]
- Implement SepAdjustPrivileges, which does both the counting of (changed) privileges as well as applying them, when requested. Use it in NtAdjustPrivilegesToken twice instead of duplicating the code there.
- Fix return value of NtAdjustPrivilegesToken by making sure to properly count the found privileges and check against the provided ones
- Lock the Token, while messing with the privileges
- Add support for SE_PRIVILEGE_REMOVED
- Proplery (re)calculate Token flags after changing privileges
- Improve failure pathes by using a common cleanup label
- Don't free the allocations atatched to the token in SepCreateToken on failure, since ObDereferenceObject will already do that.
- Make priviliges constants instead of initializing them.

git-svn-id: svn://svn.reactos.org/reactos/trunk@61109 97493ccd-5924-5043-b1f5-66cb403b36ce