JclSysInfo.pas 240 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845
  1. {**************************************************************************************************}
  2. { }
  3. { Project JEDI Code Library (JCL) }
  4. { }
  5. { The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
  6. { you may not use this file except in compliance with the License. You may obtain a copy of the }
  7. { License at http://www.mozilla.org/MPL/ }
  8. { }
  9. { Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
  10. { ANY KIND, either express or implied. See the License for the specific language governing rights }
  11. { and limitations under the License. }
  12. { }
  13. { The Original Code is JclSysInfo.pas. }
  14. { }
  15. { The Initial Developer of the Original Code is Marcel van Brakel. }
  16. { Portions created by Marcel van Brakel are Copyright (C) Marcel van Brakel. All rights reserved. }
  17. { }
  18. { Contributors: }
  19. { Alexander Radchenko }
  20. { Andre Snepvangers (asnepvangers) }
  21. { Azret Botash }
  22. { Bryan Coutch }
  23. { Carl Clark }
  24. { Eric S. Fisher }
  25. { Florent Ouchet (outchy) }
  26. { Heiko Adams }
  27. { James Azarja }
  28. { Jean-Fabien Connault (cycocrew) }
  29. { John C Molyneux }
  30. { Marcel van Brakel }
  31. { Matthias Thoma (mthoma) }
  32. { Mike Lischke }
  33. { Nick Hodges }
  34. { Olivier Sannier (obones) }
  35. { Peter Friese }
  36. { Peter Thornquist (peter3) }
  37. { Petr Vones (pvones) }
  38. { Rik Barker }
  39. { Robert Marquardt (marquardt) }
  40. { Robert Rossmair (rrossmair) }
  41. { Scott Price }
  42. { Tom Hahn (tomhahn) }
  43. { Wim de Cleen }
  44. { }
  45. {**************************************************************************************************}
  46. { }
  47. { This unit contains routines and classes to retrieve various pieces of system information. }
  48. { Examples are the location of standard folders, settings of environment variables, processor }
  49. { details and the Windows version. }
  50. { }
  51. {**************************************************************************************************}
  52. { }
  53. { Last modified: $Date:: $ }
  54. { Revision: $Rev:: $ }
  55. { Author: $Author:: $ }
  56. { }
  57. {**************************************************************************************************}
  58. // Windows NT 4 and earlier do not support GetSystemPowerStatus (while introduced
  59. // in NT4 - it is a stub there - implemented in Windows 2000 and later.
  60. unit JclSysInfo;
  61. {$I jcl.inc}
  62. interface
  63. uses
  64. {$IFDEF UNITVERSIONING}
  65. JclUnitVersioning,
  66. {$ENDIF UNITVERSIONING}
  67. {$IFDEF HAS_UNIT_LIBC}
  68. Libc,
  69. {$ENDIF HAS_UNIT_LIBC}
  70. {$IFDEF HAS_UNITSCOPE}
  71. {$IFDEF MSWINDOWS}
  72. Winapi.Windows, WinApi.ActiveX, Winapi.ShlObj,
  73. {$ENDIF MSWINDOWS}
  74. System.Classes,
  75. {$ELSE ~HAS_UNITSCOPE}
  76. {$IFDEF MSWINDOWS}
  77. Windows, ActiveX, ShlObj,
  78. {$ENDIF MSWINDOWS}
  79. Classes,
  80. {$ENDIF ~HAS_UNITSCOPE}
  81. JclBase, JclResources;
  82. // Environment Variables
  83. {$IFDEF MSWINDOWS}
  84. type
  85. TEnvironmentOption = (eoLocalMachine, eoCurrentUser, eoAdditional);
  86. TEnvironmentOptions = set of TEnvironmentOption;
  87. {$ENDIF MSWINDOWS}
  88. function DelEnvironmentVar(const Name: string): Boolean;
  89. function ExpandEnvironmentVar(var Value: string): Boolean;
  90. function ExpandEnvironmentVarCustom(var Value: string; Vars: TStrings): Boolean;
  91. function GetEnvironmentVar(const Name: string; out Value: string): Boolean; overload;
  92. function GetEnvironmentVar(const Name: string; out Value: string; Expand: Boolean): Boolean; overload;
  93. {$IFNDEF WINSCP}
  94. function GetEnvironmentVars(const Vars: TStrings): Boolean; overload;
  95. function GetEnvironmentVars(const Vars: TStrings; Expand: Boolean): Boolean; overload;
  96. {$ENDIF ~WINSCP}
  97. function SetEnvironmentVar(const Name, Value: string): Boolean;
  98. {$IFDEF MSWINDOWS}
  99. {$IFNDEF WINSCP}
  100. function CreateEnvironmentBlock(const Options: TEnvironmentOptions; const AdditionalVars: TStrings): PChar;
  101. procedure DestroyEnvironmentBlock(var Env: PChar);
  102. procedure SetGlobalEnvironmentVariable(VariableName, VariableContent: string);
  103. {$ENDIF ~WINSCP}
  104. {$ENDIF MSWINDOWS}
  105. // Common Folder Locations
  106. {$IFDEF MSWINDOWS}
  107. {$IFNDEF WINSCP}
  108. function GetCommonFilesFolder: string;
  109. {$ENDIF WINSCP}
  110. {$ENDIF MSWINDOWS}
  111. function GetCurrentFolder: string;
  112. {$IFDEF MSWINDOWS}
  113. {$IFNDEF WINSCP}
  114. function GetProgramFilesFolder: string;
  115. {$ENDIF WINSCP}
  116. function GetWindowsFolder: string;
  117. function GetWindowsSystemFolder: string;
  118. function GetWindowsTempFolder: string;
  119. function GetDesktopFolder: string;
  120. function GetProgramsFolder: string;
  121. {$ENDIF MSWINDOWS}
  122. {$IFNDEF WINSCP}
  123. function GetPersonalFolder: string;
  124. {$ENDIF ~WINSCP}
  125. {$IFDEF MSWINDOWS}
  126. {$IFNDEF WINSCP}
  127. function GetFavoritesFolder: string;
  128. function GetStartupFolder: string;
  129. function GetRecentFolder: string;
  130. function GetSendToFolder: string;
  131. function GetStartmenuFolder: string;
  132. function GetDesktopDirectoryFolder: string;
  133. function GetCommonDocumentsFolder: string;
  134. function GetNethoodFolder: string;
  135. function GetFontsFolder: string;
  136. function GetCommonStartmenuFolder: string;
  137. function GetCommonStartupFolder: string;
  138. function GetPrinthoodFolder: string;
  139. function GetProfileFolder: string;
  140. function GetCommonProgramsFolder: string;
  141. function GetCommonDesktopdirectoryFolder: string;
  142. function GetCommonAppdataFolder: string;
  143. function GetAppdataFolder: string;
  144. function GetLocalAppData: string;
  145. function GetCommonFavoritesFolder: string;
  146. function GetTemplatesFolder: string;
  147. function GetInternetCacheFolder: string;
  148. function GetCookiesFolder: string;
  149. function GetHistoryFolder: string;
  150. {$ENDIF ~WINSCP}
  151. // Advanced Power Management (APM)
  152. type
  153. TAPMLineStatus = (alsOffline, alsOnline, alsUnknown);
  154. TAPMBatteryFlag = (abfHigh, abfLow, abfCritical, abfCharging, abfNoBattery, abfUnknown);
  155. TAPMBatteryFlags = set of TAPMBatteryFlag;
  156. function GetAPMLineStatus: TAPMLineStatus;
  157. function GetAPMBatteryFlag: TAPMBatteryFlag;
  158. function GetAPMBatteryFlags: TAPMBatteryFlags;
  159. function GetAPMBatteryLifePercent: Integer;
  160. function GetAPMBatteryLifeTime: DWORD;
  161. function GetAPMBatteryFullLifeTime: DWORD;
  162. // Identification
  163. type
  164. TFileSystemFlag =
  165. (
  166. fsCaseSensitive, // The file system supports case-sensitive file names.
  167. fsCasePreservedNames, // The file system preserves the case of file names when it places a name on disk.
  168. fsSupportsUnicodeOnDisk, // The file system supports Unicode in file names as they appear on disk.
  169. fsPersistentACLs, // The file system preserves and enforces ACLs. For example, NTFS preserves and enforces ACLs, and FAT does not.
  170. fsSupportsFileCompression, // The file system supports file-based compression.
  171. fsSupportsVolumeQuotas, // The file system supports disk quotas.
  172. fsSupportsSparseFiles, // The file system supports sparse files.
  173. fsSupportsReparsePoints, // The file system supports reparse points.
  174. fsSupportsRemoteStorage, // ?
  175. fsVolumeIsCompressed, // The specified volume is a compressed volume; for example, a DoubleSpace volume.
  176. fsSupportsObjectIds, // The file system supports object identifiers.
  177. fsSupportsEncryption, // The file system supports the Encrypted File System (EFS).
  178. fsSupportsNamedStreams, // The file system supports named streams.
  179. fsVolumeIsReadOnly // The specified volume is read-only.
  180. // Windows 2000/NT and Windows Me/98/95: This value is not supported.
  181. );
  182. TFileSystemFlags = set of TFileSystemFlag;
  183. {$IFNDEF WINSCP}
  184. function GetVolumeName(const Drive: string): string;
  185. function GetVolumeSerialNumber(const Drive: string): string;
  186. function GetVolumeFileSystem(const Drive: string): string;
  187. function GetVolumeFileSystemFlags(const Volume: string): TFileSystemFlags;
  188. {$ENDIF ~WINSCP}
  189. {$ENDIF MSWINDOWS}
  190. function GetIPAddress(const HostName: string): string;
  191. {$IFDEF MSWINDOWS}
  192. procedure GetIpAddresses(Results: TStrings; const HostName: AnsiString); overload;
  193. {$ENDIF MSWINDOWS}
  194. procedure GetIpAddresses(Results: TStrings); overload;
  195. function GetLocalComputerName: string;
  196. function GetLocalUserName: string;
  197. {$IFDEF MSWINDOWS}
  198. function GetUserDomainName(const CurUser: string): string;
  199. function GetWorkGroupName: WideString;
  200. {$ENDIF MSWINDOWS}
  201. function GetDomainName: string;
  202. {$IFDEF MSWINDOWS}
  203. {$IFNDEF WINSCP}
  204. function GetRegisteredCompany: string;
  205. function GetRegisteredOwner: string;
  206. function GetWindowsProductId: string;
  207. {$ENDIF WINSCP}
  208. function GetBIOSName: string;
  209. function GetBIOSCopyright: string;
  210. function GetBIOSExtendedInfo: string;
  211. {$IFNDEF WINSCP}
  212. function GetBIOSDate: TDateTime;
  213. {$ENDIF ~WINSCP}
  214. {$ENDIF MSWINDOWS}
  215. // Processes, Tasks and Modules
  216. type
  217. TJclTerminateAppResult = (taError, taClean, taKill);
  218. {$IFNDEF WINSCP}
  219. function RunningProcessesList(const List: TStrings; FullPath: Boolean = True): Boolean;
  220. {$ENDIF WINSCP}
  221. {$IFDEF MSWINDOWS}
  222. function LoadedModulesList(const List: TStrings; ProcessID: DWORD; HandlesOnly: Boolean = False): Boolean;
  223. function GetTasksList(const List: TStrings): Boolean;
  224. function ModuleFromAddr(const Addr: Pointer): HMODULE;
  225. function IsSystemModule(const Module: HMODULE): Boolean;
  226. procedure BeginModuleFromAddrCache;
  227. procedure EndModuleFromAddrCache;
  228. function CachedModuleFromAddr(const Addr: Pointer): HMODULE;
  229. function IsMainAppWindow(Wnd: THandle): Boolean;
  230. function IsWindowResponding(Wnd: THandle; Timeout: Integer): Boolean;
  231. function GetWindowIcon(Wnd: THandle; LargeIcon: Boolean): HICON;
  232. function GetWindowCaption(Wnd: THandle): string;
  233. function TerminateTask(Wnd: THandle; Timeout: Integer): TJclTerminateAppResult;
  234. function TerminateApp(ProcessID: DWORD; Timeout: Integer): TJclTerminateAppResult;
  235. {$ENDIF MSWINDOWS}
  236. {$IFDEF MSWINDOWS}
  237. {.$IFNDEF FPC}
  238. {$IFNDEF WINSCP}
  239. function GetPidFromProcessName(const ProcessName: string): THandle;
  240. function GetProcessNameFromWnd(Wnd: THandle): string;
  241. function GetProcessNameFromPid(PID: DWORD): string;
  242. {$ENDIF WINSCP}
  243. function GetMainAppWndFromPid(PID: DWORD): THandle;
  244. function GetWndFromPid(PID: DWORD; const WindowClassName: string): HWND;
  245. {.$ENDIF ~FPC}
  246. {$IFNDEF WINSCP}
  247. function GetShellProcessName: string;
  248. {.$IFNDEF FPC}
  249. function GetShellProcessHandle: THandle;
  250. {.$ENDIF ~FPC}
  251. {$ENDIF WINSCP}
  252. // Version Information
  253. type
  254. TWindowsVersion =
  255. (wvUnknown, wvWin95, wvWin95OSR2, wvWin98, wvWin98SE, wvWinME,
  256. wvWinNT31, wvWinNT35, wvWinNT351, wvWinNT4, wvWin2000, wvWinXP,
  257. wvWin2003, wvWinXP64, wvWin2003R2, wvWinVista, wvWinServer2008,
  258. wvWin7, wvWinServer2008R2, wvWin8, wvWin8RT, wvWinServer2012,
  259. wvWin81, wvWin81RT, wvWinServer2012R2, wvWin10, wvWinServer2016,
  260. wvWinServer2019, wvWinServer, wvWin11, wvWinServer2022, wvWinServer2025);
  261. TWindowsEdition =
  262. (weUnknown, weWinXPHome, weWinXPPro, weWinXPHomeN, weWinXPProN, weWinXPHomeK,
  263. weWinXPProK, weWinXPHomeKN, weWinXPProKN, weWinXPStarter, weWinXPMediaCenter,
  264. weWinXPTablet, weWinVistaStarter, weWinVistaHomeBasic, weWinVistaHomeBasicN,
  265. weWinVistaHomePremium, weWinVistaBusiness, weWinVistaBusinessN,
  266. weWinVistaEnterprise, weWinVistaUltimate, weWin7Starter, weWin7HomeBasic,
  267. weWin7HomePremium, weWin7Professional, weWin7Enterprise, weWin7Ultimate,
  268. weWin8, weWin8Pro, weWin8Enterprise, weWin8RT, weWin81, weWin81Pro,
  269. weWin81Enterprise, weWin81RT, weWin10, weWin10Home, weWin10Pro,
  270. weWin10Enterprise, weWin10Education);
  271. TNtProductType =
  272. (ptUnknown, ptWorkStation, ptServer, ptAdvancedServer,
  273. ptPersonal, ptProfessional, ptDatacenterServer, ptEnterprise, ptWebEdition);
  274. TProcessorArchitecture =
  275. (paUnknown, // unknown processor
  276. pax8632, // x86 32 bit processors (some P4, Celeron, Athlon and older)
  277. pax8664, // x86 64 bit processors (latest P4, Celeron and Athlon64)
  278. paIA64, // Itanium processors
  279. paARM, // ARM 32 bit processors
  280. paARM64); // ARM 64 bit processors
  281. var
  282. { in case of additions, don't forget to update initialization section! }
  283. {$IFNDEF WINSCP}
  284. IsWin95: Boolean = False;
  285. IsWin95OSR2: Boolean = False;
  286. IsWin98: Boolean = False;
  287. IsWin98SE: Boolean = False;
  288. IsWinME: Boolean = False;
  289. {$ENDIF}
  290. IsWinNT: Boolean = False;
  291. {$IFNDEF WINSCP}
  292. IsWinNT3: Boolean = False;
  293. IsWinNT31: Boolean = False;
  294. IsWinNT35: Boolean = False;
  295. IsWinNT351: Boolean = False;
  296. IsWinNT4: Boolean = False;
  297. IsWin2K: Boolean = False;
  298. IsWinXP: Boolean = False;
  299. IsWin2003: Boolean = False;
  300. IsWinXP64: Boolean = False;
  301. IsWin2003R2: Boolean = False;
  302. IsWinVista: Boolean = False;
  303. IsWinServer2008: Boolean = False;
  304. IsWin7: Boolean = False;
  305. IsWinServer2008R2: Boolean = False;
  306. IsWin8: Boolean = False;
  307. IsWin8RT: Boolean = False;
  308. IsWinServer2012: Boolean = False;
  309. IsWin81: Boolean = False;
  310. IsWin81RT: Boolean = False;
  311. IsWinServer2012R2: Boolean = False;
  312. IsWin10: Boolean = False;
  313. IsWinServer2016: Boolean = False;
  314. IsWinServer2019: Boolean = False;
  315. IsWinServer2022: Boolean = False;
  316. IsWinServer2025: Boolean = False;
  317. IsWinServer: Boolean = False;
  318. IsWin11: Boolean = False;
  319. {$ENDIF}
  320. const
  321. PROCESSOR_ARCHITECTURE_INTEL = 0;
  322. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_INTEL}
  323. PROCESSOR_ARCHITECTURE_AMD64 = 9;
  324. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_AMD64}
  325. PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 = 10;
  326. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_IA32_ON_WIN64}
  327. PROCESSOR_ARCHITECTURE_IA64 = 6;
  328. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_IA64}
  329. PROCESSOR_ARCHITECTURE_ARM = 5;
  330. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_ARM}
  331. PROCESSOR_ARCHITECTURE_ARM64 = 12;
  332. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_ARM64}
  333. PROCESSOR_ARCHITECTURE_UNKNOWN = $FFFF;
  334. {$EXTERNALSYM PROCESSOR_ARCHITECTURE_UNKNOWN}
  335. const
  336. Windows11InitialBuildNumber = 22000;
  337. Windows2025ServerInitialBuildNumber = 26100;
  338. {$IFNDEF WINSCP}
  339. function GetWindowsVersion: TWindowsVersion;
  340. function GetWindowsEdition: TWindowsEdition;
  341. function NtProductType: TNtProductType;
  342. function GetWindowsVersionString: string;
  343. function GetWindowsEditionString: string;
  344. function GetWindowsProductString: string;
  345. function GetWindowsProductName: string;
  346. function NtProductTypeString: string;
  347. function GetWindowsBuildNumber: Integer;
  348. {$ENDIF WINSCP}
  349. function GetWindowsMajorVersionNumber: Integer;
  350. function GetWindowsMinorVersionNumber: Integer;
  351. function GetWindowsVersionNumber: string;
  352. function GetWindowsServicePackVersion: Integer;
  353. function GetWindowsServicePackVersionString: string;
  354. {$IFNDEF WINSCP}
  355. function GetWindowsDisplayVersion: string;
  356. function GetWindowsReleaseId: Integer;
  357. function GetWindowsReleaseName: String;
  358. function GetWindowsReleaseCode: String;
  359. function GetWindowsReleaseCodeName: String;
  360. function GetWindowsReleaseVersion: String;
  361. function GetWindows10DisplayVersion: string; {$IFDEF SUPPORTS_DEPRECATED}deprecated {$IFDEF SUPPORTS_DEPRECATED_DETAILS}'Use GetWindowsDisplayVersion'{$ENDIF};{$ENDIF}
  362. function GetWindows10ReleaseId: Integer; {$IFDEF SUPPORTS_DEPRECATED}deprecated {$IFDEF SUPPORTS_DEPRECATED_DETAILS}'Use GetWindowsReleaseId'{$ENDIF};{$ENDIF}
  363. function GetWindows10ReleaseName: String; {$IFDEF SUPPORTS_DEPRECATED}deprecated {$IFDEF SUPPORTS_DEPRECATED_DETAILS}'Use GetWindowsReleaseName'{$ENDIF};{$ENDIF}
  364. function GetWindows10ReleaseCodeName: String; {$IFDEF SUPPORTS_DEPRECATED}deprecated {$IFDEF SUPPORTS_DEPRECATED_DETAILS}'Use GetWindowsReleaseCodeName'{$ENDIF};{$ENDIF}
  365. function GetWindows10ReleaseVersion: String; {$IFDEF SUPPORTS_DEPRECATED}deprecated {$IFDEF SUPPORTS_DEPRECATED_DETAILS}'Use GetWindowsReleaseVersion'{$ENDIF};{$ENDIF}
  366. function GetWindowsServerDisplayVersion: string; {$IFDEF SUPPORTS_DEPRECATED}deprecated {$IFDEF SUPPORTS_DEPRECATED_DETAILS}'Use GetWindowsDisplayVersion'{$ENDIF};{$ENDIF}
  367. function GetWindowsServerReleaseId: Integer; {$IFDEF SUPPORTS_DEPRECATED}deprecated {$IFDEF SUPPORTS_DEPRECATED_DETAILS}'Use GetWindowsReleaseId'{$ENDIF};{$ENDIF}
  368. function GetWindowsServerReleaseVersion: String; {$IFDEF SUPPORTS_DEPRECATED}deprecated {$IFDEF SUPPORTS_DEPRECATED_DETAILS}'Use GetWindowsReleaseVersion'{$ENDIF};{$ENDIF}
  369. function GetOpenGLVersion(const Win: THandle; out Version, Vendor: AnsiString): Boolean;
  370. {$ENDIF ~WINSCP}
  371. function GetNativeSystemInfo(var SystemInfo: TSystemInfo): Boolean;
  372. function GetProcessorArchitecture: TProcessorArchitecture;
  373. function IsWindows64: Boolean;
  374. function JclCheckWinVersion(Major, Minor: Integer): Boolean;
  375. {$ENDIF MSWINDOWS}
  376. {$IFNDEF WINSCP}
  377. function GetOSVersionString: string;
  378. {$ENDIF}
  379. // Hardware
  380. {$IFDEF MSWINDOWS}
  381. {$IFNDEF WINSCP}
  382. function GetMacAddresses(const Machine: string; const Addresses: TStrings): Integer;
  383. {$ENDIF ~WINSCP}
  384. {$ENDIF MSWINDOWS}
  385. function ReadTimeStampCounter: Int64;
  386. {$IFDEF WIN64}
  387. {$EXTERNALSYM ReadTimeStampCounter}
  388. {$ENDIF WIN64}
  389. type
  390. TTLBInformation = (tiEntries, tiAssociativity);
  391. TCacheInformation = (ciLineSize {in Bytes}, ciLinesPerTag, ciAssociativity, ciSize);
  392. TIntelSpecific = record
  393. L2Cache: Cardinal;
  394. CacheDescriptors: array [0..15] of Byte;
  395. BrandID: Byte;
  396. FlushLineSize: Byte;
  397. APICID: Byte;
  398. ExFeatures: Cardinal;
  399. Ex64Features: Cardinal;
  400. Ex64Features2: Cardinal;
  401. PowerManagementFeatures: Cardinal;
  402. PhysicalAddressBits: Byte;
  403. VirtualAddressBits: Byte;
  404. end;
  405. TCyrixSpecific = record
  406. L1CacheInfo: array [0..3] of Byte;
  407. TLBInfo: array [0..3] of Byte;
  408. end;
  409. TAMDSpecific = packed record
  410. ExFeatures: Cardinal;
  411. ExFeatures2: Cardinal;
  412. Features2: Cardinal;
  413. BrandID: Byte;
  414. FlushLineSize: Byte;
  415. APICID: Byte;
  416. ExBrandID: Word;
  417. // do not split L1 MByte TLB
  418. L1MByteInstructionTLB: array [TTLBInformation] of Byte;
  419. L1MByteDataTLB: array [TTLBInformation] of Byte;
  420. // do not split L1 KByte TLB
  421. L1KByteInstructionTLB: array [TTLBInformation] of Byte;
  422. L1KByteDataTLB: array [TTLBInformation] of Byte;
  423. L1DataCache: array [TCacheInformation] of Byte;
  424. L1InstructionCache: array [TCacheInformation] of Byte;
  425. // do not split L2 MByte TLB
  426. L2MByteInstructionTLB: array [TTLBInformation] of Byte; // L2 TLB for 2-MByte and 4-MByte pages
  427. L2MByteDataTLB: array [TTLBInformation] of Byte; // L2 TLB for 2-MByte and 4-MByte pages
  428. // do not split L2 KByte TLB
  429. L2KByteDataTLB: array [TTLBInformation] of Byte; // L2 TLB for 4-KByte pages
  430. L2KByteInstructionTLB: array [TTLBInformation] of Byte; // L2 TLB for 4-KByte pages
  431. L2Cache: Cardinal;
  432. L3Cache: Cardinal;
  433. AdvancedPowerManagement: Cardinal;
  434. PhysicalAddressSize: Byte;
  435. VirtualAddressSize: Byte;
  436. end;
  437. TVIASpecific = record
  438. ExFeatures: Cardinal;
  439. DataTLB: array [TTLBInformation] of Byte;
  440. InstructionTLB: array [TTLBInformation] of Byte;
  441. L1DataCache: array [TCacheInformation] of Byte;
  442. L1InstructionCache: array [TCacheInformation] of Byte;
  443. L2DataCache: Cardinal;
  444. end;
  445. TTransmetaSpecific = record
  446. ExFeatures: Cardinal;
  447. DataTLB: array [TTLBInformation] of Byte;
  448. CodeTLB: array [TTLBInformation] of Byte;
  449. L1DataCache: array [TCacheInformation] of Byte;
  450. L1CodeCache: array [TCacheInformation] of Byte;
  451. L2Cache: Cardinal;
  452. RevisionABCD: Cardinal;
  453. RevisionXXXX: Cardinal;
  454. Frequency: Cardinal;
  455. CodeMorphingABCD: Cardinal;
  456. CodeMorphingXXXX: Cardinal;
  457. TransmetaFeatures: Cardinal;
  458. TransmetaInformations: array [0..64] of Char;
  459. CurrentVoltage: Cardinal;
  460. CurrentFrequency: Cardinal;
  461. CurrentPerformance: Cardinal;
  462. end;
  463. TCacheFamily = (
  464. cfInstructionTLB, cfDataTLB,
  465. cfL1InstructionCache, cfL1DataCache,
  466. cfL2Cache, cfL2TLB, cfL3Cache, cfTrace, cfOther);
  467. TCacheInfo = record
  468. D: Byte;
  469. Family: TCacheFamily;
  470. Size: Cardinal;
  471. WaysOfAssoc: Byte;
  472. LineSize: Byte; // for Normal Cache
  473. LinePerSector: Byte; // for L3 Normal Cache
  474. Entries: Cardinal; // for TLB
  475. I: PResStringRec;
  476. end;
  477. TFreqInfo = record
  478. RawFreq: Int64;
  479. NormFreq: Int64;
  480. InCycles: Int64;
  481. ExTicks: Int64;
  482. end;
  483. const
  484. CPU_TYPE_INTEL = 1;
  485. CPU_TYPE_CYRIX = 2;
  486. CPU_TYPE_AMD = 3;
  487. CPU_TYPE_TRANSMETA = 4;
  488. CPU_TYPE_VIA = 5;
  489. type
  490. TSSESupport = (sse, sse2, sse3, ssse3, sse41, sse42, sse4A, sse5, avx);
  491. TSSESupports = set of TSSESupport;
  492. TCpuInfo = record
  493. HasInstruction: Boolean;
  494. AES: Boolean;
  495. MMX: Boolean;
  496. ExMMX: Boolean;
  497. _3DNow: Boolean;
  498. Ex3DNow: Boolean;
  499. SSE: TSSESupports;
  500. IsFDIVOK: Boolean;
  501. Is64Bits: Boolean;
  502. DEPCapable: Boolean;
  503. HasCacheInfo: Boolean;
  504. HasExtendedInfo: Boolean;
  505. PType: Byte;
  506. Family: Byte;
  507. ExtendedFamily: Byte;
  508. Model: Byte;
  509. ExtendedModel: Byte;
  510. Stepping: Byte;
  511. Features: Cardinal;
  512. FrequencyInfo: TFreqInfo;
  513. VendorIDString: array [0..11] of AnsiChar;
  514. Manufacturer: array [0..9] of AnsiChar;
  515. CpuName: array [0..47] of AnsiChar;
  516. L1DataCacheSize: Cardinal; // in kByte
  517. L1DataCacheLineSize: Byte; // in Byte
  518. L1DataCacheAssociativity: Byte;
  519. L1InstructionCacheSize: Cardinal; // in kByte
  520. L1InstructionCacheLineSize: Byte; // in Byte
  521. L1InstructionCacheAssociativity: Byte;
  522. L2CacheSize: Cardinal; // in kByte
  523. L2CacheLineSize: Byte; // in Byte
  524. L2CacheAssociativity: Byte;
  525. L3CacheSize: Cardinal; // in kByte
  526. L3CacheLineSize: Byte; // in Byte
  527. L3CacheAssociativity: Byte;
  528. L3LinesPerSector: Byte;
  529. LogicalCore: Byte;
  530. PhysicalCore: Byte;
  531. HyperThreadingTechnology: Boolean;
  532. HardwareHyperThreadingTechnology: Boolean;
  533. // todo: TLB
  534. case CpuType: Byte of
  535. CPU_TYPE_INTEL: (IntelSpecific: TIntelSpecific;);
  536. CPU_TYPE_CYRIX: (CyrixSpecific: TCyrixSpecific;);
  537. CPU_TYPE_AMD: (AMDSpecific: TAMDSpecific;);
  538. CPU_TYPE_TRANSMETA: (TransmetaSpecific: TTransmetaSpecific;);
  539. CPU_TYPE_VIA: (ViaSpecific: TViaSpecific;);
  540. end;
  541. const
  542. VendorIDIntel: array [0..11] of AnsiChar = 'GenuineIntel';
  543. VendorIDCyrix: array [0..11] of AnsiChar = 'CyrixInstead';
  544. VendorIDAMD: array [0..11] of AnsiChar = 'AuthenticAMD';
  545. VendorIDTransmeta: array [0..11] of AnsiChar = 'GenuineTMx86';
  546. VendorIDVIA: array [0..11] of AnsiChar = 'CentaurHauls';
  547. // Constants to be used with Feature Flag set of a CPU
  548. // eg. IF (Features and FPU_FLAG = FPU_FLAG) THEN CPU has Floating-Point unit on
  549. // chip. However, Intel claims that in future models, a zero in the feature
  550. // flags will mean that the chip has that feature, however, the following flags
  551. // will work for any production 80x86 chip or clone.
  552. // eg. IF (Features and FPU_FLAG = 0) then CPU has Floating-Point unit on chip.
  553. const
  554. { 32 bits in a DWord Value }
  555. BIT_0 = $00000001;
  556. BIT_1 = $00000002;
  557. BIT_2 = $00000004;
  558. BIT_3 = $00000008;
  559. BIT_4 = $00000010;
  560. BIT_5 = $00000020;
  561. BIT_6 = $00000040;
  562. BIT_7 = $00000080;
  563. BIT_8 = $00000100;
  564. BIT_9 = $00000200;
  565. BIT_10 = $00000400;
  566. BIT_11 = $00000800;
  567. BIT_12 = $00001000;
  568. BIT_13 = $00002000;
  569. BIT_14 = $00004000;
  570. BIT_15 = $00008000;
  571. BIT_16 = $00010000;
  572. BIT_17 = $00020000;
  573. BIT_18 = $00040000;
  574. BIT_19 = $00080000;
  575. BIT_20 = $00100000;
  576. BIT_21 = $00200000;
  577. BIT_22 = $00400000;
  578. BIT_23 = $00800000;
  579. BIT_24 = $01000000;
  580. BIT_25 = $02000000;
  581. BIT_26 = $04000000;
  582. BIT_27 = $08000000;
  583. BIT_28 = $10000000;
  584. BIT_29 = $20000000;
  585. BIT_30 = $40000000;
  586. BIT_31 = DWORD($80000000);
  587. { Standard Feature Flags }
  588. FPU_FLAG = BIT_0; // Floating-Point unit on chip
  589. VME_FLAG = BIT_1; // Virtual Mode Extention
  590. DE_FLAG = BIT_2; // Debugging Extention
  591. PSE_FLAG = BIT_3; // Page Size Extention
  592. TSC_FLAG = BIT_4; // Time Stamp Counter
  593. MSR_FLAG = BIT_5; // Model Specific Registers
  594. PAE_FLAG = BIT_6; // Physical Address Extention
  595. MCE_FLAG = BIT_7; // Machine Check Exception
  596. CX8_FLAG = BIT_8; // CMPXCHG8 Instruction
  597. APIC_FLAG = BIT_9; // Software-accessible local APIC on Chip
  598. BIT_10_FLAG = BIT_10; // Reserved, do not count on value
  599. SEP_FLAG = BIT_11; // Fast System Call
  600. MTRR_FLAG = BIT_12; // Memory Type Range Registers
  601. PGE_FLAG = BIT_13; // Page Global Enable
  602. MCA_FLAG = BIT_14; // Machine Check Architecture
  603. CMOV_FLAG = BIT_15; // Conditional Move Instruction
  604. PAT_FLAG = BIT_16; // Page Attribute Table
  605. PSE36_FLAG = BIT_17; // 36-bit Page Size Extention
  606. PSN_FLAG = BIT_18; // Processor serial number is present and enabled
  607. CLFLSH_FLAG = BIT_19; // CLFLUSH intruction
  608. BIT_20_FLAG = BIT_20; // Reserved, do not count on value
  609. DS_FLAG = BIT_21; // Debug store
  610. ACPI_FLAG = BIT_22; // Thermal monitor and clock control
  611. MMX_FLAG = BIT_23; // MMX technology
  612. FXSR_FLAG = BIT_24; // Fast Floating Point Save and Restore
  613. SSE_FLAG = BIT_25; // Streaming SIMD Extensions
  614. SSE2_FLAG = BIT_26; // Streaming SIMD Extensions 2
  615. SS_FLAG = BIT_27; // Self snoop
  616. HTT_FLAG = BIT_28; // Hyper-threading technology
  617. TM_FLAG = BIT_29; // Thermal monitor
  618. BIT_30_FLAG = BIT_30; // Reserved, do not count on value
  619. PBE_FLAG = BIT_31; // Pending Break Enable
  620. { Standard Intel Feature Flags }
  621. INTEL_FPU = BIT_0; // Floating-Point unit on chip
  622. INTEL_VME = BIT_1; // Virtual Mode Extention
  623. INTEL_DE = BIT_2; // Debugging Extention
  624. INTEL_PSE = BIT_3; // Page Size Extention
  625. INTEL_TSC = BIT_4; // Time Stamp Counter
  626. INTEL_MSR = BIT_5; // Model Specific Registers
  627. INTEL_PAE = BIT_6; // Physical Address Extention
  628. INTEL_MCE = BIT_7; // Machine Check Exception
  629. INTEL_CX8 = BIT_8; // CMPXCHG8 Instruction
  630. INTEL_APIC = BIT_9; // Software-accessible local APIC on Chip
  631. INTEL_BIT_10 = BIT_10; // Reserved, do not count on value
  632. INTEL_SEP = BIT_11; // Fast System Call
  633. INTEL_MTRR = BIT_12; // Memory Type Range Registers
  634. INTEL_PGE = BIT_13; // Page Global Enable
  635. INTEL_MCA = BIT_14; // Machine Check Architecture
  636. INTEL_CMOV = BIT_15; // Conditional Move Instruction
  637. INTEL_PAT = BIT_16; // Page Attribute Table
  638. INTEL_PSE36 = BIT_17; // 36-bit Page Size Extention
  639. INTEL_PSN = BIT_18; // Processor serial number is present and enabled
  640. INTEL_CLFLSH = BIT_19; // CLFLUSH intruction
  641. INTEL_BIT_20 = BIT_20; // Reserved, do not count on value
  642. INTEL_DS = BIT_21; // Debug store
  643. INTEL_ACPI = BIT_22; // Thermal monitor and clock control
  644. INTEL_MMX = BIT_23; // MMX technology
  645. INTEL_FXSR = BIT_24; // Fast Floating Point Save and Restore
  646. INTEL_SSE = BIT_25; // Streaming SIMD Extensions
  647. INTEL_SSE2 = BIT_26; // Streaming SIMD Extensions 2
  648. INTEL_SS = BIT_27; // Self snoop
  649. INTEL_HTT = BIT_28; // Hyper-threading technology
  650. INTEL_TM = BIT_29; // Thermal monitor
  651. INTEL_IA64 = BIT_30; // IA32 emulation mode on Itanium processors (IA64)
  652. INTEL_PBE = BIT_31; // Pending Break Enable
  653. { Extended Intel Feature Flags }
  654. EINTEL_SSE3 = BIT_0; // Streaming SIMD Extensions 3
  655. EINTEL_PCLMULQDQ = BIT_1; // the processor supports the PCLMULQDQ instruction
  656. EINTEL_DTES64 = BIT_2; // the processor supports DS area using 64-bit layout
  657. EINTEL_MONITOR = BIT_3; // Monitor/MWAIT
  658. EINTEL_DSCPL = BIT_4; // CPL Qualified debug Store
  659. EINTEL_VMX = BIT_5; // Virtual Machine Technology
  660. EINTEL_SMX = BIT_6; // Safer Mode Extensions
  661. EINTEL_EST = BIT_7; // Enhanced Intel Speedstep technology
  662. EINTEL_TM2 = BIT_8; // Thermal monitor 2
  663. EINTEL_SSSE3 = BIT_9; // SSSE 3 extensions
  664. EINTEL_CNXTID = BIT_10; // L1 Context ID
  665. EINTEL_BIT_11 = BIT_11; // Reserved, do not count on value
  666. EINTEL_FMA = BIT_12; // Fused Multiply Add
  667. EINTEL_CX16 = BIT_13; // CMPXCHG16B instruction
  668. EINTEL_XTPR = BIT_14; // Send Task Priority messages
  669. EINTEL_PDCM = BIT_15; // Perf/Debug Capability MSR
  670. EINTEL_BIT_16 = BIT_16; // Reserved, do not count on value
  671. EINTEL_PCID = BIT_17; // Process-context Identifiers
  672. EINTEL_DCA = BIT_18; // Direct Cache Access
  673. EINTEL_SSE4_1 = BIT_19; // Streaming SIMD Extensions 4.1
  674. EINTEL_SSE4_2 = BIT_20; // Streaming SIMD Extensions 4.2
  675. EINTEL_X2APIC = BIT_21; // x2APIC feature
  676. EINTEL_MOVBE = BIT_22; // MOVBE instruction
  677. EINTEL_POPCNT = BIT_23; // A value of 1 indicates the processor supports the POPCNT instruction.
  678. EINTEL_TSC_DL = BIT_24; // TSC-Deadline
  679. EINTEL_AES = BIT_25; // the processor supports the AES instruction extensions
  680. EINTEL_XSAVE = BIT_26; // XSAVE/XRSTOR processor extended states feature, XSETBV/XGETBV instructions and XFEATURE_ENABLED_MASK (XCR0) register
  681. EINTEL_OSXSAVE = BIT_27; // OS has enabled features present in EINTEL_XSAVE
  682. EINTEL_AVX = BIT_28; // Advanced Vector Extensions
  683. EINTEL_BIT_29 = BIT_29; // Reserved, do not count on value
  684. EINTEL_RDRAND = BIT_30; // the processor supports the RDRAND instruction.
  685. EINTEL_BIT_31 = BIT_31; // Always return 0
  686. { Extended Intel 64 Bits Feature Flags }
  687. EINTEL64_BIT_0 = BIT_0; // Reserved, do not count on value
  688. EINTEL64_BIT_1 = BIT_1; // Reserved, do not count on value
  689. EINTEL64_BIT_2 = BIT_2; // Reserved, do not count on value
  690. EINTEL64_BIT_3 = BIT_3; // Reserved, do not count on value
  691. EINTEL64_BIT_4 = BIT_4; // Reserved, do not count on value
  692. EINTEL64_BIT_5 = BIT_5; // Reserved, do not count on value
  693. EINTEL64_BIT_6 = BIT_6; // Reserved, do not count on value
  694. EINTEL64_BIT_7 = BIT_7; // Reserved, do not count on value
  695. EINTEL64_BIT_8 = BIT_8; // Reserved, do not count on value
  696. EINTEL64_BIT_9 = BIT_9; // Reserved, do not count on value
  697. EINTEL64_BIT_10 = BIT_10; // Reserved, do not count on value
  698. EINTEL64_SYS = BIT_11; // 64 Bit - SYSCALL SYSRET
  699. EINTEL64_BIT_12 = BIT_12; // Reserved, do not count on value
  700. EINTEL64_BIT_13 = BIT_13; // Reserved, do not count on value
  701. EINTEL64_BIT_14 = BIT_14; // Reserved, do not count on value
  702. EINTEL64_BIT_15 = BIT_15; // Reserved, do not count on value
  703. EINTEL64_BIT_16 = BIT_16; // Reserved, do not count on value
  704. EINTEL64_BIT_17 = BIT_17; // Reserved, do not count on value
  705. EINTEL64_BIT_18 = BIT_18; // Reserved, do not count on value
  706. EINTEL64_BIT_19 = BIT_19; // Reserved, do not count on value
  707. EINTEL64_XD = BIT_20; // Execution Disable Bit
  708. EINTEL64_BIT_21 = BIT_21; // Reserved, do not count on value
  709. EINTEL64_BIT_22 = BIT_22; // Reserved, do not count on value
  710. EINTEL64_BIT_23 = BIT_23; // Reserved, do not count on value
  711. EINTEL64_BIT_24 = BIT_24; // Reserved, do not count on value
  712. EINTEL64_BIT_25 = BIT_25; // Reserved, do not count on value
  713. EINTEL64_1GBYTE = BIT_26; // 1G-Byte pages are available
  714. EINTEL64_RDTSCP = BIT_27; // RDTSCP and IA32_TSC_AUX are available
  715. EINTEL64_BIT_28 = BIT_28; // Reserved, do not count on value
  716. EINTEL64_EM64T = BIT_29; // Intel Extended Memory 64 Technology
  717. EINTEL64_BIT_30 = BIT_30; // Reserved, do not count on value
  718. EINTEL64_BIT_31 = BIT_31; // Reserved, do not count on value
  719. { Extended Intel 64 Bits Feature Flags continued }
  720. EINTEL64_2_LAHF = BIT_0; // LAHF/SAHF available in 64 bit mode
  721. EINTEL64_2_BIT_1 = BIT_1; // Reserved, do not count on value
  722. EINTEL64_2_BIT_2 = BIT_2; // Reserved, do not count on value
  723. EINTEL64_2_BIT_3 = BIT_3; // Reserved, do not count on value
  724. EINTEL64_2_BIT_4 = BIT_4; // Reserved, do not count on value
  725. EINTEL64_2_BIT_5 = BIT_5; // Reserved, do not count on value
  726. EINTEL64_2_BIT_6 = BIT_6; // Reserved, do not count on value
  727. EINTEL64_2_BIT_7 = BIT_7; // Reserved, do not count on value
  728. EINTEL64_2_BIT_8 = BIT_8; // Reserved, do not count on value
  729. EINTEL64_2_BIT_9 = BIT_9; // Reserved, do not count on value
  730. EINTEL64_2_BIT_10 = BIT_10; // Reserved, do not count on value
  731. EINTEL64_2_BIT_11 = BIT_11; // Reserved, do not count on value
  732. EINTEL64_2_BIT_12 = BIT_12; // Reserved, do not count on value
  733. EINTEL64_2_BIT_13 = BIT_13; // Reserved, do not count on value
  734. EINTEL64_2_BIT_14 = BIT_14; // Reserved, do not count on value
  735. EINTEL64_2_BIT_15 = BIT_15; // Reserved, do not count on value
  736. EINTEL64_2_BIT_16 = BIT_16; // Reserved, do not count on value
  737. EINTEL64_2_BIT_17 = BIT_17; // Reserved, do not count on value
  738. EINTEL64_2_BIT_18 = BIT_18; // Reserved, do not count on value
  739. EINTEL64_2_BIT_19 = BIT_19; // Reserved, do not count on value
  740. EINTEL64_2_BIT_20 = BIT_20; // Reserved, do not count on value
  741. EINTEL64_2_BIT_21 = BIT_21; // Reserved, do not count on value
  742. EINTEL64_2_BIT_22 = BIT_22; // Reserved, do not count on value
  743. EINTEL64_2_BIT_23 = BIT_23; // Reserved, do not count on value
  744. EINTEL64_2_BIT_24 = BIT_24; // Reserved, do not count on value
  745. EINTEL64_2_BIT_25 = BIT_25; // Reserved, do not count on value
  746. EINTEL64_2_BIT_26 = BIT_26; // Reserved, do not count on value
  747. EINTEL64_2_BIT_27 = BIT_27; // Reserved, do not count on value
  748. EINTEL64_2_BIT_28 = BIT_28; // Reserved, do not count on value
  749. EINTEL64_2_BIT_29 = BIT_29; // Reserved, do not count on value
  750. EINTEL64_2_BIT_30 = BIT_30; // Reserved, do not count on value
  751. EINTEL64_2_BIT_31 = BIT_31; // Reserved, do not count on value
  752. { INTEL Power Management Flags }
  753. PINTEL_TEMPSENSOR = BIT_0; // Digital temperature sensor
  754. PINTEL_TURBOBOOST = BIT_1; // Intel Turbo Boost Technology Available
  755. PINTEL_ARAT = BIT_2; // APIC-Timer-always-running feature
  756. PINTEL_BIT_3 = BIT_3; // Reverved, do not count on value
  757. PINTEL_PLN = BIT_4; // Power Limit Notification constrols
  758. PINTEL_ECMD = BIT_5; // Clock Modulation duty cycle extension
  759. PINTEL_PTM = BIT_6; // Package Thermal Management
  760. PINTEL_BIT_7 = BIT_7; // Reserved, do not count on value
  761. PINTEL_BIT_8 = BIT_8; // Reserved, do not count on value
  762. PINTEL_BIT_9 = BIT_9; // Reserved, do not count on value
  763. PINTEL_BIT_10 = BIT_10; // Reserved, do not count on value
  764. PINTEL_BIT_11 = BIT_11; // Reserved, do not count on value
  765. PINTEL_BIT_12 = BIT_12; // Reserved, do not count on value
  766. PINTEL_BIT_13 = BIT_13; // Reserved, do not count on value
  767. PINTEL_BIT_14 = BIT_14; // Reserved, do not count on value
  768. PINTEL_BIT_15 = BIT_15; // Reserved, do not count on value
  769. PINTEL_BIT_16 = BIT_16; // Reserved, do not count on value
  770. PINTEL_BIT_17 = BIT_17; // Reserved, do not count on value
  771. PINTEL_BIT_18 = BIT_18; // Reserved, do not count on value
  772. PINTEL_BIT_19 = BIT_19; // Reserved, do not count on value
  773. PINTEL_BIT_20 = BIT_20; // Reserved, do not count on value
  774. PINTEL_BIT_21 = BIT_21; // Reserved, do not count on value
  775. PINTEL_BIT_22 = BIT_22; // Reserved, do not count on value
  776. PINTEL_BIT_23 = BIT_23; // Reserved, do not count on value
  777. PINTEL_BIT_24 = BIT_24; // Reserved, do not count on value
  778. PINTEL_BIT_25 = BIT_25; // Reserved, do not count on value
  779. PINTEL_BIT_26 = BIT_26; // Reserved, do not count on value
  780. PINTEL_BIT_27 = BIT_27; // Reserved, do not count on value
  781. PINTEL_BIT_28 = BIT_28; // Reserved, do not count on value
  782. PINTEL_BIT_29 = BIT_29; // Reserved, do not count on value
  783. PINTEL_BIT_30 = BIT_30; // Reserved, do not count on value
  784. PINTEL_BIT_31 = BIT_31; // Reserved, do not count on value
  785. { AMD Standard Feature Flags }
  786. AMD_FPU = BIT_0; // Floating-Point unit on chip
  787. AMD_VME = BIT_1; // Virtual Mode Extention
  788. AMD_DE = BIT_2; // Debugging Extention
  789. AMD_PSE = BIT_3; // Page Size Extention
  790. AMD_TSC = BIT_4; // Time Stamp Counter
  791. AMD_MSR = BIT_5; // Model Specific Registers
  792. AMD_PAE = BIT_6; // Physical address Extensions
  793. AMD_MCE = BIT_7; // Machine Check Exception
  794. AMD_CX8 = BIT_8; // CMPXCHG8 Instruction
  795. AMD_APIC = BIT_9; // Software-accessible local APIC on Chip
  796. AMD_BIT_10 = BIT_10; // Reserved, do not count on value
  797. AMD_SEP_BIT = BIT_11; // SYSENTER and SYSEXIT instructions
  798. AMD_MTRR = BIT_12; // Memory Type Range Registers
  799. AMD_PGE = BIT_13; // Page Global Enable
  800. AMD_MCA = BIT_14; // Machine Check Architecture
  801. AMD_CMOV = BIT_15; // Conditional Move Instruction
  802. AMD_PAT = BIT_16; // Page Attribute Table
  803. AMD_PSE36 = BIT_17; // Page Size Extensions
  804. AMD_BIT_18 = BIT_18; // Reserved, do not count on value
  805. AMD_CLFLSH = BIT_19; // CLFLUSH instruction
  806. AMD_BIT_20 = BIT_20; // Reserved, do not count on value
  807. AMD_BIT_21 = BIT_21; // Reserved, do not count on value
  808. AMD_BIT_22 = BIT_22; // Reserved, do not count on value
  809. AMD_MMX = BIT_23; // MMX technology
  810. AMD_FXSR = BIT_24; // FXSAVE and FXSTORE instructions
  811. AMD_SSE = BIT_25; // SSE Extensions
  812. AMD_SSE2 = BIT_26; // SSE2 Extensions
  813. AMD_BIT_27 = BIT_27; // Reserved, do not count on value
  814. AMD_HTT = BIT_28; // Hyper-Threading Technology
  815. AMD_BIT_29 = BIT_29; // Reserved, do not count on value
  816. AMD_BIT_30 = BIT_30; // Reserved, do not count on value
  817. AMD_BIT_31 = BIT_31; // Reserved, do not count on value
  818. { AMD Standard Feature Flags continued }
  819. AMD2_SSE3 = BIT_0; // SSE3 extensions
  820. AMD2_PCLMULQDQ = BIT_1; // PCLMULQDQ instruction support
  821. AMD2_BIT_2 = BIT_2; // Reserved, do not count on value
  822. AMD2_MONITOR = BIT_3; // MONITOR/MWAIT instructions. See "MONITOR" and "MWAIT" in APM3.
  823. AMD2_BIT_4 = BIT_4; // Reserved, do not count on value
  824. AMD2_BIT_5 = BIT_5; // Reserved, do not count on value
  825. AMD2_BIT_6 = BIT_6; // Reserved, do not count on value
  826. AMD2_BIT_7 = BIT_7; // Reserved, do not count on value
  827. AMD2_BIT_8 = BIT_8; // Reserved, do not count on value
  828. AMD2_SSSE3 = BIT_9; // supplemental SSE3 extensions
  829. AMD2_BIT_10 = BIT_10; // Reserved, do not count on value
  830. AMD2_BIT_11 = BIT_11; // Reserved, do not count on value
  831. AMD2_FMA = BIT_12; // FMA instruction support
  832. AMD2_CMPXCHG16B = BIT_13; // CMPXCHG16B available
  833. AMD2_BIT_14 = BIT_14; // Reserved, do not count on value
  834. AMD2_BIT_15 = BIT_15; // Reserved, do not count on value
  835. AMD2_BIT_16 = BIT_16; // Reserved, do not count on value
  836. AMD2_BIT_17 = BIT_17; // Reserved, do not count on value
  837. AMD2_BIT_18 = BIT_18; // Reserved, do not count on value
  838. AMD2_SSE41 = BIT_19; // SSE4.1 instruction support
  839. AMD2_SSE42 = BIT_20; // SSE4.2 instruction support
  840. AMD2_BIT_21 = BIT_21; // Reserved, do not count on value
  841. AMD2_BIT_22 = BIT_22; // Reserved, do not count on value
  842. AMD2_POPCNT = BIT_23; // POPCNT instruction. See "POPCNT" in APM3.
  843. AMD2_BIT_24 = BIT_24; // Reserved, do not count on value
  844. AMD2_AES = BIT_25; // AES instruction support
  845. AMD2_XSAVE = BIT_26; // XSAVE (and related) instructions are supported by hardware
  846. AMD2_OSXSAVE = BIT_27; // XSAVE (and related) instructions are enabled
  847. AMD2_AVX = BIT_28; // AVX instruction support
  848. AMD2_F16C = BIT_29; // half-precision convert instruction support
  849. AMD2_BIT_30 = BIT_30; // Reserved, do not count on value
  850. AMD2_RAZ = BIT_31; // Reserved for use by hypervisor to indicate guest status
  851. { AMD Enhanced Feature Flags }
  852. EAMD_FPU = BIT_0; // Floating-Point unit on chip
  853. EAMD_VME = BIT_1; // Virtual Mode Extention
  854. EAMD_DE = BIT_2; // Debugging Extention
  855. EAMD_PSE = BIT_3; // Page Size Extention
  856. EAMD_TSC = BIT_4; // Time Stamp Counter
  857. EAMD_MSR = BIT_5; // Model Specific Registers
  858. EAMD_PAE = BIT_6; // Physical-address extensions
  859. EAMD_MCE = BIT_7; // Machine Check Exception
  860. EAMD_CX8 = BIT_8; // CMPXCHG8 Instruction
  861. EAMD_APIC = BIT_9; // Advanced Programmable Interrupt Controler
  862. EAMD_BIT_10 = BIT_10; // Reserved, do not count on value
  863. EAMD_SEP = BIT_11; // Fast System Call
  864. EAMD_MTRR = BIT_12; // Memory-Type Range Registers
  865. EAMD_PGE = BIT_13; // Page Global Enable
  866. EAMD_MCA = BIT_14; // Machine Check Architecture
  867. EAMD_CMOV = BIT_15; // Conditional Move Intructions
  868. EAMD_PAT = BIT_16; // Page Attributes Table
  869. EAMD_PSE2 = BIT_17; // Page Size Extensions
  870. EAMD_BIT_18 = BIT_18; // Reserved, do not count on value
  871. EAMD_BIT_19 = BIT_19; // Reserved, do not count on value
  872. EAMD_NX = BIT_20; // No-Execute Page Protection
  873. EAMD_BIT_21 = BIT_21; // Reserved, do not count on value
  874. EAMD_EXMMX = BIT_22; // AMD Extensions to MMX technology
  875. EAMD_MMX = BIT_23; // MMX technology
  876. EAMD_FX = BIT_24; // FXSAVE and FXSTORE instructions
  877. EAMD_FFX = BIT_25; // Fast FXSAVE and FXSTORE instructions
  878. EAMD_1GBPAGE = BIT_26; // 1-GB large page support.
  879. EAMD_RDTSCP = BIT_27; // RDTSCP instruction.
  880. EAMD_BIT_28 = BIT_28; // Reserved, do not count on value
  881. EAMD_LONG = BIT_29; // Long Mode (64-bit Core)
  882. EAMD_EX3DNOW = BIT_30; // AMD Extensions to 3DNow! intructions
  883. EAMD_3DNOW = BIT_31; // AMD 3DNOW! Technology
  884. { AMD Extended Feature Flags continued }
  885. EAMD2_LAHF = BIT_0; // LAHF/SAHF available in 64-bit mode
  886. EAMD2_CMPLEGACY = BIT_1; // core multi-processing legacy mode
  887. EAMD2_SVM = BIT_2; // Secure Virtual Machine
  888. EAMD2_EXTAPICSPACE = BIT_3; // This bit indicates the presence of extended APIC register space starting at offset 400h from the “APIC Base Address Register,” as specified in the BKDG.
  889. EAMD2_ALTMOVCR8 = BIT_4; // LOCK MOV CR0 means MOV CR8
  890. EAMD2_ABM = BIT_5; // ABM: Advanced bit manipulation. LZCNT instruction support.
  891. EAMD2_SSE4A = BIT_6; // EXTRQ, INSERTQ, MOVNTSS, and MOVNTSD instruction support.
  892. EAMD2_MISALIGNSSE = BIT_7; // Misaligned SSE mode.
  893. EAMD2_3DNOWPREFETCH = BIT_8; // PREFETCH and PREFETCHW instruction support.
  894. EAMD2_OSVW = BIT_9; // OS visible workaround.
  895. EAMD2_IBS = BIT_10; // Instruction based sampling
  896. EAMD2_XOP = BIT_11; // extended operation support
  897. EAMD2_SKINIT = BIT_12; // SKINIT, STGI, and DEV support.
  898. EAMD2_WDT = BIT_13; // Watchdog timer support.
  899. EAMD2_BIT_14 = BIT_14; // Reserved, do not count on value
  900. EAMD2_LWP = BIT_15; // lightweight profiling support
  901. EAMD2_FMA4 = BIT_16; // 4-operand FMA instruction support.
  902. EAMD2_BIT_17 = BIT_17; // Reserved, do not count on value
  903. EAMD2_BIT_18 = BIT_18; // Reserved, do not count on value
  904. EAMD2_NODEID = BIT_19; // Support for MSRC001_100C[NodeId, NodesPerProcessor]
  905. EAMD2_BIT_20 = BIT_20; // Reserved, do not count on value
  906. EAMD2_TBM = BIT_21; // trailing bit manipulation instruction support
  907. EAMD2_TOPOLOGYEXT = BIT_22; // topology extensions support
  908. EAMD2_BIT_23 = BIT_23; // Reserved, do not count on value
  909. EAMD2_BIT_24 = BIT_24; // Reserved, do not count on value
  910. EAMD2_BIT_25 = BIT_25; // Reserved, do not count on value
  911. EAMD2_BIT_26 = BIT_26; // Reserved, do not count on value
  912. EAMD2_BIT_27 = BIT_27; // Reserved, do not count on value
  913. EAMD2_BIT_28 = BIT_28; // Reserved, do not count on value
  914. EAMD2_BIT_29 = BIT_29; // Reserved, do not count on value
  915. EAMD2_BIT_30 = BIT_30; // Reserved, do not count on value
  916. EAMD2_BIT_31 = BIT_31; // Reserved, do not count on value
  917. { AMD Power Management Features Flags }
  918. PAMD_TEMPSENSOR = BIT_0; // Temperature Sensor
  919. PAMD_FREQUENCYID = BIT_1; // Frequency ID Control
  920. PAMD_VOLTAGEID = BIT_2; // Voltage ID Control
  921. PAMD_THERMALTRIP = BIT_3; // Thermal Trip
  922. PAMD_THERMALMONITOR = BIT_4; // Thermal Monitoring
  923. PAMD_BIT_5 = BIT_5; // Reserved, do not count on value
  924. PAMD_100MHZSTEP = BIT_6; // 100 Mhz multiplier control.
  925. PAMD_HWPSTATE = BIT_7; // Hardware P-State control.
  926. PAMD_TSC_INVARIANT = BIT_8; // TSC rate is invariant
  927. PAMD_CPB = BIT_9; // core performance boost
  928. PAMD_EFFFREQRO = BIT_10; // read-only effective frequency interface
  929. PAMD_BIT_11 = BIT_11; // Reserved, do not count on value
  930. PAMD_BIT_12 = BIT_12; // Reserved, do not count on value
  931. PAMD_BIT_13 = BIT_13; // Reserved, do not count on value
  932. PAMD_BIT_14 = BIT_14; // Reserved, do not count on value
  933. PAMD_BIT_15 = BIT_15; // Reserved, do not count on value
  934. PAMD_BIT_16 = BIT_16; // Reserved, do not count on value
  935. PAMD_BIT_17 = BIT_17; // Reserved, do not count on value
  936. PAMD_BIT_18 = BIT_18; // Reserved, do not count on value
  937. PAMD_BIT_19 = BIT_19; // Reserved, do not count on value
  938. PAMD_BIT_20 = BIT_20; // Reserved, do not count on value
  939. PAMD_BIT_21 = BIT_21; // Reserved, do not count on value
  940. PAMD_BIT_22 = BIT_22; // Reserved, do not count on value
  941. PAMD_BIT_23 = BIT_23; // Reserved, do not count on value
  942. PAMD_BIT_24 = BIT_24; // Reserved, do not count on value
  943. PAMD_BIT_25 = BIT_25; // Reserved, do not count on value
  944. PAMD_BIT_26 = BIT_26; // Reserved, do not count on value
  945. PAMD_BIT_27 = BIT_27; // Reserved, do not count on value
  946. PAMD_BIT_28 = BIT_28; // Reserved, do not count on value
  947. PAMD_BIT_29 = BIT_29; // Reserved, do not count on value
  948. PAMD_BIT_30 = BIT_30; // Reserved, do not count on value
  949. PAMD_BIT_31 = BIT_31; // Reserved, do not count on value
  950. { AMD TLB and L1 Associativity constants }
  951. AMD_ASSOC_RESERVED = 0;
  952. AMD_ASSOC_DIRECT = 1;
  953. // 2 to 254 = direct value to the associativity
  954. AMD_ASSOC_FULLY = 255;
  955. { AMD L2 Cache Associativity constants }
  956. AMD_L2_ASSOC_DISABLED = 0;
  957. AMD_L2_ASSOC_DIRECT = 1;
  958. AMD_L2_ASSOC_2WAY = 2;
  959. AMD_L2_ASSOC_4WAY = 4;
  960. AMD_L2_ASSOC_8WAY = 6;
  961. AMD_L2_ASSOC_16WAY = 8;
  962. AMD_L2_ASSOC_32WAY = 10;
  963. AMD_L2_ASSOC_48WAY = 11;
  964. AMD_L2_ASSOC_64WAY = 12;
  965. AMD_L2_ASSOC_96WAY = 13;
  966. AMD_L2_ASSOC_128WAY = 14;
  967. AMD_L2_ASSOC_FULLY = 15;
  968. // TODO AMD SVM and LWP bits
  969. { VIA Standard Feature Flags }
  970. VIA_FPU = BIT_0; // FPU present
  971. VIA_VME = BIT_1; // Virtual Mode Extension
  972. VIA_DE = BIT_2; // Debugging extensions
  973. VIA_PSE = BIT_3; // Page Size Extensions (4MB)
  974. VIA_TSC = BIT_4; // Time Stamp Counter
  975. VIA_MSR = BIT_5; // Model Specific Registers
  976. VIA_PAE = BIT_6; // Physical Address Extension
  977. VIA_MCE = BIT_7; // Machine Check Exception
  978. VIA_CX8 = BIT_8; // CMPXCHG8B instruction
  979. VIA_APIC = BIT_9; // APIC supported
  980. VIA_BIT_10 = BIT_10; // Reserved, do not count on value
  981. VIA_SEP = BIT_11; // Fast System Call
  982. VIA_MTRR = BIT_12; // Memory Range Registers
  983. VIA_PTE = BIT_13; // PTE Global Bit
  984. VIA_MCA = BIT_14; // Machine Check Architecture
  985. VIA_CMOVE = BIT_15; // Conditional Move
  986. VIA_PAT = BIT_16; // Page Attribute Table
  987. VIA_PSE2 = BIT_17; // 36-bit Page Size Extension
  988. VIA_SNUM = BIT_18; // Processor serial number
  989. VIA_BIT_19 = BIT_19; // Reserved, do not count on value
  990. VIA_BIT_20 = BIT_20; // Reserved, do not count on value
  991. VIA_BIT_21 = BIT_21; // Reserved, do not count on value
  992. VIA_BIT_22 = BIT_22; // Reserved, do not count on value
  993. VIA_MMX = BIT_23; // MMX
  994. VIA_FX = BIT_24; // FXSAVE and FXSTORE instructions
  995. VIA_SSE = BIT_25; // Streaming SIMD Extension
  996. VIA_BIT_26 = BIT_26; // Reserved, do not count on value
  997. VIA_BIT_27 = BIT_27; // Reserved, do not count on value
  998. VIA_BIT_28 = BIT_28; // Reserved, do not count on value
  999. VIA_BIT_29 = BIT_29; // Reserved, do not count on value
  1000. VIA_BIT_30 = BIT_30; // Reserved, do not count on value
  1001. VIA_3DNOW = BIT_31; // 3DNow! Technology
  1002. { VIA Extended Feature Flags }
  1003. EVIA_AIS = BIT_0; // Alternate Instruction Set
  1004. EVIA_AISE = BIT_1; // Alternate Instruction Set Enabled
  1005. EVIA_NO_RNG = BIT_2; // NO Random Number Generator
  1006. EVIA_RNGE = BIT_3; // Random Number Generator Enabled
  1007. EVIA_MSR = BIT_4; // Longhaul MSR 0x110A available
  1008. EVIA_FEMMS = BIT_5; // FEMMS instruction Present
  1009. EVIA_NO_ACE = BIT_6; // Advanced Cryptography Engine NOT Present
  1010. EVIA_ACEE = BIT_7; // ACE Enabled
  1011. EVIA_BIT_8 = BIT_8; // Reserved, do not count on value
  1012. EVIA_BIT_9 = BIT_9; // Reserved, do not count on value
  1013. EVIA_BIT_10 = BIT_10; // Reserved, do not count on value
  1014. EVIA_BIT_11 = BIT_11; // Reserved, do not count on value
  1015. EVIA_BIT_12 = BIT_12; // Reserved, do not count on value
  1016. EVIA_BIT_13 = BIT_13; // Reserved, do not count on value
  1017. EVIA_BIT_14 = BIT_14; // Reserved, do not count on value
  1018. EVIA_BIT_15 = BIT_15; // Reserved, do not count on value
  1019. EVIA_BIT_16 = BIT_16; // Reserved, do not count on value
  1020. EVIA_BIT_17 = BIT_17; // Reserved, do not count on value
  1021. EVIA_BIT_18 = BIT_18; // Reserved, do not count on value
  1022. EVIA_BIT_19 = BIT_19; // Reserved, do not count on value
  1023. EVIA_BIT_20 = BIT_20; // Reserved, do not count on value
  1024. EVIA_BIT_21 = BIT_21; // Reserved, do not count on value
  1025. EVIA_BIT_22 = BIT_22; // Reserved, do not count on value
  1026. EVIA_BIT_23 = BIT_23; // Reserved, do not count on value
  1027. EVIA_BIT_24 = BIT_24; // Reserved, do not count on value
  1028. EVIA_BIT_25 = BIT_25; // Reserved, do not count on value
  1029. EVIA_BIT_26 = BIT_26; // Reserved, do not count on value
  1030. EVIA_BIT_27 = BIT_27; // Reserved, do not count on value
  1031. EVIA_BIT_28 = BIT_28; // Reserved, do not count on value
  1032. EVIA_BIT_29 = BIT_29; // Reserved, do not count on value
  1033. EVIA_BIT_30 = BIT_30; // Reserved, do not count on value
  1034. EVIA_BIT_31 = BIT_31; // Reserved, do not count on value
  1035. { Cyrix Standard Feature Flags }
  1036. CYRIX_FPU = BIT_0; // Floating-Point unit on chip
  1037. CYRIX_VME = BIT_1; // Virtual Mode Extention
  1038. CYRIX_DE = BIT_2; // Debugging Extention
  1039. CYRIX_PSE = BIT_3; // Page Size Extention
  1040. CYRIX_TSC = BIT_4; // Time Stamp Counter
  1041. CYRIX_MSR = BIT_5; // Model Specific Registers
  1042. CYRIX_PAE = BIT_6; // Physical Address Extention
  1043. CYRIX_MCE = BIT_7; // Machine Check Exception
  1044. CYRIX_CX8 = BIT_8; // CMPXCHG8 Instruction
  1045. CYRIX_APIC = BIT_9; // Software-accessible local APIC on Chip
  1046. CYRIX_BIT_10 = BIT_10; // Reserved, do not count on value
  1047. CYRIX_BIT_11 = BIT_11; // Reserved, do not count on value
  1048. CYRIX_MTRR = BIT_12; // Memory Type Range Registers
  1049. CYRIX_PGE = BIT_13; // Page Global Enable
  1050. CYRIX_MCA = BIT_14; // Machine Check Architecture
  1051. CYRIX_CMOV = BIT_15; // Conditional Move Instruction
  1052. CYRIX_BIT_16 = BIT_16; // Reserved, do not count on value
  1053. CYRIX_BIT_17 = BIT_17; // Reserved, do not count on value
  1054. CYRIX_BIT_18 = BIT_18; // Reserved, do not count on value
  1055. CYRIX_BIT_19 = BIT_19; // Reserved, do not count on value
  1056. CYRIX_BIT_20 = BIT_20; // Reserved, do not count on value
  1057. CYRIX_BIT_21 = BIT_21; // Reserved, do not count on value
  1058. CYRIX_BIT_22 = BIT_22; // Reserved, do not count on value
  1059. CYRIX_MMX = BIT_23; // MMX technology
  1060. CYRIX_BIT_24 = BIT_24; // Reserved, do not count on value
  1061. CYRIX_BIT_25 = BIT_25; // Reserved, do not count on value
  1062. CYRIX_BIT_26 = BIT_26; // Reserved, do not count on value
  1063. CYRIX_BIT_27 = BIT_27; // Reserved, do not count on value
  1064. CYRIX_BIT_28 = BIT_28; // Reserved, do not count on value
  1065. CYRIX_BIT_29 = BIT_29; // Reserved, do not count on value
  1066. CYRIX_BIT_30 = BIT_30; // Reserved, do not count on value
  1067. CYRIX_BIT_31 = BIT_31; // Reserved, do not count on value
  1068. { Cyrix Enhanced Feature Flags }
  1069. ECYRIX_FPU = BIT_0; // Floating-Point unit on chip
  1070. ECYRIX_VME = BIT_1; // Virtual Mode Extention
  1071. ECYRIX_DE = BIT_2; // Debugging Extention
  1072. ECYRIX_PSE = BIT_3; // Page Size Extention
  1073. ECYRIX_TSC = BIT_4; // Time Stamp Counter
  1074. ECYRIX_MSR = BIT_5; // Model Specific Registers
  1075. ECYRIX_PAE = BIT_6; // Physical Address Extention
  1076. ECYRIX_MCE = BIT_7; // Machine Check Exception
  1077. ECYRIX_CX8 = BIT_8; // CMPXCHG8 Instruction
  1078. ECYRIX_APIC = BIT_9; // Software-accessible local APIC on Chip
  1079. ECYRIX_SEP = BIT_10; // Fast System Call
  1080. ECYRIX_BIT_11 = BIT_11; // Reserved, do not count on value
  1081. ECYRIX_MTRR = BIT_12; // Memory Type Range Registers
  1082. ECYRIX_PGE = BIT_13; // Page Global Enable
  1083. ECYRIX_MCA = BIT_14; // Machine Check Architecture
  1084. ECYRIX_ICMOV = BIT_15; // Integer Conditional Move Instruction
  1085. ECYRIX_FCMOV = BIT_16; // Floating Point Conditional Move Instruction
  1086. ECYRIX_BIT_17 = BIT_17; // Reserved, do not count on value
  1087. ECYRIX_BIT_18 = BIT_18; // Reserved, do not count on value
  1088. ECYRIX_BIT_19 = BIT_19; // Reserved, do not count on value
  1089. ECYRIX_BIT_20 = BIT_20; // Reserved, do not count on value
  1090. ECYRIX_BIT_21 = BIT_21; // Reserved, do not count on value
  1091. ECYRIX_BIT_22 = BIT_22; // Reserved, do not count on value
  1092. ECYRIX_MMX = BIT_23; // MMX technology
  1093. ECYRIX_EMMX = BIT_24; // Extended MMX Technology
  1094. ECYRIX_BIT_25 = BIT_25; // Reserved, do not count on value
  1095. ECYRIX_BIT_26 = BIT_26; // Reserved, do not count on value
  1096. ECYRIX_BIT_27 = BIT_27; // Reserved, do not count on value
  1097. ECYRIX_BIT_28 = BIT_28; // Reserved, do not count on value
  1098. ECYRIX_BIT_29 = BIT_29; // Reserved, do not count on value
  1099. ECYRIX_BIT_30 = BIT_30; // Reserved, do not count on value
  1100. ECYRIX_BIT_31 = BIT_31; // Reserved, do not count on value
  1101. { Transmeta Features }
  1102. TRANSMETA_FPU = BIT_0; // Floating-Point unit on chip
  1103. TRANSMETA_VME = BIT_1; // Virtual Mode Extention
  1104. TRANSMETA_DE = BIT_2; // Debugging Extention
  1105. TRANSMETA_PSE = BIT_3; // Page Size Extention
  1106. TRANSMETA_TSC = BIT_4; // Time Stamp Counter
  1107. TRANSMETA_MSR = BIT_5; // Model Specific Registers
  1108. TRANSMETA_BIT_6 = BIT_6; // Reserved, do not count on value
  1109. TRANSMETA_BIT_7 = BIT_7; // Reserved, do not count on value
  1110. TRANSMETA_CX8 = BIT_8; // CMPXCHG8 Instruction
  1111. TRANSMETA_BIT_9 = BIT_9; // Reserved, do not count on value
  1112. TRANSMETA_BIT_10 = BIT_10; // Reserved, do not count on value
  1113. TRANSMETA_SEP = BIT_11; // Fast system Call Extensions
  1114. TRANSMETA_BIT_12 = BIT_12; // Reserved, do not count on value
  1115. TRANSMETA_BIT_13 = BIT_13; // Reserved, do not count on value
  1116. TRANSMETA_BIT_14 = BIT_14; // Reserved, do not count on value
  1117. TRANSMETA_CMOV = BIT_15; // Conditional Move Instruction
  1118. TRANSMETA_BIT_16 = BIT_16; // Reserved, do not count on value
  1119. TRANSMETA_BIT_17 = BIT_17; // Reserved, do not count on value
  1120. TRANSMETA_PSN = BIT_18; // Processor Serial Number
  1121. TRANSMETA_BIT_19 = BIT_19; // Reserved, do not count on value
  1122. TRANSMETA_BIT_20 = BIT_20; // Reserved, do not count on value
  1123. TRANSMETA_BIT_21 = BIT_21; // Reserved, do not count on value
  1124. TRANSMETA_BIT_22 = BIT_22; // Reserved, do not count on value
  1125. TRANSMETA_MMX = BIT_23; // MMX technology
  1126. TRANSMETA_BIT_24 = BIT_24; // Reserved, do not count on value
  1127. TRANSMETA_BIT_25 = BIT_25; // Reserved, do not count on value
  1128. TRANSMETA_BIT_26 = BIT_26; // Reserved, do not count on value
  1129. TRANSMETA_BIT_27 = BIT_27; // Reserved, do not count on value
  1130. TRANSMETA_BIT_28 = BIT_28; // Reserved, do not count on value
  1131. TRANSMETA_BIT_29 = BIT_29; // Reserved, do not count on value
  1132. TRANSMETA_BIT_30 = BIT_30; // Reserved, do not count on value
  1133. TRANSMETA_BIT_31 = BIT_31; // Reserved, do not count on value
  1134. { Extended Transmeta Features }
  1135. ETRANSMETA_FPU = BIT_0; // Floating-Point unit on chip
  1136. ETRANSMETA_VME = BIT_1; // Virtual Mode Extention
  1137. ETRANSMETA_DE = BIT_2; // Debugging Extention
  1138. ETRANSMETA_PSE = BIT_3; // Page Size Extention
  1139. ETRANSMETA_TSC = BIT_4; // Time Stamp Counter
  1140. ETRANSMETA_MSR = BIT_5; // Model Specific Registers
  1141. ETRANSMETA_BIT_6 = BIT_6; // Reserved, do not count on value
  1142. ETRANSMETA_BIT_7 = BIT_7; // Reserved, do not count on value
  1143. ETRANSMETA_CX8 = BIT_8; // CMPXCHG8 Instruction
  1144. ETRANSMETA_BIT_9 = BIT_9; // Reserved, do not count on value
  1145. ETRANSMETA_BIT_10 = BIT_10; // Reserved, do not count on value
  1146. ETRANSMETA_BIT_11 = BIT_11; // Reserved, do not count on value
  1147. ETRANSMETA_BIT_12 = BIT_12; // Reserved, do not count on value
  1148. ETRANSMETA_BIT_13 = BIT_13; // Reserved, do not count on value
  1149. ETRANSMETA_BIT_14 = BIT_14; // Reserved, do not count on value
  1150. ETRANSMETA_CMOV = BIT_15; // Conditional Move Instruction
  1151. ETRANSMETA_FCMOV = BIT_16; // Float Conditional Move Instruction
  1152. ETRANSMETA_BIT_17 = BIT_17; // Reserved, do not count on value
  1153. ETRANSMETA_BIT_18 = BIT_18; // Reserved, do not count on value
  1154. ETRANSMETA_BIT_19 = BIT_19; // Reserved, do not count on value
  1155. ETRANSMETA_BIT_20 = BIT_20; // Reserved, do not count on value
  1156. ETRANSMETA_BIT_21 = BIT_21; // Reserved, do not count on value
  1157. ETRANSMETA_BIT_22 = BIT_22; // Reserved, do not count on value
  1158. ETRANSMETA_MMX = BIT_23; // MMX technology
  1159. ETRANSMETA_BIT_24 = BIT_24; // Reserved, do not count on value
  1160. ETRANSMETA_BIT_25 = BIT_25; // Reserved, do not count on value
  1161. ETRANSMETA_BIT_26 = BIT_26; // Reserved, do not count on value
  1162. ETRANSMETA_BIT_27 = BIT_27; // Reserved, do not count on value
  1163. ETRANSMETA_BIT_28 = BIT_28; // Reserved, do not count on value
  1164. ETRANSMETA_BIT_29 = BIT_29; // Reserved, do not count on value
  1165. ETRANSMETA_BIT_30 = BIT_30; // Reserved, do not count on value
  1166. ETRANSMETA_BIT_31 = BIT_31; // Reserved, do not count on value
  1167. { Transmeta Specific Features }
  1168. STRANSMETA_RECOVERY = BIT_0; // Recovery Mode
  1169. STRANSMETA_LONGRUN = BIT_1; // Long Run
  1170. STRANSMETA_BIT_2 = BIT_2; // Debugging Extention
  1171. STRANSMETA_LRTI = BIT_3; // Long Run Table Interface
  1172. STRANSMETA_BIT_4 = BIT_4; // Reserved, do not count on value
  1173. STRANSMETA_BIT_5 = BIT_5; // Reserved, do not count on value
  1174. STRANSMETA_BIT_6 = BIT_6; // Reserved, do not count on value
  1175. STRANSMETA_PTTI1 = BIT_7; // Persistent Translation Technology 1.x
  1176. STRANSMETA_PTTI2 = BIT_8; // Persistent Translation Technology 2.0
  1177. STRANSMETA_BIT_9 = BIT_9; // Reserved, do not count on value
  1178. STRANSMETA_BIT_10 = BIT_10; // Reserved, do not count on value
  1179. STRANSMETA_BIT_11 = BIT_11; // Reserved, do not count on value
  1180. STRANSMETA_BIT_12 = BIT_12; // Reserved, do not count on value
  1181. STRANSMETA_BIT_13 = BIT_13; // Reserved, do not count on value
  1182. STRANSMETA_BIT_14 = BIT_14; // Reserved, do not count on value
  1183. STRANSMETA_BIT_15 = BIT_15; // Reserved, do not count on value
  1184. STRANSMETA_BIT_16 = BIT_16; // Reserved, do not count on value
  1185. STRANSMETA_BIT_17 = BIT_17; // Reserved, do not count on value
  1186. STRANSMETA_BIT_18 = BIT_18; // Reserved, do not count on value
  1187. STRANSMETA_BIT_19 = BIT_19; // Reserved, do not count on value
  1188. STRANSMETA_BIT_20 = BIT_20; // Reserved, do not count on value
  1189. STRANSMETA_BIT_21 = BIT_21; // Reserved, do not count on value
  1190. STRANSMETA_BIT_22 = BIT_22; // Reserved, do not count on value
  1191. STRANSMETA_BIT_23 = BIT_23; // Reserved, do not count on value
  1192. STRANSMETA_BIT_24 = BIT_24; // Reserved, do not count on value
  1193. STRANSMETA_BIT_25 = BIT_25; // Reserved, do not count on value
  1194. STRANSMETA_BIT_26 = BIT_26; // Reserved, do not count on value
  1195. STRANSMETA_BIT_27 = BIT_27; // Reserved, do not count on value
  1196. STRANSMETA_BIT_28 = BIT_28; // Reserved, do not count on value
  1197. STRANSMETA_BIT_29 = BIT_29; // Reserved, do not count on value
  1198. STRANSMETA_BIT_30 = BIT_30; // Reserved, do not count on value
  1199. STRANSMETA_BIT_31 = BIT_31; // Reserved, do not count on value
  1200. { Constants of bits of the MXCSR register - Intel and AMD processors that support SSE instructions}
  1201. MXCSR_IE = BIT_0; // Invalid Operation flag
  1202. MXCSR_DE = BIT_1; // Denormal flag
  1203. MXCSR_ZE = BIT_2; // Divide by Zero flag
  1204. MXCSR_OE = BIT_3; // Overflow flag
  1205. MXCSR_UE = BIT_4; // Underflow flag
  1206. MXCSR_PE = BIT_5; // Precision flag
  1207. MXCSR_DAZ = BIT_6; // Denormal are Zero flag
  1208. MXCSR_IM = BIT_7; // Invalid Operation mask
  1209. MXCSR_DM = BIT_8; // Denormal mask
  1210. MXCSR_ZM = BIT_9; // Divide by Zero mask
  1211. MXCSR_OM = BIT_10; // Overflow mask
  1212. MXCSR_UM = BIT_11; // Underflow mask
  1213. MXCSR_PM = BIT_12; // Precision mask
  1214. MXCSR_RC1 = BIT_13; // Rounding control, bit 1
  1215. MXCSR_RC2 = BIT_14; // Rounding control, bit 2
  1216. MXCSR_RC = MXCSR_RC1 or MXCSR_RC2; // Rounding control
  1217. MXCSR_FZ = BIT_15; // Flush to Zero
  1218. const
  1219. IntelCacheDescription: array [0..102] of TCacheInfo = (
  1220. (D: $00; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr00),
  1221. (D: $01; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 32; I: @RsIntelCacheDescr01),
  1222. (D: $02; Family: cfInstructionTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 2; I: @RsIntelCacheDescr02),
  1223. (D: $03; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescr03),
  1224. (D: $04; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 8; I: @RsIntelCacheDescr04),
  1225. (D: $05; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 32; I: @RsIntelCacheDescr05),
  1226. (D: $06; Family: cfL1InstructionCache; Size: 8; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr06),
  1227. (D: $08; Family: cfL1InstructionCache; Size: 16; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr08),
  1228. (D: $09; Family: cfL1InstructionCache; Size: 32; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr09),
  1229. (D: $0A; Family: cfL1DataCache; Size: 8; WaysOfAssoc: 2; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr0A),
  1230. (D: $0B; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 4; I: @RsIntelCacheDescr0B),
  1231. (D: $0C; Family: cfL1DataCache; Size: 16; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr0C),
  1232. (D: $0D; Family: cfL1DataCache; Size: 16; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr0D),
  1233. (D: $0E; Family: cfL1DataCache; Size: 24; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr0E),
  1234. (D: $21; Family: cfL2Cache; Size: 256; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr21),
  1235. (D: $22; Family: cfL3Cache; Size: 512; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr22),
  1236. (D: $23; Family: cfL3Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr23),
  1237. (D: $25; Family: cfL3Cache; Size: 2048; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr25),
  1238. (D: $29; Family: cfL3Cache; Size: 4096; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr29),
  1239. (D: $2C; Family: cfL1DataCache; Size: 32; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr2C),
  1240. (D: $30; Family: cfL1InstructionCache; Size: 32; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr30),
  1241. (D: $39; Family: cfL2Cache; Size: 128; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr39),
  1242. (D: $3A; Family: cfL2Cache; Size: 192; WaysOfAssoc: 6; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3A),
  1243. (D: $3B; Family: cfL2Cache; Size: 128; WaysOfAssoc: 2; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3B),
  1244. (D: $3C; Family: cfL2Cache; Size: 256; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3C),
  1245. (D: $3D; Family: cfL2Cache; Size: 384; WaysOfAssoc: 6; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3D),
  1246. (D: $3E; Family: cfL2Cache; Size: 512; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr3E),
  1247. (D: $40; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr40),
  1248. (D: $41; Family: cfL2Cache; Size: 128; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr41),
  1249. (D: $42; Family: cfL2Cache; Size: 256; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr42),
  1250. (D: $43; Family: cfL2Cache; Size: 512; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr43),
  1251. (D: $44; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr44),
  1252. (D: $45; Family: cfL2Cache; Size: 2048; WaysOfAssoc: 4; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr45),
  1253. (D: $46; Family: cfL3Cache; Size: 4096; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr46),
  1254. (D: $47; Family: cfL3Cache; Size: 8192; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr47),
  1255. (D: $48; Family: cfL2Cache; Size: 3072; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr48),
  1256. (D: $49; Family: cfL2Cache; Size: 4096; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr49),
  1257. (D: $4A; Family: cfL3Cache; Size: 6144; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4A),
  1258. (D: $4B; Family: cfL3Cache; Size: 8192; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4B),
  1259. (D: $4C; Family: cfL3Cache; Size: 12288; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4C),
  1260. (D: $4D; Family: cfL3Cache; Size: 16384; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4D),
  1261. (D: $4E; Family: cfL3Cache; Size: 6144; WaysOfAssoc: 24; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr4E),
  1262. (D: $4F; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 32; I: @RsIntelCacheDescr4F),
  1263. (D: $50; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescr50),
  1264. (D: $51; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 128; I: @RsIntelCacheDescr51),
  1265. (D: $52; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 256; I: @RsIntelCacheDescr52),
  1266. (D: $55; Family: cfInstructionTLB; Size: 2048; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 7; I: @RsIntelCacheDescr55),
  1267. (D: $56; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 16; I: @RsIntelCacheDescr56),
  1268. (D: $57; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 16; I: @RsIntelCacheDescr57),
  1269. (D: $59; Family: cfDataTLB; Size: 4; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 16; I: @RsIntelCacheDescr59),
  1270. (D: $5A; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 32; I: @RsIntelCacheDescr5A),
  1271. (D: $5B; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescr5B),
  1272. (D: $5C; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 128; I: @RsIntelCacheDescr5C),
  1273. (D: $5D; Family: cfDataTLB; Size: 4096; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 256; I: @RsIntelCacheDescr5D),
  1274. (D: $60; Family: cfL1DataCache; Size: 16; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr60),
  1275. (D: $66; Family: cfL1DataCache; Size: 8; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr66),
  1276. (D: $67; Family: cfL1DataCache; Size: 16; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr67),
  1277. (D: $68; Family: cfL1DataCache; Size: 32; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr68),
  1278. (D: $70; Family: cfTrace; Size: 12; WaysOfAssoc: 8; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr70),
  1279. (D: $71; Family: cfTrace; Size: 16; WaysOfAssoc: 8; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr71),
  1280. (D: $72; Family: cfTrace; Size: 32; WaysOfAssoc: 8; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr72),
  1281. (D: $73; Family: cfTrace; Size: 64; WaysOfAssoc: 8; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr73),
  1282. (D: $76; Family: cfInstructionTLB; Size: 2048; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 8; I: @RsIntelCacheDescr76),
  1283. (D: $78; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr78),
  1284. (D: $79; Family: cfL2Cache; Size: 128; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr79),
  1285. (D: $7A; Family: cfL2Cache; Size: 256; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr7A),
  1286. (D: $7B; Family: cfL2Cache; Size: 512; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr7B),
  1287. (D: $7C; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 2; Entries: 0; I: @RsIntelCacheDescr7C),
  1288. (D: $7D; Family: cfL2Cache; Size: 2048; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr7D),
  1289. (D: $7F; Family: cfL2Cache; Size: 512; WaysOfAssoc: 2; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr7F),
  1290. (D: $80; Family: cfL2Cache; Size: 512; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr80),
  1291. (D: $82; Family: cfL2Cache; Size: 256; WaysOfAssoc: 8; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr82),
  1292. (D: $83; Family: cfL2Cache; Size: 512; WaysOfAssoc: 8; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr83),
  1293. (D: $84; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr84),
  1294. (D: $85; Family: cfL2Cache; Size: 2048; WaysOfAssoc: 8; LineSize: 32; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr85),
  1295. (D: $86; Family: cfL2Cache; Size: 512; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr86),
  1296. (D: $87; Family: cfL2Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescr87),
  1297. (D: $B0; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 128; I: @RsIntelCacheDescrB0),
  1298. (D: $B1; Family: cfInstructionTLB; Size: 2048; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 8; I: @RsIntelCacheDescrB1),
  1299. (D: $B2; Family: cfInstructionTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescrB2),
  1300. (D: $B3; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 128; I: @RsIntelCacheDescrB3),
  1301. (D: $B4; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 256; I: @RsIntelCacheDescrB4),
  1302. (D: $BA; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 64; I: @RsIntelCacheDescrBA),
  1303. (D: $C0; Family: cfDataTLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 8; I: @RsIntelCacheDescrC0),
  1304. (D: $CA; Family: cfL2TLB; Size: 4; WaysOfAssoc: 4; LineSize: 0; LinePerSector: 0; Entries: 512; I: @RsIntelCacheDescrCA),
  1305. (D: $D0; Family: cfL3Cache; Size: 512; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD0),
  1306. (D: $D1; Family: cfL3Cache; Size: 1024; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD1),
  1307. (D: $D2; Family: cfL3Cache; Size: 2048; WaysOfAssoc: 4; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD2),
  1308. (D: $D6; Family: cfL3Cache; Size: 1024; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD6),
  1309. (D: $D7; Family: cfL3Cache; Size: 2048; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD7),
  1310. (D: $D8; Family: cfL3Cache; Size: 4096; WaysOfAssoc: 8; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrD8),
  1311. (D: $DC; Family: cfL3Cache; Size: 1536; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrDC),
  1312. (D: $DD; Family: cfL3Cache; Size: 3072; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrDD),
  1313. (D: $DE; Family: cfL3Cache; Size: 6144; WaysOfAssoc: 12; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrDE),
  1314. (D: $E2; Family: cfL3Cache; Size: 2048; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrE2),
  1315. (D: $E3; Family: cfL3Cache; Size: 4096; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrE3),
  1316. (D: $E4; Family: cfL3Cache; Size: 8192; WaysOfAssoc: 16; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrE4),
  1317. (D: $EA; Family: cfL3Cache; Size: 12288; WaysOfAssoc: 24; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrEA),
  1318. (D: $EB; Family: cfL3Cache; Size: 18432; WaysOfAssoc: 24; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrEB),
  1319. (D: $EC; Family: cfL3Cache; Size: 24576; WaysOfAssoc: 24; LineSize: 64; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrEC),
  1320. (D: $F0; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrF0),
  1321. (D: $F1; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrF1),
  1322. (D: $FF; Family: cfOther; Size: 0; WaysOfAssoc: 0; LineSize: 0; LinePerSector: 0; Entries: 0; I: @RsIntelCacheDescrFF)
  1323. );
  1324. {$IFNDEF WINSCP}
  1325. procedure GetCpuInfo(var CpuInfo: TCpuInfo);
  1326. {$ENDIF ~WINSCP}
  1327. function GetIntelCacheDescription(const D: Byte): string;
  1328. function RoundFrequency(const Frequency: Integer): Integer;
  1329. {$IFDEF MSWINDOWS}
  1330. function GetCPUSpeed(var CpuSpeed: TFreqInfo): Boolean;
  1331. type
  1332. TOSEnabledFeature = (oefFPU, oefSSE, oefAVX);
  1333. TOSEnabledFeatures = set of TOSEnabledFeature;
  1334. function GetOSEnabledFeatures: TOSEnabledFeatures;
  1335. {$ENDIF MSWINDOWS}
  1336. {$IFNDEF WINSCP}
  1337. function CPUID: TCpuInfo;
  1338. {$ENDIF ~WINSCP}
  1339. function TestFDIVInstruction: Boolean;
  1340. // Memory Information
  1341. {$IFDEF MSWINDOWS}
  1342. function GetMaxAppAddress: TJclAddr;
  1343. function GetMinAppAddress: TJclAddr;
  1344. {$ENDIF MSWINDOWS}
  1345. function GetMemoryLoad: Byte;
  1346. function GetSwapFileSize: Int64;
  1347. function GetSwapFileUsage: Byte;
  1348. function GetTotalPhysicalMemory: Int64;
  1349. function GetFreePhysicalMemory: Int64;
  1350. {$IFDEF MSWINDOWS}
  1351. function GetTotalPageFileMemory: Int64;
  1352. function GetFreePageFileMemory: Int64;
  1353. function GetTotalVirtualMemory: Int64;
  1354. function GetFreeVirtualMemory: Int64;
  1355. {$ENDIF MSWINDOWS}
  1356. // Alloc granularity
  1357. procedure RoundToAllocGranularity64(var Value: Int64; Up: Boolean);
  1358. procedure RoundToAllocGranularityPtr(var Value: Pointer; Up: Boolean);
  1359. {$IFDEF MSWINDOWS}
  1360. // Keyboard Information
  1361. function GetKeyState(const VirtualKey: Cardinal): Boolean;
  1362. function GetNumLockKeyState: Boolean;
  1363. function GetScrollLockKeyState: Boolean;
  1364. function GetCapsLockKeyState: Boolean;
  1365. // Windows 95/98/Me system resources information
  1366. type
  1367. TFreeSysResKind = (rtSystem, rtGdi, rtUser);
  1368. TFreeSystemResources = record
  1369. SystemRes: Integer;
  1370. GdiRes: Integer;
  1371. UserRes: Integer;
  1372. end;
  1373. function IsSystemResourcesMeterPresent: Boolean;
  1374. function GetFreeSystemResources(const ResourceType: TFreeSysResKind): Integer; overload;
  1375. function GetFreeSystemResources: TFreeSystemResources; overload;
  1376. function GetBPP: Cardinal;
  1377. // Installed programs information
  1378. function ProgIDExists(const ProgID: string): Boolean;
  1379. function IsWordInstalled: Boolean;
  1380. function IsExcelInstalled: Boolean;
  1381. function IsAccessInstalled: Boolean;
  1382. function IsPowerPointInstalled: Boolean;
  1383. function IsFrontPageInstalled: Boolean;
  1384. function IsOutlookInstalled: Boolean;
  1385. function IsInternetExplorerInstalled: Boolean;
  1386. function IsMSProjectInstalled: Boolean;
  1387. function IsOpenOfficeInstalled: Boolean;
  1388. function IsLibreOfficeInstalled: Boolean;
  1389. {$ENDIF MSWINDOWS}
  1390. // Public global variables
  1391. var
  1392. ProcessorCount: Cardinal = 0;
  1393. AllocGranularity: Cardinal = 0;
  1394. PageSize: Cardinal = 0;
  1395. {$IFDEF UNITVERSIONING}
  1396. const
  1397. UnitVersioning: TUnitVersionInfo = (
  1398. RCSfile: '$URL$';
  1399. Revision: '$Revision$';
  1400. Date: '$Date$';
  1401. LogPath: 'JCL\source\common';
  1402. Extra: '';
  1403. Data: nil
  1404. );
  1405. {$ENDIF UNITVERSIONING}
  1406. implementation
  1407. uses
  1408. {$IFDEF WINSCP}
  1409. Registry,
  1410. {$ENDIF ~WINSCP}
  1411. {$IFDEF HAS_UNITSCOPE}
  1412. System.SysUtils, System.Math,
  1413. {$IFDEF MSWINDOWS}
  1414. Winapi.Messages, Winapi.Winsock, {$IFNDEF WINSCP}Snmp,{$ENDIF ~WINSCP}
  1415. {$IFDEF FPC}
  1416. JwaTlHelp32, JwaPsApi,
  1417. {$ELSE ~FPC}
  1418. Winapi.TLHelp32, Winapi.PsApi,
  1419. {$IFNDEF WINSCP}
  1420. JclShell,
  1421. {$ENDIF ~WINSCP}
  1422. {$ENDIF ~FPC}
  1423. {$IFNDEF WINSCP}JclRegistry,{$ENDIF ~WINSCP} JclWin32,
  1424. {$ENDIF MSWINDOWS}
  1425. {$ELSE ~HAS_UNITSCOPE}
  1426. SysUtils,
  1427. Math,
  1428. {$IFDEF MSWINDOWS}
  1429. Messages, Winsock, Snmp,
  1430. {$IFDEF FPC}
  1431. JwaTlHelp32, JwaPsApi,
  1432. {$ELSE ~FPC}
  1433. TLHelp32, PsApi,
  1434. JclShell,
  1435. {$ENDIF ~FPC}
  1436. JclRegistry, JclWin32,
  1437. {$ENDIF MSWINDOWS}
  1438. {$ENDIF ~HAS_UNITSCOPE}
  1439. {$IFNDEF WINSCP}Jcl8087, JclIniFiles,{$ENDIF ~WINSCP}
  1440. JclSysUtils, JclFileUtils, JclAnsiStrings, JclStrings;
  1441. {$IFDEF WINSCP}
  1442. type
  1443. DelphiHKEY = {$IFDEF CPUX64}type Winapi.Windows.HKEY{$ELSE}Longword{$ENDIF CPUX64};
  1444. function RegReadStringDef(const RootKey: DelphiHKEY; const Key, Name: string; Def: string): string;
  1445. var
  1446. Registry: TRegistry;
  1447. begin
  1448. Result := Def;
  1449. try
  1450. Registry := TRegistry.Create;
  1451. try
  1452. Registry.Access := KEY_READ;
  1453. Registry.RootKey := RootKey;
  1454. if Registry.OpenKey(Key, False) and
  1455. Registry.ValueExists(Name) then
  1456. begin
  1457. Result := Registry.ReadString(Name);
  1458. end;
  1459. finally
  1460. Registry.Free;
  1461. end;
  1462. except
  1463. end;
  1464. end;
  1465. {$ENDIF ~WINSCP}
  1466. {.$IFDEF FPC}
  1467. {$IFDEF MSWINDOWS}
  1468. function PidlToPath(IdList: PItemIdList): string;
  1469. begin
  1470. SetLength(Result, MAX_PATH);
  1471. if SHGetPathFromIdList(IdList, PChar(Result)) then
  1472. StrResetLength(Result)
  1473. else
  1474. Result := '';
  1475. end;
  1476. //----------------------------------------------------------------------------
  1477. function GetSpecialFolderLocation(const Folder: Integer): string;
  1478. var
  1479. FolderPidl: PItemIdList;
  1480. begin
  1481. FolderPidl := nil;
  1482. if Succeeded(SHGetSpecialFolderLocation(0, Folder, FolderPidl)) then
  1483. begin
  1484. try
  1485. Result := PidlToPath(FolderPidl);
  1486. finally
  1487. CoTaskMemFree(FolderPidl);
  1488. end;
  1489. end
  1490. else
  1491. Result := '';
  1492. end;
  1493. //----------------------------------------------------------------------------
  1494. {$ENDIF MSWINDOWS}
  1495. {.$ENDIF FPC}
  1496. {$IFNDEF WINSCP}
  1497. //=== Registry helpers =======================================================
  1498. const
  1499. HKLM_CURRENT_VERSION_WINDOWS = 'SOFTWARE\Microsoft\Windows\CurrentVersion';
  1500. HKLM_CURRENT_VERSION_NT = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion';
  1501. function RegReadHklmKeyStringValue(const Key, Name: string; Def: string; ForceNative: boolean = false): string;
  1502. var
  1503. LastAccessMode: TJclRegWOW64Access;
  1504. begin
  1505. if ForceNative then
  1506. begin
  1507. LastAccessMode := RegGetWOW64AccessMode;
  1508. try
  1509. RegSetWOW64AccessMode(raNative);
  1510. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, Key, Name, Def);
  1511. finally
  1512. RegSetWOW64AccessMode(LastAccessMode);
  1513. end;
  1514. end else
  1515. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, Key, Name, Def);
  1516. end;
  1517. function RegReadHklmKeyIntegerValue(const Key, Name: string; Def: Integer; ForceNative: boolean = false): Integer;
  1518. var
  1519. LastAccessMode: TJclRegWOW64Access;
  1520. begin
  1521. if ForceNative then
  1522. begin
  1523. LastAccessMode := RegGetWOW64AccessMode;
  1524. try
  1525. RegSetWOW64AccessMode(raNative);
  1526. Result := RegReadIntegerDef(HKEY_LOCAL_MACHINE, Key, Name, Def);
  1527. finally
  1528. RegSetWOW64AccessMode(LastAccessMode);
  1529. end;
  1530. end else
  1531. Result := RegReadIntegerDef(HKEY_LOCAL_MACHINE, Key, Name, Def);
  1532. end;
  1533. function ReadWindowsCurrentVersionStringValue(const Name: string; Def: string; ForceNative: boolean = false): string; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF SUPPORTS_INLINE}
  1534. begin
  1535. Result := RegReadHklmKeyStringValue(HKLM_CURRENT_VERSION_WINDOWS, Name, Def, ForceNative);
  1536. end;
  1537. function ReadWindowsCurrentVersionIntegerValue(const Name: string; Def: Integer; ForceNative: boolean = false): Integer; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF SUPPORTS_INLINE}
  1538. begin
  1539. Result := RegReadHklmKeyIntegerValue(HKLM_CURRENT_VERSION_WINDOWS, Name, Def, ForceNative);
  1540. end;
  1541. function ReadWindowsNTCurrentVersionStringValue(const Name: string; Def: string; ForceNative: boolean = false): string; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF SUPPORTS_INLINE}
  1542. begin
  1543. Result := RegReadHklmKeyStringValue(HKLM_CURRENT_VERSION_NT, Name, Def, ForceNative);
  1544. end;
  1545. function ReadWindowsNTCurrentVersionIntegerValue(const Name: string; Def: Integer; ForceNative: boolean = false): Integer; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF SUPPORTS_INLINE}
  1546. begin
  1547. Result := RegReadHklmKeyIntegerValue(HKLM_CURRENT_VERSION_NT, Name, Def, ForceNative);
  1548. end;
  1549. {$ENDIF WINSCP}
  1550. //=== Environment ============================================================
  1551. function DelEnvironmentVar(const Name: string): Boolean;
  1552. begin
  1553. {$IFDEF UNIX}
  1554. UnSetEnv(PChar(Name));
  1555. Result := True;
  1556. {$ENDIF UNIX}
  1557. {$IFDEF MSWINDOWS}
  1558. Result := SetEnvironmentVariable(PChar(Name), nil);
  1559. {$ENDIF MSWINDOWS}
  1560. end;
  1561. function ExpandEnvironmentVar(var Value: string): Boolean;
  1562. {$IFDEF UNIX}
  1563. begin
  1564. Result := True;
  1565. end;
  1566. {$ENDIF UNIX}
  1567. {$IFDEF MSWINDOWS}
  1568. var
  1569. R: Integer;
  1570. Expanded: string;
  1571. begin
  1572. SetLength(Expanded, 1);
  1573. R := ExpandEnvironmentStrings(PChar(Value), PChar(Expanded), 0);
  1574. SetLength(Expanded, R);
  1575. Result := ExpandEnvironmentStrings(PChar(Value), PChar(Expanded), R) <> 0;
  1576. if Result then
  1577. begin
  1578. StrResetLength(Expanded);
  1579. Value := Expanded;
  1580. end;
  1581. end;
  1582. {$ENDIF MSWINDOWS}
  1583. function ExpandEnvironmentVarCustom(var Value: string; Vars: TStrings): Boolean;
  1584. function FindClosingBrace(const R: string; var Position: Integer): Boolean;
  1585. var
  1586. Index, Len, BraceCount: Integer;
  1587. Quotes: string;
  1588. begin
  1589. Len := Length(R);
  1590. BraceCount := 0;
  1591. Quotes := '';
  1592. while (Position <= Len) do
  1593. begin
  1594. // handle quotes first
  1595. if (R[Position] = NativeSingleQuote) then
  1596. begin
  1597. Index := JclStrings.CharPos(Quotes, NativeSingleQuote);
  1598. if Index >= 0 then
  1599. SetLength(Quotes, Index - 1)
  1600. else
  1601. Quotes := Quotes + NativeSingleQuote;
  1602. end;
  1603. if (R[Position] = NativeDoubleQuote) then
  1604. begin
  1605. Index := JclStrings.CharPos(Quotes, NativeDoubleQuote);
  1606. if Index >= 0 then
  1607. SetLength(Quotes, Index - 1)
  1608. else
  1609. Quotes := Quotes + NativeDoubleQuote;
  1610. end;
  1611. if (R[Position] = '`') then
  1612. begin
  1613. Index := JclStrings.CharPos(Quotes, '`');
  1614. if Index >= 0 then
  1615. SetLength(Quotes, Index - 1)
  1616. else
  1617. Quotes := Quotes + '`';
  1618. end;
  1619. if Quotes = '' then
  1620. begin
  1621. if R[Position] = ')' then
  1622. begin
  1623. Dec(BraceCount);
  1624. if BraceCount = 0 then
  1625. Break;
  1626. end
  1627. else
  1628. if R[Position] = '(' then
  1629. Inc(BraceCount);
  1630. end;
  1631. Inc(Position);
  1632. end;
  1633. Result := Position <= Len;
  1634. // Delphi XE's CodeGear.Delphi.Targets has a bug where the closing paran is missing
  1635. // "'$(DelphiWin32DebugDCUPath'!=''". But it is still a valid string and not worth
  1636. // an exception.
  1637. //
  1638. // if Position > Len then
  1639. // raise EJclMsBuildError.CreateResFmt(@RsEEndOfString, [S]);
  1640. end;
  1641. var
  1642. Start, Position: Integer;
  1643. PropertyName, PropertyValue: string;
  1644. begin
  1645. Result := True;
  1646. repeat
  1647. // start with the last match in order to convert $(some$(other))
  1648. // evaluate properties
  1649. Start := StrLastPos('$(', Value);
  1650. if Start > 0 then
  1651. begin
  1652. Position := Start;
  1653. if not FindClosingBrace(Value, Position) then
  1654. Break;
  1655. PropertyName := Copy(Value, Start + 2, Position - Start - 2);
  1656. PropertyValue := Vars.Values[PropertyName];
  1657. if PropertyValue <> '' then
  1658. StrReplace(Value,
  1659. Copy(Value, Start, Position - Start + 1), // $(PropertyName)
  1660. PropertyValue,
  1661. [rfReplaceAll, rfIgnoreCase])
  1662. else
  1663. begin
  1664. Result := False;
  1665. Start := 0;
  1666. end;
  1667. end;
  1668. until Start = 0;
  1669. end;
  1670. {$IFDEF UNIX}
  1671. function GetEnvironmentVar(const Name: string; var Value: string): Boolean;
  1672. begin
  1673. Value := getenv(PChar(Name));
  1674. Result := Value <> '';
  1675. end;
  1676. function GetEnvironmentVar(const Name: string; var Value: string; Expand: Boolean): Boolean;
  1677. begin
  1678. Result := GetEnvironmentVar(Name, Value); // Expand is there just for x-platform compatibility
  1679. end;
  1680. {$ENDIF UNIX}
  1681. {$IFDEF MSWINDOWS}
  1682. function GetEnvironmentVar(const Name: string; out Value: string): Boolean;
  1683. begin
  1684. Result := GetEnvironmentVar(Name, Value, True);
  1685. end;
  1686. function GetEnvironmentVar(const Name: string; out Value: string; Expand: Boolean): Boolean;
  1687. var
  1688. R: DWORD;
  1689. begin
  1690. R := {$IFDEF HAS_UNITSCOPE}Winapi.{$ENDIF}Windows.GetEnvironmentVariable(PChar(Name), nil, 0);
  1691. SetLength(Value, R);
  1692. R := {$IFDEF HAS_UNITSCOPE}Winapi.{$ENDIF}Windows.GetEnvironmentVariable(PChar(Name), PChar(Value), R);
  1693. Result := R <> 0;
  1694. if not Result then
  1695. Value := ''
  1696. else
  1697. begin
  1698. SetLength(Value, R);
  1699. if Expand then
  1700. ExpandEnvironmentVar(Value);
  1701. end;
  1702. end;
  1703. {$ENDIF MSWINDOWS}
  1704. {$IFDEF LINUX}
  1705. function GetEnvironmentVars(const Vars: TStrings): Boolean;
  1706. var
  1707. P: PPChar;
  1708. begin
  1709. Vars.BeginUpdate;
  1710. try
  1711. Vars.Clear;
  1712. P := System.envp;
  1713. Result := P <> nil;
  1714. while (P <> nil) and (P^ <> nil) do
  1715. begin
  1716. Vars.Add(P^);
  1717. Inc(P);
  1718. end;
  1719. finally
  1720. Vars.EndUpdate;
  1721. end;
  1722. end;
  1723. function GetEnvironmentVars(const Vars: TStrings; Expand: Boolean): Boolean;
  1724. begin
  1725. Result := GetEnvironmentVars(Vars); // Expand is there just for x-platform compatibility
  1726. end;
  1727. {$ENDIF LINUX}
  1728. {$IFDEF MSWINDOWS}
  1729. {$IFNDEF WINSCP}
  1730. function GetEnvironmentVars(const Vars: TStrings): Boolean;
  1731. begin
  1732. Result := GetEnvironmentVars(Vars, True);
  1733. end;
  1734. function GetEnvironmentVars(const Vars: TStrings; Expand: Boolean): Boolean;
  1735. var
  1736. Raw: PChar;
  1737. Expanded: string;
  1738. I: Integer;
  1739. begin
  1740. Vars.BeginUpdate;
  1741. try
  1742. Vars.Clear;
  1743. Raw := GetEnvironmentStrings;
  1744. try
  1745. MultiSzToStrings(Vars, Raw);
  1746. Result := True;
  1747. finally
  1748. FreeEnvironmentStrings(Raw);
  1749. end;
  1750. if Expand then
  1751. begin
  1752. for I := 0 to Vars.Count - 1 do
  1753. begin
  1754. Expanded := Vars[I];
  1755. if ExpandEnvironmentVar(Expanded) then
  1756. Vars[I] := Expanded;
  1757. end;
  1758. end;
  1759. finally
  1760. Vars.EndUpdate;
  1761. end;
  1762. end;
  1763. {$ENDIF ~WINSCP}
  1764. {$ENDIF MSWINDOWS}
  1765. function SetEnvironmentVar(const Name, Value: string): Boolean;
  1766. begin
  1767. {$IFDEF UNIX}
  1768. SetEnv(PChar(Name), PChar(Value), 1);
  1769. Result := True;
  1770. {$ENDIF UNIX}
  1771. {$IFDEF MSWINDOWS}
  1772. Result := SetEnvironmentVariable(PChar(Name), PChar(Value));
  1773. {$ENDIF MSWINDOWS}
  1774. end;
  1775. {$IFDEF MSWINDOWS}
  1776. {$IFNDEF WINSCP}
  1777. function CreateEnvironmentBlock(const Options: TEnvironmentOptions; const AdditionalVars: TStrings): PChar;
  1778. const
  1779. RegLocalEnvironment = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
  1780. RegUserEnvironment = '\Environment\';
  1781. var
  1782. KeyNames, TempList: TStrings;
  1783. Temp, Name, Value: string;
  1784. I: Integer;
  1785. begin
  1786. TempList := TStringList.Create;
  1787. try
  1788. // add additional environment variables
  1789. if eoAdditional in Options then
  1790. for I := 0 to AdditionalVars.Count - 1 do
  1791. begin
  1792. Temp := AdditionalVars[I];
  1793. ExpandEnvironmentVar(Temp);
  1794. TempList.Add(Temp);
  1795. end;
  1796. // get environment strings from local machine
  1797. if eoLocalMachine in Options then
  1798. begin
  1799. KeyNames := TStringList.Create;
  1800. try
  1801. if RegGetValueNames(HKEY_LOCAL_MACHINE, RegLocalEnvironment, KeyNames) then
  1802. begin
  1803. for I := 0 to KeyNames.Count - 1 do
  1804. begin
  1805. Name := KeyNames[I];
  1806. Value := RegReadString(HKEY_LOCAL_MACHINE, RegLocalEnvironment, Name);
  1807. ExpandEnvironmentVar(Value);
  1808. TempList.Add(Name + '=' + Value);
  1809. end;
  1810. end;
  1811. finally
  1812. FreeAndNil(KeyNames);
  1813. end;
  1814. end;
  1815. // get environment strings from current user
  1816. if eoCurrentUser in Options then
  1817. begin
  1818. KeyNames := TStringLIst.Create;
  1819. try
  1820. if RegGetValueNames(HKEY_CURRENT_USER, RegUserEnvironment, KeyNames) then
  1821. begin
  1822. for I := 0 to KeyNames.Count - 1 do
  1823. begin
  1824. Name := KeyNames[I];
  1825. Value := RegReadString(HKEY_CURRENT_USER, RegUserEnvironment, Name);
  1826. ExpandEnvironmentVar(Value);
  1827. TempList.Add(Name + '=' + Value);
  1828. end;
  1829. end;
  1830. finally
  1831. KeyNames.Free;
  1832. end;
  1833. end;
  1834. // transform stringlist into multi-PChar
  1835. Result := nil;
  1836. StringsToMultiSz(Result, TempList);
  1837. finally
  1838. FreeAndNil(TempList);
  1839. end;
  1840. end;
  1841. {$ENDIF ~WINSCP}
  1842. // frees an environment block allocated by CreateEnvironmentBlock and
  1843. // sets Env to nil
  1844. {$IFNDEF WINSCP}
  1845. procedure DestroyEnvironmentBlock(var Env: PChar);
  1846. begin
  1847. FreeMultiSz(Env);
  1848. end;
  1849. procedure SetGlobalEnvironmentVariable(VariableName, VariableContent: string);
  1850. const
  1851. cEnvironment = 'Environment';
  1852. begin
  1853. if VariableName = '' then
  1854. Exit;
  1855. if VariableContent = '' then
  1856. begin
  1857. RegDeleteEntry(HKEY_CURRENT_USER, cEnvironment, VariableName);
  1858. SetEnvironmentVariable(PChar(VariableName), nil);
  1859. end
  1860. else
  1861. begin
  1862. RegWriteString(HKEY_CURRENT_USER, cEnvironment, VariableName, VariableContent);
  1863. SetEnvironmentVariable(PChar(VariableName), PChar(VariableContent));
  1864. end;
  1865. SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, LPARAM(PChar(cEnvironment)));
  1866. end;
  1867. //=== Common Folders =========================================================
  1868. { TODO : Check for documented solution }
  1869. function GetCommonFilesFolder: string;
  1870. begin
  1871. // Don't use 'ReadCurrentVersionStringValue' with 'ForceNative' access here,
  1872. // as we want the platform (x86/x64) specific common folder.
  1873. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, HKLM_CURRENT_VERSION_WINDOWS,
  1874. 'CommonFilesDir', '');
  1875. end;
  1876. {$ENDIF ~WINSCP}
  1877. {$ENDIF MSWINDOWS}
  1878. function GetCurrentFolder: string;
  1879. {$IFDEF UNIX}
  1880. const
  1881. InitialSize = 64;
  1882. var
  1883. Size: Integer;
  1884. begin
  1885. Size := InitialSize;
  1886. while True do
  1887. begin
  1888. SetLength(Result, Size);
  1889. if getcwd(PChar(Result), Size) <> nil then
  1890. begin
  1891. StrResetLength(Result);
  1892. Exit;
  1893. end;
  1894. {$IFDEF FPC}
  1895. if GetLastOSError <> ERANGE then
  1896. {$ELSE ~FPC}
  1897. if GetLastError <> ERANGE then
  1898. {$ENDIF ~FPC}
  1899. RaiseLastOSError;
  1900. Size := Size * 2;
  1901. end;
  1902. end;
  1903. {$ENDIF UNIX}
  1904. {$IFDEF MSWINDOWS}
  1905. var
  1906. Required: Cardinal;
  1907. begin
  1908. Result := '';
  1909. Required := GetCurrentDirectory(0, nil);
  1910. if Required <> 0 then
  1911. begin
  1912. SetLength(Result, Required);
  1913. GetCurrentDirectory(Required, PChar(Result));
  1914. StrResetLength(Result);
  1915. end;
  1916. end;
  1917. {$ENDIF MSWINDOWS}
  1918. {$IFDEF MSWINDOWS}
  1919. {$IFNDEF WINSCP}
  1920. { TODO : Check for documented solution }
  1921. function GetProgramFilesFolder: string;
  1922. begin
  1923. // Don't use 'ReadCurrentVersionStringValue' with 'ForceNative' access here,
  1924. // as we want the platform (x86/x64) specific common folder.
  1925. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, HKLM_CURRENT_VERSION_WINDOWS, 'ProgramFilesDir', '');
  1926. end;
  1927. {$ENDIF WINSCP}
  1928. { TODO : Check for documented solution }
  1929. function GetWindowsFolder: string;
  1930. var
  1931. Required: Cardinal;
  1932. begin
  1933. Result := '';
  1934. Required := GetWindowsDirectory(nil, 0);
  1935. if Required <> 0 then
  1936. begin
  1937. SetLength(Result, Required);
  1938. GetWindowsDirectory(PChar(Result), Required);
  1939. StrResetLength(Result);
  1940. end;
  1941. end;
  1942. { TODO : Check for documented solution }
  1943. function GetWindowsSystemFolder: string;
  1944. var
  1945. Required: Cardinal;
  1946. begin
  1947. Result := '';
  1948. Required := GetSystemDirectory(nil, 0);
  1949. if Required <> 0 then
  1950. begin
  1951. SetLength(Result, Required);
  1952. GetSystemDirectory(PChar(Result), Required);
  1953. StrResetLength(Result);
  1954. end;
  1955. end;
  1956. function GetWindowsTempFolder: string;
  1957. begin
  1958. Result := PathRemoveSeparator(PathGetTempPath);
  1959. end;
  1960. function GetDesktopFolder: string;
  1961. begin
  1962. Result := GetSpecialFolderLocation(CSIDL_DESKTOP);
  1963. end;
  1964. { TODO : Check GetProgramsFolder = GetProgramFilesFolder }
  1965. function GetProgramsFolder: string;
  1966. begin
  1967. Result := GetSpecialFolderLocation(CSIDL_PROGRAMS);
  1968. end;
  1969. {$ENDIF MSWINDOWS}
  1970. {$IFNDEF WINSCP}
  1971. function GetPersonalFolder: string;
  1972. begin
  1973. {$IFDEF UNIX}
  1974. Result := GetEnvironmentVariable('HOME');
  1975. {$ENDIF UNIX}
  1976. {$IFDEF MSWINDOWS}
  1977. Result := GetSpecialFolderLocation(CSIDL_PERSONAL);
  1978. {$ENDIF MSWINDOWS}
  1979. end;
  1980. {$IFDEF MSWINDOWS}
  1981. function GetFavoritesFolder: string;
  1982. begin
  1983. Result := GetSpecialFolderLocation(CSIDL_FAVORITES);
  1984. end;
  1985. function GetStartupFolder: string;
  1986. begin
  1987. Result := GetSpecialFolderLocation(CSIDL_STARTUP);
  1988. end;
  1989. function GetRecentFolder: string;
  1990. begin
  1991. Result := GetSpecialFolderLocation(CSIDL_RECENT);
  1992. end;
  1993. function GetSendToFolder: string;
  1994. begin
  1995. Result := GetSpecialFolderLocation(CSIDL_SENDTO);
  1996. end;
  1997. function GetStartmenuFolder: string;
  1998. begin
  1999. Result := GetSpecialFolderLocation(CSIDL_STARTMENU);
  2000. end;
  2001. function GetDesktopDirectoryFolder: string;
  2002. begin
  2003. Result := GetSpecialFolderLocation(CSIDL_DESKTOPDIRECTORY);
  2004. end;
  2005. function GetCommonDocumentsFolder: string;
  2006. begin
  2007. Result := GetSpecialFolderLocation(CSIDL_COMMON_DOCUMENTS);
  2008. end;
  2009. function GetNethoodFolder: string;
  2010. begin
  2011. Result := GetSpecialFolderLocation(CSIDL_NETHOOD);
  2012. end;
  2013. function GetFontsFolder: string;
  2014. begin
  2015. Result := GetSpecialFolderLocation(CSIDL_FONTS);
  2016. end;
  2017. function GetCommonStartmenuFolder: string;
  2018. begin
  2019. Result := GetSpecialFolderLocation(CSIDL_COMMON_STARTMENU);
  2020. end;
  2021. function GetCommonProgramsFolder: string;
  2022. begin
  2023. Result := GetSpecialFolderLocation(CSIDL_COMMON_PROGRAMS);
  2024. end;
  2025. function GetCommonStartupFolder: string;
  2026. begin
  2027. Result := GetSpecialFolderLocation(CSIDL_COMMON_STARTUP);
  2028. end;
  2029. function GetCommonDesktopdirectoryFolder: string;
  2030. begin
  2031. Result := GetSpecialFolderLocation(CSIDL_COMMON_DESKTOPDIRECTORY);
  2032. end;
  2033. function GetCommonAppdataFolder: string;
  2034. begin
  2035. Result := GetSpecialFolderLocation(CSIDL_COMMON_APPDATA);
  2036. end;
  2037. function GetAppdataFolder: string;
  2038. begin
  2039. Result := GetSpecialFolderLocation(CSIDL_APPDATA);
  2040. end;
  2041. function GetLocalAppData: string;
  2042. begin
  2043. Result := GetSpecialFolderLocation(CSIDL_LOCAL_APPDATA);
  2044. end;
  2045. function GetPrinthoodFolder: string;
  2046. begin
  2047. Result := GetSpecialFolderLocation(CSIDL_PRINTHOOD);
  2048. end;
  2049. function GetCommonFavoritesFolder: string;
  2050. begin
  2051. Result := GetSpecialFolderLocation(CSIDL_COMMON_FAVORITES);
  2052. end;
  2053. function GetTemplatesFolder: string;
  2054. begin
  2055. Result := GetSpecialFolderLocation(CSIDL_TEMPLATES);
  2056. end;
  2057. function GetInternetCacheFolder: string;
  2058. begin
  2059. Result := GetSpecialFolderLocation(CSIDL_INTERNET_CACHE);
  2060. end;
  2061. function GetCookiesFolder: string;
  2062. begin
  2063. Result := GetSpecialFolderLocation(CSIDL_COOKIES);
  2064. end;
  2065. function GetHistoryFolder: string;
  2066. begin
  2067. Result := GetSpecialFolderLocation(CSIDL_HISTORY);
  2068. end;
  2069. function GetProfileFolder: string;
  2070. begin
  2071. Result := GetSpecialFolderLocation(CSIDL_PROFILE);
  2072. end;
  2073. {$ENDIF ~WINSCP}
  2074. // the following special folders are pure virtual and cannot be
  2075. // mapped to a directory path:
  2076. // CSIDL_INTERNET
  2077. // CSIDL_CONTROLS
  2078. // CSIDL_PRINTERS
  2079. // CSIDL_BITBUCKET
  2080. // CSIDL_DRIVES
  2081. // CSIDL_NETWORK
  2082. // CSIDL_ALTSTARTUP
  2083. // CSIDL_COMMON_ALTSTARTUP
  2084. // Identification
  2085. type
  2086. TVolumeInfoKind = (vikName, vikSerial, vikFileSystem);
  2087. function GetVolumeInfoHelper(const Drive: string; InfoKind: TVolumeInfoKind): string;
  2088. var
  2089. VolumeSerialNumber: DWORD;
  2090. MaximumComponentLength: DWORD;
  2091. Flags: DWORD;
  2092. Name: array [0..MAX_PATH] of Char;
  2093. FileSystem: array [0..15] of Char;
  2094. ErrorMode: Cardinal;
  2095. DriveStr: string;
  2096. begin
  2097. { TODO : Change to RootPath }
  2098. { TODO : Perform better checking of Drive param or document that no checking
  2099. is performed. RM Suggested:
  2100. DriveStr := Drive;
  2101. if (Length(Drive) < 2) or (Drive[2] <> ':') then
  2102. DriveStr := GetCurrentFolder;
  2103. DriveStr := DriveStr[1] + ':\'; }
  2104. Result := '';
  2105. DriveStr := Drive + ':\';
  2106. ErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  2107. try
  2108. Flags := 0;
  2109. MaximumComponentLength := 0;
  2110. if GetVolumeInformation(PChar(DriveStr), Name, Length(Name), @VolumeSerialNumber,
  2111. MaximumComponentLength, Flags, FileSystem, Length(FileSystem)) then
  2112. case InfoKind of
  2113. vikName:
  2114. Result := StrPas(Name);
  2115. vikSerial:
  2116. begin
  2117. Result := IntToHex(HiWord(VolumeSerialNumber), 4) + '-' +
  2118. IntToHex(LoWord(VolumeSerialNumber), 4);
  2119. end;
  2120. vikFileSystem:
  2121. Result := StrPas(FileSystem);
  2122. end;
  2123. finally
  2124. SetErrorMode(ErrorMode);
  2125. end;
  2126. end;
  2127. function GetVolumeName(const Drive: string): string;
  2128. begin
  2129. Result := GetVolumeInfoHelper(Drive, vikName);
  2130. end;
  2131. function GetVolumeSerialNumber(const Drive: string): string;
  2132. begin
  2133. Result := GetVolumeInfoHelper(Drive, vikSerial);
  2134. end;
  2135. function GetVolumeFileSystem(const Drive: string): string;
  2136. begin
  2137. Result := GetVolumeInfoHelper(Drive, vikFileSystem);
  2138. end;
  2139. { TODO -cHelp : Donator (incl. TFileSystemFlag[s]): Robert Rossmair }
  2140. function GetVolumeFileSystemFlags(const Volume: string): TFileSystemFlags;
  2141. const
  2142. FileSystemFlags: array [TFileSystemFlag] of DWORD =
  2143. ( FILE_CASE_SENSITIVE_SEARCH, // fsCaseSensitive
  2144. FILE_CASE_PRESERVED_NAMES, // fsCasePreservedNames
  2145. FILE_UNICODE_ON_DISK, // fsSupportsUnicodeOnDisk
  2146. FILE_PERSISTENT_ACLS, // fsPersistentACLs
  2147. FILE_FILE_COMPRESSION, // fsSupportsFileCompression
  2148. FILE_VOLUME_QUOTAS, // fsSupportsVolumeQuotas
  2149. FILE_SUPPORTS_SPARSE_FILES, // fsSupportsSparseFiles
  2150. FILE_SUPPORTS_REPARSE_POINTS, // fsSupportsReparsePoints
  2151. FILE_SUPPORTS_REMOTE_STORAGE, // fsSupportsRemoteStorage
  2152. FILE_VOLUME_IS_COMPRESSED, // fsVolumeIsCompressed
  2153. FILE_SUPPORTS_OBJECT_IDS, // fsSupportsObjectIds
  2154. FILE_SUPPORTS_ENCRYPTION, // fsSupportsEncryption
  2155. FILE_NAMED_STREAMS, // fsSupportsNamedStreams
  2156. FILE_READ_ONLY_VOLUME // fsVolumeIsReadOnly
  2157. );
  2158. var
  2159. MaximumComponentLength, Flags: Cardinal;
  2160. Flag: TFileSystemFlag;
  2161. begin
  2162. Flags := 0;
  2163. MaximumComponentLength := 0;
  2164. if not GetVolumeInformation(PChar(PathAddSeparator(Volume)), nil, 0, nil,
  2165. MaximumComponentLength, Flags, nil, 0) then
  2166. RaiseLastOSError;
  2167. Result := [];
  2168. for Flag := Low(TFileSystemFlag) to High(TFileSystemFlag) do
  2169. if (Flags and FileSystemFlags[Flag]) <> 0 then
  2170. Include(Result, Flag);
  2171. end;
  2172. {$ENDIF MSWINDOWS}
  2173. { TODO -cDoc: Contributor: twm }
  2174. function GetIPAddress(const HostName: string): string;
  2175. var
  2176. {$IFDEF MSWINDOWS}
  2177. R: Integer;
  2178. WSAData: TWSAData;
  2179. {$ENDIF MSWINDOWS}
  2180. HostEnt: PHostEnt;
  2181. Host: AnsiString;
  2182. SockAddr: TSockAddrIn;
  2183. begin
  2184. Result := '';
  2185. {$IFDEF MSWINDOWS}
  2186. WSAData.wVersion := 0;
  2187. R := WSAStartup(MakeWord(1, 1), WSAData);
  2188. if R = 0 then
  2189. try
  2190. {$ENDIF MSWINDOWS}
  2191. Host := AnsiString(HostName);
  2192. if Host = '' then
  2193. begin
  2194. SetLength(Host, MAX_PATH);
  2195. GetHostName(PAnsiChar(Host), MAX_PATH);
  2196. end;
  2197. HostEnt := GetHostByName(PAnsiChar(Host));
  2198. if HostEnt <> nil then
  2199. begin
  2200. SockAddr.sin_addr.S_addr := Longint(PLongint(HostEnt^.h_addr_list^)^);
  2201. Result := string(AnsiString(inet_ntoa(SockAddr.sin_addr)));
  2202. end;
  2203. {$IFDEF MSWINDOWS}
  2204. finally
  2205. WSACleanup;
  2206. end;
  2207. {$ENDIF MSWINDOWS}
  2208. end;
  2209. { TODO -cDoc: Donator: twm }
  2210. {$IFDEF MSWINDOWS}
  2211. procedure GetIpAddresses(Results: TStrings);
  2212. begin
  2213. GetIpAddresses(Results, '');
  2214. end;
  2215. procedure GetIpAddresses(Results: TStrings; const HostName: AnsiString);
  2216. type
  2217. TaPInAddr = array[0..10] of PInAddr;
  2218. PaPInAddr = ^TaPInAddr;
  2219. var
  2220. R: Integer;
  2221. HostEnt: PHostEnt;
  2222. pptr: PaPInAddr;
  2223. Host: AnsiString;
  2224. i: Integer;
  2225. WSAData: TWSAData;
  2226. begin
  2227. //need a socket for ioctl()
  2228. WSAData.wVersion := 0;
  2229. R := WSAStartup(MakeWord(1, 1), WSAData);
  2230. if R = 0 then begin
  2231. try
  2232. if HostName = '' then
  2233. begin
  2234. SetLength(Host, MAX_PATH);
  2235. GetHostName(PAnsiChar(Host), MAX_PATH);
  2236. end
  2237. else
  2238. Host := HostName;
  2239. HostEnt := GetHostByName(PAnsiChar(Host));
  2240. if HostEnt <> nil then
  2241. begin
  2242. pPtr := PaPInAddr(HostEnt^.h_addr_list);
  2243. i := 0;
  2244. while pPtr^[I] <> nil do begin
  2245. Results.Add(string(AnsiString(inet_ntoa(pptr^[i]^)))); // OF AnsiString to TStrings
  2246. Inc(i);
  2247. end;
  2248. end;
  2249. finally
  2250. WSACleanup;
  2251. end;
  2252. end;
  2253. end;
  2254. {$ENDIF MSWINDOWS}
  2255. {$IFDEF UNIX}
  2256. { TODO -cDoc: Donator: twm, Contributor rrossmair }
  2257. // Returns all IP addresses of the local machine in the form
  2258. // <interface>=<IP-Address> (which allows for access to the interface names
  2259. // by means of Results.Names and the addresses through Results.Values)
  2260. //
  2261. // Example:
  2262. //
  2263. // lo=127.0.0.1
  2264. // eth0=10.10.10.1
  2265. // ppp0=217.82.187.130
  2266. //
  2267. // note that this will append to Results!
  2268. //
  2269. procedure GetIpAddresses(Results: TStrings);
  2270. var
  2271. Sock: Integer;
  2272. IfReq: TIfReq;
  2273. SockAddrPtr: PSockAddrIn;
  2274. ListSave, IfList: PIfNameIndex;
  2275. begin
  2276. //need a socket for ioctl()
  2277. Sock := socket(AF_INET, SOCK_STREAM, 0);
  2278. if Sock < 0 then
  2279. RaiseLastOSError;
  2280. try
  2281. //returns pointer to dynamically allocated list of structs
  2282. ListSave := if_nameindex();
  2283. try
  2284. IfList := ListSave;
  2285. //walk thru the array returned and query for each
  2286. //interface's address
  2287. while IfList^.if_index <> 0 do
  2288. begin
  2289. //copy in the interface name to look up address of
  2290. {$IFDEF FPC}
  2291. strncpy(IfReq.ifr_ifrn.ifrn_name, IfList^.if_name, IFNAMSIZ);
  2292. {$ELSE ~FPC}
  2293. strncpy(IfReq.ifrn_name, IfList^.if_name, IFNAMSIZ);
  2294. {$ENDIF ~FPC}
  2295. //get the address for this interface
  2296. if ioctl(Sock, SIOCGIFADDR, @IfReq) <> 0 then
  2297. RaiseLastOSError;
  2298. //print out the address
  2299. {$IFDEF FPC}
  2300. SockAddrPtr := PSockAddrIn(@IfReq.ifr_ifru.ifru_addr);
  2301. Results.Add(Format('%s=%s', [IfReq.ifr_ifrn.ifrn_name, inet_ntoa(SockAddrPtr^.sin_addr)]));
  2302. {$ELSE ~FPC}
  2303. SockAddrPtr := PSockAddrIn(@IfReq.ifru_addr);
  2304. Results.Add(Format('%s=%s', [IfReq.ifrn_name, inet_ntoa(SockAddrPtr^.sin_addr)]));
  2305. {$ENDIF ~FPC}
  2306. Inc(IfList);
  2307. end;
  2308. finally
  2309. //free the dynamic memory kernel allocated for us
  2310. if_freenameindex(ListSave);
  2311. end;
  2312. finally
  2313. Libc.__close(Sock)
  2314. end;
  2315. end;
  2316. {$ENDIF UNIX}
  2317. function GetLocalComputerName: string;
  2318. {$IFDEF LINUX}
  2319. var
  2320. MachineInfo: utsname;
  2321. begin
  2322. uname(MachineInfo);
  2323. Result := MachineInfo.nodename;
  2324. end;
  2325. {$ENDIF LINUX}
  2326. {$IFDEF MSWINDOWS}
  2327. var
  2328. Count: DWORD;
  2329. Buf: array[0..MAX_PATH] of Char;
  2330. begin
  2331. Count := Length(Buf) - 1;
  2332. // GetComputerName can return a string larger than MAX_COMPUTERNAME_LENGTH which was the NetBios limit.
  2333. // The Windows 10 allows to enter 260 (MAX_PATH) chars computer name's field.
  2334. if GetComputerName(Buf, Count) then
  2335. SetString(Result, Buf, Count)
  2336. else
  2337. Result := '';
  2338. end;
  2339. {$ENDIF MSWINDOWS}
  2340. function GetLocalUserName: string;
  2341. {$IFDEF UNIX}
  2342. begin
  2343. Result := GetEnv('USER');
  2344. end;
  2345. {$ENDIF UNIX}
  2346. {$IFDEF MSWINDOWS}
  2347. var
  2348. Count: DWORD;
  2349. begin
  2350. Count := 256 + 1; // UNLEN + 1
  2351. // set buffer size to 256 + 2 characters
  2352. { TODO : Win2k solution }
  2353. SetLength(Result, Count);
  2354. if GetUserName(PChar(Result), Count) then
  2355. StrResetLength(Result)
  2356. else
  2357. Result := '';
  2358. end;
  2359. {$ENDIF MSWINDOWS}
  2360. {$IFDEF MSWINDOWS}
  2361. {$IFNDEF WINSCP}
  2362. function GetRegisteredCompany: string;
  2363. begin
  2364. { TODO : check for MSDN documentation }
  2365. if IsWinNT then
  2366. Result := ReadWindowsNTCurrentVersionStringValue('RegisteredOrganization', '', True)
  2367. else
  2368. Result := ReadWindowsCurrentVersionStringValue('RegisteredOrganization', '', True);
  2369. end;
  2370. function GetRegisteredOwner: string;
  2371. begin
  2372. { TODO : check for MSDN documentation }
  2373. if IsWinNT then
  2374. Result := ReadWindowsNTCurrentVersionStringValue('RegisteredOwner', '', True)
  2375. else
  2376. Result := ReadWindowsCurrentVersionStringValue('RegisteredOwner', '', True);
  2377. end;
  2378. function GetWindowsProductId: string;
  2379. begin
  2380. { TODO : check for MSDN documentation }
  2381. if IsWinNT then
  2382. Result := ReadWindowsNTCurrentVersionStringValue('ProductId', '', True)
  2383. else
  2384. Result := ReadWindowsCurrentVersionStringValue('ProductId', '', True);
  2385. end;
  2386. {$ENDIF WINSCP}
  2387. { TODO: Check supported platforms, maybe complete rewrite }
  2388. function GetUserDomainName(const CurUser: string): string;
  2389. var
  2390. Count1, Count2: DWORD;
  2391. Sd: PSID; // PSecurityDescriptor; // FPC requires PSID
  2392. Snu: SID_Name_Use;
  2393. begin
  2394. Count1 := 0;
  2395. Count2 := 0;
  2396. Sd := nil;
  2397. Snu := SIDTypeUser;
  2398. Result := '';
  2399. LookUpAccountName(nil, PChar(CurUser), Sd, Count1, PChar(Result), Count2, Snu);
  2400. // set buffer size to Count2 + 2 characters for safety
  2401. SetLength(Result, Count2 + 1);
  2402. Sd := AllocMem(Count1);
  2403. try
  2404. if LookUpAccountName(nil, PChar(CurUser), Sd, Count1, PChar(Result), Count2, Snu) then
  2405. StrResetLength(Result)
  2406. else
  2407. Result := EmptyStr;
  2408. finally
  2409. FreeMem(Sd);
  2410. end;
  2411. end;
  2412. function GetWorkGroupName: WideString;
  2413. var
  2414. WkstaInfo: PByte;
  2415. WkstaInfo100: PWKSTA_INFO_100;
  2416. begin
  2417. if NetWkstaGetInfo(nil, 100, WkstaInfo) <> NERR_Success then
  2418. raise EJclWin32Error.CreateRes(@RsENetWkstaGetInfo);
  2419. WkstaInfo100 := PWKSTA_INFO_100(WkstaInfo);
  2420. Result := WideString(PWideChar(WkstaInfo100^.wki100_langroup));
  2421. NetApiBufferFree(Pointer(WkstaInfo));
  2422. end;
  2423. {$ENDIF MSWINDOWS}
  2424. function GetDomainName: string;
  2425. {$IFDEF UNIX}
  2426. var
  2427. MachineInfo: utsname;
  2428. begin
  2429. uname(MachineInfo);
  2430. Result := MachineInfo.domainname;
  2431. end;
  2432. {$ENDIF UNIX}
  2433. {$IFDEF MSWINDOWS}
  2434. //091123 HA Use LookupAccountSid to fetch the current users domain ...
  2435. //begin
  2436. // Result := GetUserDomainName(GetLocalUserName);
  2437. //end;
  2438. var
  2439. hProcess, hAccessToken: THandle;
  2440. InfoBuffer: PChar;
  2441. AccountName: array [0..UNLEN] of Char;
  2442. DomainName: array [0..UNLEN] of Char;
  2443. InfoBufferSize: Cardinal;
  2444. AccountSize: Cardinal;
  2445. DomainSize: Cardinal;
  2446. snu: SID_NAME_USE;
  2447. begin
  2448. InfoBufferSize := 1000;
  2449. AccountSize := Length(AccountName);
  2450. DomainSize := Length(DomainName);
  2451. hProcess := GetCurrentProcess;
  2452. if OpenProcessToken(hProcess, TOKEN_READ, hAccessToken) then
  2453. try
  2454. GetMem(InfoBuffer, InfoBufferSize);
  2455. try
  2456. if GetTokenInformation(hAccessToken, TokenUser, InfoBuffer, InfoBufferSize, InfoBufferSize) then
  2457. LookupAccountSid(nil, PSIDAndAttributes(InfoBuffer)^.sid, AccountName, AccountSize,
  2458. DomainName, DomainSize, snu)
  2459. else
  2460. RaiseLastOSError;
  2461. finally
  2462. FreeMem(InfoBuffer)
  2463. end;
  2464. Result := DomainName;
  2465. finally
  2466. CloseHandle(hAccessToken);
  2467. end
  2468. end;
  2469. {$ENDIF MSWINDOWS}
  2470. {$IFDEF MSWINDOWS}
  2471. // Reference: How to Obtain BIOS Information from the Registry
  2472. // http://support.microsoft.com/default.aspx?scid=kb;en-us;q195268
  2473. function GetBIOSName: string;
  2474. const
  2475. Win9xBIOSInfoKey = 'Enum\Root\*PNP0C01\0000';
  2476. begin
  2477. if IsWinNT then
  2478. Result := ''
  2479. else
  2480. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, Win9xBIOSInfoKey, 'BIOSName', '');
  2481. end;
  2482. function GetBIOSCopyright: string;
  2483. const
  2484. ADR_BIOSCOPYRIGHT = $FE091;
  2485. begin
  2486. Result := '';
  2487. if not IsWinNT and not IsBadReadPtr(Pointer(ADR_BIOSCOPYRIGHT), 2) then
  2488. try
  2489. Result := string(AnsiString(PAnsiChar(ADR_BIOSCOPYRIGHT)));
  2490. except
  2491. Result := '';
  2492. end;
  2493. end;
  2494. function GetBIOSExtendedInfo: string;
  2495. const
  2496. ADR_BIOSEXTENDEDINFO = $FEC71;
  2497. begin
  2498. Result := '';
  2499. if not IsWinNT and not IsBadReadPtr(Pointer(ADR_BIOSEXTENDEDINFO), 2) then
  2500. try
  2501. Result := string(AnsiString(PAnsiChar(ADR_BIOSEXTENDEDINFO)));
  2502. except
  2503. Result := '';
  2504. end;
  2505. end;
  2506. // Reference: How to Obtain BIOS Information from the Registry
  2507. // http://support.microsoft.com/default.aspx?scid=kb;en-us;q195268
  2508. { TODO : the date string can be e.g. 00/00/00 }
  2509. {$IFNDEF WINSCP}
  2510. function GetBIOSDate: TDateTime;
  2511. const
  2512. WIN10_REG_PATH = 'HARDWARE\DESCRIPTION\System\BIOS';
  2513. WIN10_REG_KEY = 'BIOSReleaseDate';
  2514. WinNT_REG_PATH = 'HARDWARE\DESCRIPTION\System';
  2515. WinNT_REG_KEY = 'SystemBiosDate';
  2516. Win9x_REG_PATH = 'Enum\Root\*PNP0C01\0000';
  2517. Win9x_REG_KEY = 'BiosDate';
  2518. var
  2519. RegStr: string;
  2520. {$IFDEF RTL150_UP}
  2521. FormatSettings: TFormatSettings;
  2522. {$ELSE ~RTL150_UP}
  2523. RegFormat: string;
  2524. RegSeparator: Char;
  2525. {$ENDIF ~RTL150_UP}
  2526. begin
  2527. if IsWinNT then
  2528. begin
  2529. // location of the Bios date seems to have changed on newer systems (From windows 10 ?)
  2530. // The new location seems to exist since a while, but older location disappeared on newer OS
  2531. if RegValueExists(HKEY_LOCAL_MACHINE, WIN10_REG_PATH, WIN10_REG_KEY) then
  2532. RegStr := RegReadString(HKEY_LOCAL_MACHINE, WIN10_REG_PATH, WIN10_REG_KEY)
  2533. else
  2534. RegStr := RegReadString(HKEY_LOCAL_MACHINE, WinNT_REG_PATH, WinNT_REG_KEY);
  2535. end
  2536. else
  2537. begin
  2538. RegStr := RegReadString(HKEY_LOCAL_MACHINE, Win9x_REG_PATH, Win9x_REG_KEY);
  2539. end;
  2540. {$IFDEF RTL150_UP}
  2541. FillChar(FormatSettings, SizeOf(FormatSettings), 0);
  2542. FormatSettings.DateSeparator := '/';
  2543. FormatSettings.ShortDateFormat := 'm/d/y';
  2544. if not TryStrToDate(RegStr, Result, FormatSettings) then
  2545. begin
  2546. FormatSettings.ShortDateFormat := 'y/m/d';
  2547. if not TryStrToDate(RegStr, Result, FormatSettings) then
  2548. Result := 0;
  2549. end;
  2550. {$ELSE ~RTL150_UP}
  2551. Result := 0;
  2552. { TODO : change to a threadsafe solution }
  2553. RegFormat := ShortDateFormat;
  2554. RegSeparator := DateSeparator;
  2555. try
  2556. DateSeparator := '/';
  2557. try
  2558. ShortDateFormat := 'm/d/y';
  2559. Result := StrToDate(RegStr);
  2560. except
  2561. try
  2562. ShortDateFormat := 'y/m/d';
  2563. Result := StrToDate(RegStr);
  2564. except
  2565. end;
  2566. end;
  2567. finally
  2568. ShortDateFormat := RegFormat;
  2569. DateSeparator := RegSeparator;
  2570. end;
  2571. {$ENDIF ~RTL150_UP}
  2572. end;
  2573. {$ENDIF ~WINSCP}
  2574. {$ENDIF MSWINDOWS}
  2575. //=== Processes, Tasks and Modules ===========================================
  2576. {$IFDEF UNIX}
  2577. const
  2578. CommLen = 16; // synchronize with size of comm in struct task_struct in
  2579. // /usr/include/linux/sched.h
  2580. SProcDirectory = '/proc';
  2581. function RunningProcessesList(const List: TStrings; FullPath: Boolean): Boolean;
  2582. var
  2583. ProcDir: PDirectoryStream;
  2584. PtrDirEnt: PDirEnt;
  2585. Scratch: TDirEnt;
  2586. ProcID: __pid_t;
  2587. E: Integer;
  2588. FileName: string;
  2589. F: PIOFile;
  2590. begin
  2591. Result := False;
  2592. ProcDir := opendir(SProcDirectory);
  2593. if ProcDir <> nil then
  2594. begin
  2595. PtrDirEnt := nil;
  2596. {$IFDEF FPC}
  2597. if readdir_r(ProcDir, @Scratch, @PtrDirEnt) <> 0 then
  2598. Exit;
  2599. {$ELSE ~FPC}
  2600. if readdir_r(ProcDir, @Scratch, PtrDirEnt) <> 0 then
  2601. Exit;
  2602. {$ENDIF ~FPC}
  2603. List.BeginUpdate;
  2604. try
  2605. while PtrDirEnt <> nil do
  2606. begin
  2607. Val(PtrDirEnt^.d_name, ProcID, E);
  2608. if E = 0 then // name was process id
  2609. begin
  2610. FileName := '';
  2611. if FullPath then
  2612. FileName := SymbolicLinkTarget(Format('/proc/%s/exe', [PtrDirEnt^.d_name]));
  2613. if FileName = '' then // usually due to insufficient access rights
  2614. begin
  2615. // read stat
  2616. FileName := Format('/proc/%s/stat', [PtrDirEnt^.d_name]);
  2617. F := fopen(PChar(FileName), 'r');
  2618. if F = nil then
  2619. raise EJclError.CreateResFmt(@RsInvalidProcessID, [ProcID]);
  2620. try
  2621. SetLength(FileName, CommLen);
  2622. if fscanf(F, PChar(Format('%%*d (%%%d[^)])', [CommLen])), PChar(FileName)) <> 1 then
  2623. RaiseLastOSError;
  2624. StrResetLength(FileName);
  2625. finally
  2626. fclose(F);
  2627. end;
  2628. end;
  2629. List.AddObject(FileName, Pointer(ProcID));
  2630. end;
  2631. {$IFDEF FPC}
  2632. if readdir_r(ProcDir, @Scratch, @PtrDirEnt) <> 0 then
  2633. Break;
  2634. {$ELSE ~FPC}
  2635. if readdir_r(ProcDir, @Scratch, PtrDirEnt) <> 0 then
  2636. Break;
  2637. {$ENDIF ~FPC}
  2638. end;
  2639. finally
  2640. List.EndUpdate;
  2641. end;
  2642. end;
  2643. end;
  2644. {$ENDIF UNIX}
  2645. {$IFDEF MSWINDOWS}
  2646. {$IFNDEF WINSCP}
  2647. function RunningProcessesList(const List: TStrings; FullPath: Boolean): Boolean;
  2648. // This function always returns an empty string on Win9x
  2649. function ProcessFileName(PID: DWORD): string;
  2650. var
  2651. Handle: THandle;
  2652. begin
  2653. Result := '';
  2654. Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
  2655. if Handle <> 0 then
  2656. try
  2657. SetLength(Result, MAX_PATH);
  2658. if FullPath then
  2659. begin
  2660. if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
  2661. StrResetLength(Result)
  2662. else
  2663. Result := '';
  2664. end
  2665. else
  2666. begin
  2667. if GetModuleBaseName(Handle, 0, PChar(Result), MAX_PATH) > 0 then
  2668. StrResetLength(Result)
  2669. else
  2670. Result := '';
  2671. end;
  2672. finally
  2673. CloseHandle(Handle);
  2674. end;
  2675. end;
  2676. { TODO: Check return value of CreateToolhelp32Snapshot on Windows NT (0?) }
  2677. function BuildListTH: Boolean;
  2678. var
  2679. SnapProcHandle: THandle;
  2680. ProcEntry: TProcessEntry32;
  2681. NextProc: Boolean;
  2682. FileName: string;
  2683. Win2kOrNewer: Boolean;
  2684. begin
  2685. SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  2686. Result := (SnapProcHandle <> INVALID_HANDLE_VALUE);
  2687. if Result then
  2688. try
  2689. Win2kOrNewer := JclCheckWinVersion(5, 0); // Win2k or newer
  2690. ProcEntry.dwSize := SizeOf(ProcEntry);
  2691. NextProc := Process32First(SnapProcHandle, ProcEntry);
  2692. while NextProc do
  2693. begin
  2694. if ProcEntry.th32ProcessID = 0 then
  2695. begin
  2696. // PID 0 is always the "System Idle Process" but this name cannot be
  2697. // retrieved from the system and has to be fabricated.
  2698. FileName := LoadResString(@RsSystemIdleProcess);
  2699. end
  2700. else
  2701. begin
  2702. if Win2kOrNewer then
  2703. begin
  2704. FileName := ProcessFileName(ProcEntry.th32ProcessID);
  2705. if FileName = '' then
  2706. FileName := ProcEntry.szExeFile;
  2707. end
  2708. else
  2709. begin
  2710. FileName := ProcEntry.szExeFile;
  2711. if not FullPath then
  2712. FileName := ExtractFileName(FileName);
  2713. end;
  2714. end;
  2715. List.AddObject(FileName, Pointer(ProcEntry.th32ProcessID));
  2716. NextProc := Process32Next(SnapProcHandle, ProcEntry);
  2717. end;
  2718. finally
  2719. CloseHandle(SnapProcHandle);
  2720. end;
  2721. end;
  2722. function BuildListPS: Boolean;
  2723. var
  2724. PIDs: array [0..1024] of DWORD;
  2725. Needed: DWORD;
  2726. I: Integer;
  2727. FileName: string;
  2728. begin
  2729. Needed := 0;
  2730. Result := EnumProcesses(@PIDs, SizeOf(PIDs), Needed);
  2731. if Result then
  2732. begin
  2733. for I := 0 to (Needed div SizeOf(DWORD)) - 1 do
  2734. begin
  2735. case PIDs[I] of
  2736. 0:
  2737. // PID 0 is always the "System Idle Process" but this name cannot be
  2738. // retrieved from the system and has to be fabricated.
  2739. FileName := LoadResString(@RsSystemIdleProcess);
  2740. 2:
  2741. // On NT 4 PID 2 is the "System Process" but this name cannot be
  2742. // retrieved from the system and has to be fabricated.
  2743. if IsWinNT4 then
  2744. FileName := LoadResString(@RsSystemProcess)
  2745. else
  2746. FileName := ProcessFileName(PIDs[I]);
  2747. 8:
  2748. // On Win2K PID 8 is the "System Process" but this name cannot be
  2749. // retrieved from the system and has to be fabricated.
  2750. if IsWin2k or IsWinXP then
  2751. FileName := LoadResString(@RsSystemProcess)
  2752. else
  2753. FileName := ProcessFileName(PIDs[I]);
  2754. else
  2755. FileName := ProcessFileName(PIDs[I]);
  2756. end;
  2757. if FileName <> '' then
  2758. List.AddObject(FileName, Pointer(PIDs[I]));
  2759. end;
  2760. end;
  2761. end;
  2762. begin
  2763. { TODO : safer solution? }
  2764. List.BeginUpdate;
  2765. try
  2766. if GetWindowsVersion in [wvWinNT31, wvWinNT35, wvWinNT351, wvWinNT4] then
  2767. Result := BuildListPS
  2768. else
  2769. Result := BuildListTH;
  2770. finally
  2771. List.EndUpdate;
  2772. end;
  2773. end;
  2774. {$ENDIF WINSCP}
  2775. { TODO Windows 9x ? }
  2776. function LoadedModulesList(const List: TStrings; ProcessID: DWORD; HandlesOnly: Boolean): Boolean;
  2777. procedure AddToList(ProcessHandle: THandle; Module: HMODULE);
  2778. var
  2779. FileName: array [0..MAX_PATH] of Char;
  2780. ModuleInfo: TModuleInfo;
  2781. begin
  2782. ModuleInfo.EntryPoint := nil;
  2783. {$IFDEF FPC}
  2784. if GetModuleInformation(ProcessHandle, Module, ModuleInfo, SizeOf(ModuleInfo)) then
  2785. {$ELSE ~FPC}
  2786. if GetModuleInformation(ProcessHandle, Module, @ModuleInfo, SizeOf(ModuleInfo)) then
  2787. {$ENDIF ~FPC}
  2788. begin
  2789. if HandlesOnly then
  2790. List.AddObject('', Pointer(ModuleInfo.lpBaseOfDll))
  2791. else
  2792. if GetModuleFileNameEx(ProcessHandle, Module, Filename, Length(Filename)) > 0 then
  2793. List.AddObject(FileName, Pointer(ModuleInfo.lpBaseOfDll));
  2794. end;
  2795. end;
  2796. function EnumModulesVQ(ProcessHandle: THandle): Boolean;
  2797. var
  2798. MemInfo: TMemoryBasicInformation;
  2799. Base: PChar;
  2800. LastAllocBase, LastBase: Pointer;
  2801. Res: DWORD;
  2802. begin
  2803. Base := nil;
  2804. LastAllocBase := nil;
  2805. ResetMemory(MemInfo, SizeOf(MemInfo));
  2806. Res := VirtualQueryEx(ProcessHandle, Base, MemInfo, SizeOf(MemInfo));
  2807. Result := (Res = SizeOf(MemInfo));
  2808. while Res = SizeOf(MemInfo) do
  2809. begin
  2810. if MemInfo.AllocationBase <> LastAllocBase then
  2811. begin
  2812. {$IFDEF FPC}
  2813. if MemInfo._Type = MEM_IMAGE then
  2814. {$ELSE ~FPC}
  2815. if MemInfo.Type_9 = MEM_IMAGE then
  2816. {$ENDIF ~FPC}
  2817. AddToList(ProcessHandle, HMODULE(MemInfo.AllocationBase));
  2818. LastAllocBase := MemInfo.AllocationBase;
  2819. end;
  2820. LastBase := Base;
  2821. Inc(Base, MemInfo.RegionSize);
  2822. if Base < LastBase then // WINE returns some questionable RegionSize values causing an infinite loop
  2823. Break;
  2824. Res := VirtualQueryEx(ProcessHandle, Base, MemInfo, SizeOf(MemInfo));
  2825. end;
  2826. end;
  2827. function EnumModulesPS: Boolean;
  2828. var
  2829. ProcessHandle: THandle;
  2830. Needed: DWORD;
  2831. Modules: array of THandle;
  2832. I, Cnt: Integer;
  2833. begin
  2834. Result := False;
  2835. ProcessHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessID);
  2836. if ProcessHandle <> 0 then
  2837. try
  2838. Needed := 0;
  2839. Result := EnumProcessModules(ProcessHandle, nil, 0, Needed);
  2840. if Result then
  2841. begin
  2842. Cnt := Needed div SizeOf(HMODULE);
  2843. SetLength(Modules, Cnt);
  2844. if EnumProcessModules(ProcessHandle, @Modules[0], Needed, Needed) then
  2845. for I := 0 to Cnt - 1 do
  2846. AddToList(ProcessHandle, Modules[I]);
  2847. end
  2848. else
  2849. Result := EnumModulesVQ(ProcessHandle);
  2850. finally
  2851. CloseHandle(ProcessHandle);
  2852. end;
  2853. end;
  2854. { TODO: Check return value of CreateToolhelp32Snapshot on Windows NT (0?) }
  2855. function EnumModulesTH: Boolean;
  2856. var
  2857. SnapProcHandle: THandle;
  2858. Module: TModuleEntry32;
  2859. Next: Boolean;
  2860. begin
  2861. SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcessID);
  2862. Result := (SnapProcHandle <> INVALID_HANDLE_VALUE);
  2863. if Result then
  2864. try
  2865. ResetMemory(Module, SizeOf(Module));
  2866. Module.dwSize := SizeOf(Module);
  2867. Next := Module32First(SnapProcHandle, Module);
  2868. while Next do
  2869. begin
  2870. if HandlesOnly then
  2871. List.AddObject('', Pointer(Module.hModule))
  2872. else
  2873. List.AddObject(Module.szExePath, Pointer(Module.hModule));
  2874. Next := Module32Next(SnapProcHandle, Module);
  2875. end;
  2876. finally
  2877. CloseHandle(SnapProcHandle);
  2878. end;
  2879. end;
  2880. begin
  2881. List.BeginUpdate;
  2882. try
  2883. if IsWinNT then
  2884. Result := EnumModulesPS
  2885. else
  2886. Result := EnumModulesTH;
  2887. finally
  2888. List.EndUpdate;
  2889. end;
  2890. end;
  2891. function EnumTaskWindowsProc(Wnd: THandle; List: TStrings): Boolean; stdcall;
  2892. var
  2893. Caption: array [0..1024] of Char;
  2894. begin
  2895. if IsMainAppWindow(Wnd) and (GetWindowText(Wnd, Caption, Length(Caption)) > 0) then
  2896. List.AddObject(Caption, Pointer(Wnd));
  2897. Result := True;
  2898. end;
  2899. function GetTasksList(const List: TStrings): Boolean;
  2900. begin
  2901. List.BeginUpdate;
  2902. try
  2903. Result := EnumWindows(@EnumTaskWindowsProc, LPARAM(List));
  2904. finally
  2905. List.EndUpdate;
  2906. end;
  2907. end;
  2908. function ModuleFromAddr(const Addr: Pointer): HMODULE;
  2909. var
  2910. MI: TMemoryBasicInformation;
  2911. begin
  2912. if (VirtualQuery(Addr, MI, SizeOf(MI)) = SizeOf(MI)) and (MI.State = MEM_COMMIT) then
  2913. Result := HMODULE(MI.AllocationBase)
  2914. else
  2915. Result := 0;
  2916. end;
  2917. function IsSystemModule(const Module: HMODULE): Boolean;
  2918. var
  2919. CurModule: PLibModule;
  2920. begin
  2921. Result := False;
  2922. if Module <> 0 then
  2923. begin
  2924. CurModule := LibModuleList;
  2925. while CurModule <> nil do
  2926. begin
  2927. if CurModule.Instance = Module then
  2928. begin
  2929. Result := True;
  2930. Break;
  2931. end;
  2932. CurModule := CurModule.Next;
  2933. end;
  2934. end;
  2935. end;
  2936. // Cache for the slow VirtualQuery calls
  2937. //
  2938. // BeginModuleFromAddrCache;
  2939. // try
  2940. // Module := CachedModuleFromAddr(Address);
  2941. // ...
  2942. // finally
  2943. // EndModuleFromAddrCache;
  2944. // end;
  2945. type
  2946. PModuleAddrSize = ^TModuleAddrSize;
  2947. TModuleAddrSize = record
  2948. BaseAddress: TJclAddr;
  2949. Size: SizeInt;
  2950. Module: HMODULE;
  2951. end;
  2952. TModuleAddrSizeList = class(TList)
  2953. public
  2954. Counter: Integer;
  2955. LastAccessIndex: Integer;
  2956. end;
  2957. // The main module (EXE) and the module that contains the JclSysInfo unit can be
  2958. // cached once for all Begin/EndModuleFromAddrCache blocks.
  2959. var
  2960. MainModuleAddrSize, InstanceModuleAddrSize: TModuleAddrSize;
  2961. threadvar
  2962. ModuleAddrSize: TModuleAddrSizeList;
  2963. procedure BeginModuleFromAddrCache;
  2964. const
  2965. ModuleCodeOffset = $1000;
  2966. var
  2967. List: TModuleAddrSizeList;
  2968. MainModule: HMODULE;
  2969. P: PModuleAddrSize;
  2970. begin
  2971. List := ModuleAddrSize;
  2972. if List = nil then
  2973. begin
  2974. List := TModuleAddrSizeList.Create;
  2975. List.Counter := 1;
  2976. List.LastAccessIndex := -1;
  2977. ModuleAddrSize := List;
  2978. // Query the module addresses for the main module and JclSysInfo's module and
  2979. // add them to the list.
  2980. MainModule := 0;
  2981. if MainModuleAddrSize.Module = 0 then
  2982. begin
  2983. MainModule := GetModuleHandle(nil);
  2984. CachedModuleFromAddr(Pointer(MainModule + ModuleCodeOffset));
  2985. if List.Count = 1 then
  2986. begin
  2987. // If JclSysInfo is in the main module then we can skip this
  2988. if MainModule <> HInstance then
  2989. begin
  2990. CachedModuleFromAddr(Pointer(HInstance + ModuleCodeOffset));
  2991. if List.Count = 2 then
  2992. InstanceModuleAddrSize := PModuleAddrSize(List[1])^;
  2993. end;
  2994. MainModuleAddrSize := PModuleAddrSize(List[0])^;
  2995. List.LastAccessIndex := -1;
  2996. end;
  2997. end;
  2998. if (MainModule = 0) and (MainModuleAddrSize.Module <> 0) then
  2999. begin
  3000. New(P);
  3001. P^ := MainModuleAddrSize;
  3002. List.Add(P);
  3003. if InstanceModuleAddrSize.Module <> 0 then
  3004. begin
  3005. New(P);
  3006. P^ := InstanceModuleAddrSize;
  3007. List.Add(P);
  3008. end;
  3009. end;
  3010. end
  3011. else
  3012. Inc(List.Counter);
  3013. end;
  3014. procedure EndModuleFromAddrCache;
  3015. var
  3016. List: TModuleAddrSizeList;
  3017. I: Integer;
  3018. begin
  3019. List := ModuleAddrSize;
  3020. if List <> nil then
  3021. begin
  3022. Dec(List.Counter);
  3023. if List.Counter = 0 then
  3024. begin
  3025. for I := 0 to List.Count - 1 do
  3026. Dispose(PModuleAddrSize(List[I]));
  3027. List.Free;
  3028. ModuleAddrSize := nil;
  3029. end;
  3030. end;
  3031. end;
  3032. function CachedModuleFromAddr(const Addr: Pointer): HMODULE;
  3033. var
  3034. P: PModuleAddrSize;
  3035. List: TModuleAddrSizeList;
  3036. I, LastAccessIndex: Integer;
  3037. MI: TMemoryBasicInformation;
  3038. begin
  3039. List := ModuleAddrSize;
  3040. if List = nil then
  3041. begin
  3042. Result := ModuleFromAddr(Addr);
  3043. Exit;
  3044. end;
  3045. LastAccessIndex := List.LastAccessIndex;
  3046. if LastAccessIndex <> -1 then
  3047. begin
  3048. P := List[LastAccessIndex];
  3049. if (P.BaseAddress <= TJclAddr(Addr)) and
  3050. (TJclAddr(Addr) < P.BaseAddress + TJclAddr(P.Size)) then
  3051. begin
  3052. Result := P.Module;
  3053. Exit;
  3054. end;
  3055. end;
  3056. for I := 0 to List.Count - 1 do
  3057. begin
  3058. P := List[I];
  3059. if (P.BaseAddress <= TJclAddr(Addr)) and
  3060. (TJclAddr(Addr) < P.BaseAddress + TJclAddr(P.Size)) then
  3061. begin
  3062. List.LastAccessIndex := I;
  3063. Result := P.Module;
  3064. Exit;
  3065. end;
  3066. end;
  3067. if (VirtualQuery(Addr, MI, SizeOf(MI)) = SizeOf(MI)) and (MI.State = MEM_COMMIT) then
  3068. begin
  3069. New(P);
  3070. P.Module := HMODULE(MI.AllocationBase);
  3071. P.BaseAddress := TJclAddr(MI.BaseAddress);
  3072. P.Size := MI.RegionSize;
  3073. List.LastAccessIndex := List.Add(P);
  3074. Result := HMODULE(MI.AllocationBase);
  3075. end
  3076. else
  3077. Result := 0;
  3078. end;
  3079. // Reference: http://msdn.microsoft.com/library/periodic/period97/win321197.htm
  3080. { TODO : wrong link }
  3081. function IsMainAppWindow(Wnd: THandle): Boolean;
  3082. var
  3083. ParentWnd: THandle;
  3084. ExStyle: DWORD;
  3085. begin
  3086. if IsWindowVisible(Wnd) then
  3087. begin
  3088. ParentWnd := THandle(GetWindowLongPtr(Wnd, GWLP_HWNDPARENT));
  3089. ExStyle := GetWindowLong(Wnd, GWL_EXSTYLE);
  3090. Result := ((ParentWnd = 0) or (ParentWnd = GetDesktopWindow)) and
  3091. ((ExStyle and WS_EX_TOOLWINDOW = 0) or (ExStyle and WS_EX_APPWINDOW <> 0));
  3092. end
  3093. else
  3094. Result := False;
  3095. end;
  3096. function IsWindowResponding(Wnd: THandle; Timeout: Integer): Boolean;
  3097. var
  3098. Res: DWORD;
  3099. begin
  3100. Res := 0;
  3101. Result := SendMessageTimeout(Wnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, Timeout, {$IFDEF RTL230_UP}@{$ENDIF}Res) <> 0;
  3102. end;
  3103. function GetWindowIcon(Wnd: THandle; LargeIcon: Boolean): HICON;
  3104. var
  3105. Width, Height: Integer;
  3106. TempIcon: HICON;
  3107. IconType: DWORD;
  3108. begin
  3109. if LargeIcon then
  3110. begin
  3111. Width := GetSystemMetrics(SM_CXICON);
  3112. Height := GetSystemMetrics(SM_CYICON);
  3113. IconType := ICON_BIG;
  3114. TempIcon := GetClassLong(Wnd, GCL_HICON);
  3115. end
  3116. else
  3117. begin
  3118. Width := GetSystemMetrics(SM_CXSMICON);
  3119. Height := GetSystemMetrics(SM_CYSMICON);
  3120. IconType := ICON_SMALL;
  3121. TempIcon := GetClassLong(Wnd, GCL_HICONSM);
  3122. end;
  3123. if TempIcon = 0 then
  3124. TempIcon := SendMessage(Wnd, WM_GETICON, IconType, 0);
  3125. if (TempIcon = 0) and not LargeIcon then
  3126. TempIcon := SendMessage(Wnd, WM_GETICON, ICON_BIG, 0);
  3127. Result := CopyImage(TempIcon, IMAGE_ICON, Width, Height, 0);
  3128. end;
  3129. function GetWindowCaption(Wnd: THandle): string;
  3130. var
  3131. Buffer: string;
  3132. Size: Integer;
  3133. begin
  3134. Size := GetWindowTextLength(Wnd);
  3135. if Size = 0 then
  3136. Size := 1; // always allocate at least one byte, otherwise PChar(Buffer) returns nil
  3137. SetLength(Buffer, Size);
  3138. // strings always have an additional null character
  3139. Size := GetWindowText(Wnd, PChar(Buffer), Size + 1);
  3140. Result := Copy(Buffer, 1, Size);
  3141. end;
  3142. // Q178893
  3143. // http://support.microsoft.com/default.aspx?scid=kb;en-us;178893
  3144. function EnumTerminateAppWindowsProc(Wnd: THandle; ProcessID: DWORD): Boolean; stdcall;
  3145. var
  3146. PID: DWORD;
  3147. begin
  3148. GetWindowThreadProcessId(Wnd, @PID);
  3149. if ProcessID = PID then
  3150. PostMessage(Wnd, WM_CLOSE, 0, 0);
  3151. Result := True;
  3152. end;
  3153. function TerminateApp(ProcessID: DWORD; Timeout: Integer): TJclTerminateAppResult;
  3154. var
  3155. ProcessHandle: THandle;
  3156. begin
  3157. Result := taError;
  3158. if ProcessID <> GetCurrentProcessId then
  3159. begin
  3160. ProcessHandle := OpenProcess(SYNCHRONIZE or PROCESS_TERMINATE, False, ProcessID);
  3161. if ProcessHandle <> 0 then
  3162. try
  3163. EnumWindows(@EnumTerminateAppWindowsProc, LPARAM(ProcessID));
  3164. if WaitForSingleObject(ProcessHandle, Timeout) = WAIT_OBJECT_0 then
  3165. Result := taClean
  3166. else
  3167. if TerminateProcess(ProcessHandle, 0) then
  3168. Result := taKill;
  3169. finally
  3170. CloseHandle(ProcessHandle);
  3171. end;
  3172. end;
  3173. end;
  3174. function TerminateTask(Wnd: THandle; Timeout: Integer): TJclTerminateAppResult;
  3175. var
  3176. PID: DWORD;
  3177. begin
  3178. if GetWindowThreadProcessId(Wnd, @PID) <> 0 then
  3179. Result := TerminateApp(PID, Timeout)
  3180. else
  3181. Result := taError;
  3182. end;
  3183. {$IFNDEF WINSCP}
  3184. function GetProcessNameFromWnd(Wnd: THandle): string;
  3185. var
  3186. List: TStringList;
  3187. PID: DWORD;
  3188. I: Integer;
  3189. begin
  3190. Result := '';
  3191. if IsWindow(Wnd) then
  3192. begin
  3193. PID := DWORD(-1);
  3194. GetWindowThreadProcessId(Wnd, @PID);
  3195. List := TStringList.Create;
  3196. try
  3197. if RunningProcessesList(List, True) then
  3198. begin
  3199. I := List.IndexOfObject(Pointer(PID));
  3200. if I > -1 then
  3201. Result := List[I];
  3202. end;
  3203. finally
  3204. List.Free;
  3205. end;
  3206. end;
  3207. end;
  3208. function GetPidFromProcessName(const ProcessName: string): THandle;
  3209. var
  3210. List: TStringList;
  3211. I: Integer;
  3212. HasFullPath: Boolean;
  3213. begin
  3214. Result := INVALID_HANDLE_VALUE;
  3215. List := TStringList.Create;
  3216. try
  3217. HasFullPath := ExtractFilePath(ProcessName) <> '';
  3218. if RunningProcessesList(List, HasFullPath) then
  3219. begin
  3220. I := List.IndexOf(ProcessName);
  3221. if I > -1 then
  3222. Result := DWORD(List.Objects[I]);
  3223. end;
  3224. finally
  3225. List.Free;
  3226. end;
  3227. end;
  3228. function GetProcessNameFromPid(PID: DWORD): string;
  3229. var
  3230. List: TStringList;
  3231. I: Integer;
  3232. begin
  3233. // Note: there are other ways to retrieve the name of the process given it's
  3234. // PID but this implementation seems to work best without making assumptions
  3235. // although it may not be the most efficient implementation.
  3236. Result := '';
  3237. List := TStringList.Create;
  3238. try
  3239. if RunningProcessesList(List, True) then
  3240. begin
  3241. I := List.IndexOfObject(Pointer(PID));
  3242. if I > -1 then
  3243. Result := List[I];
  3244. end;
  3245. finally
  3246. List.Free;
  3247. end;
  3248. end;
  3249. {$ENDIF}
  3250. type
  3251. PSearch = ^TSearch;
  3252. TSearch = record
  3253. PID: DWORD;
  3254. Wnd: THandle;
  3255. end;
  3256. function EnumMainAppWindowsProc(Wnd: THandle; Res: PSearch): Boolean; stdcall;
  3257. var
  3258. WindowPid: DWORD;
  3259. begin
  3260. WindowPid := 0;
  3261. GetWindowThreadProcessId(Wnd, @WindowPid);
  3262. if (WindowPid = Res^.PID) and IsMainAppWindow(Wnd) then
  3263. begin
  3264. Res^.Wnd := Wnd;
  3265. Result := False;
  3266. end
  3267. else
  3268. Result := True;
  3269. end;
  3270. function GetMainAppWndFromPid(PID: DWORD): THandle;
  3271. var
  3272. SearchRec: TSearch;
  3273. begin
  3274. SearchRec.PID := PID;
  3275. SearchRec.Wnd := 0;
  3276. EnumWindows(@EnumMainAppWindowsProc, LPARAM(@SearchRec));
  3277. Result := SearchRec.Wnd;
  3278. end;
  3279. type
  3280. PEnumWndStruct = ^TEnumWndStruct;
  3281. TEnumWndStruct = record
  3282. PID: DWORD;
  3283. WndClassName: string;
  3284. ResultWnd: HWND;
  3285. end;
  3286. function EnumPidWinProc(Wnd: HWND; Enum: PEnumWndStruct): BOOL; stdcall;
  3287. var
  3288. PID: DWORD;
  3289. C: PChar;
  3290. CLen: Integer;
  3291. begin
  3292. Result := True;
  3293. GetWindowThreadProcessId(Wnd, @PID);
  3294. if (PID = Enum.PID) then
  3295. begin
  3296. CLen := Length(Enum.WndClassName)+1;
  3297. C := StrAlloc(CLen);
  3298. if (GetClassName(Wnd, C, CLen) > 0) and (C = Enum.WndClassName) then
  3299. begin
  3300. Result := False;
  3301. Enum.ResultWnd := Wnd;
  3302. end;
  3303. StrDispose(C);
  3304. end;
  3305. end;
  3306. function GetWndFromPid(PID: DWORD; const WindowClassName: string): HWND;
  3307. var
  3308. EnumWndStruct: TEnumWndStruct;
  3309. begin
  3310. EnumWndStruct.PID := PID;
  3311. EnumWndStruct.WndClassName := WindowClassName;
  3312. EnumWndStruct.ResultWnd := 0;
  3313. EnumWindows(@EnumPidWinProc, LPARAM(@EnumWndStruct));
  3314. Result := EnumWndStruct.ResultWnd;
  3315. end;
  3316. {$IFNDEF WINSCP}
  3317. function GetShellProcessName: string;
  3318. const
  3319. cShellKey = HKLM_CURRENT_VERSION_NT + '\WinLogon';
  3320. cShellValue = 'Shell';
  3321. cShellDefault = 'explorer.exe';
  3322. cShellSystemIniFileName = 'system.ini';
  3323. cShellBootSection = 'boot';
  3324. begin
  3325. if IsWinNT then
  3326. Result := RegReadStringDef(HKEY_LOCAL_MACHINE, cShellKey, cShellValue, '')
  3327. else
  3328. Result := IniReadString(PathAddSeparator(GetWindowsFolder) + cShellSystemIniFileName, cShellBootSection, cShellValue);
  3329. if Result = '' then
  3330. Result := cShellDefault;
  3331. end;
  3332. function GetShellProcessHandle: THandle;
  3333. var
  3334. Pid: Longword;
  3335. begin
  3336. Pid := GetPidFromProcessName(GetShellProcessName);
  3337. Result := OpenProcess(PROCESS_ALL_ACCESS, False, Pid);
  3338. if Result = 0 then
  3339. RaiseLastOSError;
  3340. end;
  3341. //=== Version Information ====================================================
  3342. { Q159/238
  3343. Windows 95 retail, OEM 4.00.950 7/11/95
  3344. Windows 95 retail SP1 4.00.950A 7/11/95-12/31/95
  3345. OEM Service Release 2 4.00.1111* (4.00.950B) 8/24/96
  3346. OEM Service Release 2.1 4.03.1212-1214* (4.00.950B) 8/24/96-8/27/97
  3347. OEM Service Release 2.5 4.03.1214* (4.00.950C) 8/24/96-11/18/97
  3348. Windows 98 retail, OEM 4.10.1998 5/11/98
  3349. Windows 98 Second Edition 4.10.2222A 4/23/99
  3350. Windows Millennium 4.90.3000
  3351. }
  3352. { TODO : Distinquish between all these different releases? }
  3353. var
  3354. KernelVersionHi: DWORD;
  3355. function GetWindowsVersion: TWindowsVersion;
  3356. var
  3357. TrimmedWin32CSDVersion: string;
  3358. SystemInfo: TSystemInfo;
  3359. OSVersionInfoEx: TOSVersionInfoEx;
  3360. Win32MajorVersionEx, Win32MinorVersionEx, WindowsReleaseId: integer;
  3361. ProductName: string;
  3362. const
  3363. SM_SERVERR2 = 89;
  3364. begin
  3365. Win32MajorVersionEx := -1;
  3366. Win32MinorVersionEx := -1;
  3367. Result := wvUnknown;
  3368. TrimmedWin32CSDVersion := Trim(Win32CSDVersion);
  3369. case Win32Platform of
  3370. VER_PLATFORM_WIN32_WINDOWS:
  3371. case Win32MinorVersion of
  3372. 0..9:
  3373. if (TrimmedWin32CSDVersion = 'B') or (TrimmedWin32CSDVersion = 'C') then
  3374. Result := wvWin95OSR2
  3375. else
  3376. Result := wvWin95;
  3377. 10..89:
  3378. // On Windows ME Win32MinorVersion can be 10 (indicating Windows 98
  3379. // under certain circumstances (image name is setup.exe). Checking
  3380. // the kernel version is one way of working around that.
  3381. if KernelVersionHi = $0004005A then // 4.90.x.x
  3382. Result := wvWinME
  3383. else
  3384. if (TrimmedWin32CSDVersion = 'A') or (TrimmedWin32CSDVersion = 'B') then
  3385. Result := wvWin98SE
  3386. else
  3387. Result := wvWin98;
  3388. 90:
  3389. Result := wvWinME;
  3390. end;
  3391. VER_PLATFORM_WIN32_NT:
  3392. case Win32MajorVersion of
  3393. 3:
  3394. case Win32MinorVersion of
  3395. 1:
  3396. Result := wvWinNT31;
  3397. 5:
  3398. Result := wvWinNT35;
  3399. 51:
  3400. Result := wvWinNT351;
  3401. end;
  3402. 4:
  3403. Result := wvWinNT4;
  3404. 5:
  3405. case Win32MinorVersion of
  3406. 0:
  3407. Result := wvWin2000;
  3408. 1:
  3409. Result := wvWinXP;
  3410. 2:
  3411. begin
  3412. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3413. SystemInfo.dwOemId := 0;
  3414. GetNativeSystemInfo(SystemInfo);
  3415. if GetSystemMetrics(SM_SERVERR2) <> 0 then
  3416. Result := wvWin2003R2
  3417. else
  3418. if (SystemInfo.wProcessorArchitecture <> PROCESSOR_ARCHITECTURE_INTEL) and
  3419. GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3420. Result := wvWinXP64
  3421. else
  3422. Result := wvWin2003;
  3423. end;
  3424. end;
  3425. 6:
  3426. begin
  3427. // Starting with Windows 8.1, the GetVersion(Ex) API is deprecated and will detect the
  3428. // application as Windows 8 (kernel version 6.2) until an application manifest is included
  3429. // See https://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
  3430. if Win32MinorVersion = 2 then
  3431. begin
  3432. ProductName := GetWindowsProductName;
  3433. if (Pos(RsOSVersionWin81, ProductName) = 1) or (Pos(RsOSVersionWinServer2012R2, ProductName) = 1) then
  3434. Win32MinorVersionEx := 3 // Windows 8.1 and Windows Server 2012R2
  3435. else
  3436. if (Pos(RsOSVersionWin8, ProductName) = 1) or (Pos(RsOSVersionWinServer2012, ProductName) = 1) then
  3437. Win32MinorVersionEx := 2 // Windows 8 and Windows Server 2012
  3438. else
  3439. begin
  3440. Win32MajorVersionEx := GetWindowsMajorVersionNumber;
  3441. if Win32MajorVersionEx = 6 then
  3442. Win32MinorVersionEx := 4 // Windows 10 (builds < 9926) and Windows Server 2016 (builds < 10074)
  3443. else
  3444. if Win32MajorVersionEx = 10 then
  3445. Win32MinorVersionEx := -1 // Windows 10 (builds >= 9926) and Windows Server 2016/2019/2022/2025 (builds >= 10074), set to -1 to escape case block
  3446. else
  3447. Win32MinorVersionEx := Win32MinorVersion;
  3448. end;
  3449. end
  3450. else
  3451. Win32MinorVersionEx := Win32MinorVersion;
  3452. case Win32MinorVersionEx of
  3453. 0:
  3454. begin
  3455. // Windows Vista and Windows Server 2008
  3456. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3457. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3458. Result := wvWinVista
  3459. else
  3460. Result := wvWinServer2008;
  3461. end;
  3462. 1:
  3463. begin
  3464. // Windows 7 and Windows Server 2008 R2
  3465. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3466. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3467. Result := wvWin7
  3468. else
  3469. Result := wvWinServer2008R2;
  3470. end;
  3471. 2:
  3472. begin
  3473. // Windows 8 and Windows Server 2012
  3474. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3475. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3476. Result := wvWin8
  3477. else
  3478. Result := wvWinServer2012;
  3479. end;
  3480. 3:
  3481. begin
  3482. // Windows 8.1 and Windows Server 2012 R2
  3483. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3484. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3485. Result := wvWin81
  3486. else
  3487. Result := wvWinServer2012R2;
  3488. end;
  3489. 4:
  3490. begin
  3491. // Windows 10 (builds < 9926) and Windows Server 2016 (builds < 10074)
  3492. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3493. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3494. Result := wvWin10
  3495. else
  3496. Result := wvWinServer2016;
  3497. end;
  3498. end;
  3499. end;
  3500. 10:
  3501. begin
  3502. // Windows 10 if manifest is present
  3503. Win32MajorVersionEx := Win32MajorVersion;
  3504. Win32MinorVersionEx := Win32MinorVersion;
  3505. end;
  3506. end;
  3507. end;
  3508. // This part will only be hit with Windows 10, Windows Server 2016 and beyond where an application manifest is not included
  3509. if (Win32MajorVersionEx >= 10) then
  3510. begin
  3511. case Win32MajorVersionEx of
  3512. 10:
  3513. begin
  3514. if (Win32MinorVersionEx = -1) then
  3515. Win32MinorVersionEx := GetWindowsMinorVersionNumber;
  3516. case Win32MinorVersionEx of
  3517. 0:
  3518. begin
  3519. // Windows 10 (builds >= 9926), Windows Server 2016 (builds >= 10074) and beyond
  3520. OSVersionInfoEx.dwOSVersionInfoSize := SizeOf(OSVersionInfoEx);
  3521. if GetVersionEx(OSVersionInfoEx) and (OSVersionInfoEx.wProductType = VER_NT_WORKSTATION) then
  3522. begin
  3523. if GetWindowsBuildNumber >= Windows11InitialBuildNumber then
  3524. Result := wvWin11
  3525. else
  3526. Result := wvWin10
  3527. end else
  3528. begin
  3529. WindowsReleaseId := StrToIntDef(ReadWindowsNTCurrentVersionStringValue('ReleaseId', '0'), -1);
  3530. case WindowsReleaseId of
  3531. 1607:
  3532. Result := wvWinServer2016;
  3533. 1809:
  3534. Result := wvWinServer2019;
  3535. 2009:
  3536. begin
  3537. if GetWindowsBuildNumber >= Windows2025ServerInitialBuildNumber then
  3538. Result := wvWinServer2025
  3539. else
  3540. Result := wvWinServer2022;
  3541. end
  3542. else
  3543. Result := wvWinServer;
  3544. end;
  3545. end;
  3546. end;
  3547. end;
  3548. end;
  3549. end;
  3550. end;
  3551. end;
  3552. function GetWindowsEdition: TWindowsEdition;
  3553. var
  3554. Edition: string;
  3555. begin
  3556. Result := weUnknown;
  3557. Edition := GetWindowsProductName;
  3558. // Remove (tm) in 'Windows (TM) Vista Ultimate'
  3559. Edition := StringReplace(Edition, '(TM) ', '', [rfReplaceAll, rfIgnoreCase]);
  3560. if Pos('Windows XP', Edition) = 1 then
  3561. begin
  3562. // Windows XP Editions
  3563. if Pos('Home Edition N', Edition) > 0 then
  3564. Result := weWinXPHomeN
  3565. else
  3566. if Pos('Professional N', Edition) > 0 then
  3567. Result := weWinXPProN
  3568. else
  3569. if Pos('Home Edition K', Edition) > 0 then
  3570. Result := weWinXPHomeK
  3571. else
  3572. if Pos('Professional K', Edition) > 0 then
  3573. Result := weWinXPProK
  3574. else
  3575. if Pos('Home Edition KN', Edition) > 0 then
  3576. Result := weWinXPHomeKN
  3577. else
  3578. if Pos('Professional KN', Edition) > 0 then
  3579. Result := weWinXPProKN
  3580. else
  3581. if Pos('Home', Edition) > 0 then
  3582. Result := weWinXPHome
  3583. else
  3584. if Pos('Professional', Edition) > 0 then
  3585. Result := weWinXPPro
  3586. else
  3587. if Pos('Starter', Edition) > 0 then
  3588. Result := weWinXPStarter
  3589. else
  3590. if Pos('Media Center', Edition) > 0 then
  3591. Result := weWinXPMediaCenter
  3592. else
  3593. if Pos('Tablet', Edition) > 0 then
  3594. Result := weWinXPTablet;
  3595. end
  3596. else
  3597. if (Pos('Windows Vista', Edition) = 1) then
  3598. begin
  3599. // Windows Vista Editions
  3600. if Pos('Starter', Edition) > 0 then
  3601. Result := weWinVistaStarter
  3602. else
  3603. if Pos('Home Basic N', Edition) > 0 then
  3604. Result := weWinVistaHomeBasicN
  3605. else
  3606. if Pos('Home Basic', Edition) > 0 then
  3607. Result := weWinVistaHomeBasic
  3608. else
  3609. if Pos('Home Premium', Edition) > 0 then
  3610. Result := weWinVistaHomePremium
  3611. else
  3612. if Pos('Business N', Edition) > 0 then
  3613. Result := weWinVistaBusinessN
  3614. else
  3615. if Pos('Business', Edition) > 0 then
  3616. Result := weWinVistaBusiness
  3617. else
  3618. if Pos('Enterprise', Edition) > 0 then
  3619. Result := weWinVistaEnterprise
  3620. else
  3621. if Pos('Ultimate', Edition) > 0 then
  3622. Result := weWinVistaUltimate;
  3623. end
  3624. else
  3625. if Pos('Windows 7', Edition) = 1 then
  3626. begin
  3627. // Windows 7 Editions
  3628. if Pos('Starter', Edition) > 0 then
  3629. Result := weWin7Starter
  3630. else
  3631. if Pos('Home Basic', Edition) > 0 then
  3632. Result := weWin7HomeBasic
  3633. else
  3634. if Pos('Home Premium', Edition) > 0 then
  3635. Result := weWin7HomePremium
  3636. else
  3637. if Pos('Professional', Edition) > 0 then
  3638. Result := weWin7Professional
  3639. else
  3640. if Pos('Enterprise', Edition) > 0 then
  3641. Result := weWin7Enterprise
  3642. else
  3643. if Pos('Ultimate', Edition) > 0 then
  3644. Result := weWin7Ultimate;
  3645. end
  3646. else
  3647. if Pos('Windows 8.1', Edition) = 1 then
  3648. begin
  3649. // Windows 8.1 Editions
  3650. if Pos('Pro', Edition) > 0 then
  3651. Result := weWin81Pro
  3652. else
  3653. if Pos('Enterprise', Edition) > 0 then
  3654. Result := weWin81Enterprise
  3655. else
  3656. Result := weWin81;
  3657. end
  3658. else
  3659. if Pos('Windows 8', Edition) = 1 then
  3660. begin
  3661. // Windows 8 Editions
  3662. if Pos('Pro', Edition) > 0 then
  3663. Result := weWin8Pro
  3664. else
  3665. if Pos('Enterprise', Edition) > 0 then
  3666. Result := weWin8Enterprise
  3667. else
  3668. Result := weWin8;
  3669. end
  3670. else
  3671. if Pos('Windows RT 8.1', Edition) = 1 then
  3672. Result := weWin81RT
  3673. else
  3674. if Pos('Windows RT', Edition) = 1 then
  3675. Result := weWin8RT
  3676. else
  3677. if Pos('Windows 10', Edition) = 1 then
  3678. begin
  3679. // Windows 10/11 Editions
  3680. if Pos('Home', Edition) > 0 then
  3681. Result := weWin10Home
  3682. else
  3683. if Pos('Pro', Edition) > 0 then
  3684. Result := weWin10Pro
  3685. else
  3686. if Pos('Enterprise', Edition) > 0 then
  3687. Result := weWin10Enterprise
  3688. else
  3689. if Pos('Education', Edition) > 0 then
  3690. Result := weWin10Education
  3691. else
  3692. Result := weWin10;
  3693. end;
  3694. end;
  3695. function NtProductType: TNtProductType;
  3696. const
  3697. ProductTypeKey = 'SYSTEM\CurrentControlSet\Control\ProductOptions';
  3698. var
  3699. Product: string;
  3700. OSVersionInfo: TOSVersionInfoEx;
  3701. SystemInfo: TSystemInfo;
  3702. begin
  3703. Result := ptUnknown;
  3704. ResetMemory(OSVersionInfo, SizeOf(OSVersionInfo));
  3705. ResetMemory(SystemInfo, SizeOf(SystemInfo));
  3706. OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);
  3707. GetNativeSystemInfo(SystemInfo);
  3708. // Favor documented API over registry
  3709. if IsWinNT4 and (GetWindowsServicePackVersion >= 6) then
  3710. begin
  3711. if GetVersionEx(OSVersionInfo) then
  3712. begin
  3713. if (OSVersionInfo.wProductType = VER_NT_WORKSTATION) then
  3714. Result := ptWorkstation
  3715. else
  3716. if (OSVersionInfo.wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
  3717. Result := ptEnterprise
  3718. else
  3719. Result := ptServer;
  3720. end;
  3721. end
  3722. else
  3723. if IsWin2K then
  3724. begin
  3725. if GetVersionEx(OSVersionInfo) then
  3726. begin
  3727. if OSVersionInfo.wProductType in [VER_NT_SERVER, VER_NT_DOMAIN_CONTROLLER] then
  3728. begin
  3729. if (OSVersionInfo.wSuiteMask and VER_SUITE_DATACENTER) <> 0 then
  3730. Result := ptDatacenterServer
  3731. else
  3732. if (OSVersionInfo.wSuiteMask and VER_SUITE_ENTERPRISE) <> 0 then
  3733. Result := ptAdvancedServer
  3734. else
  3735. Result := ptServer;
  3736. end
  3737. else
  3738. Result := ptProfessional;
  3739. end;
  3740. end
  3741. else
  3742. if IsWinXP64 or IsWin2003 or IsWin2003R2 then // all (5.2)
  3743. begin
  3744. if GetVersionEx(OSVersionInfo) then
  3745. begin
  3746. if OSVersionInfo.wProductType in [VER_NT_SERVER, VER_NT_DOMAIN_CONTROLLER] then
  3747. begin
  3748. if (OSVersionInfo.wSuiteMask and VER_SUITE_DATACENTER) = VER_SUITE_DATACENTER then
  3749. Result := ptDatacenterServer
  3750. else
  3751. if (OSVersionInfo.wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
  3752. Result := ptEnterprise
  3753. else
  3754. if (OSVersionInfo.wSuiteMask = VER_SUITE_BLADE) then
  3755. Result := ptWebEdition
  3756. else
  3757. Result := ptServer;
  3758. end
  3759. else
  3760. if (OSVersionInfo.wProductType = VER_NT_WORKSTATION) then
  3761. Result := ptProfessional;
  3762. end;
  3763. end
  3764. else
  3765. if JclCheckWinVersion(5, 1) then // Windows XP or newer
  3766. begin
  3767. if GetVersionEx(OSVersionInfo) then
  3768. begin
  3769. //if IsWinXP or IsWinVista or IsWin7 or IsWin8 or IsWin81 or IsWin10 or IsWin11 then
  3770. if OSVersionInfo.wProductType = VER_NT_WORKSTATION then // workstation
  3771. begin
  3772. if (OSVersionInfo.wSuiteMask and VER_SUITE_PERSONAL) = VER_SUITE_PERSONAL then
  3773. Result := ptPersonal
  3774. else
  3775. Result := ptProfessional;
  3776. end
  3777. else
  3778. //if IsWinServer2008 or IsWinServer2008R2 or IsWinServer2012 or IsWinServer2012R2 then
  3779. if OSVersionInfo.wProductType in [VER_NT_SERVER, VER_NT_DOMAIN_CONTROLLER] then // server
  3780. begin
  3781. if (OSVersionInfo.wSuiteMask and VER_SUITE_DATACENTER) = VER_SUITE_DATACENTER then
  3782. Result := ptDatacenterServer
  3783. else
  3784. if (OSVersionInfo.wSuiteMask and VER_SUITE_ENTERPRISE) = VER_SUITE_ENTERPRISE then
  3785. Result := ptEnterprise
  3786. else
  3787. Result := ptServer;
  3788. end;
  3789. end;
  3790. end;
  3791. if Result = ptUnknown then
  3792. begin
  3793. // Non Windows 2000/XP system or the above method failed, try registry
  3794. Product := RegReadStringDef(HKEY_LOCAL_MACHINE, ProductTypeKey, 'ProductType', '');
  3795. if CompareText(Product, 'WINNT') = 0 then
  3796. Result := ptWorkStation
  3797. else
  3798. if CompareText(Product, 'SERVERNT') = 0 then
  3799. Result := {ptServer} ptAdvancedServer
  3800. else
  3801. if CompareText(Product, 'LANMANNT') = 0 then
  3802. Result := {ptAdvancedServer} ptServer
  3803. else
  3804. Result := ptUnknown;
  3805. end;
  3806. end;
  3807. function GetWindowsVersionString: string;
  3808. begin
  3809. case GetWindowsVersion of
  3810. wvWin95:
  3811. Result := LoadResString(@RsOSVersionWin95);
  3812. wvWin95OSR2:
  3813. Result := LoadResString(@RsOSVersionWin95OSR2);
  3814. wvWin98:
  3815. Result := LoadResString(@RsOSVersionWin98);
  3816. wvWin98SE:
  3817. Result := LoadResString(@RsOSVersionWin98SE);
  3818. wvWinME:
  3819. Result := LoadResString(@RsOSVersionWinME);
  3820. wvWinNT31, wvWinNT35, wvWinNT351:
  3821. Result := Format(LoadResString(@RsOSVersionWinNT3), [Win32MinorVersion]);
  3822. wvWinNT4:
  3823. Result := Format(LoadResString(@RsOSVersionWinNT4), [Win32MinorVersion]);
  3824. wvWin2000:
  3825. Result := LoadResString(@RsOSVersionWin2000);
  3826. wvWinXP:
  3827. Result := LoadResString(@RsOSVersionWinXP);
  3828. wvWin2003:
  3829. Result := LoadResString(@RsOSVersionWin2003);
  3830. wvWin2003R2:
  3831. Result := LoadResString(@RsOSVersionWin2003R2);
  3832. wvWinXP64:
  3833. Result := LoadResString(@RsOSVersionWinXP64);
  3834. wvWinVista:
  3835. Result := LoadResString(@RsOSVersionWinVista);
  3836. wvWinServer2008:
  3837. Result := LoadResString(@RsOSVersionWinServer2008);
  3838. wvWin7:
  3839. Result := LoadResString(@RsOSVersionWin7);
  3840. wvWinServer2008R2:
  3841. Result := LoadResString(@RsOSVersionWinServer2008R2);
  3842. wvWin8:
  3843. Result := LoadResString(@RsOSVersionWin8);
  3844. wvWin8RT:
  3845. Result := LoadResString(@RsOSVersionWin8RT);
  3846. wvWinServer2012:
  3847. Result := LoadResString(@RsOSVersionWinServer2012);
  3848. wvWin81:
  3849. Result := LoadResString(@RsOSVersionWin81);
  3850. wvWin81RT:
  3851. Result := LoadResString(@RsOSVersionWin81RT);
  3852. wvWinServer2012R2:
  3853. Result := LoadResString(@RsOSVersionWinServer2012R2);
  3854. wvWin10:
  3855. Result := LoadResString(@RsOSVersionWin10);
  3856. wvWinServer2016:
  3857. Result := LoadResString(@RsOSVersionWinServer2016);
  3858. wvWinServer2019:
  3859. Result := LoadResString(@RsOSVersionWinServer2019);
  3860. wvWinServer2022:
  3861. Result := LoadResString(@RsOSVersionWinServer2022);
  3862. wvWinServer2025:
  3863. Result := LoadResString(@RsOSVersionWinServer2025);
  3864. wvWinServer:
  3865. Result := LoadResString(@RsOSVersionWinServer);
  3866. wvWin11:
  3867. Result := LoadResString(@RsOSVersionWin11);
  3868. else
  3869. Result := '';
  3870. end;
  3871. end;
  3872. function GetWindowsEditionString: string;
  3873. begin
  3874. case GetWindowsEdition of
  3875. weWinXPHome:
  3876. Result := LoadResString(@RsEditionWinXPHome);
  3877. weWinXPPro:
  3878. Result := LoadResString(@RsEditionWinXPPro);
  3879. weWinXPHomeN:
  3880. Result := LoadResString(@RsEditionWinXPHomeN);
  3881. weWinXPProN:
  3882. Result := LoadResString(@RsEditionWinXPProN);
  3883. weWinXPHomeK:
  3884. Result := LoadResString(@RsEditionWinXPHomeK);
  3885. weWinXPProK:
  3886. Result := LoadResString(@RsEditionWinXPProK);
  3887. weWinXPHomeKN:
  3888. Result := LoadResString(@RsEditionWinXPHomeKN);
  3889. weWinXPProKN:
  3890. Result := LoadResString(@RsEditionWinXPProKN);
  3891. weWinXPStarter:
  3892. Result := LoadResString(@RsEditionWinXPStarter);
  3893. weWinXPMediaCenter:
  3894. Result := LoadResString(@RsEditionWinXPMediaCenter);
  3895. weWinXPTablet:
  3896. Result := LoadResString(@RsEditionWinXPTablet);
  3897. weWinVistaStarter:
  3898. Result := LoadResString(@RsEditionWinVistaStarter);
  3899. weWinVistaHomeBasic:
  3900. Result := LoadResString(@RsEditionWinVistaHomeBasic);
  3901. weWinVistaHomeBasicN:
  3902. Result := LoadResString(@RsEditionWinVistaHomeBasicN);
  3903. weWinVistaHomePremium:
  3904. Result := LoadResString(@RsEditionWinVistaHomePremium);
  3905. weWinVistaBusiness:
  3906. Result := LoadResString(@RsEditionWinVistaBusiness);
  3907. weWinVistaBusinessN:
  3908. Result := LoadResString(@RsEditionWinVistaBusinessN);
  3909. weWinVistaEnterprise:
  3910. Result := LoadResString(@RsEditionWinVistaEnterprise);
  3911. weWinVistaUltimate:
  3912. Result := LoadResString(@RsEditionWinVistaUltimate);
  3913. weWin7Starter:
  3914. Result := LoadResString(@RsEditionWin7Starter);
  3915. weWin7HomeBasic:
  3916. Result := LoadResString(@RsEditionWin7HomeBasic);
  3917. weWin7HomePremium:
  3918. Result := LoadResString(@RsEditionWin7HomePremium);
  3919. weWin7Professional:
  3920. Result := LoadResString(@RsEditionWin7Professional);
  3921. weWin7Enterprise:
  3922. Result := LoadResString(@RsEditionWin7Enterprise);
  3923. weWin7Ultimate:
  3924. Result := LoadResString(@RsEditionWin7Ultimate);
  3925. weWin8Pro:
  3926. Result := LoadResString(@RsEditionWin8Pro);
  3927. weWin8Enterprise:
  3928. Result := LoadResString(@RsEditionWin8Enterprise);
  3929. weWin8RT:
  3930. Result := LoadResString(@RsEditionWin8RT);
  3931. weWin81Pro:
  3932. Result := LoadResString(@RsEditionWin81Pro);
  3933. weWin81Enterprise:
  3934. Result := LoadResString(@RsEditionWin81Enterprise);
  3935. weWin81RT:
  3936. Result := LoadResString(@RsEditionWin81RT);
  3937. weWin10Home:
  3938. Result := LoadResString(@RsEditionWin10Home);
  3939. weWin10Pro:
  3940. Result := LoadResString(@RsEditionWin10Pro);
  3941. weWin10Enterprise:
  3942. Result := LoadResString(@RsEditionWin10Enterprise);
  3943. weWin10Education:
  3944. Result := LoadResString(@RsEditionWin10Education);
  3945. else
  3946. Result := '';
  3947. end;
  3948. end;
  3949. function GetWindowsProductString: string;
  3950. begin
  3951. Result := GetWindowsVersionString;
  3952. if GetWindowsEditionString <> '' then
  3953. Result := Result + ' ' + GetWindowsEditionString;
  3954. end;
  3955. function GetWindowsProductName: string;
  3956. begin
  3957. // On Windows 10/11, the productname in the 'WOW6432Node' key differs from the value
  3958. // in the 'native' registry key, resulting in incorrected info en edition detection!
  3959. // It is not known, whether this is aldo the case for older Windows versions,
  3960. // which alos have the 'WOW6432Node' registry key.
  3961. Result := ReadWindowsNTCurrentVersionStringValue('ProductName', '', IsWin10 or IsWin11);
  3962. end;
  3963. function NtProductTypeString: string;
  3964. begin
  3965. case NtProductType of
  3966. ptWorkStation:
  3967. Result := LoadResString(@RsProductTypeWorkStation);
  3968. ptServer:
  3969. Result := LoadResString(@RsProductTypeServer);
  3970. ptAdvancedServer:
  3971. Result := LoadResString(@RsProductTypeAdvancedServer);
  3972. ptPersonal:
  3973. Result := LoadResString(@RsProductTypePersonal);
  3974. ptProfessional:
  3975. Result := LoadResString(@RsProductTypeProfessional);
  3976. ptDatacenterServer:
  3977. Result := LoadResString(@RsProductTypeDatacenterServer);
  3978. ptEnterprise:
  3979. Result := LoadResString(@RsProductTypeEnterprise);
  3980. ptWebEdition:
  3981. Result := LoadResString(@RsProductTypeWebEdition);
  3982. else
  3983. Result := '';
  3984. end;
  3985. end;
  3986. function GetWindowsBuildNumber: Integer;
  3987. begin
  3988. // Starting with Windows 8.1, the GetVersion(Ex) API is deprecated and will detect the
  3989. // application as Windows 8 (kernel version 6.2) until an application manifest is included
  3990. // See https://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
  3991. if ((Win32MajorVersion = 6) and (Win32MinorVersion = 2)) or (Win32MajorVersion = 10) then
  3992. Result := StrToIntDef(ReadWindowsNTCurrentVersionStringValue('CurrentBuildNumber', IntToStr(Win32BuildNumber)), Win32BuildNumber)
  3993. else
  3994. Result := Win32BuildNumber;
  3995. end;
  3996. {$ENDIF WINSCP}
  3997. function GetWindowsMajorVersionNumber: Integer;
  3998. {$IFNDEF WINSCP}
  3999. var
  4000. Ver: string;
  4001. I: Integer;
  4002. {$ENDIF WINSCP}
  4003. begin
  4004. {$IFNDEF WINSCP}
  4005. // WINSCP: We have the manifest
  4006. // Starting with Windows 8.1, the GetVersion(Ex) API is deprecated and will detect the
  4007. // application as Windows 8 (kernel version 6.2) until an application manifest is included
  4008. // See https://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
  4009. if ((Win32MajorVersion = 6) and (Win32MinorVersion = 2)) or (Win32MajorVersion = 10) then
  4010. begin
  4011. // CurrentMajorVersionNumber present in registry starting with Windows 10
  4012. // If CurrentMajorVersionNumber not present in registry then use CurrentVersion
  4013. Result := ReadWindowsNTCurrentVersionIntegerValue('CurrentMajorVersionNumber', -1);
  4014. if Result = -1 then
  4015. begin
  4016. Ver := ReadWindowsNTCurrentVersionStringValue('CurrentVersion', IntToStr(Win32MajorVersion) + '.' + IntToStr(Win32MinorVersion));
  4017. I := Pos('.', Ver);
  4018. if I > 0 then
  4019. Result := StrToIntDef(Copy(Ver, 1, I - 1), Win32MajorVersion) // don't use StrBefore because it uses StrCaseMap that may not be initialized yet
  4020. else
  4021. Result := StrToIntDef(Ver, Win32MajorVersion);
  4022. end;
  4023. end
  4024. else
  4025. {$ENDIF WINSCP}
  4026. Result := Win32MajorVersion;
  4027. end;
  4028. function GetWindowsMinorVersionNumber: Integer;
  4029. {$IFNDEF WINSCP}
  4030. var
  4031. Ver: string;
  4032. I: Integer;
  4033. {$ENDIF WINSCP}
  4034. begin
  4035. {$IFNDEF WINSCP}
  4036. // WINSCP: We have the manifest
  4037. // Starting with Windows 8.1, the GetVersion(Ex) API is deprecated and will detect the
  4038. // application as Windows 8 (kernel version 6.2) until an application manifest is included
  4039. // See https://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
  4040. if ((Win32MajorVersion = 6) and (Win32MinorVersion = 2)) or (Win32MajorVersion = 10) then
  4041. begin
  4042. // CurrentMinorVersionNumber present in registry starting with Windows 10
  4043. // If CurrentMinorVersionNumber not present then use CurrentVersion
  4044. Result := ReadWindowsNTCurrentVersionIntegerValue('CurrentMinorVersionNumber', -1);
  4045. if Result = -1 then
  4046. begin
  4047. Ver := ReadWindowsNTCurrentVersionStringValue('CurrentVersion', IntToStr(Win32MajorVersion) + '.' + IntToStr(Win32MinorVersion));
  4048. I := Pos('.', Ver);
  4049. if (I > 0) and (I < Length(Ver)) then
  4050. Result := StrToIntDef(Copy(Ver, I + 1, Length(Ver)), 2) // don't use StrAfter because it uses StrCaseMap that may not be initialized yet
  4051. else
  4052. Result := 2;
  4053. end;
  4054. end
  4055. else
  4056. {$ENDIF WINSCP}
  4057. Result := Win32MinorVersion;
  4058. end;
  4059. function GetWindowsVersionNumber: string;
  4060. begin
  4061. // Returns version number as MajorVersionNumber.MinorVersionNumber (string type)
  4062. Result := Format('%d.%d', [GetWindowsMajorVersionNumber, GetWindowsMinorVersionNumber]);
  4063. end;
  4064. function GetWindowsServicePackVersion: Integer;
  4065. const
  4066. RegWindowsControl = 'SYSTEM\CurrentControlSet\Control\Windows';
  4067. var
  4068. {$IFNDEF WINSCP}
  4069. SP: Integer;
  4070. {$ENDIF ~WINSCP}
  4071. VersionInfo: TOSVersionInfoEx;
  4072. begin
  4073. Result := 0;
  4074. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion >= 5) then // 2000/XP and newer
  4075. begin
  4076. ResetMemory(VersionInfo, SizeOf(VersionInfo));
  4077. VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
  4078. if GetVersionEx(VersionInfo) then
  4079. Result := VersionInfo.wServicePackMajor;
  4080. end
  4081. {$IFNDEF WINSCP}
  4082. // WINSCP: We support Windows XP (5.1) and newer only
  4083. else
  4084. begin
  4085. SP := RegReadIntegerDef(HKEY_LOCAL_MACHINE, RegWindowsControl, 'CSDVersion', 0);
  4086. try
  4087. Result := StrToInt(IntToHex(SP, 4)) div 100; // 0x0200 => 02.00 => 2
  4088. except
  4089. on EConvertError do
  4090. Result := 0;
  4091. end;
  4092. {$ENDIF ~WINSCP}
  4093. end;
  4094. function GetWindowsServicePackVersionString: string;
  4095. var
  4096. SP: Integer;
  4097. begin
  4098. SP := GetWindowsServicePackVersion;
  4099. if SP > 0 then
  4100. Result := Format(LoadResString(@RsSPInfo), [SP])
  4101. else
  4102. Result := '';
  4103. end;
  4104. {$IFNDEF WINSCP}
  4105. function GetWindowsDisplayVersion: string;
  4106. begin
  4107. // Starting with Windows 10 20H2, the DisplayVersion registry entry is being populated ("20H2")
  4108. if IsWin10 or IsWin11 or IsWinServer then
  4109. Result := ReadWindowsNTCurrentVersionStringValue('DisplayVersion', '')
  4110. else
  4111. Result := '';
  4112. end;
  4113. function GetWindowsReleaseId: Integer;
  4114. begin
  4115. // Starting with Windows 10 21H1, the ReleaseId registry entry is no more incremented (still populated as "2009" like Windows 10 20H2 and Windows 11)
  4116. // and the DisplayVersion registry entry is to be used instead ("20H2")
  4117. if IsWin10 or IsWin11 or IsWinServer then
  4118. Result := StrToIntDef(ReadWindowsNTCurrentVersionStringValue('ReleaseId', '0'), -1)
  4119. else
  4120. Result := -1;
  4121. end;
  4122. function GetWindowsReleaseName: String;
  4123. var
  4124. WindowsDisplayVersion: string;
  4125. begin
  4126. if IsWin10 then
  4127. begin
  4128. case GetWindowsReleaseId of
  4129. 1507:
  4130. Result := ''; // RTM
  4131. 1511:
  4132. Result := 'November Update';
  4133. 1607:
  4134. Result := 'Anniversary Update';
  4135. 1703:
  4136. Result := 'Creators Update';
  4137. 1709:
  4138. Result := 'Fall Creators Update';
  4139. 1803:
  4140. Result := 'April 2018 Update';
  4141. 1809:
  4142. Result := 'October 2018 Update';
  4143. 1903:
  4144. Result := 'May 2019 Update';
  4145. 1909:
  4146. Result := 'November 2019 Update';
  4147. 2004:
  4148. Result := 'May 2020 Update';
  4149. 2009:
  4150. begin
  4151. WindowsDisplayVersion := GetWindowsDisplayVersion;
  4152. if WindowsDisplayVersion = '20H2' then
  4153. Result := 'October 2020 Update'
  4154. else
  4155. if WindowsDisplayVersion = '21H1' then
  4156. Result := 'May 2021 Update'
  4157. else
  4158. if WindowsDisplayVersion = '21H2' then
  4159. Result := 'November 2021 Update'
  4160. else
  4161. if WindowsDisplayVersion = '22H2' then
  4162. Result := '2022 Update'
  4163. else
  4164. Result := WindowsDisplayVersion + ' Update';
  4165. end
  4166. else
  4167. Result := IntToStr(GetWindowsReleaseId) + ' Update';
  4168. end;
  4169. Result := Trim(GetWindowsVersionString + ' ' + Result);
  4170. end
  4171. else if IsWin11 then // And higher versions too?
  4172. begin
  4173. // WindowsReleaseId = 2009 for Win 11
  4174. Result := '';
  4175. WindowsDisplayVersion := GetWindowsDisplayVersion;
  4176. if WindowsDisplayVersion = '21H2' then
  4177. Result := '' // RTM
  4178. else
  4179. if WindowsDisplayVersion = '22H2' then
  4180. Result := '2022 Update'
  4181. else
  4182. if WindowsDisplayVersion = '23H2' then
  4183. Result := '2023 Update'
  4184. else
  4185. if WindowsDisplayVersion = '24H2' then
  4186. Result := '2024 Update'
  4187. else
  4188. Result := WindowsDisplayVersion + ' Update';
  4189. Result := Trim(GetWindowsVersionString + ' ' + Result);
  4190. end
  4191. else
  4192. Result := '';
  4193. end;
  4194. function GetWindowsReleaseCode: String;
  4195. var
  4196. WindowsReleaseId: Integer;
  4197. begin
  4198. // Looks much like the 'GetWindowsReleaseCodeName', except for the Windows 10 versions
  4199. // prior to Release Id 1903 - those have a different 'code' vs the 'code name'.
  4200. if IsWin10 then
  4201. begin
  4202. WindowsReleaseId := GetWindowsReleaseId;
  4203. if WindowsReleaseId < 1903 then
  4204. Result := IntToStr(WindowsReleaseId)
  4205. else
  4206. case WindowsReleaseId of
  4207. 1903:
  4208. Result := '19H1';
  4209. 1909:
  4210. Result := '19H2';
  4211. 2004:
  4212. Result := '20H1';
  4213. 2009:
  4214. Result := GetWindowsDisplayVersion;
  4215. else
  4216. Result := '';
  4217. end;
  4218. end
  4219. else
  4220. Result := GetWindowsDisplayVersion;
  4221. end;
  4222. function GetWindowsReleaseCodeName: String;
  4223. begin
  4224. if IsWin10 then
  4225. begin
  4226. case GetWindowsReleaseId of
  4227. 1507:
  4228. Result := 'Threshold 1';
  4229. 1511:
  4230. Result := 'Threshold 2';
  4231. 1607:
  4232. Result := 'Redstone 1';
  4233. 1703:
  4234. Result := 'Redstone 2';
  4235. 1709:
  4236. Result := 'Redstone 3';
  4237. 1803:
  4238. Result := 'Redstone 4';
  4239. 1809:
  4240. Result := 'Redstone 5';
  4241. 1903:
  4242. Result := '19H1';
  4243. 1909:
  4244. Result := '19H2';
  4245. 2004:
  4246. Result := '20H1';
  4247. 2009:
  4248. Result := GetWindowsDisplayVersion;
  4249. else
  4250. Result := '';
  4251. end;
  4252. end
  4253. else
  4254. Result := GetWindowsDisplayVersion;
  4255. end;
  4256. function GetWindowsReleaseVersion: String;
  4257. var
  4258. WindowsReleaseId: Integer;
  4259. begin
  4260. if IsWin10 then
  4261. begin
  4262. WindowsReleaseId := GetWindowsReleaseId;
  4263. if WindowsReleaseId > 0 then
  4264. begin
  4265. if WindowsReleaseId < 2009 then
  4266. Result := LoadResString(@RsOSVersionWin10) + ', version ' + IntToStr(WindowsReleaseId)
  4267. else
  4268. Result := LoadResString(@RsOSVersionWin10) + ', version ' + GetWindowsDisplayVersion
  4269. end
  4270. else
  4271. Result := '';
  4272. end
  4273. else if IsWinServer then
  4274. begin
  4275. WindowsReleaseId := GetWindowsReleaseId;
  4276. if WindowsReleaseId > 0 then
  4277. begin
  4278. if WindowsReleaseId < 2009 then
  4279. Result := LoadResString(@RsOSVersionWinServer) + ', version ' + IntToStr(WindowsReleaseId)
  4280. else
  4281. Result := LoadResString(@RsOSVersionWinServer) + ', version ' + GetWindowsDisplayVersion
  4282. end
  4283. else
  4284. Result := '';
  4285. end
  4286. else if IsWin11 then // And higher versions too?
  4287. Result := GetWindowsVersionString + ', version ' + GetWindowsDisplayVersion
  4288. else
  4289. Result := '';
  4290. end;
  4291. function GetWindows10DisplayVersion: string;
  4292. begin
  4293. if IsWin10 then
  4294. Result := GetWindowsDisplayVersion()
  4295. else
  4296. Result := '';
  4297. end;
  4298. function GetWindows10ReleaseId: Integer;
  4299. begin
  4300. if IsWin10 then
  4301. Result := GetWindowsReleaseId()
  4302. else
  4303. Result := -1;
  4304. end;
  4305. function GetWindows10ReleaseName: String;
  4306. begin
  4307. if IsWin10 then
  4308. Result := GetWindowsReleaseName()
  4309. else
  4310. Result := '';
  4311. end;
  4312. function GetWindows10ReleaseCodeName: String;
  4313. begin
  4314. if IsWin10 then
  4315. Result := GetWindowsReleaseCodeName()
  4316. else
  4317. Result := '';
  4318. end;
  4319. function GetWindows10ReleaseVersion: String;
  4320. begin
  4321. if IsWin10 then
  4322. Result := GetWindowsReleaseVersion()
  4323. else
  4324. Result := '';
  4325. end;
  4326. function GetWindowsServerDisplayVersion: string;
  4327. begin
  4328. if IsWinServer then
  4329. Result := GetWindowsDisplayVersion()
  4330. else
  4331. Result := '';
  4332. end;
  4333. function GetWindowsServerReleaseId: Integer;
  4334. begin
  4335. if IsWinServer then
  4336. Result := GetWindowsReleaseId()
  4337. else
  4338. Result := -1;
  4339. end;
  4340. function GetWindowsServerReleaseVersion: String;
  4341. begin
  4342. if IsWinServer then
  4343. Result := GetWindowsReleaseVersion()
  4344. else
  4345. Result := '';
  4346. end;
  4347. // Imports copied from OpenGL unit. Direct using of OpenGL unit might cause unexpected problems due
  4348. // setting 8087CW in the intialization section
  4349. {
  4350. function glGetString(name: Cardinal): PChar; stdcall; external opengl32;
  4351. function glGetError: Cardinal; stdcall; external opengl32;
  4352. function gluErrorString(errCode: Cardinal): PChar; stdcall; external 'glu32.dll';
  4353. }
  4354. type
  4355. TglGetStringFunc = function(name: Cardinal): PAnsiChar; stdcall;
  4356. TglGetErrorFunc = function: Cardinal; stdcall;
  4357. TgluErrorStringFunc = function(errCode: Cardinal): PAnsiChar; stdcall;
  4358. TwglCreateContextFunc = function(DC: HDC): HGLRC; stdcall;
  4359. TwglDeleteContextFunc = function(p1: HGLRC): BOOL; stdcall;
  4360. TwglMakeCurrentFunc = function(DC: HDC; p2: HGLRC): BOOL; stdcall;
  4361. const
  4362. glu32 = 'glu32.dll'; // do not localize
  4363. glGetStringName = 'glGetString'; // do not localize
  4364. glGetErrorName = 'glGetError'; // do not localize
  4365. gluErrorStringName = 'gluErrorString'; // do not localize
  4366. wglCreateContextName = 'wglCreateContext'; // do not localize
  4367. wglDeleteContextName = 'wglDeleteContext'; // do not localize
  4368. wglMakeCurrentName = 'wglMakeCurrent'; // do not localize
  4369. ChoosePixelFormatName = 'ChoosePixelFormat'; // do not localize
  4370. SetPixelFormatName = 'SetPixelFormat'; // do not localize
  4371. function GetOpenGLVersion(const Win: THandle; out Version, Vendor: AnsiString): Boolean;
  4372. const
  4373. GL_NO_ERROR = 0;
  4374. GL_VENDOR = $1F00;
  4375. GL_VERSION = $1F02;
  4376. var
  4377. OpenGlLib, Glu32Lib: HModule;
  4378. glGetStringFunc: TglGetStringFunc;
  4379. glGetErrorFunc: TglGetErrorFunc;
  4380. gluErrorStringFunc: TgluErrorStringFunc;
  4381. wglCreateContextFunc: TwglCreateContextFunc;
  4382. wglDeleteContextFunc: TwglDeleteContextFunc;
  4383. wglMakeCurrentFunc: TwglMakeCurrentFunc;
  4384. pfd: TPixelFormatDescriptor;
  4385. iFormatIndex: Integer;
  4386. hGLContext: HGLRC;
  4387. hGLDC: HDC;
  4388. pcTemp: PAnsiChar;
  4389. glErr: Cardinal;
  4390. bError: Boolean;
  4391. sOpenGLVersion, sOpenGLVendor: AnsiString;
  4392. Save8087CW: Word;
  4393. procedure FunctionFailedError(Name: string);
  4394. begin
  4395. raise EJclError.CreateResFmt(@RsEOpenGLInfo, [Name]);
  4396. end;
  4397. begin
  4398. @glGetStringFunc := nil;
  4399. @glGetErrorFunc := nil;
  4400. @gluErrorStringFunc := nil;
  4401. @wglCreateContextFunc := nil;
  4402. @wglDeleteContextFunc := nil;
  4403. @wglMakeCurrentFunc := nil;
  4404. Glu32Lib := 0;
  4405. OpenGlLib := SafeLoadLibrary(opengl32);
  4406. try
  4407. if OpenGlLib <> 0 then
  4408. begin
  4409. Glu32Lib := SafeLoadLibrary(glu32); // do not localize
  4410. if (OpenGlLib <> 0) and (Glu32Lib <> 0) then
  4411. begin
  4412. glGetStringFunc := GetProcAddress(OpenGlLib, glGetStringName);
  4413. glGetErrorFunc := GetProcAddress(OpenGlLib, glGetErrorName);
  4414. gluErrorStringFunc := GetProcAddress(Glu32Lib, gluErrorStringName);
  4415. wglCreateContextFunc := GetProcAddress(OpenGlLib, wglCreateContextName);
  4416. wglDeleteContextFunc := GetProcAddress(OpenGlLib, wglDeleteContextName);
  4417. wglMakeCurrentFunc := GetProcAddress(OpenGlLib, wglMakeCurrentName);
  4418. end;
  4419. end;
  4420. if not (Assigned(glGetStringFunc) and Assigned(glGetErrorFunc) and Assigned(gluErrorStringFunc) and
  4421. Assigned(wglCreateContextFunc) and Assigned(wglDeleteContextFunc) and Assigned(wglMakeCurrentFunc)) then
  4422. begin
  4423. @glGetStringFunc := nil;
  4424. Result := False;
  4425. Vendor := AnsiString(LoadResString(@RsOpenGLInfoError));
  4426. Version := AnsiString(LoadResString(@RsOpenGLInfoError));
  4427. Exit;
  4428. end;
  4429. { To call for the version information string we must first have an active
  4430. context established for use. We can, of course, close this after use }
  4431. Save8087CW := Get8087ControlWord;
  4432. try
  4433. Set8087CW($133F);
  4434. hGLContext := 0;
  4435. Result := False;
  4436. bError := False;
  4437. if Win = 0 then
  4438. begin
  4439. Result := False;
  4440. Vendor := AnsiString(LoadResString(@RsOpenGLInfoError));
  4441. Version := AnsiString(LoadResString(@RsOpenGLInfoError));
  4442. Exit;
  4443. end;
  4444. ResetMemory(pfd, SizeOf(pfd));
  4445. with pfd do
  4446. begin
  4447. nSize := SizeOf(pfd);
  4448. nVersion := 1; { The Current Version of the descriptor is 1 }
  4449. dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
  4450. iPixelType := PFD_TYPE_RGBA;
  4451. cColorBits := 24; { support 24-bit colour }
  4452. cDepthBits := 32; { Depth of the z-buffer }
  4453. iLayerType := PFD_MAIN_PLANE;
  4454. end;
  4455. hGLDC := GetDC(Win);
  4456. try
  4457. iFormatIndex := ChoosePixelFormat(hGLDC, @pfd);
  4458. if iFormatIndex = 0 then
  4459. FunctionFailedError(ChoosePixelFormatName);
  4460. if not SetPixelFormat(hGLDC, iFormatIndex, @pfd) then
  4461. FunctionFailedError(SetPixelFormatName);
  4462. hGLContext := wglCreateContextFunc(hGLDC);
  4463. if hGLContext = 0 then
  4464. FunctionFailedError(wglCreateContextName);
  4465. if not wglMakeCurrentFunc(hGLDC, hGLContext) then
  4466. FunctionFailedError(wglMakeCurrentName);
  4467. { TODO : Review the following. Not sure I am 100% happy with this code
  4468. in its current structure. }
  4469. pcTemp := glGetStringFunc(GL_VERSION);
  4470. if pcTemp <> nil then
  4471. begin
  4472. { TODO : Store this information in a Global Variable, and return that??
  4473. This would save this work being performed again with later calls }
  4474. sOpenGLVersion := StrPasA(pcTemp);
  4475. end
  4476. else
  4477. begin
  4478. bError := True;
  4479. glErr := glGetErrorFunc;
  4480. if glErr <> GL_NO_ERROR then
  4481. begin
  4482. sOpenGLVersion := gluErrorStringFunc(glErr);
  4483. sOpenGLVendor := '';
  4484. end;
  4485. end;
  4486. pcTemp := glGetStringFunc(GL_VENDOR);
  4487. if pcTemp <> nil then
  4488. begin
  4489. { TODO : Store this information in a Global Variable, and return that??
  4490. This would save this work being performed again with later calls }
  4491. sOpenGLVendor := StrPasA(pcTemp);
  4492. end
  4493. else
  4494. begin
  4495. bError := True;
  4496. glErr := glGetErrorFunc;
  4497. if glErr <> GL_NO_ERROR then
  4498. begin
  4499. sOpenGLVendor := gluErrorStringFunc(glErr);
  4500. Exit;
  4501. end;
  4502. end;
  4503. Result := (not bError);
  4504. Version := sOpenGLVersion;
  4505. Vendor := sOpenGLVendor;
  4506. finally
  4507. { Close all resources }
  4508. wglMakeCurrentFunc(hGLDC, 0);
  4509. if hGLContext <> 0 then
  4510. wglDeleteContextFunc(hGLContext);
  4511. end;
  4512. finally
  4513. Set8087CW(Save8087CW);
  4514. end;
  4515. finally
  4516. if (OpenGlLib <> 0) then
  4517. FreeLibrary(OpenGlLib);
  4518. if (Glu32Lib <> 0) then
  4519. FreeLibrary(Glu32Lib);
  4520. end;
  4521. end;
  4522. {$ENDIF ~WINSCP}
  4523. function GetNativeSystemInfo(var SystemInfo: TSystemInfo): Boolean;
  4524. type
  4525. TGetNativeSystemInfo = procedure (var SystemInfo: TSystemInfo); stdcall;
  4526. var
  4527. LibraryHandle: HMODULE;
  4528. _GetNativeSystemInfo: TGetNativeSystemInfo;
  4529. begin
  4530. Result := False;
  4531. LibraryHandle := GetModuleHandle(kernel32);
  4532. if LibraryHandle <> 0 then
  4533. begin
  4534. _GetNativeSystemInfo := GetProcAddress(LibraryHandle, PAnsiChar('GetNativeSystemInfo'));
  4535. if Assigned(_GetNativeSystemInfo) then
  4536. begin
  4537. _GetNativeSystemInfo(SystemInfo);
  4538. Result := True;
  4539. end
  4540. else
  4541. GetSystemInfo(SystemInfo);
  4542. end
  4543. else
  4544. GetSystemInfo(SystemInfo);
  4545. end;
  4546. var
  4547. CachedGetProcessorArchitecture: DWORD = DWORD(-1);
  4548. function GetProcessorArchitecture: TProcessorArchitecture;
  4549. var
  4550. ASystemInfo: TSystemInfo;
  4551. begin
  4552. if CachedGetProcessorArchitecture = DWORD(-1) then
  4553. begin
  4554. ASystemInfo.dwOemId := 0;
  4555. GetNativeSystemInfo(ASystemInfo);
  4556. CachedGetProcessorArchitecture := ASystemInfo.wProcessorArchitecture;
  4557. end;
  4558. case CachedGetProcessorArchitecture of
  4559. PROCESSOR_ARCHITECTURE_INTEL:
  4560. Result := pax8632;
  4561. PROCESSOR_ARCHITECTURE_IA64:
  4562. Result := paIA64;
  4563. PROCESSOR_ARCHITECTURE_AMD64:
  4564. Result := pax8664;
  4565. PROCESSOR_ARCHITECTURE_ARM:
  4566. Result := paARM;
  4567. PROCESSOR_ARCHITECTURE_ARM64:
  4568. Result := paARM64;
  4569. else
  4570. Result := paUnknown;
  4571. end;
  4572. end;
  4573. function IsWindows64: Boolean;
  4574. begin
  4575. Result := GetProcessorArchitecture in [paIA64, pax8664, paARM64];
  4576. end;
  4577. function JclCheckWinVersion(Major, Minor: Integer): Boolean;
  4578. begin
  4579. {$IFDEF RTL150_UP}
  4580. Result := CheckWin32Version(Major, Minor);
  4581. {$ELSE}
  4582. // Delphi 6 and older have a wrong implementation
  4583. Result := (Win32MajorVersion > Major) or
  4584. ((Win32MajorVersion = Major) and (Win32MinorVersion >= Minor));
  4585. {$ENDIF RTL150_UP}
  4586. end;
  4587. {$ENDIF MSWINDOWS}
  4588. {$IFNDEF WINSCP}
  4589. function GetOSVersionString: string;
  4590. {$IFDEF UNIX}
  4591. var
  4592. MachineInfo: utsname;
  4593. begin
  4594. uname(MachineInfo);
  4595. Result := Format('%s %s', [MachineInfo.sysname, MachineInfo.release]);
  4596. end;
  4597. {$ENDIF UNIX}
  4598. {$IFDEF MSWINDOWS}
  4599. begin
  4600. Result := Format('%s %s', [GetWindowsVersionString, GetWindowsServicePackVersionString]);
  4601. end;
  4602. {$ENDIF MSWINDOWS}
  4603. {$ENDIF}
  4604. //=== Hardware ===============================================================
  4605. // Helper function for GetMacAddress()
  4606. // Converts the adapter_address array to a string
  4607. function AdapterToString(Adapter: PJclByteArray): string;
  4608. begin
  4609. Result := Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
  4610. [Integer(Adapter[0]), Integer(Adapter[1]),
  4611. Integer(Adapter[2]), Integer(Adapter[3]),
  4612. Integer(Adapter[4]), Integer(Adapter[5])]);
  4613. end;
  4614. {$IFNDEF WINSCP}
  4615. { TODO: RTLD version of NetBios }
  4616. {$IFDEF MSWINDOWS}
  4617. type
  4618. TNetBios = function(P: PNCB): Byte; stdcall;
  4619. var
  4620. NetBiosLib: HINST = 0;
  4621. _NetBios: TNetBios;
  4622. {$IFDEF FPC}
  4623. NullAdapterAddress: array [0..5] of Byte = ($00, $00, $00, $00, $00, $00);
  4624. OID_ipMACEntAddr: array [0..9] of UINT = (1, 3, 6, 1, 2, 1, 2, 2, 1, 6);
  4625. OID_ifEntryType: array [0..9] of UINT = (1, 3, 6, 1, 2, 1, 2, 2, 1, 3);
  4626. OID_ifEntryNum: array [0..7] of UINT = (1, 3, 6, 1, 2, 1, 2, 1);
  4627. {$ENDIF FPC}
  4628. function GetMacAddresses(const Machine: string; const Addresses: TStrings): Integer;
  4629. procedure ExitNetbios;
  4630. begin
  4631. if NetBiosLib <> 0 then
  4632. begin
  4633. FreeLibrary(NetBiosLib);
  4634. NetBiosLib := 0;
  4635. end;
  4636. end;
  4637. function InitNetbios: Boolean;
  4638. begin
  4639. Result := True;
  4640. if NetBiosLib = 0 then
  4641. begin
  4642. NetBiosLib := SafeLoadLibrary('netapi32.dll');
  4643. Result := NetBiosLib <> 0;
  4644. if Result then
  4645. begin
  4646. @_NetBios := GetProcAddress(NetBiosLib, PAnsiChar('Netbios'));
  4647. Result := @_NetBios <> nil;
  4648. if not Result then
  4649. ExitNetbios;
  4650. end;
  4651. end;
  4652. end;
  4653. function NetBios(P: PNCB): Byte;
  4654. begin
  4655. if InitNetbios then
  4656. Result := _NetBios(P)
  4657. else
  4658. Result := 1; // anything other than NRC_GOODRET will do
  4659. end;
  4660. procedure GetMacAddressesNetBios;
  4661. // Platform SDK
  4662. // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netbios/netbios_1l82.asp
  4663. // Microsoft Knowledge Base Article - 118623
  4664. // HOWTO: Get the MAC Address for an Ethernet Adapter
  4665. // http://support.microsoft.com/default.aspx?scid=kb;en-us;118623
  4666. type
  4667. AStat = packed record
  4668. adapt: TAdapterStatus;
  4669. NameBuff: array [0..29] of TNameBuffer;
  4670. end;
  4671. var
  4672. NCB: TNCB;
  4673. Enum: TLanaEnum;
  4674. I, L, NameLen: Integer;
  4675. Adapter: AStat;
  4676. MachineName: AnsiString;
  4677. begin
  4678. MachineName := AnsiString(UpperCase(Machine));
  4679. if MachineName = '' then
  4680. MachineName := '*';
  4681. NameLen := Length(MachineName);
  4682. L := NCBNAMSZ - NameLen;
  4683. if L > 0 then
  4684. begin
  4685. SetLength(MachineName, NCBNAMSZ);
  4686. FillChar(MachineName[NameLen + 1], L, ' ');
  4687. end;
  4688. // From Junior/RO in NG: Microsoft's implementation limits NETBIOS names to 15 characters
  4689. MachineName[NCBNAMSZ] := #0;
  4690. ResetMemory(NCB, SizeOf(NCB));
  4691. NCB.ncb_command := NCBENUM;
  4692. NCB.ncb_buffer := Pointer(@Enum);
  4693. NCB.ncb_length := SizeOf(Enum);
  4694. if NetBios(@NCB) = NRC_GOODRET then
  4695. begin
  4696. Result := Enum.Length;
  4697. for I := 0 to Ord(Enum.Length) - 1 do
  4698. begin
  4699. ResetMemory(NCB, SizeOf(NCB));
  4700. NCB.ncb_command := NCBRESET;
  4701. NCB.ncb_lana_num := Enum.lana[I];
  4702. if NetBios(@NCB) = NRC_GOODRET then
  4703. begin
  4704. ResetMemory(NCB, SizeOf(NCB));
  4705. NCB.ncb_command := NCBASTAT;
  4706. NCB.ncb_lana_num := Enum.lana[I];
  4707. Move(MachineName[1], NCB.ncb_callname, SizeOf(NCB.ncb_callname));
  4708. NCB.ncb_buffer := PUCHAR(@Adapter);
  4709. NCB.ncb_length := SizeOf(Adapter);
  4710. if NetBios(@NCB) = NRC_GOODRET then
  4711. Addresses.Add(AdapterToString(@Adapter.adapt));
  4712. end;
  4713. end;
  4714. end;
  4715. end;
  4716. procedure GetMacAddressesSnmp;
  4717. const
  4718. InetMib1 = 'inetmib1.dll';
  4719. {$IFNDEF FPC // can't resolve address of const }
  4720. NullAdapterAddress: array [0..5] of Byte = ($00, $00, $00, $00, $00, $00);
  4721. OID_ipMACEntAddr: array [0..9] of UINT = (1, 3, 6, 1, 2, 1, 2, 2, 1, 6);
  4722. OID_ifEntryType: array [0..9] of UINT = (1, 3, 6, 1, 2, 1, 2, 2, 1, 3);
  4723. OID_ifEntryNum: array [0..7] of UINT = (1, 3, 6, 1, 2, 1, 2, 1);
  4724. {$ENDIF ~FPC}
  4725. var
  4726. PollForTrapEvent: THandle;
  4727. SupportedView: PAsnObjectIdentifier;
  4728. MIB_ifMACEntAddr: TAsnObjectIdentifier;
  4729. MIB_ifEntryType: TAsnObjectIdentifier;
  4730. MIB_ifEntryNum: TAsnObjectIdentifier;
  4731. VarBindList: TSnmpVarBindList;
  4732. VarBind: array [0..1] of TSnmpVarBind;
  4733. ErrorStatus, ErrorIndex: TAsnInteger32;
  4734. DTmp: Integer;
  4735. Ret: Boolean;
  4736. MAC: PJclByteArray;
  4737. begin
  4738. if LoadSnmp then
  4739. try
  4740. if LoadSnmpExtension(InetMib1) then
  4741. try
  4742. MIB_ifMACEntAddr.idLength := Length(OID_ipMACEntAddr);
  4743. MIB_ifMACEntAddr.ids := @OID_ipMACEntAddr;
  4744. MIB_ifEntryType.idLength := Length(OID_ifEntryType);
  4745. MIB_ifEntryType.ids := @OID_ifEntryType;
  4746. MIB_ifEntryNum.idLength := Length(OID_ifEntryNum);
  4747. MIB_ifEntryNum.ids := @OID_ifEntryNum;
  4748. PollForTrapEvent := 0;
  4749. SupportedView := nil;
  4750. if SnmpExtensionInit(GetTickCount, PollForTrapEvent, SupportedView) then
  4751. begin
  4752. VarBindList.list := @VarBind[0];
  4753. VarBind[0].name := DEFINE_NULLOID;
  4754. VarBind[1].name := DEFINE_NULLOID;
  4755. VarBindList.len := 1;
  4756. SnmpUtilOidCpy(@VarBind[0].name, @MIB_ifEntryNum);
  4757. ErrorIndex := 0;
  4758. ErrorStatus := 0;
  4759. Ret := SnmpExtensionQuery(SNMP_PDU_GETNEXT, VarBindList, ErrorStatus, ErrorIndex);
  4760. if Ret then
  4761. begin
  4762. Result := VarBind[0].value.number;
  4763. VarBindList.len := 2;
  4764. SnmpUtilOidCpy(@VarBind[0].name, @MIB_ifEntryType);
  4765. SnmpUtilOidCpy(@VarBind[1].name, @MIB_ifMACEntAddr);
  4766. while Ret do
  4767. begin
  4768. Ret := SnmpExtensionQuery(SNMP_PDU_GETNEXT, VarBindList, ErrorStatus, ErrorIndex);
  4769. if Ret then
  4770. begin
  4771. Ret := SnmpUtilOidNCmp(@VarBind[0].name, @MIB_ifEntryType, MIB_ifEntryType.idLength) = SNMP_ERRORSTATUS_NOERROR;
  4772. if Ret then
  4773. begin
  4774. DTmp := VarBind[0].value.number;
  4775. if DTmp = 6 then
  4776. begin
  4777. Ret := SnmpUtilOidNCmp(@VarBind[1].name, @MIB_ifMACEntAddr, MIB_ifMACEntAddr.idLength) = SNMP_ERRORSTATUS_NOERROR;
  4778. if Ret and (VarBind[1].value.address.stream <> nil) then
  4779. begin
  4780. MAC := PJclByteArray(VarBind[1].value.address.stream);
  4781. if not CompareMem(MAC, @NullAdapterAddress, SizeOf(NullAdapterAddress)) then
  4782. Addresses.Add(AdapterToString(MAC));
  4783. end;
  4784. end;
  4785. end;
  4786. end;
  4787. end;
  4788. end;
  4789. SnmpUtilVarBindFree(@VarBind[0]);
  4790. SnmpUtilVarBindFree(@VarBind[1]);
  4791. end;
  4792. finally
  4793. UnloadSnmpExtension;
  4794. end;
  4795. finally
  4796. UnloadSnmp;
  4797. end;
  4798. end;
  4799. begin
  4800. Result := -1;
  4801. Addresses.BeginUpdate;
  4802. try
  4803. Addresses.Clear;
  4804. GetMacAddressesNetBios;
  4805. if (Result <= 0) and (Machine = '') then
  4806. GetMacAddressesSnmp;
  4807. finally
  4808. Addresses.EndUpdate;
  4809. end;
  4810. end;
  4811. {$ENDIF ~WINSCP}
  4812. {$ENDIF MSWINDOWS}
  4813. function ReadTimeStampCounter: Int64; assembler;
  4814. asm
  4815. DW $310F
  4816. // TSC in EDX:EAX
  4817. {$IFDEF CPU64}
  4818. SHL RDX, 32
  4819. OR RAX, RDX
  4820. // Result in RAX
  4821. {$ENDIF CPU64}
  4822. end;
  4823. function GetIntelCacheDescription(const D: Byte): string;
  4824. var
  4825. I: Integer;
  4826. begin
  4827. Result := '';
  4828. if D <> 0 then
  4829. for I := Low(IntelCacheDescription) to High(IntelCacheDescription) do
  4830. if IntelCacheDescription[I].D = D then
  4831. begin
  4832. Result := LoadResString(IntelCacheDescription[I].I);
  4833. Break;
  4834. end;
  4835. // (outchy) added a return value for unknow D value
  4836. if Result = '' then
  4837. Result := Format(LoadResString(@RsIntelUnknownCache),[D]);
  4838. end;
  4839. {$IFNDEF WINSCP}
  4840. procedure GetCpuInfo(var CpuInfo: TCpuInfo);
  4841. begin
  4842. CpuInfo := CPUID;
  4843. CpuInfo.IsFDIVOK := TestFDIVInstruction;
  4844. if CpuInfo.HasInstruction then
  4845. begin
  4846. {$IFDEF MSWINDOWS}
  4847. if (CpuInfo.Features and TSC_FLAG) = TSC_FLAG then
  4848. GetCpuSpeed(CpuInfo.FrequencyInfo);
  4849. {$ENDIF MSWINDOWS}
  4850. end;
  4851. end;
  4852. {$ENDIF ~WINSCP}
  4853. function RoundFrequency(const Frequency: Integer): Integer;
  4854. const
  4855. NF: array [0..8] of Integer = (0, 20, 33, 50, 60, 66, 80, 90, 100);
  4856. var
  4857. Freq, RF: Integer;
  4858. I: Byte;
  4859. Hi, Lo: Byte;
  4860. begin
  4861. RF := 0;
  4862. Freq := Frequency mod 100;
  4863. for I := 0 to 8 do
  4864. begin
  4865. if Freq < NF[I] then
  4866. begin
  4867. Hi := I;
  4868. Lo := I - 1;
  4869. if (NF[Hi] - Freq) > (Freq - NF[Lo]) then
  4870. RF := NF[Lo] - Freq
  4871. else
  4872. RF := NF[Hi] - Freq;
  4873. Break;
  4874. end;
  4875. end;
  4876. Result := Frequency + RF;
  4877. end;
  4878. function GetCPUSpeed(var CpuSpeed: TFreqInfo): Boolean;
  4879. {$IFDEF UNIX}
  4880. begin
  4881. { TODO : GetCPUSpeed: Solution for Linux }
  4882. Result := False;
  4883. end;
  4884. {$ENDIF UNIX}
  4885. {$IFDEF MSWINDOWS}
  4886. var
  4887. T0, T1: Int64;
  4888. CountFreq: Int64;
  4889. Freq, Freq2, Freq3, Total: Int64;
  4890. TotalCycles, Cycles: Int64;
  4891. Stamp0, Stamp1: Int64;
  4892. TotalTicks, Ticks: Double;
  4893. Tries, Priority: Integer;
  4894. Thread: THandle;
  4895. begin
  4896. Stamp0 := 0;
  4897. Stamp1 := 0;
  4898. Freq := 0;
  4899. Freq2 := 0;
  4900. Freq3 := 0;
  4901. Tries := 0;
  4902. TotalCycles := 0;
  4903. TotalTicks := 0;
  4904. Total := 0;
  4905. Thread := GetCurrentThread();
  4906. CountFreq := 0;
  4907. Result := QueryPerformanceFrequency(CountFreq);
  4908. if Result then
  4909. begin
  4910. while ((Tries < 3) or ((Tries < 20) and ((Abs(3 * Freq - Total) > 3) or
  4911. (Abs(3 * Freq2 - Total) > 3) or (Abs(3 * Freq3 - Total) > 3)))) do
  4912. begin
  4913. Inc(Tries);
  4914. Freq3 := Freq2;
  4915. Freq2 := Freq;
  4916. T0 := 0;
  4917. QueryPerformanceCounter(T0);
  4918. T1 := T0;
  4919. Priority := GetThreadPriority(Thread);
  4920. if Priority <> THREAD_PRIORITY_ERROR_RETURN then
  4921. SetThreadPriority(Thread, THREAD_PRIORITY_TIME_CRITICAL);
  4922. try
  4923. while T1 - T0 < 50 do
  4924. begin
  4925. QueryPerformanceCounter(T1);
  4926. Stamp0 := ReadTimeStampCounter;
  4927. end;
  4928. T0 := T1;
  4929. while T1 - T0 < 1000 do
  4930. begin
  4931. QueryPerformanceCounter(T1);
  4932. Stamp1 := ReadTimeStampCounter;
  4933. end;
  4934. finally
  4935. if Priority <> THREAD_PRIORITY_ERROR_RETURN then
  4936. SetThreadPriority(Thread, Priority);
  4937. end;
  4938. Cycles := Stamp1 - Stamp0;
  4939. Ticks := T1 - T0;
  4940. Ticks := Ticks * 100000;
  4941. // avoid division by zero
  4942. if CountFreq = 0 then
  4943. Ticks := High(Int64)
  4944. else
  4945. Ticks := Ticks / (CountFreq / 10);
  4946. TotalTicks := TotalTicks + Ticks;
  4947. TotalCycles := TotalCycles + Cycles;
  4948. // avoid division by zero
  4949. if IsZero(Ticks) then
  4950. Freq := High(Freq)
  4951. else
  4952. Freq := Round(Cycles / Ticks);
  4953. Total := Freq + Freq2 + Freq3;
  4954. end;
  4955. // avoid division by zero
  4956. if IsZero(TotalTicks) then
  4957. begin
  4958. Freq3 := High(Freq3);
  4959. Freq2 := High(Freq2);
  4960. CpuSpeed.RawFreq := High(CpuSpeed.RawFreq);
  4961. end
  4962. else
  4963. begin
  4964. Freq3 := Round((TotalCycles * 10) / TotalTicks); // freq. in multiples of 10^5 Hz
  4965. Freq2 := Round((TotalCycles * 100) / TotalTicks); // freq. in multiples of 10^4 Hz
  4966. CpuSpeed.RawFreq := Round(TotalCycles / TotalTicks);
  4967. end;
  4968. CpuSpeed.NormFreq := CpuSpeed.RawFreq;
  4969. if Freq2 - (Freq3 * 10) >= 6 then
  4970. Inc(Freq3);
  4971. Freq := CpuSpeed.RawFreq * 10;
  4972. if (Freq3 - Freq) >= 6 then
  4973. Inc(CpuSpeed.NormFreq);
  4974. CpuSpeed.ExTicks := Round(TotalTicks);
  4975. CpuSpeed.InCycles := TotalCycles;
  4976. CpuSpeed.NormFreq := RoundFrequency(CpuSpeed.NormFreq);
  4977. Result := True;
  4978. end;
  4979. end;
  4980. function GetOSEnabledFeatures: TOSEnabledFeatures;
  4981. var
  4982. EnabledFeatures: Int64;
  4983. begin
  4984. // Windows 7 or newer
  4985. if JclCheckWinVersion(6, 1) then
  4986. begin
  4987. EnabledFeatures := $FFFFFFFF;
  4988. EnabledFeatures := EnabledFeatures shl 32;
  4989. EnabledFeatures := EnabledFeatures or $FFFFFFFF;
  4990. try
  4991. EnabledFeatures := GetEnabledExtendedFeatures(EnabledFeatures);
  4992. except
  4993. on EJclError do
  4994. begin
  4995. // If the function doesn't exist (anymore) we shouldn't crash.
  4996. Result := [];
  4997. Exit;
  4998. end;
  4999. end;
  5000. Result := [];
  5001. if (EnabledFeatures and XSTATE_MASK_LEGACY_FLOATING_POINT) <> 0 then
  5002. Include(Result, oefFPU);
  5003. if (EnabledFeatures and XSTATE_MASK_LEGACY_SSE) <> 0 then
  5004. Include(Result, oefSSE);
  5005. if (EnabledFeatures and XSTATE_MASK_GSSE) <> 0 then
  5006. Include(Result, oefAVX);
  5007. end
  5008. else
  5009. Result := [];
  5010. end;
  5011. {$ENDIF MSWINDOWS}
  5012. {$IFNDEF WINSCP}
  5013. function CPUID: TCpuInfo;
  5014. function HasCPUIDInstruction: Boolean;
  5015. const
  5016. ID_FLAG = $200000;
  5017. {$IFNDEF DELPHI64_TEMPORARY}
  5018. begin
  5019. {$ENDIF ~DELPHI64_TEMPORARY}
  5020. asm
  5021. {$IFDEF CPU32}
  5022. PUSHFD
  5023. POP EAX
  5024. MOV ECX, EAX
  5025. XOR EAX, ID_FLAG
  5026. AND ECX, ID_FLAG
  5027. PUSH EAX
  5028. POPFD
  5029. PUSHFD
  5030. POP EAX
  5031. AND EAX, ID_FLAG
  5032. XOR EAX, ECX
  5033. SETNZ Result
  5034. {$ENDIF CPU32}
  5035. {$IFDEF CPU64}
  5036. {$IFDEF FPC}
  5037. {$DEFINE DELPHI64_TEMPORARY}
  5038. {$ENDIF FPC}
  5039. {$IFDEF DELPHI64_TEMPORARY}
  5040. PUSHFQ
  5041. {$ELSE ~DELPHI64_TEMPORARY}
  5042. PUSHFD
  5043. {$ENDIF ~DELPHI64_TEMPORARY}
  5044. POP RAX
  5045. MOV RCX, RAX
  5046. XOR RAX, ID_FLAG
  5047. AND RCX, ID_FLAG
  5048. PUSH RAX
  5049. {$IFDEF DELPHI64_TEMPORARY}
  5050. POPFQ
  5051. {$ELSE ~DELPHI64_TEMPORARY}
  5052. POPFD
  5053. {$ENDIF ~DELPHI64_TEMPORARY}
  5054. {$IFDEF DELPHI64_TEMPORARY}
  5055. PUSHFQ
  5056. {$ELSE ~DELPHI64_TEMPORARY}
  5057. PUSHFD
  5058. {$ENDIF ~DELPHI64_TEMPORARY}
  5059. POP RAX
  5060. AND RAX, ID_FLAG
  5061. XOR RAX, RCX
  5062. SETNZ Result
  5063. {$IFDEF FPC}
  5064. {$UNDEF DELPHI64_TEMPORARY}
  5065. {$ENDIF FPC}
  5066. {$ENDIF CPU64}
  5067. end;
  5068. {$IFNDEF DELPHI64_TEMPORARY}
  5069. end;
  5070. {$ENDIF ~DELPHI64_TEMPORARY}
  5071. procedure CallCPUID(ValueEAX, ValueECX: Cardinal; out ReturnedEAX, ReturnedEBX, ReturnedECX, ReturnedEDX);
  5072. {$IFNDEF DELPHI64_TEMPORARY}
  5073. begin
  5074. {$ENDIF ~DELPHI64_TEMPORARY}
  5075. asm
  5076. {$IFDEF CPU32}
  5077. // save context
  5078. PUSH EDI
  5079. PUSH EBX
  5080. // init parameters
  5081. MOV EAX, ValueEAX
  5082. MOV ECX, ValueECX
  5083. // CPUID
  5084. DB 0FH
  5085. DB 0A2H
  5086. // store results
  5087. MOV EDI, ReturnedEAX
  5088. MOV Cardinal PTR [EDI], EAX
  5089. MOV EAX, ReturnedEBX
  5090. MOV EDI, ReturnedECX
  5091. MOV Cardinal PTR [EAX], EBX
  5092. MOV Cardinal PTR [EDI], ECX
  5093. MOV EAX, ReturnedEDX
  5094. MOV Cardinal PTR [EAX], EDX
  5095. // restore context
  5096. POP EBX
  5097. POP EDI
  5098. {$ENDIF CPU32}
  5099. {$IFDEF CPU64}
  5100. // save context
  5101. PUSH RBX
  5102. // init parameters
  5103. MOV EAX, ValueEAX
  5104. MOV ECX, ValueECX
  5105. // CPUID
  5106. CPUID
  5107. // store results
  5108. MOV R8, ReturnedEAX
  5109. MOV R9, ReturnedEBX
  5110. MOV R10, ReturnedECX
  5111. MOV R11, ReturnedEDX
  5112. MOV Cardinal PTR [R8], EAX
  5113. MOV Cardinal PTR [R9], EBX
  5114. MOV Cardinal PTR [R10], ECX
  5115. MOV Cardinal PTR [R11], EDX
  5116. // restore context
  5117. POP RBX
  5118. {$ENDIF CPU64}
  5119. end;
  5120. {$IFNDEF DELPHI64_TEMPORARY}
  5121. end;
  5122. {$ENDIF ~DELPHI64_TEMPORARY}
  5123. procedure ProcessStandard(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  5124. var
  5125. VersionInfo, AdditionalInfo, ExFeatures: Cardinal;
  5126. begin
  5127. if HiVal >= 1 then
  5128. begin
  5129. CallCPUID(1, 0, VersionInfo, AdditionalInfo, ExFeatures, CPUInfo.Features);
  5130. CPUInfo.PType := (VersionInfo and $00003000) shr 12;
  5131. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  5132. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  5133. CPUInfo.Stepping := (VersionInfo and $0000000F);
  5134. CPUInfo.ExtendedModel := (VersionInfo and $000F0000) shr 16;
  5135. CPUInfo.ExtendedFamily := (VersionInfo and $0FF00000) shr 20;
  5136. if CPUInfo.CpuType = CPU_TYPE_INTEL then
  5137. begin
  5138. CPUInfo.IntelSpecific.ExFeatures := ExFeatures;
  5139. CPUInfo.IntelSpecific.BrandID := AdditionalInfo and $000000FF;
  5140. CPUInfo.IntelSpecific.FlushLineSize := (AdditionalInfo and $0000FF00) shr 8;
  5141. CPUInfo.IntelSpecific.APICID := (AdditionalInfo and $FF000000) shr 24;
  5142. CPUInfo.HyperThreadingTechnology := (CPUInfo.Features and INTEL_HTT) <> 0;
  5143. if CPUInfo.HyperThreadingTechnology then
  5144. begin
  5145. CPUInfo.LogicalCore := (AdditionalInfo and $00FF0000) shr 16;
  5146. if CPUInfo.LogicalCore = 0 then
  5147. CPUInfo.LogicalCore := 1;
  5148. end;
  5149. if HiVal >= 2 then
  5150. begin
  5151. CPUInfo.HasCacheInfo := True;
  5152. // TODO: multiple loops
  5153. CallCPUID(2, 0, CPUInfo.IntelSpecific.CacheDescriptors[0], CPUInfo.IntelSpecific.CacheDescriptors[4],
  5154. CPUInfo.IntelSpecific.CacheDescriptors[8], CPUInfo.IntelSpecific.CacheDescriptors[12]);
  5155. end;
  5156. end;
  5157. end;
  5158. end;
  5159. procedure ProcessIntel(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  5160. var
  5161. ExHiVal, Unused, AddressSize, CoreInfo: Cardinal;
  5162. I, J: Integer;
  5163. begin
  5164. CPUInfo.CpuType := CPU_TYPE_INTEL;
  5165. CPUInfo.Manufacturer := 'Intel';
  5166. ProcessStandard(CPUInfo, HiVal);
  5167. if HiVal >= 4 then
  5168. begin
  5169. CallCPUID(4, 0, CoreInfo, Unused, Unused, Unused);
  5170. CPUInfo.PhysicalCore := ((CoreInfo and $FC000000) shr 26) + 1;
  5171. end;
  5172. if HiVal >= 6 then
  5173. CallCPUID(6, 0, CPUInfo.IntelSpecific.PowerManagementFeatures, Unused, Unused, Unused);
  5174. // check Intel extended
  5175. CallCPUID($80000000, 0, ExHiVal, Unused, Unused, Unused);
  5176. if ExHiVal >= $80000001 then
  5177. begin
  5178. CPUInfo.HasExtendedInfo := True;
  5179. CallCPUID($80000001, 0, Unused, Unused, CPUInfo.IntelSpecific.Ex64Features2,
  5180. CPUInfo.IntelSpecific.Ex64Features);
  5181. end;
  5182. if ExHiVal >= $80000002 then
  5183. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  5184. if ExHiVal >= $80000003 then
  5185. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  5186. if ExHiVal >= $80000004 then
  5187. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  5188. if ExHiVal >= $80000006 then
  5189. CallCPUID($80000006, 0, Unused, Unused, CPUInfo.IntelSpecific.L2Cache, Unused);
  5190. if ExHiVal >= $80000008 then
  5191. begin
  5192. CallCPUID($80000008, 0, AddressSize, Unused, Unused, Unused);
  5193. CPUInfo.IntelSpecific.PhysicalAddressBits := AddressSize and $000000FF;
  5194. CPUInfo.IntelSpecific.VirtualAddressBits := (AddressSize and $0000FF00) shr 8;
  5195. end;
  5196. if CPUInfo.HasCacheInfo then
  5197. begin
  5198. if (CPUInfo.IntelSpecific.L2Cache <> 0) then
  5199. begin
  5200. CPUInfo.L2CacheSize := CPUInfo.IntelSpecific.L2Cache shr 16;
  5201. CPUInfo.L2CacheLineSize := CPUInfo.IntelSpecific.L2Cache and $FF;
  5202. CPUInfo.L2CacheAssociativity := (CPUInfo.IntelSpecific.L2Cache shr 12) and $F;
  5203. end;
  5204. for I := Low(CPUInfo.IntelSpecific.CacheDescriptors) to High(CPUInfo.IntelSpecific.CacheDescriptors) do
  5205. if CPUInfo.IntelSpecific.CacheDescriptors[I]<>0 then
  5206. for J := Low(IntelCacheDescription) to High(IntelCacheDescription) do
  5207. if IntelCacheDescription[J].D = CPUInfo.IntelSpecific.CacheDescriptors[I] then
  5208. with IntelCacheDescription[J] do
  5209. case Family of
  5210. //cfInstructionTLB:
  5211. //cfDataTLB:
  5212. cfL1InstructionCache:
  5213. begin
  5214. Inc(CPUInfo.L1InstructionCacheSize,Size);
  5215. CPUInfo.L1InstructionCacheLineSize := LineSize;
  5216. CPUInfo.L1InstructionCacheAssociativity := WaysOfAssoc;
  5217. end;
  5218. cfL1DataCache:
  5219. begin
  5220. Inc(CPUInfo.L1DataCacheSize,Size);
  5221. CPUInfo.L1DataCacheLineSize := LineSize;
  5222. CPUInfo.L1DataCacheAssociativity := WaysOfAssoc;
  5223. end;
  5224. cfL2Cache:
  5225. if (CPUInfo.IntelSpecific.L2Cache = 0) then
  5226. begin
  5227. Inc(CPUInfo.L2CacheSize,Size);
  5228. CPUInfo.L2CacheLineSize := LineSize;
  5229. CPUInfo.L2CacheAssociativity := WaysOfAssoc;
  5230. end;
  5231. cfL3Cache:
  5232. begin
  5233. Inc(CPUInfo.L3CacheSize,Size);
  5234. CPUInfo.L3CacheLineSize := LineSize;
  5235. CPUInfo.L3CacheAssociativity := WaysOfAssoc;
  5236. CPUInfo.L3LinesPerSector := LinePerSector;
  5237. end;
  5238. //cfTrace: // no numeric informations
  5239. //cfOther:
  5240. end;
  5241. end;
  5242. if not CPUInfo.HasExtendedInfo then
  5243. begin
  5244. case CPUInfo.Family of
  5245. 4:
  5246. case CPUInfo.Model of
  5247. 1:
  5248. CPUInfo.CpuName := 'Intel 486DX Processor';
  5249. 2:
  5250. CPUInfo.CpuName := 'Intel 486SX Processor';
  5251. 3:
  5252. CPUInfo.CpuName := 'Intel DX2 Processor';
  5253. 4:
  5254. CPUInfo.CpuName := 'Intel 486 Processor';
  5255. 5:
  5256. CPUInfo.CpuName := 'Intel SX2 Processor';
  5257. 7:
  5258. CPUInfo.CpuName := 'Write-Back Enhanced Intel DX2 Processor';
  5259. 8:
  5260. CPUInfo.CpuName := 'Intel DX4 Processor';
  5261. else
  5262. CPUInfo.CpuName := 'Intel 486 Processor';
  5263. end;
  5264. 5:
  5265. CPUInfo.CpuName := 'Pentium';
  5266. 6:
  5267. case CPUInfo.Model of
  5268. 1:
  5269. CPUInfo.CpuName := 'Pentium Pro';
  5270. 3:
  5271. CPUInfo.CpuName := 'Pentium II';
  5272. 5:
  5273. case CPUInfo.L2CacheSize of
  5274. 0:
  5275. CPUInfo.CpuName := 'Celeron';
  5276. 1024:
  5277. CPUInfo.CpuName := 'Pentium II Xeon';
  5278. 2048:
  5279. CPUInfo.CpuName := 'Pentium II Xeon';
  5280. else
  5281. CPUInfo.CpuName := 'Pentium II';
  5282. end;
  5283. 6:
  5284. case CPUInfo.L2CacheSize of
  5285. 0:
  5286. CPUInfo.CpuName := 'Celeron';
  5287. 128:
  5288. CPUInfo.CpuName := 'Celeron';
  5289. else
  5290. CPUInfo.CpuName := 'Pentium II';
  5291. end;
  5292. 7:
  5293. case CPUInfo.L2CacheSize of
  5294. 1024:
  5295. CPUInfo.CpuName := 'Pentium III Xeon';
  5296. 2048:
  5297. CPUInfo.CpuName := 'Pentium III Xeon';
  5298. else
  5299. CPUInfo.CpuName := 'Pentium III';
  5300. end;
  5301. 8:
  5302. case CPUInfo.IntelSpecific.BrandID of
  5303. 1:
  5304. CPUInfo.CpuName := 'Celeron';
  5305. 2:
  5306. CPUInfo.CpuName := 'Pentium III';
  5307. 3:
  5308. CPUInfo.CpuName := 'Pentium III Xeon';
  5309. 4:
  5310. CPUInfo.CpuName := 'Pentium III';
  5311. else
  5312. CPUInfo.CpuName := 'Pentium III';
  5313. end;
  5314. 10:
  5315. CPUInfo.CpuName := 'Pentium III Xeon';
  5316. 11:
  5317. CPUInfo.CpuName := 'Pentium III';
  5318. else
  5319. StrPCopyA(CPUInfo.CpuName, AnsiString(Format('P6 (Model %d)', [CPUInfo.Model])));
  5320. end;
  5321. 15:
  5322. case CPUInfo.IntelSpecific.BrandID of
  5323. 1:
  5324. CPUInfo.CpuName := 'Celeron';
  5325. 8:
  5326. CPUInfo.CpuName := 'Pentium 4';
  5327. 14:
  5328. CPUInfo.CpuName := 'Xeon';
  5329. else
  5330. CPUInfo.CpuName := 'Pentium 4';
  5331. end;
  5332. else
  5333. StrPCopyA(CPUInfo.CpuName, AnsiString(Format('P%d', [CPUInfo.Family])));
  5334. end;
  5335. end;
  5336. CPUInfo.HardwareHyperThreadingTechnology := CPUInfo.LogicalCore <> CPUInfo.PhysicalCore;
  5337. CPUInfo.AES := (CPUInfo.IntelSpecific.ExFeatures and EINTEL_AES) <> 0;
  5338. CPUInfo.MMX := (CPUInfo.Features and MMX_FLAG) <> 0;
  5339. CPUInfo.SSE := [];
  5340. if (CPUInfo.Features and SSE_FLAG) <> 0 then
  5341. Include(CPUInfo.SSE, sse);
  5342. if (CPUInfo.Features and SSE2_FLAG) <> 0 then
  5343. Include(CPUInfo.SSE, sse2);
  5344. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_SSE3) <> 0 then
  5345. Include(CPUInfo.SSE, sse3);
  5346. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_SSSE3) <> 0 then
  5347. Include(CPUInfo.SSE, ssse3);
  5348. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_SSE4_1) <> 0 then
  5349. Include(CPUInfo.SSE, sse41);
  5350. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_SSE4_2) <> 0 then
  5351. Include(CPUInfo.SSE, sse42);
  5352. if (CPUInfo.IntelSpecific.ExFeatures and EINTEL_AVX) <> 0 then
  5353. Include(CPUInfo.SSE, avx);
  5354. CPUInfo.Is64Bits := CPUInfo.HasExtendedInfo and ((CPUInfo.IntelSpecific.Ex64Features and EINTEL64_EM64T)<>0);
  5355. CPUInfo.DepCapable := CPUInfo.HasExtendedInfo and ((CPUInfo.IntelSpecific.Ex64Features and EINTEL64_XD) <> 0);
  5356. end;
  5357. procedure ProcessAMD(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  5358. var
  5359. ExHiVal, Unused, VersionInfo, AdditionalInfo: Cardinal;
  5360. begin
  5361. CPUInfo.CpuType := CPU_TYPE_AMD;
  5362. CPUInfo.Manufacturer := 'AMD';
  5363. // check AMD extended
  5364. if HiVal >= 1 then
  5365. begin
  5366. CallCPUID(1, 0, VersionInfo, AdditionalInfo, CPUInfo.AMDSpecific.Features2, CPUInfo.Features);
  5367. CPUInfo.AMDSpecific.BrandID := AdditionalInfo and $000000FF;
  5368. CPUInfo.AMDSpecific.FlushLineSize := (AdditionalInfo and $0000FF00) shr 8;
  5369. CPUInfo.AMDSpecific.APICID := (AdditionalInfo and $FF000000) shr 24;
  5370. CPUInfo.HyperThreadingTechnology := (CPUInfo.Features and AMD_HTT) <> 0;
  5371. if CPUInfo.HyperThreadingTechnology then
  5372. begin
  5373. CPUInfo.LogicalCore := (AdditionalInfo and $00FF0000) shr 16;
  5374. if CPUInfo.LogicalCore = 0 then
  5375. CPUInfo.LogicalCore := 1;
  5376. end;
  5377. end;
  5378. CallCPUID($80000000, 0, ExHiVal, Unused, Unused, Unused);
  5379. if ExHiVal <> 0 then
  5380. begin
  5381. // AMD only
  5382. CPUInfo.HasExtendedInfo := True;
  5383. if ExHiVal >= $80000001 then
  5384. begin
  5385. CallCPUID($80000001, 0, VersionInfo, AdditionalInfo, CPUInfo.AMDSpecific.ExFeatures2, CPUInfo.AMDSpecific.ExFeatures);
  5386. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  5387. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  5388. CPUInfo.Stepping := (VersionInfo and $0000000F);
  5389. CPUInfo.ExtendedModel := (VersionInfo and $000F0000) shr 16;
  5390. CPUInfo.ExtendedFamily := (VersionInfo and $0FF00000) shr 20;
  5391. CPUInfo.AMDSpecific.ExBrandID := AdditionalInfo and $0000FFFF;
  5392. end;
  5393. if ExHiVal >= $80000002 then
  5394. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  5395. if ExHiVal >= $80000003 then
  5396. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  5397. if ExHiVal >= $80000004 then
  5398. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  5399. if ExHiVal >= $80000005 then
  5400. begin
  5401. CPUInfo.HasCacheInfo := True;
  5402. CallCPUID($80000005, 0, CPUInfo.AMDSpecific.L1MByteInstructionTLB, CPUInfo.AMDSpecific.L1KByteInstructionTLB,
  5403. CPUInfo.AMDSpecific.L1DataCache, CPUInfo.AMDSpecific.L1InstructionCache);
  5404. end;
  5405. if ExHiVal >= $80000006 then
  5406. CallCPUID($80000006, 0, CPUInfo.AMDSpecific.L2MByteInstructionTLB, CPUInfo.AMDSpecific.L2KByteInstructionTLB,
  5407. CPUInfo.AMDSpecific.L2Cache, CPUInfo.AMDSpecific.L3Cache);
  5408. if CPUInfo.HasCacheInfo then
  5409. begin
  5410. CPUInfo.L1DataCacheSize := CPUInfo.AMDSpecific.L1DataCache[ciSize];
  5411. CPUInfo.L1DataCacheLineSize := CPUInfo.AMDSpecific.L1DataCache[ciLineSize];
  5412. CPUInfo.L1DataCacheAssociativity := CPUInfo.AMDSpecific.L1DataCache[ciAssociativity];
  5413. CPUInfo.L1InstructionCacheSize := CPUInfo.AMDSpecific.L1InstructionCache[ciSize];
  5414. CPUInfo.L1InstructionCacheLineSize := CPUInfo.AMDSpecific.L1InstructionCache[ciLineSize];
  5415. CPUInfo.L1InstructionCacheAssociativity := CPUInfo.AMDSpecific.L1InstructionCache[ciAssociativity];
  5416. CPUInfo.L2CacheLineSize := CPUInfo.AMDSpecific.L2Cache and $FF;
  5417. CPUInfo.L2CacheAssociativity := (CPUInfo.AMDSpecific.L2Cache shr 12) and $F;
  5418. CPUInfo.L2CacheSize := CPUInfo.AMDSpecific.L2Cache shr 16;
  5419. CPUInfo.L3CacheLineSize := CPUInfo.AMDSpecific.L3Cache and $FF;
  5420. CPUInfo.L3CacheAssociativity := (CPUInfo.AMDSpecific.L3Cache shr 12) and $F;
  5421. CPUInfo.L3CacheSize := CPUInfo.AMDSpecific.L3Cache shr 19 {MB}; //(CPUInfo.AMDSpecific.L3Cache shr 18) * 512 {kB};
  5422. end;
  5423. if ExHiVal >= $80000007 then
  5424. CallCPUID($80000007, 0, Unused, Unused, Unused, CPUInfo.AMDSpecific.AdvancedPowerManagement);
  5425. if ExHiVal >= $80000008 then
  5426. begin
  5427. CallCPUID($80000008, 0, Unused, VersionInfo, AdditionalInfo, Unused);
  5428. CPUInfo.AMDSpecific.PhysicalAddressSize := VersionInfo and $000000FF;
  5429. CPUInfo.AMDSpecific.VirtualAddressSize := (VersionInfo and $0000FF00) shr 8;
  5430. CPUInfo.PhysicalCore := (AdditionalInfo and $000000FF) + 1;
  5431. end;
  5432. end
  5433. else
  5434. begin
  5435. ProcessStandard(CPUInfo, HiVal);
  5436. case CPUInfo.Family of
  5437. 4:
  5438. CPUInfo.CpuName := 'Am486(R) or Am5x86';
  5439. 5:
  5440. case CPUInfo.Model of
  5441. 0:
  5442. CPUInfo.CpuName := 'AMD-K5 (Model 0)';
  5443. 1:
  5444. CPUInfo.CpuName := 'AMD-K5 (Model 1)';
  5445. 2:
  5446. CPUInfo.CpuName := 'AMD-K5 (Model 2)';
  5447. 3:
  5448. CPUInfo.CpuName := 'AMD-K5 (Model 3)';
  5449. 6:
  5450. CPUInfo.CpuName := 'AMD-K6® (Model 6)';
  5451. 7:
  5452. CPUInfo.CpuName := 'AMD-K6® (Model 7)';
  5453. 8:
  5454. CPUInfo.CpuName := 'AMD-K6®-2 (Model 8)';
  5455. 9:
  5456. CPUInfo.CpuName := 'AMD-K6®-III (Model 9)';
  5457. else
  5458. StrFmtA(CPUInfo.CpuName, PAnsiChar(AnsiString(LoadResString(@RsUnknownAMDModel))), [CPUInfo.Model]);
  5459. end;
  5460. 6:
  5461. case CPUInfo.Model of
  5462. 1:
  5463. CPUInfo.CpuName := 'AMD Athlon™ (Model 1)';
  5464. 2:
  5465. CPUInfo.CpuName := 'AMD Athlon™ (Model 2)';
  5466. 3:
  5467. CPUInfo.CpuName := 'AMD Duron™ (Model 3)';
  5468. 4:
  5469. CPUInfo.CpuName := 'AMD Athlon™ (Model 4)';
  5470. 6:
  5471. CPUInfo.CpuName := 'AMD Athlon™ XP (Model 6)';
  5472. 7:
  5473. CPUInfo.CpuName := 'AMD Duron™ (Model 7)';
  5474. 8:
  5475. CPUInfo.CpuName := 'AMD Athlon™ XP (Model 8)';
  5476. 10:
  5477. CPUInfo.CpuName := 'AMD Athlon™ XP (Model 10)';
  5478. else
  5479. StrFmtA(CPUInfo.CpuName, PAnsiChar(AnsiString(LoadResString(@RsUnknownAMDModel))), [CPUInfo.Model]);
  5480. end;
  5481. 8:
  5482. else
  5483. CPUInfo.CpuName := 'Unknown AMD Chip';
  5484. end;
  5485. end;
  5486. CPUInfo.HardwareHyperThreadingTechnology := CPUInfo.LogicalCore <> CPUInfo.PhysicalCore;
  5487. CPUInfo.AES := (CPUInfo.AMDSpecific.Features2 and AMD2_AES) <> 0;
  5488. CPUInfo.MMX := (CPUInfo.Features and AMD_MMX) <> 0;
  5489. CPUInfo.ExMMX := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_EXMMX) <> 0);
  5490. CPUInfo._3DNow := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_3DNOW) <> 0);
  5491. CPUInfo.Ex3DNow := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_EX3DNOW) <> 0);
  5492. CPUInfo.SSE := [];
  5493. if (CPUInfo.Features and AMD_SSE) <> 0 then
  5494. Include(CPUInfo.SSE, sse);
  5495. if (CPUInfo.Features and AMD_SSE2) <> 0 then
  5496. Include(CPUInfo.SSE, sse2);
  5497. if (CPUInfo.AMDSpecific.Features2 and AMD2_SSE3) <> 0 then
  5498. Include(CPUInfo.SSE, sse3);
  5499. if CPUInfo.HasExtendedInfo then
  5500. begin
  5501. if (CPUInfo.AMDSpecific.ExFeatures2 and EAMD2_SSE4A) <> 0 then
  5502. Include(CPUInfo.SSE, sse4A);
  5503. if (CPUInfo.AMDSpecific.Features2 and AMD2_SSE41) <> 0 then
  5504. Include(CPUInfo.SSE, sse41);
  5505. if (CPUInfo.AMDSpecific.Features2 and AMD2_SSE42) <> 0 then
  5506. Include(CPUInfo.SSE, sse42);
  5507. end;
  5508. CPUInfo.Is64Bits := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_LONG) <> 0);
  5509. CPUInfo.DEPCapable := CPUInfo.HasExtendedInfo and ((CPUInfo.AMDSpecific.ExFeatures and EAMD_NX) <> 0);
  5510. end;
  5511. procedure ProcessCyrix(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  5512. var
  5513. ExHiVal, Unused, VersionInfo, AdditionalInfo: Cardinal;
  5514. begin
  5515. CPUInfo.CpuType := CPU_TYPE_CYRIX;
  5516. CPUInfo.Manufacturer := 'Cyrix';
  5517. // check Cyrix extended
  5518. CallCPUID($80000000, 0, ExHiVal, Unused, Unused, Unused);
  5519. if ExHiVal <> 0 then
  5520. begin
  5521. // Cyrix only
  5522. CPUInfo.HasExtendedInfo := True;
  5523. if ExHiVal >= $80000001 then
  5524. begin
  5525. CallCPUID($80000001, 0, VersionInfo, AdditionalInfo, Unused, CPUInfo.Features);
  5526. CPUInfo.PType := (VersionInfo and $0000F000) shr 12;
  5527. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  5528. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  5529. CPUInfo.Stepping := (VersionInfo and $0000000F);
  5530. end;
  5531. if ExHiVal >= $80000002 then
  5532. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  5533. if ExHiVal >= $80000003 then
  5534. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  5535. if ExHiVal >= $80000004 then
  5536. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  5537. if ExHiVal >= $80000005 then
  5538. begin
  5539. CPUInfo.HasCacheInfo := True;
  5540. CallCPUID($80000005, 0, Unused, CPUInfo.CyrixSpecific.TLBInfo, CPUInfo.CyrixSpecific.L1CacheInfo, Unused);
  5541. end;
  5542. end
  5543. else
  5544. begin
  5545. ProcessStandard(CPUInfo, HiVal);
  5546. case CPUInfo.Family of
  5547. 4:
  5548. CPUInfo.CpuName := 'Cyrix MediaGX';
  5549. 5:
  5550. case CPUInfo.Model of
  5551. 2:
  5552. CPUInfo.CpuName := 'Cyrix 6x86';
  5553. 4:
  5554. CPUInfo.CpuName := 'Cyrix GXm';
  5555. end;
  5556. 6:
  5557. CPUInfo.CpuName := '6x86MX';
  5558. else
  5559. StrPCopyA(CPUInfo.CpuName, AnsiString(Format('%dx86', [CPUInfo.Family])));
  5560. end;
  5561. end;
  5562. end;
  5563. procedure ProcessVIA(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  5564. var
  5565. ExHiVal, Unused, VersionInfo: Cardinal;
  5566. begin
  5567. CPUInfo.CpuType := CPU_TYPE_VIA;
  5568. CPUInfo.Manufacturer := 'Via';
  5569. // check VIA extended
  5570. CallCPUID($80000000, 0, ExHiVal, Unused, Unused, Unused);
  5571. if ExHiVal <> 0 then
  5572. begin
  5573. if ExHiVal >= $80000001 then
  5574. begin
  5575. CPUInfo.HasExtendedInfo := True;
  5576. CallCPUID($80000001, 0, VersionInfo, Unused, Unused, CPUInfo.ViaSpecific.ExFeatures);
  5577. CPUInfo.PType := (VersionInfo and $00003000) shr 12;
  5578. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  5579. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  5580. CPUInfo.Stepping := (VersionInfo and $0000000F);
  5581. end;
  5582. if ExHiVal >= $80000002 then
  5583. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  5584. if ExHiVal >= $80000003 then
  5585. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  5586. if ExHiVal >= $80000004 then
  5587. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  5588. if ExHiVal >= $80000005 then
  5589. begin
  5590. CPUInfo.HasCacheInfo := True;
  5591. CallCPUID($80000005, 0, Unused, CPUInfo.ViaSpecific.InstructionTLB, CPUInfo.ViaSpecific.L1DataCache,
  5592. CPUInfo.ViaSpecific.L1InstructionCache);
  5593. end;
  5594. if ExHiVal >= $80000006 then
  5595. CallCPUID($80000006, 0, Unused, Unused, CPUInfo.ViaSpecific.L2DataCache, Unused);
  5596. if CPUInfo.HasCacheInfo then
  5597. begin
  5598. CPUInfo.L1DataCacheSize := CPUInfo.VIASpecific.L1DataCache[ciSize];
  5599. CPUInfo.L1DataCacheLineSize := CPUInfo.VIASpecific.L1DataCache[ciLineSize];
  5600. CPUInfo.L1DataCacheAssociativity := CPUInfo.VIASpecific.L1DataCache[ciAssociativity];
  5601. CPUInfo.L1InstructionCacheSize := CPUInfo.VIASpecific.L1InstructionCache[ciSize];
  5602. CPUInfo.L1InstructionCacheLineSize := CPUInfo.VIASpecific.L1InstructionCache[ciLineSize];
  5603. CPUInfo.L1InstructionCacheAssociativity := CPUInfo.VIASpecific.L1InstructionCache[ciAssociativity];
  5604. CPUInfo.L2CacheLineSize := CPUInfo.VIASpecific.L2DataCache and $FF;
  5605. CPUInfo.L2CacheAssociativity := (CPUInfo.VIASpecific.L2DataCache shr 12) and $F;
  5606. CPUInfo.L2CacheSize := CPUInfo.VIASpecific.L2DataCache shr 16;
  5607. end;
  5608. CallCPUID($C0000000, 0, ExHiVal, Unused, Unused, Unused);
  5609. if ExHiVal >= $C0000001 then
  5610. CallCPUID($C0000001, 0, Unused, Unused, Unused, CPUInfo.ViaSpecific.ExFeatures);
  5611. end
  5612. else
  5613. ProcessStandard(CPUInfo, HiVal);
  5614. if not CPUInfo.HasExtendedInfo then
  5615. CPUInfo.CpuName := 'C3';
  5616. CPUInfo.MMX := (CPUInfo.Features and VIA_MMX) <> 0;
  5617. CPUInfo.SSE := [];
  5618. if (CPUInfo.Features and VIA_SSE) <> 0 then
  5619. Include(CPUInfo.SSE, sse);
  5620. CPUInfo._3DNow := (CPUInfo.Features and VIA_3DNOW) <> 0;
  5621. end;
  5622. procedure ProcessTransmeta(var CPUInfo: TCpuInfo; HiVal: Cardinal);
  5623. var
  5624. ExHiVal, Unused, VersionInfo: Cardinal;
  5625. begin
  5626. CPUInfo.CpuType := CPU_TYPE_TRANSMETA;
  5627. CPUInfo.Manufacturer := 'Transmeta';
  5628. if (HiVal >= 1) then
  5629. begin
  5630. CallCPUID(1, 0, VersionInfo, Unused, Unused, CPUInfo.Features);
  5631. CPUInfo.PType := (VersionInfo and $00003000) shr 12;
  5632. CPUInfo.Family := (VersionInfo and $00000F00) shr 8;
  5633. CPUInfo.Model := (VersionInfo and $000000F0) shr 4;
  5634. CPUInfo.Stepping := (VersionInfo and $0000000F);
  5635. end;
  5636. // no information when eax is 2
  5637. // eax is 3 means Serial Number, not detected there
  5638. // small CPU description, overriden if ExHiVal >= 80000002
  5639. CallCPUID($80000000, 0, ExHiVal, CPUInfo.CpuName[0], CPUInfo.CpuName[8], CPUInfo.CpuName[4]);
  5640. if ExHiVal <> 0 then
  5641. begin
  5642. CPUInfo.HasExtendedInfo := True;
  5643. if ExHiVal >= $80000001 then
  5644. CallCPUID($80000001, 0, Unused, Unused, Unused, CPUInfo.TransmetaSpecific.ExFeatures);
  5645. if ExHiVal >= $80000002 then
  5646. CallCPUID($80000002, 0, CPUInfo.CpuName[0], CPUInfo.CpuName[4], CPUInfo.CpuName[8], CPUInfo.CpuName[12]);
  5647. if ExHiVal >= $80000003 then
  5648. CallCPUID($80000003, 0, CPUInfo.CpuName[16], CPUInfo.CpuName[20], CPUInfo.CpuName[24], CPUInfo.CpuName[28]);
  5649. if ExHiVal >= $80000004 then
  5650. CallCPUID($80000004, 0, CPUInfo.CpuName[32], CPUInfo.CpuName[36], CPUInfo.CpuName[40], CPUInfo.CpuName[44]);
  5651. if ExHiVal >= $80000005 then
  5652. begin
  5653. CPUInfo.HasCacheInfo := True;
  5654. CallCPUID($80000005, 0, Unused, CPUInfo.TransmetaSpecific.CodeTLB, CPUInfo.TransmetaSpecific.L1DataCache,
  5655. CPUInfo.TransmetaSpecific.L1CodeCache);
  5656. end;
  5657. if CPUInfo.HasCacheInfo then
  5658. begin
  5659. CPUInfo.L1DataCacheSize := CPUInfo.TransmetaSpecific.L1DataCache[ciSize];
  5660. CPUInfo.L1DataCacheLineSize := CPUInfo.TransmetaSpecific.L1DataCache[ciLineSize];
  5661. CPUInfo.L1DataCacheAssociativity := CPUInfo.TransmetaSpecific.L1DataCache[ciAssociativity];
  5662. CPUInfo.L1InstructionCacheSize := CPUInfo.TransmetaSpecific.L1CodeCache[ciSize];
  5663. CPUInfo.L1InstructionCacheLineSize := CPUInfo.TransmetaSpecific.L1CodeCache[ciLineSize];
  5664. CPUInfo.L1InstructionCacheAssociativity := CPUInfo.TransmetaSpecific.L1CodeCache[ciAssociativity];
  5665. CPUInfo.L2CacheLineSize := CPUInfo.TransmetaSpecific.L2Cache and $FF;
  5666. CPUInfo.L2CacheAssociativity := (CPUInfo.TransmetaSpecific.L2Cache shr 12) and $F;
  5667. CPUInfo.L2CacheSize := CPUInfo.TransmetaSpecific.L2Cache shr 16;
  5668. end;
  5669. if ExHiVal >= $80000006 then
  5670. CallCPUID($80000006, 0, Unused, Unused, CPUInfo.TransmetaSpecific.L2Cache, Unused);
  5671. end
  5672. else
  5673. CPUInfo.CpuName := 'Crusoe';
  5674. CallCPUID($80860000, 0, ExHiVal, Unused, Unused, Unused);
  5675. if ExHiVal <> 0 then
  5676. begin
  5677. if ExHiVal >= $80860001 then
  5678. CallCPUID($80860001, 0, Unused, CPUInfo.TransmetaSpecific.RevisionABCD, CPUInfo.TransmetaSpecific.RevisionXXXX,
  5679. CPUInfo.TransmetaSpecific.TransmetaFeatures);
  5680. if ExHiVal >= $80860002 then
  5681. CallCPUID($80860002, 0, Unused, CPUInfo.TransmetaSpecific.CodeMorphingABCD, CPUInfo.TransmetaSpecific.CodeMorphingXXXX, Unused);
  5682. if ExHiVal >= $80860003 then
  5683. CallCPUID($80860003, 0, CPUInfo.TransmetaSpecific.TransmetaInformations[0], CPUInfo.TransmetaSpecific.TransmetaInformations[4],
  5684. CPUInfo.TransmetaSpecific.TransmetaInformations[8], CPUInfo.TransmetaSpecific.TransmetaInformations[12]);
  5685. if ExHiVal >= $80860004 then
  5686. CallCPUID($80860004, 0, CPUInfo.TransmetaSpecific.TransmetaInformations[16], CPUInfo.TransmetaSpecific.TransmetaInformations[20],
  5687. CPUInfo.TransmetaSpecific.TransmetaInformations[24], CPUInfo.TransmetaSpecific.TransmetaInformations[28]);
  5688. if ExHiVal >= $80860005 then
  5689. CallCPUID($80860005, 0, CPUInfo.TransmetaSpecific.TransmetaInformations[32], CPUInfo.TransmetaSpecific.TransmetaInformations[36],
  5690. CPUInfo.TransmetaSpecific.TransmetaInformations[40], CPUInfo.TransmetaSpecific.TransmetaInformations[44]);
  5691. if ExHiVal >= $80860006 then
  5692. CallCPUID($80860006, 0, CPUInfo.TransmetaSpecific.TransmetaInformations[48], CPUInfo.TransmetaSpecific.TransmetaInformations[52],
  5693. CPUInfo.TransmetaSpecific.TransmetaInformations[56], CPUInfo.TransmetaSpecific.TransmetaInformations[60]);
  5694. if (ExHiVal >= $80860007) and ((CPUInfo.TransmetaSpecific.TransmetaFeatures and STRANSMETA_LONGRUN) <> 0) then
  5695. CallCPUID($80860007, 0, CPUInfo.TransmetaSpecific.CurrentFrequency, CPUInfo.TransmetaSpecific.CurrentVoltage,
  5696. CPUInfo.TransmetaSpecific.CurrentPerformance, Unused);
  5697. end;
  5698. CPUInfo.MMX := (CPUInfo.Features and TRANSMETA_MMX) <> 0;
  5699. end;
  5700. var
  5701. HiVal: Cardinal;
  5702. begin
  5703. ResetMemory(Result, sizeof(Result));
  5704. Result.LogicalCore := 1;
  5705. Result.PhysicalCore := 1;
  5706. if HasCPUIDInstruction then
  5707. begin
  5708. Result.HasInstruction := True;
  5709. CallCPUID(0, 0, HiVal, Result.VendorIDString[0], Result.VendorIDString[8],
  5710. Result.VendorIDString[4]);
  5711. if Result.VendorIDString = VendorIDIntel then
  5712. ProcessIntel(Result, HiVal)
  5713. else if Result.VendorIDString = VendorIDAMD then
  5714. ProcessAMD(Result, HiVal)
  5715. else if Result.VendorIDString = VendorIDCyrix then
  5716. ProcessCyrix(Result, HiVal)
  5717. else if Result.VendorIDString = VendorIDVIA then
  5718. ProcessVIA(Result, HiVal)
  5719. else if Result.VendorIDString = VendorIDTransmeta then
  5720. ProcessTransmeta(Result, HiVal)
  5721. else
  5722. ProcessStandard(Result, HiVal);
  5723. end
  5724. else
  5725. Result.Family := 4;
  5726. if Result.CpuType = 0 then
  5727. begin
  5728. Result.Manufacturer := 'Unknown';
  5729. Result.CpuName := 'Unknown';
  5730. end;
  5731. end;
  5732. {$ENDIF ~WINSCP}
  5733. function TestFDIVInstruction: Boolean;
  5734. {$IFDEF CPU32}
  5735. var
  5736. TopNum: Double;
  5737. BottomNum: Double;
  5738. One: Double;
  5739. ISOK: Boolean;
  5740. begin
  5741. // The following code was found in Borlands fdiv.asm file in the
  5742. // Delphi 3\Source\RTL\SYS directory, (I made some minor modifications)
  5743. // therefore I cannot take credit for it.
  5744. TopNum := 2658955;
  5745. BottomNum := PI;
  5746. One := 1;
  5747. asm
  5748. PUSH EAX
  5749. FLD [TopNum]
  5750. FDIV [BottomNum]
  5751. FMUL [BottomNum]
  5752. FSUBR [TopNum]
  5753. FCOMP [One]
  5754. FSTSW AX
  5755. SHR EAX, 8
  5756. AND EAX, 01H
  5757. MOV ISOK, AL
  5758. POP EAX
  5759. end;
  5760. Result := ISOK;
  5761. end;
  5762. {$ENDIF CPU32}
  5763. {$IFDEF CPU64}
  5764. begin
  5765. Result := True;
  5766. end;
  5767. {$ENDIF CPU64}
  5768. //=== Alloc granularity ======================================================
  5769. procedure RoundToAllocGranularity64(var Value: Int64; Up: Boolean);
  5770. begin
  5771. if (Value mod AllocGranularity) <> 0 then
  5772. if Up then
  5773. Value := ((Value div AllocGranularity) + 1) * AllocGranularity
  5774. else
  5775. Value := (Value div AllocGranularity) * AllocGranularity;
  5776. end;
  5777. procedure RoundToAllocGranularityPtr(var Value: Pointer; Up: Boolean);
  5778. var
  5779. Addr: TJclAddr;
  5780. begin
  5781. Addr := TJclAddr(Value);
  5782. if (Addr mod AllocGranularity) <> 0 then
  5783. begin
  5784. if Up then
  5785. Addr := ((Addr div AllocGranularity) + 1) * AllocGranularity
  5786. else
  5787. Addr := (Addr div AllocGranularity) * AllocGranularity;
  5788. Value := Pointer(Addr);
  5789. end;
  5790. end;
  5791. //=== Advanced Power Management (APM) ========================================
  5792. {$IFDEF MSWINDOWS}
  5793. function GetAPMLineStatus: TAPMLineStatus;
  5794. var
  5795. SystemPowerStatus: TSystemPowerStatus;
  5796. begin
  5797. Result := alsUnknown;
  5798. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5799. Exit; // so we return alsUnknown
  5800. SystemPowerStatus.ACLineStatus := 0;
  5801. if not GetSystemPowerStatus(SystemPowerStatus) then
  5802. RaiseLastOSError
  5803. else
  5804. begin
  5805. case SystemPowerStatus.ACLineStatus of
  5806. 0:
  5807. Result := alsOffline;
  5808. 1:
  5809. Result := alsOnline;
  5810. 255:
  5811. Result := alsUnknown;
  5812. end;
  5813. end;
  5814. end;
  5815. function GetAPMBatteryFlag: TAPMBatteryFlag;
  5816. var
  5817. SystemPowerStatus: TSystemPowerStatus;
  5818. begin
  5819. Result := abfUnknown;
  5820. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5821. Exit; // so we return abfUnknown
  5822. SystemPowerStatus.ACLineStatus := 0;
  5823. if not GetSystemPowerStatus(SystemPowerStatus) then
  5824. RaiseLastOSError
  5825. else
  5826. begin
  5827. case SystemPowerStatus.BatteryFlag of
  5828. 1:
  5829. Result := abfHigh;
  5830. 2:
  5831. Result := abfLow;
  5832. 4:
  5833. Result := abfCritical;
  5834. 8:
  5835. Result := abfCharging;
  5836. 128:
  5837. Result := abfNoBattery;
  5838. 255:
  5839. Result := abfUnknown;
  5840. end;
  5841. end;
  5842. end;
  5843. function GetAPMBatteryFlags: TAPMBatteryFlags;
  5844. var
  5845. SystemPowerStatus: TSystemPowerStatus;
  5846. begin
  5847. Result := [];
  5848. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5849. begin
  5850. Result := [abfUnknown];
  5851. Exit; // so we return [abfUnknown]
  5852. end;
  5853. SystemPowerStatus.ACLineStatus := 0;
  5854. if not GetSystemPowerStatus(SystemPowerStatus) then
  5855. RaiseLastOSError
  5856. else
  5857. begin
  5858. if (SystemPowerStatus.BatteryFlag and 1) <> 0 then
  5859. Result := Result + [abfHigh];
  5860. if (SystemPowerStatus.BatteryFlag and 2) <> 0 then
  5861. Result := Result + [abfLow];
  5862. if (SystemPowerStatus.BatteryFlag and 4) <> 0 then
  5863. Result := Result + [abfCritical];
  5864. if (SystemPowerStatus.BatteryFlag and 8) <> 0 then
  5865. Result := Result + [abfCharging];
  5866. if (SystemPowerStatus.BatteryFlag and 128) <> 0 then
  5867. Result := Result + [abfNoBattery];
  5868. if SystemPowerStatus.BatteryFlag = 255 then
  5869. Result := Result + [abfUnknown];
  5870. end;
  5871. end;
  5872. function GetAPMBatteryLifePercent: Integer;
  5873. var
  5874. SystemPowerStatus: TSystemPowerStatus;
  5875. begin
  5876. Result := 0;
  5877. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5878. Exit;
  5879. SystemPowerStatus.ACLineStatus := 0;
  5880. if not GetSystemPowerStatus(SystemPowerStatus) then
  5881. RaiseLastOSError
  5882. else
  5883. Result := SystemPowerStatus.BatteryLifePercent;
  5884. end;
  5885. function GetAPMBatteryLifeTime: DWORD;
  5886. var
  5887. SystemPowerStatus: TSystemPowerStatus;
  5888. begin
  5889. Result := 0;
  5890. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5891. Exit;
  5892. SystemPowerStatus.ACLineStatus := 0;
  5893. if not GetSystemPowerStatus(SystemPowerStatus) then
  5894. RaiseLastOSError
  5895. else
  5896. Result := SystemPowerStatus.BatteryLifeTime;
  5897. end;
  5898. function GetAPMBatteryFullLifeTime: DWORD;
  5899. var
  5900. SystemPowerStatus: TSystemPowerStatus;
  5901. begin
  5902. Result := 0;
  5903. if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion < 5) then // Windows NT doesn't support GetSystemPowerStatus
  5904. Exit;
  5905. SystemPowerStatus.ACLineStatus := 0;
  5906. if not GetSystemPowerStatus(SystemPowerStatus) then
  5907. RaiseLastOSError
  5908. else
  5909. Result := SystemPowerStatus.BatteryFullLifeTime;
  5910. end;
  5911. //=== Memory Information =====================================================
  5912. function GetMaxAppAddress: TJclAddr;
  5913. var
  5914. SystemInfo: TSystemInfo;
  5915. begin
  5916. ResetMemory(SystemInfo, SizeOf(SystemInfo));
  5917. GetSystemInfo(SystemInfo);
  5918. Result := TJclAddr(SystemInfo.lpMaximumApplicationAddress);
  5919. end;
  5920. function GetMinAppAddress: TJclAddr;
  5921. var
  5922. SystemInfo: TSystemInfo;
  5923. begin
  5924. ResetMemory(SystemInfo, SizeOf(SystemInfo));
  5925. GetSystemInfo(SystemInfo);
  5926. Result := TJclAddr(SystemInfo.lpMinimumApplicationAddress);
  5927. end;
  5928. {$ENDIF MSWINDOWS}
  5929. function GetMemoryLoad: Byte;
  5930. {$IFDEF UNIX}
  5931. var
  5932. SystemInf: TSysInfo;
  5933. begin
  5934. {$IFDEF FPC}
  5935. SysInfo(@SystemInf);
  5936. {$ELSE ~FPC}
  5937. SysInfo(SystemInf);
  5938. {$ENDIF ~FPC}
  5939. with SystemInf do
  5940. Result := 100 - Round(100 * freeram / totalram);
  5941. end;
  5942. {$ENDIF UNIX}
  5943. {$IFDEF MSWINDOWS}
  5944. var
  5945. MemoryStatusEx: TMemoryStatusEx;
  5946. begin
  5947. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5948. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5949. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5950. RaiseLastOSError;
  5951. Result := MemoryStatusEx.dwMemoryLoad;
  5952. end;
  5953. {$ENDIF MSWINDOWS}
  5954. function GetSwapFileSize: Int64;
  5955. {$IFDEF UNIX}
  5956. var
  5957. SystemInf: TSysInfo;
  5958. begin
  5959. {$IFDEF FPC}
  5960. SysInfo(@SystemInf);
  5961. {$ELSE ~FPC}
  5962. SysInfo(SystemInf);
  5963. {$ENDIF ~FPC}
  5964. Result := SystemInf.totalswap;
  5965. end;
  5966. {$ENDIF UNIX}
  5967. {$IFDEF MSWINDOWS}
  5968. var
  5969. MemoryStatusEx: TMemoryStatusEx;
  5970. begin
  5971. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5972. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5973. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5974. RaiseLastOSError;
  5975. Result := MemoryStatusEx.ullTotalPageFile - MemoryStatusEx.ullAvailPageFile;
  5976. end;
  5977. {$ENDIF MSWINDOWS}
  5978. function GetSwapFileUsage: Byte;
  5979. {$IFDEF UNIX}
  5980. var
  5981. SystemInf: TSysInfo;
  5982. begin
  5983. {$IFDEF FPC}
  5984. SysInfo(@SystemInf);
  5985. {$ELSE ~FPC}
  5986. SysInfo(SystemInf);
  5987. {$ENDIF ~FPC}
  5988. with SystemInf do
  5989. Result := 100 - Trunc(100 * FreeSwap / TotalSwap);
  5990. end;
  5991. {$ENDIF UNIX}
  5992. {$IFDEF MSWINDOWS}
  5993. var
  5994. MemoryStatusEx: TMemoryStatusEx;
  5995. begin
  5996. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  5997. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  5998. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  5999. RaiseLastOSError;
  6000. if MemoryStatusEx.ullTotalPageFile > 0 then
  6001. Result := 100 - Trunc(MemoryStatusEx.ullAvailPageFile / MemoryStatusEx.ullTotalPageFile * 100)
  6002. else
  6003. Result := 0;
  6004. end;
  6005. {$ENDIF MSWINDOWS}
  6006. function GetTotalPhysicalMemory: Int64;
  6007. {$IFDEF UNIX}
  6008. var
  6009. SystemInf: TSysInfo;
  6010. begin
  6011. {$IFDEF FPC}
  6012. SysInfo(@SystemInf);
  6013. {$ELSE ~FPC}
  6014. SysInfo(SystemInf);
  6015. {$ENDIF ~FPC}
  6016. Result := SystemInf.totalram;
  6017. end;
  6018. {$ENDIF UNIX}
  6019. {$IFDEF MSWINDOWS}
  6020. var
  6021. MemoryStatusEx: TMemoryStatusEx;
  6022. begin
  6023. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  6024. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  6025. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  6026. RaiseLastOSError;
  6027. Result := MemoryStatusEx.ullTotalPhys;
  6028. end;
  6029. {$ENDIF MSWINDOWS}
  6030. function GetFreePhysicalMemory: Int64;
  6031. {$IFDEF UNIX}
  6032. var
  6033. SystemInf: TSysInfo;
  6034. begin
  6035. {$IFDEF FPC}
  6036. SysInfo(@SystemInf);
  6037. {$ELSE ~FPC}
  6038. SysInfo(SystemInf);
  6039. {$ENDIF ~FPC}
  6040. Result := SystemInf.freeram;
  6041. end;
  6042. {$ENDIF UNIX}
  6043. {$IFDEF MSWINDOWS}
  6044. var
  6045. MemoryStatusEx: TMemoryStatusEx;
  6046. begin
  6047. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  6048. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  6049. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  6050. RaiseLastOSError;
  6051. Result := MemoryStatusEx.ullAvailPhys;
  6052. end;
  6053. function GetTotalPageFileMemory: Int64;
  6054. var
  6055. MemoryStatusEx: TMemoryStatusEx;
  6056. begin
  6057. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  6058. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  6059. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  6060. RaiseLastOSError;
  6061. Result := MemoryStatusEx.ullTotalPageFile;
  6062. end;
  6063. function GetFreePageFileMemory: Int64;
  6064. var
  6065. MemoryStatusEx: TMemoryStatusEx;
  6066. begin
  6067. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  6068. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  6069. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  6070. RaiseLastOSError;
  6071. Result := MemoryStatusEx.ullAvailPageFile;
  6072. end;
  6073. function GetTotalVirtualMemory: Int64;
  6074. var
  6075. MemoryStatusEx: TMemoryStatusEx;
  6076. begin
  6077. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  6078. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  6079. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  6080. RaiseLastOSError;
  6081. Result := MemoryStatusEx.ullTotalVirtual;
  6082. end;
  6083. function GetFreeVirtualMemory: Int64;
  6084. var
  6085. MemoryStatusEx: TMemoryStatusEx;
  6086. begin
  6087. ResetMemory(MemoryStatusEx, SizeOf(MemoryStatusEx));
  6088. MemoryStatusEx.dwLength := SizeOf(MemoryStatusEx);
  6089. if not GlobalMemoryStatusEx(MemoryStatusEx) then
  6090. RaiseLastOSError;
  6091. Result := MemoryStatusEx.ullAvailVirtual;
  6092. end;
  6093. //=== Keyboard Information ===================================================
  6094. function GetKeybStateHelper(VirtualKey: Cardinal; Mask: Byte): Boolean;
  6095. var
  6096. Keys: TKeyboardState;
  6097. begin
  6098. Keys[0] := 0;
  6099. Result := GetKeyBoardState(Keys) and (Keys[VirtualKey] and Mask <> 0);
  6100. end;
  6101. function GetKeyState(const VirtualKey: Cardinal): Boolean;
  6102. begin
  6103. Result := GetKeybStateHelper(VirtualKey, $80);
  6104. end;
  6105. function GetNumLockKeyState: Boolean;
  6106. begin
  6107. Result := GetKeybStateHelper(VK_NUMLOCK, $01);
  6108. end;
  6109. function GetScrollLockKeyState: Boolean;
  6110. begin
  6111. Result := GetKeybStateHelper(VK_SCROLL, $01);
  6112. end;
  6113. function GetCapsLockKeyState: Boolean;
  6114. begin
  6115. Result := GetKeybStateHelper(VK_CAPITAL, $01);
  6116. end;
  6117. //=== Windows 95/98/ME system resources information ==========================
  6118. { TODO -oPJH : compare to Win9xFreeSysResources }
  6119. var
  6120. ResmeterLibHandle: THandle;
  6121. MyGetFreeSystemResources: function(ResType: UINT): UINT; stdcall;
  6122. procedure UnloadSystemResourcesMeterLib;
  6123. begin
  6124. if ResmeterLibHandle <> 0 then
  6125. begin
  6126. @MyGetFreeSystemResources := nil;
  6127. try
  6128. FreeLibrary(ResmeterLibHandle);
  6129. except
  6130. // Ignore any exception from the DLL's DllMain(DLL_PROCESS_DETACH) function
  6131. end;
  6132. ResmeterLibHandle := 0;
  6133. end;
  6134. end;
  6135. function IsSystemResourcesMeterPresent: Boolean;
  6136. procedure LoadResmeter;
  6137. begin
  6138. ResmeterLibHandle := SafeLoadLibrary('rsrc32.dll', SEM_FAILCRITICALERRORS);
  6139. if ResmeterLibHandle <> 0 then
  6140. begin
  6141. @MyGetFreeSystemResources := GetProcAddress(ResmeterLibHandle, PAnsiChar('_MyGetFreeSystemResources32@4'));
  6142. if not Assigned(MyGetFreeSystemResources) then
  6143. UnloadSystemResourcesMeterLib;
  6144. end;
  6145. end;
  6146. begin
  6147. if not IsWinNT and (ResmeterLibHandle = 0) then
  6148. LoadResmeter;
  6149. Result := (ResmeterLibHandle <> 0);
  6150. end;
  6151. function GetFreeSystemResources(const ResourceType: TFreeSysResKind): Integer;
  6152. const
  6153. ParamValues: array [TFreeSysResKind] of UINT = (0, 1, 2);
  6154. begin
  6155. if IsSystemResourcesMeterPresent then
  6156. Result := MyGetFreeSystemResources(ParamValues[ResourceType])
  6157. else
  6158. Result := -1;
  6159. end;
  6160. function GetFreeSystemResources: TFreeSystemResources;
  6161. begin
  6162. with Result do
  6163. begin
  6164. SystemRes := GetFreeSystemResources(rtSystem);
  6165. GdiRes := GetFreeSystemResources(rtGdi);
  6166. UserRes := GetFreeSystemResources(rtUser);
  6167. end;
  6168. end;
  6169. function GetBPP: Cardinal;
  6170. var
  6171. DC: HDC;
  6172. begin
  6173. DC := GetDC(HWND_DESKTOP);
  6174. if DC <> 0 then
  6175. begin
  6176. Result := GetDeviceCaps(DC, BITSPIXEL) * GetDeviceCaps(DC, PLANES);
  6177. ReleaseDC(HWND_DESKTOP, DC);
  6178. end
  6179. else
  6180. Result := 0;
  6181. end;
  6182. //=== Installed programs =====================================================
  6183. function ProgIDExists(const ProgID: string): Boolean;
  6184. var
  6185. Tmp: TGUID;
  6186. WideProgID: WideString;
  6187. begin
  6188. WideProgID := ProgID;
  6189. Result := Succeeded(CLSIDFromProgID(PWideChar(WideProgID), Tmp));
  6190. end;
  6191. function IsWordInstalled: Boolean;
  6192. begin
  6193. Result := ProgIDExists('Word.Application');
  6194. end;
  6195. function IsExcelInstalled: Boolean;
  6196. begin
  6197. Result := ProgIDExists('Excel.Application');
  6198. end;
  6199. function IsAccessInstalled: Boolean;
  6200. begin
  6201. Result := ProgIDExists('Access.Application');
  6202. end;
  6203. function IsPowerPointInstalled: Boolean;
  6204. begin
  6205. Result := ProgIDExists('PowerPoint.Application');
  6206. end;
  6207. function IsFrontPageInstalled: Boolean;
  6208. begin
  6209. Result := ProgIDExists('FrontPage.Application');
  6210. end;
  6211. function IsOutlookInstalled: Boolean;
  6212. begin
  6213. Result := ProgIDExists('Outlook.Application');
  6214. end;
  6215. function IsInternetExplorerInstalled: Boolean;
  6216. begin
  6217. Result := ProgIDExists('InternetExplorer.Application');
  6218. end;
  6219. function IsMSProjectInstalled: Boolean;
  6220. begin
  6221. Result := ProgIDExists('MSProject.Application');
  6222. end;
  6223. function IsOpenOfficeInstalled: Boolean;
  6224. begin
  6225. Result := ProgIDExists('com.sun.star.ServiceManager');
  6226. end;
  6227. function IsLibreOfficeInstalled: Boolean;
  6228. begin
  6229. Result := ProgIDExists('com.sun.star.ServiceManager.1');
  6230. end;
  6231. //=== Initialization/Finalization ============================================
  6232. procedure InitSysInfo;
  6233. var
  6234. SystemInfo: TSystemInfo;
  6235. {$IFNDEF WINSCP}
  6236. Kernel32FileName: string;
  6237. VerFixedFileInfo: TVSFixedFileInfo;
  6238. {$ENDIF}
  6239. begin
  6240. try
  6241. { processor information related initialization }
  6242. ResetMemory(SystemInfo, SizeOf(SystemInfo));
  6243. GetSystemInfo(SystemInfo);
  6244. ProcessorCount := SystemInfo.dwNumberOfProcessors;
  6245. AllocGranularity := SystemInfo.dwAllocationGranularity;
  6246. PageSize := SystemInfo.dwPageSize;
  6247. { Windows version information }
  6248. IsWinNT := Win32Platform = VER_PLATFORM_WIN32_NT;
  6249. {$IFNDEF WINSCP}
  6250. Kernel32FileName := GetModulePath(GetModuleHandle(kernel32));
  6251. VerFixedFileInfo.dwFileDateLS := 0;
  6252. if not IsWinNT and VersionFixedFileInfo(Kernel32FileName, VerFixedFileInfo) then
  6253. KernelVersionHi := VerFixedFileInfo.dwProductVersionMS
  6254. else
  6255. KernelVersionHi := 0;
  6256. case GetWindowsVersion of
  6257. wvUnknown:
  6258. ;
  6259. wvWin95:
  6260. IsWin95 := True;
  6261. wvWin95OSR2:
  6262. IsWin95OSR2 := True;
  6263. wvWin98:
  6264. IsWin98 := True;
  6265. wvWin98SE:
  6266. IsWin98SE := True;
  6267. wvWinME:
  6268. IsWinME := True;
  6269. wvWinNT31:
  6270. begin
  6271. IsWinNT3 := True;
  6272. IsWinNT31 := True;
  6273. end;
  6274. wvWinNT35:
  6275. begin
  6276. IsWinNT3 := True;
  6277. IsWinNT35 := True;
  6278. end;
  6279. wvWinNT351:
  6280. begin
  6281. IsWinNT3 := True;
  6282. IsWinNT35 := True;
  6283. IsWinNT351 := True;
  6284. end;
  6285. wvWinNT4:
  6286. IsWinNT4 := True;
  6287. wvWin2000:
  6288. IsWin2K := True;
  6289. wvWinXP:
  6290. IsWinXP := True;
  6291. wvWin2003:
  6292. IsWin2003 := True;
  6293. wvWinXP64:
  6294. IsWinXP64 := True;
  6295. wvWin2003R2:
  6296. IsWin2003R2 := True;
  6297. wvWinVista:
  6298. IsWinVista := True;
  6299. wvWinServer2008:
  6300. IsWinServer2008 := True;
  6301. wvWin7:
  6302. IsWin7 := True;
  6303. wvWinServer2008R2:
  6304. IsWinServer2008R2 := True;
  6305. wvWin8:
  6306. IsWin8 := True;
  6307. wvWin8RT:
  6308. IsWin8RT := True;
  6309. wvWinServer2012:
  6310. IsWinServer2012 := True;
  6311. wvWin81:
  6312. IsWin81 := True;
  6313. wvWin81RT:
  6314. IsWin81RT := True;
  6315. wvWinServer2012R2:
  6316. IsWinServer2012R2 := True;
  6317. wvWin10:
  6318. IsWin10 := True;
  6319. wvWinServer2016:
  6320. IsWinServer2016 := True;
  6321. wvWinServer2019:
  6322. IsWinServer2019 := True;
  6323. wvWinServer2022:
  6324. IsWinServer2022 := True;
  6325. wvWinServer2025:
  6326. IsWinServer2025 := True;
  6327. wvWinServer:
  6328. IsWinServer := True;
  6329. wvWin11:
  6330. IsWin11 := True;
  6331. end;
  6332. {$ENDIF}
  6333. except
  6334. // Don't crash the application if anything goes wrong detecting the correct
  6335. // Windows version information.
  6336. end;
  6337. end;
  6338. procedure FinalizeSysInfo;
  6339. begin
  6340. UnloadSystemResourcesMeterLib;
  6341. end;
  6342. initialization
  6343. InitSysInfo;
  6344. {$IFDEF UNITVERSIONING}
  6345. RegisterUnitVersion(HInstance, UnitVersioning);
  6346. {$ENDIF UNITVERSIONING}
  6347. finalization
  6348. {$IFDEF UNITVERSIONING}
  6349. UnregisterUnitVersion(HInstance);
  6350. {$ENDIF UNITVERSIONING}
  6351. FinalizeSysInfo;
  6352. {$ENDIF MSWINDOWS}
  6353. end.