okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2f335a5ea
main
1<# 2.SYNOPSIS 3Enables the 'Lock pages in memory' privilege (SeLockMemoryPrivilege) on Windows. 4.DESCRIPTION 5Strata keeps the experts the GPU does not hold in a host memory arena. With SeLockMemoryPrivilege 6granted, Windows lets it allocate that arena in 2 MB large pages (MEM_LARGE_PAGES); without it the 7engine says at start that the large pages were refused and uses 4 KB pages (docs/DETAILS.md, #1412). 8The same can be done by hand with secpol.msc (User Rights Assignment, "Lock pages in memory"). 9 10NOTE: Windows applies security token privilege changes ONLY after sign-out/sign-in or reboot. 11#> 12 13[CmdletBinding ()] 14param ( 15 [string ]$AccountName =$env:USERNAME 16) 17 18function Test-IsAdmin { 19$currentPrincipal =New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity ]::GetCurrent ()) 20return $currentPrincipal .IsInRole ([Security.Principal.WindowsBuiltInRole ]::Administrator ) 21} 22 23if (-not (Test-IsAdmin )) { 24Write-Host "[!] This script must be run as Administrator." -ForegroundColor Yellow 25Write-Host " Right-click PowerShell -> 'Run as Administrator', then run:" 26Write-Host " .\tools\windows\enable_large_pages.ps1" 27Write-Host "" 28Write-Host " GUI Alternative:" 29Write-Host " 1. Press Win + R, type 'secpol.msc' and press Enter." 30Write-Host " 2. Navigate to: Security Settings -> Local Policies -> User Rights Assignment" 31Write-Host " 3. Double-click 'Lock pages in memory'." 32Write-Host " 4. Click 'Add User or Group...', add ' $AccountName ', and click OK." 33Write-Host " 5. Sign out of Windows and sign back in." 34exit 1 35} 36 37Write-Host "=== Configuring 'Lock pages in memory' (SeLockMemoryPrivilege) for $AccountName ===" -ForegroundColor Cyan 38 39$tempInf = [System.IO.Path ]::GetTempFileName () 40$tempSdb = [System.IO.Path ]::ChangeExtension ($tempInf ,".sdb" ) 41 42try { 43Write-Host "1. Exporting current security policy..." 44secedit /export /cfg$tempInf |Out-Null 45 46$content =Get-Content $tempInf -Raw 47$userSid = (New-Object System.Security.Principal.NTAccount($AccountName )).Translate ([System.Security.Principal.SecurityIdentifier ]).Value 48 49if ($content -match "SeLockMemoryPrivilege\s*=\s*(.*)" ) { 50$currentList =$matches [1 ].Trim () 51if ($currentList -match [regex ]::Escape ($userSid )-or $currentList -match [regex ]::Escape ($AccountName )) { 52Write-Host "[OK] $AccountName already possesses SeLockMemoryPrivilege." -ForegroundColor Green 53Write-Host " If 'whoami /priv' still shows it as missing, please SIGN OUT and sign back in to refresh your token." 54return 55 } 56$newList =" $currentList ,* $userSid " 57$content =$content -replace "SeLockMemoryPrivilege\s*=.*" ,"SeLockMemoryPrivilege = $newList " 58 }else { 59# Section [Privilege Rights] 60if ($content -match "\[Privilege Rights\]" ) { 61$content =$content -replace "\[Privilege Rights\]" ,"[Privilege Rights]`r`nSeLockMemoryPrivilege = * $userSid " 62 }else { 63$content +="`r`n[Privilege Rights]`r`nSeLockMemoryPrivilege = * $userSid `r`n" 64 } 65 } 66 67Set-Content -Path$tempInf -Value$content -Encoding ASCII 68 69Write-Host "2. Importing updated policy database..." 70secedit /import /db$tempSdb /cfg$tempInf |Out-Null 71 72Write-Host "3. Applying updated policy to Windows system..." 73secedit /configure /db$tempSdb /cfg$tempInf /areas USER_RIGHTS |Out-Null # only the user rights, nothing else of the exported policy 74 75Write-Host "" 76Write-Host "[SUCCESS] SeLockMemoryPrivilege has been granted to $AccountName ( $userSid )!" -ForegroundColor Green 77Write-Host "==========================================================================" -ForegroundColor Cyan 78Write-Host "IMPORTANT: You MUST sign out of Windows and sign back in (or restart)" -ForegroundColor Yellow 79Write-Host " for the new privilege to take effect on your user session." -ForegroundColor Yellow 80Write-Host "==========================================================================" -ForegroundColor Cyan 81} 82catch { 83Write-Host "[ERROR] Failed to configure privilege automatically: $_ " -ForegroundColor Red 84Write-Host "Please use the GUI steps via secpol.msc outlined above." 85} 86finally { 87if (Test-Path $tempInf ) {Remove-Item $tempInf -Force -ErrorAction SilentlyContinue } 88if (Test-Path $tempSdb ) {Remove-Item $tempSdb -Force -ErrorAction SilentlyContinue } 89}