SystemInformation.cxx 146 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #if defined(_WIN32)
  11. # define NOMINMAX // use our min,max
  12. # if !defined(_WIN32_WINNT) && !(defined(_MSC_VER) && _MSC_VER < 1300)
  13. # define _WIN32_WINNT 0x0501
  14. # endif
  15. # include <winsock.h> // WSADATA, include before sys/types.h
  16. #endif
  17. #if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
  18. # define _GNU_SOURCE
  19. #endif
  20. // TODO:
  21. // We need an alternative implementation for many functions in this file
  22. // when USE_ASM_INSTRUCTIONS gets defined as 0.
  23. //
  24. // Consider using these on Win32/Win64 for some of them:
  25. //
  26. // IsProcessorFeaturePresent
  27. // http://msdn.microsoft.com/en-us/library/ms724482(VS.85).aspx
  28. //
  29. // GetProcessMemoryInfo
  30. // http://msdn.microsoft.com/en-us/library/ms683219(VS.85).aspx
  31. #include "kwsysPrivate.h"
  32. #include KWSYS_HEADER(stl/string)
  33. #include KWSYS_HEADER(stl/vector)
  34. #include KWSYS_HEADER(ios/iosfwd)
  35. #include KWSYS_HEADER(SystemInformation.hxx)
  36. #include KWSYS_HEADER(Process.h)
  37. #include KWSYS_HEADER(ios/iostream)
  38. #include KWSYS_HEADER(ios/sstream)
  39. #include KWSYS_HEADER(ios/fstream)
  40. // Work-around CMake dependency scanning limitation. This must
  41. // duplicate the above list of headers.
  42. #if 0
  43. # include "SystemInformation.hxx.in"
  44. # include "Process.h.in"
  45. # include "Configure.hxx.in"
  46. # include "kwsys_stl.hxx.in"
  47. # include "kwsys_stl_vector.in"
  48. # include "kwsys_stl_iosfwd.in"
  49. # include "kwsys_ios_sstream.h.in"
  50. # include "kwsys_ios_iostream.h.in"
  51. # include "kwsys_ios_fstream.h.in"
  52. #endif
  53. #if defined(_WIN32)
  54. # include <windows.h>
  55. # if defined(_MSC_VER) && _MSC_VER >= 1800
  56. # define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
  57. # endif
  58. # include <errno.h>
  59. # if defined(KWSYS_SYS_HAS_PSAPI)
  60. # include <psapi.h>
  61. # endif
  62. # if !defined(siginfo_t)
  63. typedef int siginfo_t;
  64. # endif
  65. #else
  66. # include <sys/types.h>
  67. # include <sys/time.h>
  68. # include <sys/utsname.h> // int uname(struct utsname *buf);
  69. # include <sys/resource.h> // getrlimit
  70. # include <unistd.h>
  71. # include <signal.h>
  72. # include <fcntl.h>
  73. # include <errno.h> // extern int errno;
  74. #endif
  75. #ifdef __FreeBSD__
  76. # include <sys/sysctl.h>
  77. # include <fenv.h>
  78. # include <sys/socket.h>
  79. # include <netdb.h>
  80. # include <netinet/in.h>
  81. # if defined(KWSYS_SYS_HAS_IFADDRS_H)
  82. # include <ifaddrs.h>
  83. # define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
  84. # endif
  85. #endif
  86. #if defined(__OpenBSD__) || defined(__NetBSD__)
  87. # include <sys/param.h>
  88. # include <sys/sysctl.h>
  89. #endif
  90. #if defined(KWSYS_SYS_HAS_MACHINE_CPU_H)
  91. # include <machine/cpu.h>
  92. #endif
  93. #if defined(__DragonFly__)
  94. # include <sys/sysctl.h>
  95. #endif
  96. #ifdef __APPLE__
  97. # include <sys/sysctl.h>
  98. # include <mach/vm_statistics.h>
  99. # include <mach/host_info.h>
  100. # include <mach/mach.h>
  101. # include <mach/mach_types.h>
  102. # include <fenv.h>
  103. # include <sys/socket.h>
  104. # include <netdb.h>
  105. # include <netinet/in.h>
  106. # if defined(KWSYS_SYS_HAS_IFADDRS_H)
  107. # include <ifaddrs.h>
  108. # define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
  109. # endif
  110. # if !(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 >= 1050)
  111. # undef KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE
  112. # endif
  113. #endif
  114. #ifdef __linux
  115. # include <fenv.h>
  116. # include <sys/socket.h>
  117. # include <netdb.h>
  118. # include <netinet/in.h>
  119. # if defined(KWSYS_SYS_HAS_IFADDRS_H)
  120. # include <ifaddrs.h>
  121. # if !defined(__LSB_VERSION__) /* LSB has no getifaddrs */
  122. # define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
  123. # endif
  124. # endif
  125. # if defined(KWSYS_CXX_HAS_RLIMIT64)
  126. typedef struct rlimit64 ResourceLimitType;
  127. # define GetResourceLimit getrlimit64
  128. # else
  129. typedef struct rlimit ResourceLimitType;
  130. # define GetResourceLimit getrlimit
  131. # endif
  132. #elif defined( __hpux )
  133. # include <sys/param.h>
  134. # include <sys/pstat.h>
  135. # if defined(KWSYS_SYS_HAS_MPCTL_H)
  136. # include <sys/mpctl.h>
  137. # endif
  138. #endif
  139. #ifdef __HAIKU__
  140. # include <OS.h>
  141. #endif
  142. #if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
  143. # include <execinfo.h>
  144. # if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
  145. # include <cxxabi.h>
  146. # endif
  147. # if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
  148. # include <dlfcn.h>
  149. # endif
  150. #else
  151. # undef KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE
  152. # undef KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP
  153. #endif
  154. #include <memory.h>
  155. #include <stdlib.h>
  156. #include <stdio.h>
  157. #include <string.h>
  158. #include <ctype.h> // int isdigit(int c);
  159. #if defined(KWSYS_USE_LONG_LONG)
  160. # if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
  161. # define iostreamLongLong(x) (x)
  162. # else
  163. # define iostreamLongLong(x) ((long)x)
  164. # endif
  165. #elif defined(KWSYS_USE___INT64)
  166. # if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
  167. # define iostreamLongLong(x) (x)
  168. # else
  169. # define iostreamLongLong(x) ((long)x)
  170. # endif
  171. #else
  172. # error "No Long Long"
  173. #endif
  174. #if defined(KWSYS_CXX_HAS_ATOLL)
  175. # define atoLongLong atoll
  176. #else
  177. # if defined(KWSYS_CXX_HAS__ATOI64)
  178. # define atoLongLong _atoi64
  179. # elif defined(KWSYS_CXX_HAS_ATOL)
  180. # define atoLongLong atol
  181. # else
  182. # define atoLongLong atoi
  183. # endif
  184. #endif
  185. #if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(_WIN64)
  186. #define USE_ASM_INSTRUCTIONS 1
  187. #else
  188. #define USE_ASM_INSTRUCTIONS 0
  189. #endif
  190. #if defined(_MSC_VER) && (_MSC_VER >= 1400)
  191. #include <intrin.h>
  192. #define USE_CPUID_INTRINSICS 1
  193. #else
  194. #define USE_CPUID_INTRINSICS 0
  195. #endif
  196. #if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
  197. # define USE_CPUID 1
  198. #else
  199. # define USE_CPUID 0
  200. #endif
  201. #if USE_CPUID
  202. #define CPUID_AWARE_COMPILER
  203. /**
  204. * call CPUID instruction
  205. *
  206. * Will return false if the instruction failed.
  207. */
  208. static bool call_cpuid(int select, int result[4])
  209. {
  210. #if USE_CPUID_INTRINSICS
  211. __cpuid(result, select);
  212. return true;
  213. #else
  214. int tmp[4];
  215. #if defined(_MSC_VER)
  216. // Use SEH to determine CPUID presence
  217. __try {
  218. _asm {
  219. #ifdef CPUID_AWARE_COMPILER
  220. ; we must push/pop the registers <<CPUID>> writes to, as the
  221. ; optimiser does not know about <<CPUID>>, and so does not expect
  222. ; these registers to change.
  223. push eax
  224. push ebx
  225. push ecx
  226. push edx
  227. #endif
  228. ; <<CPUID>>
  229. mov eax, select
  230. #ifdef CPUID_AWARE_COMPILER
  231. cpuid
  232. #else
  233. _asm _emit 0x0f
  234. _asm _emit 0xa2
  235. #endif
  236. mov tmp[0 * TYPE int], eax
  237. mov tmp[1 * TYPE int], ebx
  238. mov tmp[2 * TYPE int], ecx
  239. mov tmp[3 * TYPE int], edx
  240. #ifdef CPUID_AWARE_COMPILER
  241. pop edx
  242. pop ecx
  243. pop ebx
  244. pop eax
  245. #endif
  246. }
  247. }
  248. __except(1)
  249. {
  250. return false;
  251. }
  252. memcpy(result, tmp, sizeof(tmp));
  253. #elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
  254. unsigned int a, b, c, d;
  255. __asm {
  256. mov EAX, select;
  257. cpuid
  258. mov a, EAX;
  259. mov b, EBX;
  260. mov c, ECX;
  261. mov d, EDX;
  262. }
  263. result[0] = a;
  264. result[1] = b;
  265. result[2] = c;
  266. result[3] = d;
  267. #endif
  268. // The cpuid instruction succeeded.
  269. return true;
  270. #endif
  271. }
  272. #endif
  273. namespace KWSYS_NAMESPACE
  274. {
  275. template<typename T>
  276. T min(T a, T b){ return a<b ? a : b; }
  277. extern "C" { typedef void (*SigAction)(int,siginfo_t*,void*); }
  278. // Define SystemInformationImplementation class
  279. typedef void (*DELAY_FUNC)(unsigned int uiMS);
  280. class SystemInformationImplementation
  281. {
  282. public:
  283. typedef SystemInformation::LongLong LongLong;
  284. SystemInformationImplementation ();
  285. ~SystemInformationImplementation ();
  286. const char * GetVendorString();
  287. const char * GetVendorID();
  288. kwsys_stl::string GetTypeID();
  289. kwsys_stl::string GetFamilyID();
  290. kwsys_stl::string GetModelID();
  291. kwsys_stl::string GetModelName();
  292. kwsys_stl::string GetSteppingCode();
  293. const char * GetExtendedProcessorName();
  294. const char * GetProcessorSerialNumber();
  295. int GetProcessorCacheSize();
  296. unsigned int GetLogicalProcessorsPerPhysical();
  297. float GetProcessorClockFrequency();
  298. int GetProcessorAPICID();
  299. int GetProcessorCacheXSize(long int);
  300. bool DoesCPUSupportFeature(long int);
  301. const char * GetOSName();
  302. const char * GetHostname();
  303. int GetFullyQualifiedDomainName(kwsys_stl::string &fqdn);
  304. const char * GetOSRelease();
  305. const char * GetOSVersion();
  306. const char * GetOSPlatform();
  307. bool Is64Bits();
  308. unsigned int GetNumberOfLogicalCPU(); // per physical cpu
  309. unsigned int GetNumberOfPhysicalCPU();
  310. bool DoesCPUSupportCPUID();
  311. // Retrieve memory information in megabyte.
  312. size_t GetTotalVirtualMemory();
  313. size_t GetAvailableVirtualMemory();
  314. size_t GetTotalPhysicalMemory();
  315. size_t GetAvailablePhysicalMemory();
  316. LongLong GetProcessId();
  317. // Retrieve memory information in kib
  318. LongLong GetHostMemoryTotal();
  319. LongLong GetHostMemoryAvailable(const char *envVarName);
  320. LongLong GetHostMemoryUsed();
  321. LongLong GetProcMemoryAvailable(
  322. const char *hostLimitEnvVarName,
  323. const char *procLimitEnvVarName);
  324. LongLong GetProcMemoryUsed();
  325. // enable/disable stack trace signal handler.
  326. static
  327. void SetStackTraceOnError(int enable);
  328. // get current stack
  329. static
  330. kwsys_stl::string GetProgramStack(int firstFrame, int wholePath);
  331. /** Run the different checks */
  332. void RunCPUCheck();
  333. void RunOSCheck();
  334. void RunMemoryCheck();
  335. public:
  336. typedef struct tagID
  337. {
  338. int Type;
  339. int Family;
  340. int Model;
  341. int Revision;
  342. int ExtendedFamily;
  343. int ExtendedModel;
  344. kwsys_stl::string ProcessorName;
  345. kwsys_stl::string Vendor;
  346. kwsys_stl::string SerialNumber;
  347. kwsys_stl::string ModelName;
  348. } ID;
  349. typedef struct tagCPUPowerManagement
  350. {
  351. bool HasVoltageID;
  352. bool HasFrequencyID;
  353. bool HasTempSenseDiode;
  354. } CPUPowerManagement;
  355. typedef struct tagCPUExtendedFeatures
  356. {
  357. bool Has3DNow;
  358. bool Has3DNowPlus;
  359. bool SupportsMP;
  360. bool HasMMXPlus;
  361. bool HasSSEMMX;
  362. bool SupportsHyperthreading;
  363. unsigned int LogicalProcessorsPerPhysical;
  364. int APIC_ID;
  365. CPUPowerManagement PowerManagement;
  366. } CPUExtendedFeatures;
  367. typedef struct CPUtagFeatures
  368. {
  369. bool HasFPU;
  370. bool HasTSC;
  371. bool HasMMX;
  372. bool HasSSE;
  373. bool HasSSEFP;
  374. bool HasSSE2;
  375. bool HasIA64;
  376. bool HasAPIC;
  377. bool HasCMOV;
  378. bool HasMTRR;
  379. bool HasACPI;
  380. bool HasSerial;
  381. bool HasThermal;
  382. int CPUSpeed;
  383. int L1CacheSize;
  384. int L2CacheSize;
  385. int L3CacheSize;
  386. CPUExtendedFeatures ExtendedFeatures;
  387. } CPUFeatures;
  388. enum Manufacturer
  389. {
  390. AMD, Intel, NSC, UMC, Cyrix, NexGen, IDT, Rise, Transmeta, Sun, IBM,
  391. Motorola, HP, UnknownManufacturer
  392. };
  393. protected:
  394. // For windows
  395. bool RetrieveCPUFeatures();
  396. bool RetrieveCPUIdentity();
  397. bool RetrieveCPUCacheDetails();
  398. bool RetrieveClassicalCPUCacheDetails();
  399. bool RetrieveCPUClockSpeed();
  400. bool RetrieveClassicalCPUClockSpeed();
  401. bool RetrieveCPUExtendedLevelSupport(int);
  402. bool RetrieveExtendedCPUFeatures();
  403. bool RetrieveProcessorSerialNumber();
  404. bool RetrieveCPUPowerManagement();
  405. bool RetrieveClassicalCPUIdentity();
  406. bool RetrieveExtendedCPUIdentity();
  407. // Processor information
  408. Manufacturer ChipManufacturer;
  409. CPUFeatures Features;
  410. ID ChipID;
  411. float CPUSpeedInMHz;
  412. unsigned int NumberOfLogicalCPU;
  413. unsigned int NumberOfPhysicalCPU;
  414. int CPUCount(); // For windows
  415. unsigned char LogicalCPUPerPhysicalCPU();
  416. unsigned char GetAPICId(); // For windows
  417. bool IsHyperThreadingSupported();
  418. static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int); // For windows
  419. // For Linux and Cygwin, /proc/cpuinfo formats are slightly different
  420. bool RetreiveInformationFromCpuInfoFile();
  421. kwsys_stl::string ExtractValueFromCpuInfoFile(kwsys_stl::string buffer,
  422. const char* word, size_t init=0);
  423. bool QueryLinuxMemory();
  424. bool QueryCygwinMemory();
  425. static void Delay (unsigned int);
  426. static void DelayOverhead (unsigned int);
  427. void FindManufacturer(const kwsys_stl::string &family = "");
  428. // For Mac
  429. bool ParseSysCtl();
  430. int CallSwVers(const char *arg, kwsys_stl::string &ver);
  431. void TrimNewline(kwsys_stl::string&);
  432. kwsys_stl::string ExtractValueFromSysCtl(const char* word);
  433. kwsys_stl::string SysCtlBuffer;
  434. // For Solaris
  435. bool QuerySolarisMemory();
  436. bool QuerySolarisProcessor();
  437. kwsys_stl::string ParseValueFromKStat(const char* arguments);
  438. kwsys_stl::string RunProcess(kwsys_stl::vector<const char*> args);
  439. //For Haiku OS
  440. bool QueryHaikuInfo();
  441. //For QNX
  442. bool QueryQNXMemory();
  443. bool QueryQNXProcessor();
  444. //For OpenBSD, FreeBSD, NetBSD, DragonFly
  445. bool QueryBSDMemory();
  446. bool QueryBSDProcessor();
  447. //For HP-UX
  448. bool QueryHPUXMemory();
  449. bool QueryHPUXProcessor();
  450. //For Microsoft Windows
  451. bool QueryWindowsMemory();
  452. //For AIX
  453. bool QueryAIXMemory();
  454. bool QueryProcessorBySysconf();
  455. bool QueryProcessor();
  456. // Evaluate the memory information.
  457. bool QueryMemoryBySysconf();
  458. bool QueryMemory();
  459. size_t TotalVirtualMemory;
  460. size_t AvailableVirtualMemory;
  461. size_t TotalPhysicalMemory;
  462. size_t AvailablePhysicalMemory;
  463. size_t CurrentPositionInFile;
  464. // Operating System information
  465. bool QueryOSInformation();
  466. kwsys_stl::string OSName;
  467. kwsys_stl::string Hostname;
  468. kwsys_stl::string OSRelease;
  469. kwsys_stl::string OSVersion;
  470. kwsys_stl::string OSPlatform;
  471. };
  472. SystemInformation::SystemInformation()
  473. {
  474. this->Implementation = new SystemInformationImplementation;
  475. }
  476. SystemInformation::~SystemInformation()
  477. {
  478. delete this->Implementation;
  479. }
  480. const char * SystemInformation::GetVendorString()
  481. {
  482. return this->Implementation->GetVendorString();
  483. }
  484. const char * SystemInformation::GetVendorID()
  485. {
  486. return this->Implementation->GetVendorID();
  487. }
  488. kwsys_stl::string SystemInformation::GetTypeID()
  489. {
  490. return this->Implementation->GetTypeID();
  491. }
  492. kwsys_stl::string SystemInformation::GetFamilyID()
  493. {
  494. return this->Implementation->GetFamilyID();
  495. }
  496. kwsys_stl::string SystemInformation::GetModelID()
  497. {
  498. return this->Implementation->GetModelID();
  499. }
  500. kwsys_stl::string SystemInformation::GetModelName()
  501. {
  502. return this->Implementation->GetModelName();
  503. }
  504. kwsys_stl::string SystemInformation::GetSteppingCode()
  505. {
  506. return this->Implementation->GetSteppingCode();
  507. }
  508. const char * SystemInformation::GetExtendedProcessorName()
  509. {
  510. return this->Implementation->GetExtendedProcessorName();
  511. }
  512. const char * SystemInformation::GetProcessorSerialNumber()
  513. {
  514. return this->Implementation->GetProcessorSerialNumber();
  515. }
  516. int SystemInformation::GetProcessorCacheSize()
  517. {
  518. return this->Implementation->GetProcessorCacheSize();
  519. }
  520. unsigned int SystemInformation::GetLogicalProcessorsPerPhysical()
  521. {
  522. return this->Implementation->GetLogicalProcessorsPerPhysical();
  523. }
  524. float SystemInformation::GetProcessorClockFrequency()
  525. {
  526. return this->Implementation->GetProcessorClockFrequency();
  527. }
  528. int SystemInformation::GetProcessorAPICID()
  529. {
  530. return this->Implementation->GetProcessorAPICID();
  531. }
  532. int SystemInformation::GetProcessorCacheXSize(long int l)
  533. {
  534. return this->Implementation->GetProcessorCacheXSize(l);
  535. }
  536. bool SystemInformation::DoesCPUSupportFeature(long int i)
  537. {
  538. return this->Implementation->DoesCPUSupportFeature(i);
  539. }
  540. kwsys_stl::string SystemInformation::GetCPUDescription()
  541. {
  542. kwsys_ios::ostringstream oss;
  543. oss
  544. << this->GetNumberOfPhysicalCPU()
  545. << " core ";
  546. if (this->GetModelName().empty())
  547. {
  548. oss
  549. << this->GetProcessorClockFrequency()
  550. << " MHz "
  551. << this->GetVendorString()
  552. << " "
  553. << this->GetExtendedProcessorName();
  554. }
  555. else
  556. {
  557. oss << this->GetModelName();
  558. }
  559. // remove extra spaces
  560. kwsys_stl::string tmp=oss.str();
  561. size_t pos;
  562. while( (pos=tmp.find(" "))!=kwsys_stl::string::npos)
  563. {
  564. tmp.replace(pos,2," ");
  565. }
  566. return tmp;
  567. }
  568. const char * SystemInformation::GetOSName()
  569. {
  570. return this->Implementation->GetOSName();
  571. }
  572. const char * SystemInformation::GetHostname()
  573. {
  574. return this->Implementation->GetHostname();
  575. }
  576. kwsys_stl::string SystemInformation::GetFullyQualifiedDomainName()
  577. {
  578. kwsys_stl::string fqdn;
  579. this->Implementation->GetFullyQualifiedDomainName(fqdn);
  580. return fqdn;
  581. }
  582. const char * SystemInformation::GetOSRelease()
  583. {
  584. return this->Implementation->GetOSRelease();
  585. }
  586. const char * SystemInformation::GetOSVersion()
  587. {
  588. return this->Implementation->GetOSVersion();
  589. }
  590. const char * SystemInformation::GetOSPlatform()
  591. {
  592. return this->Implementation->GetOSPlatform();
  593. }
  594. int SystemInformation::GetOSIsWindows()
  595. {
  596. #if defined(_WIN32)
  597. return 1;
  598. #else
  599. return 0;
  600. #endif
  601. }
  602. int SystemInformation::GetOSIsLinux()
  603. {
  604. #if defined(__linux)
  605. return 1;
  606. #else
  607. return 0;
  608. #endif
  609. }
  610. int SystemInformation::GetOSIsApple()
  611. {
  612. #if defined(__APPLE__)
  613. return 1;
  614. #else
  615. return 0;
  616. #endif
  617. }
  618. kwsys_stl::string SystemInformation::GetOSDescription()
  619. {
  620. kwsys_ios::ostringstream oss;
  621. oss
  622. << this->GetOSName()
  623. << " "
  624. << this->GetOSRelease()
  625. << " "
  626. << this->GetOSVersion();
  627. return oss.str();
  628. }
  629. bool SystemInformation::Is64Bits()
  630. {
  631. return this->Implementation->Is64Bits();
  632. }
  633. unsigned int SystemInformation::GetNumberOfLogicalCPU() // per physical cpu
  634. {
  635. return this->Implementation->GetNumberOfLogicalCPU();
  636. }
  637. unsigned int SystemInformation::GetNumberOfPhysicalCPU()
  638. {
  639. return this->Implementation->GetNumberOfPhysicalCPU();
  640. }
  641. bool SystemInformation::DoesCPUSupportCPUID()
  642. {
  643. return this->Implementation->DoesCPUSupportCPUID();
  644. }
  645. // Retrieve memory information in megabyte.
  646. size_t SystemInformation::GetTotalVirtualMemory()
  647. {
  648. return this->Implementation->GetTotalVirtualMemory();
  649. }
  650. size_t SystemInformation::GetAvailableVirtualMemory()
  651. {
  652. return this->Implementation->GetAvailableVirtualMemory();
  653. }
  654. size_t SystemInformation::GetTotalPhysicalMemory()
  655. {
  656. return this->Implementation->GetTotalPhysicalMemory();
  657. }
  658. size_t SystemInformation::GetAvailablePhysicalMemory()
  659. {
  660. return this->Implementation->GetAvailablePhysicalMemory();
  661. }
  662. kwsys_stl::string SystemInformation::GetMemoryDescription(
  663. const char *hostLimitEnvVarName,
  664. const char *procLimitEnvVarName)
  665. {
  666. kwsys_ios::ostringstream oss;
  667. oss
  668. << "Host Total: "
  669. << iostreamLongLong(this->GetHostMemoryTotal())
  670. << " KiB, Host Available: "
  671. << iostreamLongLong(this->GetHostMemoryAvailable(hostLimitEnvVarName))
  672. << " KiB, Process Available: "
  673. << iostreamLongLong(
  674. this->GetProcMemoryAvailable(hostLimitEnvVarName,procLimitEnvVarName))
  675. << " KiB";
  676. return oss.str();
  677. }
  678. // host memory info in units of KiB.
  679. SystemInformation::LongLong SystemInformation::GetHostMemoryTotal()
  680. {
  681. return this->Implementation->GetHostMemoryTotal();
  682. }
  683. SystemInformation::LongLong
  684. SystemInformation::GetHostMemoryAvailable(const char *hostLimitEnvVarName)
  685. {
  686. return this->Implementation->GetHostMemoryAvailable(hostLimitEnvVarName);
  687. }
  688. SystemInformation::LongLong SystemInformation::GetHostMemoryUsed()
  689. {
  690. return this->Implementation->GetHostMemoryUsed();
  691. }
  692. // process memory info in units of KiB.
  693. SystemInformation::LongLong
  694. SystemInformation::GetProcMemoryAvailable(
  695. const char *hostLimitEnvVarName,
  696. const char *procLimitEnvVarName)
  697. {
  698. return this->Implementation->GetProcMemoryAvailable(
  699. hostLimitEnvVarName,
  700. procLimitEnvVarName);
  701. }
  702. SystemInformation::LongLong SystemInformation::GetProcMemoryUsed()
  703. {
  704. return this->Implementation->GetProcMemoryUsed();
  705. }
  706. SystemInformation::LongLong SystemInformation::GetProcessId()
  707. {
  708. return this->Implementation->GetProcessId();
  709. }
  710. void SystemInformation::SetStackTraceOnError(int enable)
  711. {
  712. SystemInformationImplementation::SetStackTraceOnError(enable);
  713. }
  714. kwsys_stl::string SystemInformation::GetProgramStack(int firstFrame, int wholePath)
  715. {
  716. return SystemInformationImplementation::GetProgramStack(firstFrame, wholePath);
  717. }
  718. /** Run the different checks */
  719. void SystemInformation::RunCPUCheck()
  720. {
  721. this->Implementation->RunCPUCheck();
  722. }
  723. void SystemInformation::RunOSCheck()
  724. {
  725. this->Implementation->RunOSCheck();
  726. }
  727. void SystemInformation::RunMemoryCheck()
  728. {
  729. this->Implementation->RunMemoryCheck();
  730. }
  731. // --------------------------------------------------------------
  732. // SystemInformationImplementation starts here
  733. #define STORE_TLBCACHE_INFO(x,y) x = (x < y) ? y : x
  734. #define TLBCACHE_INFO_UNITS (15)
  735. #define CLASSICAL_CPU_FREQ_LOOP 10000000
  736. #define RDTSC_INSTRUCTION _asm _emit 0x0f _asm _emit 0x31
  737. #define MMX_FEATURE 0x00000001
  738. #define MMX_PLUS_FEATURE 0x00000002
  739. #define SSE_FEATURE 0x00000004
  740. #define SSE2_FEATURE 0x00000008
  741. #define AMD_3DNOW_FEATURE 0x00000010
  742. #define AMD_3DNOW_PLUS_FEATURE 0x00000020
  743. #define IA64_FEATURE 0x00000040
  744. #define MP_CAPABLE 0x00000080
  745. #define HYPERTHREAD_FEATURE 0x00000100
  746. #define SERIALNUMBER_FEATURE 0x00000200
  747. #define APIC_FEATURE 0x00000400
  748. #define SSE_FP_FEATURE 0x00000800
  749. #define SSE_MMX_FEATURE 0x00001000
  750. #define CMOV_FEATURE 0x00002000
  751. #define MTRR_FEATURE 0x00004000
  752. #define L1CACHE_FEATURE 0x00008000
  753. #define L2CACHE_FEATURE 0x00010000
  754. #define L3CACHE_FEATURE 0x00020000
  755. #define ACPI_FEATURE 0x00040000
  756. #define THERMALMONITOR_FEATURE 0x00080000
  757. #define TEMPSENSEDIODE_FEATURE 0x00100000
  758. #define FREQUENCYID_FEATURE 0x00200000
  759. #define VOLTAGEID_FREQUENCY 0x00400000
  760. // Status Flag
  761. #define HT_NOT_CAPABLE 0
  762. #define HT_ENABLED 1
  763. #define HT_DISABLED 2
  764. #define HT_SUPPORTED_NOT_ENABLED 3
  765. #define HT_CANNOT_DETECT 4
  766. // EDX[28] Bit 28 is set if HT is supported
  767. #define HT_BIT 0x10000000
  768. // EAX[11:8] Bit 8-11 contains family processor ID.
  769. #define FAMILY_ID 0x0F00
  770. #define PENTIUM4_ID 0x0F00
  771. // EAX[23:20] Bit 20-23 contains extended family processor ID
  772. #define EXT_FAMILY_ID 0x0F00000
  773. // EBX[23:16] Bit 16-23 in ebx contains the number of logical
  774. #define NUM_LOGICAL_BITS 0x00FF0000
  775. // processors per physical processor when execute cpuid with
  776. // eax set to 1
  777. // EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique
  778. #define INITIAL_APIC_ID_BITS 0xFF000000
  779. // initial APIC ID for the processor this code is running on.
  780. // Default value = 0xff if HT is not supported
  781. // Hide implementation details in an anonymous namespace.
  782. namespace {
  783. // *****************************************************************************
  784. #if defined(__linux) || defined(__APPLE__)
  785. int LoadLines(
  786. FILE *file,
  787. kwsys_stl::vector<kwsys_stl::string> &lines)
  788. {
  789. // Load each line in the given file into a the vector.
  790. int nRead=0;
  791. const int bufSize=1024;
  792. char buf[bufSize]={'\0'};
  793. while (!feof(file) && !ferror(file))
  794. {
  795. errno=0;
  796. if (fgets(buf,bufSize,file) == 0)
  797. {
  798. if (ferror(file) && (errno==EINTR))
  799. {
  800. clearerr(file);
  801. }
  802. continue;
  803. }
  804. char *pBuf=buf;
  805. while(*pBuf)
  806. {
  807. if (*pBuf=='\n') *pBuf='\0';
  808. pBuf+=1;
  809. }
  810. lines.push_back(buf);
  811. ++nRead;
  812. }
  813. if (ferror(file))
  814. {
  815. return 0;
  816. }
  817. return nRead;
  818. }
  819. # if defined(__linux)
  820. // *****************************************************************************
  821. int LoadLines(
  822. const char *fileName,
  823. kwsys_stl::vector<kwsys_stl::string> &lines)
  824. {
  825. FILE *file=fopen(fileName,"r");
  826. if (file==0)
  827. {
  828. return 0;
  829. }
  830. int nRead=LoadLines(file,lines);
  831. fclose(file);
  832. return nRead;
  833. }
  834. # endif
  835. // ****************************************************************************
  836. template<typename T>
  837. int NameValue(
  838. kwsys_stl::vector<kwsys_stl::string> &lines,
  839. kwsys_stl::string name, T &value)
  840. {
  841. size_t nLines=lines.size();
  842. for (size_t i=0; i<nLines; ++i)
  843. {
  844. size_t at=lines[i].find(name);
  845. if (at==kwsys_stl::string::npos)
  846. {
  847. continue;
  848. }
  849. kwsys_ios::istringstream is(lines[i].substr(at+name.size()));
  850. is >> value;
  851. return 0;
  852. }
  853. return -1;
  854. }
  855. #endif
  856. #if defined(__linux)
  857. // ****************************************************************************
  858. template<typename T>
  859. int GetFieldsFromFile(
  860. const char *fileName,
  861. const char **fieldNames,
  862. T *values)
  863. {
  864. kwsys_stl::vector<kwsys_stl::string> fields;
  865. if (!LoadLines(fileName,fields))
  866. {
  867. return -1;
  868. }
  869. int i=0;
  870. while (fieldNames[i]!=NULL)
  871. {
  872. int ierr=NameValue(fields,fieldNames[i],values[i]);
  873. if (ierr)
  874. {
  875. return -(i+2);
  876. }
  877. i+=1;
  878. }
  879. return 0;
  880. }
  881. // ****************************************************************************
  882. template<typename T>
  883. int GetFieldFromFile(
  884. const char *fileName,
  885. const char *fieldName,
  886. T &value)
  887. {
  888. const char *fieldNames[2]={fieldName,NULL};
  889. T values[1]={T(0)};
  890. int ierr=GetFieldsFromFile(fileName,fieldNames,values);
  891. if (ierr)
  892. {
  893. return ierr;
  894. }
  895. value=values[0];
  896. return 0;
  897. }
  898. #endif
  899. // ****************************************************************************
  900. #if defined(__APPLE__)
  901. template<typename T>
  902. int GetFieldsFromCommand(
  903. const char *command,
  904. const char **fieldNames,
  905. T *values)
  906. {
  907. FILE *file=popen(command,"r");
  908. if (file==0)
  909. {
  910. return -1;
  911. }
  912. kwsys_stl::vector<kwsys_stl::string> fields;
  913. int nl=LoadLines(file,fields);
  914. pclose(file);
  915. if (nl==0)
  916. {
  917. return -1;
  918. }
  919. int i=0;
  920. while (fieldNames[i]!=NULL)
  921. {
  922. int ierr=NameValue(fields,fieldNames[i],values[i]);
  923. if (ierr)
  924. {
  925. return -(i+2);
  926. }
  927. i+=1;
  928. }
  929. return 0;
  930. }
  931. #endif
  932. // ****************************************************************************
  933. #if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
  934. void StacktraceSignalHandler(
  935. int sigNo,
  936. siginfo_t *sigInfo,
  937. void * /*sigContext*/)
  938. {
  939. #if defined(__linux) || defined(__APPLE__)
  940. kwsys_ios::ostringstream oss;
  941. oss
  942. << kwsys_ios::endl
  943. << "=========================================================" << kwsys_ios::endl
  944. << "Process id " << getpid() << " ";
  945. switch (sigNo)
  946. {
  947. case SIGINT:
  948. oss << "Caught SIGINT";
  949. break;
  950. case SIGTERM:
  951. oss << "Caught SIGTERM";
  952. break;
  953. case SIGABRT:
  954. oss << "Caught SIGABRT";
  955. break;
  956. case SIGFPE:
  957. oss
  958. << "Caught SIGFPE at "
  959. << (sigInfo->si_addr==0?"0x":"")
  960. << sigInfo->si_addr
  961. << " ";
  962. switch (sigInfo->si_code)
  963. {
  964. # if defined(FPE_INTDIV)
  965. case FPE_INTDIV:
  966. oss << "integer division by zero";
  967. break;
  968. # endif
  969. # if defined(FPE_INTOVF)
  970. case FPE_INTOVF:
  971. oss << "integer overflow";
  972. break;
  973. # endif
  974. case FPE_FLTDIV:
  975. oss << "floating point divide by zero";
  976. break;
  977. case FPE_FLTOVF:
  978. oss << "floating point overflow";
  979. break;
  980. case FPE_FLTUND:
  981. oss << "floating point underflow";
  982. break;
  983. case FPE_FLTRES:
  984. oss << "floating point inexact result";
  985. break;
  986. case FPE_FLTINV:
  987. oss << "floating point invalid operation";
  988. break;
  989. #if defined(FPE_FLTSUB)
  990. case FPE_FLTSUB:
  991. oss << "floating point subscript out of range";
  992. break;
  993. #endif
  994. default:
  995. oss << "code " << sigInfo->si_code;
  996. break;
  997. }
  998. break;
  999. case SIGSEGV:
  1000. oss
  1001. << "Caught SIGSEGV at "
  1002. << (sigInfo->si_addr==0?"0x":"")
  1003. << sigInfo->si_addr
  1004. << " ";
  1005. switch (sigInfo->si_code)
  1006. {
  1007. case SEGV_MAPERR:
  1008. oss << "address not mapped to object";
  1009. break;
  1010. case SEGV_ACCERR:
  1011. oss << "invalid permission for mapped object";
  1012. break;
  1013. default:
  1014. oss << "code " << sigInfo->si_code;
  1015. break;
  1016. }
  1017. break;
  1018. case SIGBUS:
  1019. oss
  1020. << "Caught SIGBUS at "
  1021. << (sigInfo->si_addr==0?"0x":"")
  1022. << sigInfo->si_addr
  1023. << " ";
  1024. switch (sigInfo->si_code)
  1025. {
  1026. case BUS_ADRALN:
  1027. oss << "invalid address alignment";
  1028. break;
  1029. # if defined(BUS_ADRERR)
  1030. case BUS_ADRERR:
  1031. oss << "nonexistent physical address";
  1032. break;
  1033. # endif
  1034. # if defined(BUS_OBJERR)
  1035. case BUS_OBJERR:
  1036. oss << "object-specific hardware error";
  1037. break;
  1038. # endif
  1039. # if defined(BUS_MCEERR_AR)
  1040. case BUS_MCEERR_AR:
  1041. oss << "Hardware memory error consumed on a machine check; action required.";
  1042. break;
  1043. # endif
  1044. # if defined(BUS_MCEERR_AO)
  1045. case BUS_MCEERR_AO:
  1046. oss << "Hardware memory error detected in process but not consumed; action optional.";
  1047. break;
  1048. # endif
  1049. default:
  1050. oss << "code " << sigInfo->si_code;
  1051. break;
  1052. }
  1053. break;
  1054. case SIGILL:
  1055. oss
  1056. << "Caught SIGILL at "
  1057. << (sigInfo->si_addr==0?"0x":"")
  1058. << sigInfo->si_addr
  1059. << " ";
  1060. switch (sigInfo->si_code)
  1061. {
  1062. case ILL_ILLOPC:
  1063. oss << "illegal opcode";
  1064. break;
  1065. # if defined(ILL_ILLOPN)
  1066. case ILL_ILLOPN:
  1067. oss << "illegal operand";
  1068. break;
  1069. # endif
  1070. # if defined(ILL_ILLADR)
  1071. case ILL_ILLADR:
  1072. oss << "illegal addressing mode.";
  1073. break;
  1074. # endif
  1075. case ILL_ILLTRP:
  1076. oss << "illegal trap";
  1077. break;
  1078. case ILL_PRVOPC:
  1079. oss << "privileged opcode";
  1080. break;
  1081. # if defined(ILL_PRVREG)
  1082. case ILL_PRVREG:
  1083. oss << "privileged register";
  1084. break;
  1085. # endif
  1086. # if defined(ILL_COPROC)
  1087. case ILL_COPROC:
  1088. oss << "co-processor error";
  1089. break;
  1090. # endif
  1091. # if defined(ILL_BADSTK)
  1092. case ILL_BADSTK:
  1093. oss << "internal stack error";
  1094. break;
  1095. # endif
  1096. default:
  1097. oss << "code " << sigInfo->si_code;
  1098. break;
  1099. }
  1100. break;
  1101. default:
  1102. oss << "Caught " << sigNo << " code " << sigInfo->si_code;
  1103. break;
  1104. }
  1105. oss
  1106. << kwsys_ios::endl
  1107. << "Program Stack:" << kwsys_ios::endl
  1108. << SystemInformationImplementation::GetProgramStack(2,0)
  1109. << "=========================================================" << kwsys_ios::endl;
  1110. kwsys_ios::cerr << oss.str() << kwsys_ios::endl;
  1111. // restore the previously registered handlers
  1112. // and abort
  1113. SystemInformationImplementation::SetStackTraceOnError(0);
  1114. abort();
  1115. #else
  1116. // avoid warning C4100
  1117. (void)sigNo;
  1118. (void)sigInfo;
  1119. #endif
  1120. }
  1121. #endif
  1122. #if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
  1123. #define safes(_arg)((_arg)?(_arg):"???")
  1124. // Description:
  1125. // A container for symbol properties. Each instance
  1126. // must be Initialized.
  1127. class SymbolProperties
  1128. {
  1129. public:
  1130. SymbolProperties();
  1131. // Description:
  1132. // The SymbolProperties instance must be initialized by
  1133. // passing a stack address.
  1134. void Initialize(void *address);
  1135. // Description:
  1136. // Get the symbol's stack address.
  1137. void *GetAddress() const { return this->Address; }
  1138. // Description:
  1139. // If not set paths will be removed. eg, from a binary
  1140. // or source file.
  1141. void SetReportPath(int rp){ this->ReportPath=rp; }
  1142. // Description:
  1143. // Set/Get the name of the binary file that the symbol
  1144. // is found in.
  1145. void SetBinary(const char *binary)
  1146. { this->Binary=safes(binary); }
  1147. kwsys_stl::string GetBinary() const;
  1148. // Description:
  1149. // Set the name of the function that the symbol is found in.
  1150. // If c++ demangling is supported it will be demangled.
  1151. void SetFunction(const char *function)
  1152. { this->Function=this->Demangle(function); }
  1153. kwsys_stl::string GetFunction() const
  1154. { return this->Function; }
  1155. // Description:
  1156. // Set/Get the name of the source file where the symbol
  1157. // is defined.
  1158. void SetSourceFile(const char *sourcefile)
  1159. { this->SourceFile=safes(sourcefile); }
  1160. kwsys_stl::string GetSourceFile() const
  1161. { return this->GetFileName(this->SourceFile); }
  1162. // Description:
  1163. // Set/Get the line number where the symbol is defined
  1164. void SetLineNumber(long linenumber){ this->LineNumber=linenumber; }
  1165. long GetLineNumber() const { return this->LineNumber; }
  1166. // Description:
  1167. // Set the address where the biinary image is mapped
  1168. // into memory.
  1169. void SetBinaryBaseAddress(void *address)
  1170. { this->BinaryBaseAddress=address; }
  1171. private:
  1172. void *GetRealAddress() const
  1173. { return (void*)((char*)this->Address-(char*)this->BinaryBaseAddress); }
  1174. kwsys_stl::string GetFileName(const kwsys_stl::string &path) const;
  1175. kwsys_stl::string Demangle(const char *symbol) const;
  1176. private:
  1177. kwsys_stl::string Binary;
  1178. void *BinaryBaseAddress;
  1179. void *Address;
  1180. kwsys_stl::string SourceFile;
  1181. kwsys_stl::string Function;
  1182. long LineNumber;
  1183. int ReportPath;
  1184. };
  1185. // --------------------------------------------------------------------------
  1186. kwsys_ios::ostream &operator<<(
  1187. kwsys_ios::ostream &os,
  1188. const SymbolProperties &sp)
  1189. {
  1190. #if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
  1191. os
  1192. << kwsys_ios::hex << sp.GetAddress() << " : "
  1193. << sp.GetFunction()
  1194. << " [(" << sp.GetBinary() << ") "
  1195. << sp.GetSourceFile() << ":"
  1196. << kwsys_ios::dec << sp.GetLineNumber() << "]";
  1197. #elif defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
  1198. void *addr = sp.GetAddress();
  1199. char **syminfo = backtrace_symbols(&addr,1);
  1200. os << safes(syminfo[0]);
  1201. free(syminfo);
  1202. #else
  1203. (void)os;
  1204. (void)sp;
  1205. #endif
  1206. return os;
  1207. }
  1208. // --------------------------------------------------------------------------
  1209. SymbolProperties::SymbolProperties()
  1210. {
  1211. // not using an initializer list
  1212. // to avoid some PGI compiler warnings
  1213. this->SetBinary("???");
  1214. this->SetBinaryBaseAddress(NULL);
  1215. this->Address = NULL;
  1216. this->SetSourceFile("???");
  1217. this->SetFunction("???");
  1218. this->SetLineNumber(-1);
  1219. this->SetReportPath(0);
  1220. // avoid PGI compiler warnings
  1221. this->GetRealAddress();
  1222. this->GetFunction();
  1223. this->GetSourceFile();
  1224. this->GetLineNumber();
  1225. }
  1226. // --------------------------------------------------------------------------
  1227. kwsys_stl::string SymbolProperties::GetFileName(const kwsys_stl::string &path) const
  1228. {
  1229. kwsys_stl::string file(path);
  1230. if (!this->ReportPath)
  1231. {
  1232. size_t at = file.rfind("/");
  1233. if (at!=kwsys_stl::string::npos)
  1234. {
  1235. file = file.substr(at+1,kwsys_stl::string::npos);
  1236. }
  1237. }
  1238. return file;
  1239. }
  1240. // --------------------------------------------------------------------------
  1241. kwsys_stl::string SymbolProperties::GetBinary() const
  1242. {
  1243. // only linux has proc fs
  1244. #if defined(__linux__)
  1245. if (this->Binary=="/proc/self/exe")
  1246. {
  1247. kwsys_stl::string binary;
  1248. char buf[1024]={'\0'};
  1249. ssize_t ll=0;
  1250. if ((ll=readlink("/proc/self/exe",buf,1024))>0)
  1251. {
  1252. buf[ll]='\0';
  1253. binary=buf;
  1254. }
  1255. else
  1256. {
  1257. binary="/proc/self/exe";
  1258. }
  1259. return this->GetFileName(binary);
  1260. }
  1261. #endif
  1262. return this->GetFileName(this->Binary);
  1263. }
  1264. // --------------------------------------------------------------------------
  1265. kwsys_stl::string SymbolProperties::Demangle(const char *symbol) const
  1266. {
  1267. kwsys_stl::string result = safes(symbol);
  1268. #if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
  1269. int status = 0;
  1270. size_t bufferLen = 1024;
  1271. char *buffer = (char*)malloc(1024);
  1272. char *demangledSymbol =
  1273. abi::__cxa_demangle(symbol, buffer, &bufferLen, &status);
  1274. if (!status)
  1275. {
  1276. result = demangledSymbol;
  1277. }
  1278. free(buffer);
  1279. #else
  1280. (void)symbol;
  1281. #endif
  1282. return result;
  1283. }
  1284. // --------------------------------------------------------------------------
  1285. void SymbolProperties::Initialize(void *address)
  1286. {
  1287. this->Address = address;
  1288. #if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
  1289. // first fallback option can demangle c++ functions
  1290. Dl_info info;
  1291. int ierr=dladdr(this->Address,&info);
  1292. if (ierr && info.dli_sname && info.dli_saddr)
  1293. {
  1294. this->SetBinary(info.dli_fname);
  1295. this->SetFunction(info.dli_sname);
  1296. }
  1297. #else
  1298. // second fallback use builtin backtrace_symbols
  1299. // to decode the bactrace.
  1300. #endif
  1301. }
  1302. #endif // don't define this class if we're not using it
  1303. } // anonymous namespace
  1304. SystemInformationImplementation::SystemInformationImplementation()
  1305. {
  1306. this->TotalVirtualMemory = 0;
  1307. this->AvailableVirtualMemory = 0;
  1308. this->TotalPhysicalMemory = 0;
  1309. this->AvailablePhysicalMemory = 0;
  1310. this->CurrentPositionInFile = 0;
  1311. this->ChipManufacturer = UnknownManufacturer;
  1312. memset(&this->Features, 0, sizeof(CPUFeatures));
  1313. this->ChipID.Type = 0;
  1314. this->ChipID.Family = 0;
  1315. this->ChipID.Model = 0;
  1316. this->ChipID.Revision = 0;
  1317. this->ChipID.ExtendedFamily = 0;
  1318. this->ChipID.ExtendedModel = 0;
  1319. this->CPUSpeedInMHz = 0;
  1320. this->NumberOfLogicalCPU = 0;
  1321. this->NumberOfPhysicalCPU = 0;
  1322. this->OSName = "";
  1323. this->Hostname = "";
  1324. this->OSRelease = "";
  1325. this->OSVersion = "";
  1326. this->OSPlatform = "";
  1327. }
  1328. SystemInformationImplementation::~SystemInformationImplementation()
  1329. {
  1330. }
  1331. void SystemInformationImplementation::RunCPUCheck()
  1332. {
  1333. #ifdef WIN32
  1334. // Check to see if this processor supports CPUID.
  1335. bool supportsCPUID = DoesCPUSupportCPUID();
  1336. if (supportsCPUID)
  1337. {
  1338. // Retrieve the CPU details.
  1339. RetrieveCPUIdentity();
  1340. this->FindManufacturer();
  1341. RetrieveCPUFeatures();
  1342. }
  1343. // These two may be called without support for the CPUID instruction.
  1344. // (But if the instruction is there, they should be called *after*
  1345. // the above call to RetrieveCPUIdentity... that's why the two if
  1346. // blocks exist with the same "if (supportsCPUID)" logic...
  1347. //
  1348. if (!RetrieveCPUClockSpeed())
  1349. {
  1350. RetrieveClassicalCPUClockSpeed();
  1351. }
  1352. if (supportsCPUID)
  1353. {
  1354. // Retrieve cache information.
  1355. if (!RetrieveCPUCacheDetails())
  1356. {
  1357. RetrieveClassicalCPUCacheDetails();
  1358. }
  1359. // Retrieve the extended CPU details.
  1360. if (!RetrieveExtendedCPUIdentity())
  1361. {
  1362. RetrieveClassicalCPUIdentity();
  1363. }
  1364. RetrieveExtendedCPUFeatures();
  1365. RetrieveCPUPowerManagement();
  1366. // Now attempt to retrieve the serial number (if possible).
  1367. RetrieveProcessorSerialNumber();
  1368. }
  1369. this->CPUCount();
  1370. #elif defined(__APPLE__)
  1371. this->ParseSysCtl();
  1372. #elif defined (__SVR4) && defined (__sun)
  1373. this->QuerySolarisProcessor();
  1374. #elif defined(__HAIKU__)
  1375. this->QueryHaikuInfo();
  1376. #elif defined(__QNX__)
  1377. this->QueryQNXProcessor();
  1378. #elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
  1379. this->QueryBSDProcessor();
  1380. #elif defined(__hpux)
  1381. this->QueryHPUXProcessor();
  1382. #elif defined(__linux) || defined(__CYGWIN__)
  1383. this->RetreiveInformationFromCpuInfoFile();
  1384. #else
  1385. this->QueryProcessor();
  1386. #endif
  1387. }
  1388. void SystemInformationImplementation::RunOSCheck()
  1389. {
  1390. this->QueryOSInformation();
  1391. }
  1392. void SystemInformationImplementation::RunMemoryCheck()
  1393. {
  1394. #if defined(__APPLE__)
  1395. this->ParseSysCtl();
  1396. #elif defined (__SVR4) && defined (__sun)
  1397. this->QuerySolarisMemory();
  1398. #elif defined(__HAIKU__)
  1399. this->QueryHaikuInfo();
  1400. #elif defined(__QNX__)
  1401. this->QueryQNXMemory();
  1402. #elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
  1403. this->QueryBSDMemory();
  1404. #elif defined(__CYGWIN__)
  1405. this->QueryCygwinMemory();
  1406. #elif defined(_WIN32)
  1407. this->QueryWindowsMemory();
  1408. #elif defined(__hpux)
  1409. this->QueryHPUXMemory();
  1410. #elif defined(__linux)
  1411. this->QueryLinuxMemory();
  1412. #elif defined(_AIX)
  1413. this->QueryAIXMemory();
  1414. #else
  1415. this->QueryMemory();
  1416. #endif
  1417. }
  1418. /** Get the vendor string */
  1419. const char * SystemInformationImplementation::GetVendorString()
  1420. {
  1421. return this->ChipID.Vendor.c_str();
  1422. }
  1423. /** Get the OS Name */
  1424. const char * SystemInformationImplementation::GetOSName()
  1425. {
  1426. return this->OSName.c_str();
  1427. }
  1428. /** Get the hostname */
  1429. const char* SystemInformationImplementation::GetHostname()
  1430. {
  1431. if (this->Hostname.empty())
  1432. {
  1433. this->Hostname="localhost";
  1434. #if defined(_WIN32)
  1435. WORD wVersionRequested;
  1436. WSADATA wsaData;
  1437. char name[255];
  1438. wVersionRequested = MAKEWORD(2,0);
  1439. if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
  1440. {
  1441. gethostname(name,sizeof(name));
  1442. WSACleanup( );
  1443. }
  1444. this->Hostname = name;
  1445. #else
  1446. struct utsname unameInfo;
  1447. int errorFlag = uname(&unameInfo);
  1448. if(errorFlag == 0)
  1449. {
  1450. this->Hostname = unameInfo.nodename;
  1451. }
  1452. #endif
  1453. }
  1454. return this->Hostname.c_str();
  1455. }
  1456. /** Get the FQDN */
  1457. int SystemInformationImplementation::GetFullyQualifiedDomainName(
  1458. kwsys_stl::string &fqdn)
  1459. {
  1460. // in the event of absolute failure return localhost.
  1461. fqdn="localhost";
  1462. #if defined(_WIN32)
  1463. int ierr;
  1464. // TODO - a more robust implementation for windows, see comments
  1465. // in unix implementation.
  1466. WSADATA wsaData;
  1467. WORD ver=MAKEWORD(2,0);
  1468. ierr=WSAStartup(ver,&wsaData);
  1469. if (ierr)
  1470. {
  1471. return -1;
  1472. }
  1473. char base[256]={'\0'};
  1474. ierr=gethostname(base,256);
  1475. if (ierr)
  1476. {
  1477. WSACleanup();
  1478. return -2;
  1479. }
  1480. fqdn=base;
  1481. HOSTENT *hent=gethostbyname(base);
  1482. if (hent)
  1483. {
  1484. fqdn=hent->h_name;
  1485. }
  1486. WSACleanup();
  1487. return 0;
  1488. #elif defined(KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN)
  1489. // gethostname typical returns an alias for loopback interface
  1490. // we want the fully qualified domain name. Because there are
  1491. // any number of interfaces on this system we look for the
  1492. // first of these that contains the name returned by gethostname
  1493. // and is longer. failing that we return gethostname and indicate
  1494. // with a failure code. Return of a failure code is not necessarilly
  1495. // an indication of an error. for instance gethostname may return
  1496. // the fully qualified domain name, or there may not be one if the
  1497. // system lives on a private network such as in the case of a cluster
  1498. // node.
  1499. int ierr=0;
  1500. char base[NI_MAXHOST];
  1501. ierr=gethostname(base,NI_MAXHOST);
  1502. if (ierr)
  1503. {
  1504. return -1;
  1505. }
  1506. size_t baseSize=strlen(base);
  1507. fqdn=base;
  1508. struct ifaddrs *ifas;
  1509. struct ifaddrs *ifa;
  1510. ierr=getifaddrs(&ifas);
  1511. if (ierr)
  1512. {
  1513. return -2;
  1514. }
  1515. for (ifa=ifas; ifa!=NULL; ifa=ifa->ifa_next)
  1516. {
  1517. int fam = ifa->ifa_addr? ifa->ifa_addr->sa_family : -1;
  1518. if ((fam==AF_INET) || (fam==AF_INET6))
  1519. {
  1520. char host[NI_MAXHOST]={'\0'};
  1521. const size_t addrlen
  1522. = (fam==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6));
  1523. ierr=getnameinfo(
  1524. ifa->ifa_addr,
  1525. static_cast<socklen_t>(addrlen),
  1526. host,
  1527. NI_MAXHOST,
  1528. NULL,
  1529. 0,
  1530. NI_NAMEREQD);
  1531. if (ierr)
  1532. {
  1533. // don't report the failure now since we may succeed on another
  1534. // interface. If all attempts fail then return the failure code.
  1535. ierr=-3;
  1536. continue;
  1537. }
  1538. kwsys_stl::string candidate=host;
  1539. if ((candidate.find(base)!=kwsys_stl::string::npos) && baseSize<candidate.size())
  1540. {
  1541. // success, stop now.
  1542. ierr=0;
  1543. fqdn=candidate;
  1544. break;
  1545. }
  1546. }
  1547. }
  1548. freeifaddrs(ifas);
  1549. return ierr;
  1550. #else
  1551. /* TODO: Implement on more platforms. */
  1552. fqdn=this->GetHostname();
  1553. return -1;
  1554. #endif
  1555. }
  1556. /** Get the OS release */
  1557. const char* SystemInformationImplementation::GetOSRelease()
  1558. {
  1559. return this->OSRelease.c_str();
  1560. }
  1561. /** Get the OS version */
  1562. const char* SystemInformationImplementation::GetOSVersion()
  1563. {
  1564. return this->OSVersion.c_str();
  1565. }
  1566. /** Get the OS platform */
  1567. const char* SystemInformationImplementation::GetOSPlatform()
  1568. {
  1569. return this->OSPlatform.c_str();
  1570. }
  1571. /** Get the vendor ID */
  1572. const char * SystemInformationImplementation::GetVendorID()
  1573. {
  1574. // Return the vendor ID.
  1575. switch (this->ChipManufacturer)
  1576. {
  1577. case Intel:
  1578. return "Intel Corporation";
  1579. case AMD:
  1580. return "Advanced Micro Devices";
  1581. case NSC:
  1582. return "National Semiconductor";
  1583. case Cyrix:
  1584. return "Cyrix Corp., VIA Inc.";
  1585. case NexGen:
  1586. return "NexGen Inc., Advanced Micro Devices";
  1587. case IDT:
  1588. return "IDT\\Centaur, Via Inc.";
  1589. case UMC:
  1590. return "United Microelectronics Corp.";
  1591. case Rise:
  1592. return "Rise";
  1593. case Transmeta:
  1594. return "Transmeta";
  1595. case Sun:
  1596. return "Sun Microelectronics";
  1597. case IBM:
  1598. return "IBM";
  1599. case Motorola:
  1600. return "Motorola";
  1601. case HP:
  1602. return "Hewlett-Packard";
  1603. case UnknownManufacturer:
  1604. default:
  1605. return "Unknown Manufacturer";
  1606. }
  1607. }
  1608. /** Return the type ID of the CPU */
  1609. kwsys_stl::string SystemInformationImplementation::GetTypeID()
  1610. {
  1611. kwsys_ios::ostringstream str;
  1612. str << this->ChipID.Type;
  1613. return str.str();
  1614. }
  1615. /** Return the family of the CPU present */
  1616. kwsys_stl::string SystemInformationImplementation::GetFamilyID()
  1617. {
  1618. kwsys_ios::ostringstream str;
  1619. str << this->ChipID.Family;
  1620. return str.str();
  1621. }
  1622. // Return the model of CPU present */
  1623. kwsys_stl::string SystemInformationImplementation::GetModelID()
  1624. {
  1625. kwsys_ios::ostringstream str;
  1626. str << this->ChipID.Model;
  1627. return str.str();
  1628. }
  1629. // Return the model name of CPU present */
  1630. kwsys_stl::string SystemInformationImplementation::GetModelName()
  1631. {
  1632. return this->ChipID.ModelName;
  1633. }
  1634. /** Return the stepping code of the CPU present. */
  1635. kwsys_stl::string SystemInformationImplementation::GetSteppingCode()
  1636. {
  1637. kwsys_ios::ostringstream str;
  1638. str << this->ChipID.Revision;
  1639. return str.str();
  1640. }
  1641. /** Return the stepping code of the CPU present. */
  1642. const char * SystemInformationImplementation::GetExtendedProcessorName()
  1643. {
  1644. return this->ChipID.ProcessorName.c_str();
  1645. }
  1646. /** Return the serial number of the processor
  1647. * in hexadecimal: xxxx-xxxx-xxxx-xxxx-xxxx-xxxx. */
  1648. const char * SystemInformationImplementation::GetProcessorSerialNumber()
  1649. {
  1650. return this->ChipID.SerialNumber.c_str();
  1651. }
  1652. /** Return the logical processors per physical */
  1653. unsigned int SystemInformationImplementation::GetLogicalProcessorsPerPhysical()
  1654. {
  1655. return this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical;
  1656. }
  1657. /** Return the processor clock frequency. */
  1658. float SystemInformationImplementation::GetProcessorClockFrequency()
  1659. {
  1660. return this->CPUSpeedInMHz;
  1661. }
  1662. /** Return the APIC ID. */
  1663. int SystemInformationImplementation::GetProcessorAPICID()
  1664. {
  1665. return this->Features.ExtendedFeatures.APIC_ID;
  1666. }
  1667. /** Return the L1 cache size. */
  1668. int SystemInformationImplementation::GetProcessorCacheSize()
  1669. {
  1670. return this->Features.L1CacheSize;
  1671. }
  1672. /** Return the chosen cache size. */
  1673. int SystemInformationImplementation::GetProcessorCacheXSize(long int dwCacheID)
  1674. {
  1675. switch (dwCacheID)
  1676. {
  1677. case L1CACHE_FEATURE:
  1678. return this->Features.L1CacheSize;
  1679. case L2CACHE_FEATURE:
  1680. return this->Features.L2CacheSize;
  1681. case L3CACHE_FEATURE:
  1682. return this->Features.L3CacheSize;
  1683. }
  1684. return -1;
  1685. }
  1686. bool SystemInformationImplementation::DoesCPUSupportFeature(long int dwFeature)
  1687. {
  1688. bool bHasFeature = false;
  1689. // Check for MMX instructions.
  1690. if (((dwFeature & MMX_FEATURE) != 0) && this->Features.HasMMX) bHasFeature = true;
  1691. // Check for MMX+ instructions.
  1692. if (((dwFeature & MMX_PLUS_FEATURE) != 0) && this->Features.ExtendedFeatures.HasMMXPlus) bHasFeature = true;
  1693. // Check for SSE FP instructions.
  1694. if (((dwFeature & SSE_FEATURE) != 0) && this->Features.HasSSE) bHasFeature = true;
  1695. // Check for SSE FP instructions.
  1696. if (((dwFeature & SSE_FP_FEATURE) != 0) && this->Features.HasSSEFP) bHasFeature = true;
  1697. // Check for SSE MMX instructions.
  1698. if (((dwFeature & SSE_MMX_FEATURE) != 0) && this->Features.ExtendedFeatures.HasSSEMMX) bHasFeature = true;
  1699. // Check for SSE2 instructions.
  1700. if (((dwFeature & SSE2_FEATURE) != 0) && this->Features.HasSSE2) bHasFeature = true;
  1701. // Check for 3DNow! instructions.
  1702. if (((dwFeature & AMD_3DNOW_FEATURE) != 0) && this->Features.ExtendedFeatures.Has3DNow) bHasFeature = true;
  1703. // Check for 3DNow+ instructions.
  1704. if (((dwFeature & AMD_3DNOW_PLUS_FEATURE) != 0) && this->Features.ExtendedFeatures.Has3DNowPlus) bHasFeature = true;
  1705. // Check for IA64 instructions.
  1706. if (((dwFeature & IA64_FEATURE) != 0) && this->Features.HasIA64) bHasFeature = true;
  1707. // Check for MP capable.
  1708. if (((dwFeature & MP_CAPABLE) != 0) && this->Features.ExtendedFeatures.SupportsMP) bHasFeature = true;
  1709. // Check for a serial number for the processor.
  1710. if (((dwFeature & SERIALNUMBER_FEATURE) != 0) && this->Features.HasSerial) bHasFeature = true;
  1711. // Check for a local APIC in the processor.
  1712. if (((dwFeature & APIC_FEATURE) != 0) && this->Features.HasAPIC) bHasFeature = true;
  1713. // Check for CMOV instructions.
  1714. if (((dwFeature & CMOV_FEATURE) != 0) && this->Features.HasCMOV) bHasFeature = true;
  1715. // Check for MTRR instructions.
  1716. if (((dwFeature & MTRR_FEATURE) != 0) && this->Features.HasMTRR) bHasFeature = true;
  1717. // Check for L1 cache size.
  1718. if (((dwFeature & L1CACHE_FEATURE) != 0) && (this->Features.L1CacheSize != -1)) bHasFeature = true;
  1719. // Check for L2 cache size.
  1720. if (((dwFeature & L2CACHE_FEATURE) != 0) && (this->Features.L2CacheSize != -1)) bHasFeature = true;
  1721. // Check for L3 cache size.
  1722. if (((dwFeature & L3CACHE_FEATURE) != 0) && (this->Features.L3CacheSize != -1)) bHasFeature = true;
  1723. // Check for ACPI capability.
  1724. if (((dwFeature & ACPI_FEATURE) != 0) && this->Features.HasACPI) bHasFeature = true;
  1725. // Check for thermal monitor support.
  1726. if (((dwFeature & THERMALMONITOR_FEATURE) != 0) && this->Features.HasThermal) bHasFeature = true;
  1727. // Check for temperature sensing diode support.
  1728. if (((dwFeature & TEMPSENSEDIODE_FEATURE) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode) bHasFeature = true;
  1729. // Check for frequency ID support.
  1730. if (((dwFeature & FREQUENCYID_FEATURE) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID) bHasFeature = true;
  1731. // Check for voltage ID support.
  1732. if (((dwFeature & VOLTAGEID_FREQUENCY) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasVoltageID) bHasFeature = true;
  1733. return bHasFeature;
  1734. }
  1735. void SystemInformationImplementation::Delay(unsigned int uiMS)
  1736. {
  1737. #ifdef WIN32
  1738. LARGE_INTEGER Frequency, StartCounter, EndCounter;
  1739. __int64 x;
  1740. // Get the frequency of the high performance counter.
  1741. if (!QueryPerformanceFrequency (&Frequency)) return;
  1742. x = Frequency.QuadPart / 1000 * uiMS;
  1743. // Get the starting position of the counter.
  1744. QueryPerformanceCounter (&StartCounter);
  1745. do {
  1746. // Get the ending position of the counter.
  1747. QueryPerformanceCounter (&EndCounter);
  1748. } while (EndCounter.QuadPart - StartCounter.QuadPart < x);
  1749. #endif
  1750. (void)uiMS;
  1751. }
  1752. bool SystemInformationImplementation::DoesCPUSupportCPUID()
  1753. {
  1754. #if USE_CPUID
  1755. int dummy[4] = { 0, 0, 0, 0 };
  1756. #if USE_ASM_INSTRUCTIONS
  1757. return call_cpuid(0, dummy);
  1758. #else
  1759. call_cpuid(0, dummy);
  1760. return dummy[0] || dummy[1] || dummy[2] || dummy[3];
  1761. #endif
  1762. #else
  1763. // Assume no cpuid instruction.
  1764. return false;
  1765. #endif
  1766. }
  1767. bool SystemInformationImplementation::RetrieveCPUFeatures()
  1768. {
  1769. #if USE_CPUID
  1770. int cpuinfo[4] = { 0, 0, 0, 0 };
  1771. if (!call_cpuid(1, cpuinfo))
  1772. {
  1773. return false;
  1774. }
  1775. // Retrieve the features of CPU present.
  1776. this->Features.HasFPU = ((cpuinfo[3] & 0x00000001) != 0); // FPU Present --> Bit 0
  1777. this->Features.HasTSC = ((cpuinfo[3] & 0x00000010) != 0); // TSC Present --> Bit 4
  1778. this->Features.HasAPIC = ((cpuinfo[3] & 0x00000200) != 0); // APIC Present --> Bit 9
  1779. this->Features.HasMTRR = ((cpuinfo[3] & 0x00001000) != 0); // MTRR Present --> Bit 12
  1780. this->Features.HasCMOV = ((cpuinfo[3] & 0x00008000) != 0); // CMOV Present --> Bit 15
  1781. this->Features.HasSerial = ((cpuinfo[3] & 0x00040000) != 0); // Serial Present --> Bit 18
  1782. this->Features.HasACPI = ((cpuinfo[3] & 0x00400000) != 0); // ACPI Capable --> Bit 22
  1783. this->Features.HasMMX = ((cpuinfo[3] & 0x00800000) != 0); // MMX Present --> Bit 23
  1784. this->Features.HasSSE = ((cpuinfo[3] & 0x02000000) != 0); // SSE Present --> Bit 25
  1785. this->Features.HasSSE2 = ((cpuinfo[3] & 0x04000000) != 0); // SSE2 Present --> Bit 26
  1786. this->Features.HasThermal = ((cpuinfo[3] & 0x20000000) != 0); // Thermal Monitor Present --> Bit 29
  1787. this->Features.HasIA64 = ((cpuinfo[3] & 0x40000000) != 0); // IA64 Present --> Bit 30
  1788. #if USE_ASM_INSTRUCTIONS
  1789. // Retrieve extended SSE capabilities if SSE is available.
  1790. if (this->Features.HasSSE) {
  1791. // Attempt to __try some SSE FP instructions.
  1792. __try
  1793. {
  1794. // Perform: orps xmm0, xmm0
  1795. _asm
  1796. {
  1797. _emit 0x0f
  1798. _emit 0x56
  1799. _emit 0xc0
  1800. }
  1801. // SSE FP capable processor.
  1802. this->Features.HasSSEFP = true;
  1803. }
  1804. __except(1)
  1805. {
  1806. // bad instruction - processor or OS cannot handle SSE FP.
  1807. this->Features.HasSSEFP = false;
  1808. }
  1809. }
  1810. else
  1811. {
  1812. // Set the advanced SSE capabilities to not available.
  1813. this->Features.HasSSEFP = false;
  1814. }
  1815. #else
  1816. this->Features.HasSSEFP = false;
  1817. #endif
  1818. // Retrieve Intel specific extended features.
  1819. if (this->ChipManufacturer == Intel)
  1820. {
  1821. this->Features.ExtendedFeatures.SupportsHyperthreading = ((cpuinfo[3] & 0x10000000) != 0); // Intel specific: Hyperthreading --> Bit 28
  1822. this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = (this->Features.ExtendedFeatures.SupportsHyperthreading) ? ((cpuinfo[1] & 0x00FF0000) >> 16) : 1;
  1823. if ((this->Features.ExtendedFeatures.SupportsHyperthreading) && (this->Features.HasAPIC))
  1824. {
  1825. // Retrieve APIC information if there is one present.
  1826. this->Features.ExtendedFeatures.APIC_ID = ((cpuinfo[1] & 0xFF000000) >> 24);
  1827. }
  1828. }
  1829. return true;
  1830. #else
  1831. return false;
  1832. #endif
  1833. }
  1834. /** Find the manufacturer given the vendor id */
  1835. void SystemInformationImplementation::FindManufacturer(const kwsys_stl::string& family)
  1836. {
  1837. if (this->ChipID.Vendor == "GenuineIntel") this->ChipManufacturer = Intel; // Intel Corp.
  1838. else if (this->ChipID.Vendor == "UMC UMC UMC ") this->ChipManufacturer = UMC; // United Microelectronics Corp.
  1839. else if (this->ChipID.Vendor == "AuthenticAMD") this->ChipManufacturer = AMD; // Advanced Micro Devices
  1840. else if (this->ChipID.Vendor == "AMD ISBETTER") this->ChipManufacturer = AMD; // Advanced Micro Devices (1994)
  1841. else if (this->ChipID.Vendor == "CyrixInstead") this->ChipManufacturer = Cyrix; // Cyrix Corp., VIA Inc.
  1842. else if (this->ChipID.Vendor == "NexGenDriven") this->ChipManufacturer = NexGen; // NexGen Inc. (now AMD)
  1843. else if (this->ChipID.Vendor == "CentaurHauls") this->ChipManufacturer = IDT; // IDT/Centaur (now VIA)
  1844. else if (this->ChipID.Vendor == "RiseRiseRise") this->ChipManufacturer = Rise; // Rise
  1845. else if (this->ChipID.Vendor == "GenuineTMx86") this->ChipManufacturer = Transmeta; // Transmeta
  1846. else if (this->ChipID.Vendor == "TransmetaCPU") this->ChipManufacturer = Transmeta; // Transmeta
  1847. else if (this->ChipID.Vendor == "Geode By NSC") this->ChipManufacturer = NSC; // National Semiconductor
  1848. else if (this->ChipID.Vendor == "Sun") this->ChipManufacturer = Sun; // Sun Microelectronics
  1849. else if (this->ChipID.Vendor == "IBM") this->ChipManufacturer = IBM; // IBM Microelectronics
  1850. else if (this->ChipID.Vendor == "Hewlett-Packard") this->ChipManufacturer = HP; // Hewlett-Packard
  1851. else if (this->ChipID.Vendor == "Motorola") this->ChipManufacturer = Motorola; // Motorola Microelectronics
  1852. else if (family.substr(0, 7) == "PA-RISC") this->ChipManufacturer = HP; // Hewlett-Packard
  1853. else this->ChipManufacturer = UnknownManufacturer; // Unknown manufacturer
  1854. }
  1855. /** */
  1856. bool SystemInformationImplementation::RetrieveCPUIdentity()
  1857. {
  1858. #if USE_CPUID
  1859. int localCPUVendor[4];
  1860. int localCPUSignature[4];
  1861. if (!call_cpuid(0, localCPUVendor))
  1862. {
  1863. return false;
  1864. }
  1865. if (!call_cpuid(1, localCPUSignature))
  1866. {
  1867. return false;
  1868. }
  1869. // Process the returned information.
  1870. // ; eax = 0 --> eax: maximum value of CPUID instruction.
  1871. // ; ebx: part 1 of 3; CPU signature.
  1872. // ; edx: part 2 of 3; CPU signature.
  1873. // ; ecx: part 3 of 3; CPU signature.
  1874. char vbuf[13];
  1875. memcpy (&(vbuf[0]), &(localCPUVendor[1]), sizeof (int));
  1876. memcpy (&(vbuf[4]), &(localCPUVendor[3]), sizeof (int));
  1877. memcpy (&(vbuf[8]), &(localCPUVendor[2]), sizeof (int));
  1878. vbuf[12] = '\0';
  1879. this->ChipID.Vendor = vbuf;
  1880. // Retrieve the family of CPU present.
  1881. // ; eax = 1 --> eax: CPU ID - bits 31..16 - unused, bits 15..12 - type, bits 11..8 - family, bits 7..4 - model, bits 3..0 - mask revision
  1882. // ; ebx: 31..24 - default APIC ID, 23..16 - logical processor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID
  1883. // ; edx: CPU feature flags
  1884. this->ChipID.ExtendedFamily = ((localCPUSignature[0] & 0x0FF00000) >> 20); // Bits 27..20 Used
  1885. this->ChipID.ExtendedModel = ((localCPUSignature[0] & 0x000F0000) >> 16); // Bits 19..16 Used
  1886. this->ChipID.Type = ((localCPUSignature[0] & 0x0000F000) >> 12); // Bits 15..12 Used
  1887. this->ChipID.Family = ((localCPUSignature[0] & 0x00000F00) >> 8); // Bits 11..8 Used
  1888. this->ChipID.Model = ((localCPUSignature[0] & 0x000000F0) >> 4); // Bits 7..4 Used
  1889. this->ChipID.Revision = ((localCPUSignature[0] & 0x0000000F) >> 0); // Bits 3..0 Used
  1890. return true;
  1891. #else
  1892. return false;
  1893. #endif
  1894. }
  1895. /** */
  1896. bool SystemInformationImplementation::RetrieveCPUCacheDetails()
  1897. {
  1898. #if USE_CPUID
  1899. int L1Cache[4] = { 0, 0, 0, 0 };
  1900. int L2Cache[4] = { 0, 0, 0, 0 };
  1901. // Check to see if what we are about to do is supported...
  1902. if (RetrieveCPUExtendedLevelSupport (0x80000005))
  1903. {
  1904. if (!call_cpuid(0x80000005, L1Cache))
  1905. {
  1906. return false;
  1907. }
  1908. // Save the L1 data cache size (in KB) from ecx: bits 31..24 as well as data cache size from edx: bits 31..24.
  1909. this->Features.L1CacheSize = ((L1Cache[2] & 0xFF000000) >> 24);
  1910. this->Features.L1CacheSize += ((L1Cache[3] & 0xFF000000) >> 24);
  1911. }
  1912. else
  1913. {
  1914. // Store -1 to indicate the cache could not be queried.
  1915. this->Features.L1CacheSize = -1;
  1916. }
  1917. // Check to see if what we are about to do is supported...
  1918. if (RetrieveCPUExtendedLevelSupport (0x80000006))
  1919. {
  1920. if (!call_cpuid(0x80000006, L2Cache))
  1921. {
  1922. return false;
  1923. }
  1924. // Save the L2 unified cache size (in KB) from ecx: bits 31..16.
  1925. this->Features.L2CacheSize = ((L2Cache[2] & 0xFFFF0000) >> 16);
  1926. }
  1927. else
  1928. {
  1929. // Store -1 to indicate the cache could not be queried.
  1930. this->Features.L2CacheSize = -1;
  1931. }
  1932. // Define L3 as being not present as we cannot test for it.
  1933. this->Features.L3CacheSize = -1;
  1934. #endif
  1935. // Return failure if we cannot detect either cache with this method.
  1936. return ((this->Features.L1CacheSize == -1) && (this->Features.L2CacheSize == -1)) ? false : true;
  1937. }
  1938. /** */
  1939. bool SystemInformationImplementation::RetrieveClassicalCPUCacheDetails()
  1940. {
  1941. #if USE_CPUID
  1942. int TLBCode = -1, TLBData = -1, L1Code = -1, L1Data = -1, L1Trace = -1, L2Unified = -1, L3Unified = -1;
  1943. int TLBCacheData[4] = { 0, 0, 0, 0 };
  1944. int TLBPassCounter = 0;
  1945. int TLBCacheUnit = 0;
  1946. do {
  1947. if (!call_cpuid(2, TLBCacheData))
  1948. {
  1949. return false;
  1950. }
  1951. int bob = ((TLBCacheData[0] & 0x00FF0000) >> 16);
  1952. (void)bob;
  1953. // Process the returned TLB and cache information.
  1954. for (int nCounter = 0; nCounter < TLBCACHE_INFO_UNITS; nCounter ++)
  1955. {
  1956. // First of all - decide which unit we are dealing with.
  1957. switch (nCounter)
  1958. {
  1959. // eax: bits 8..15 : bits 16..23 : bits 24..31
  1960. case 0: TLBCacheUnit = ((TLBCacheData[0] & 0x0000FF00) >> 8); break;
  1961. case 1: TLBCacheUnit = ((TLBCacheData[0] & 0x00FF0000) >> 16); break;
  1962. case 2: TLBCacheUnit = ((TLBCacheData[0] & 0xFF000000) >> 24); break;
  1963. // ebx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
  1964. case 3: TLBCacheUnit = ((TLBCacheData[1] & 0x000000FF) >> 0); break;
  1965. case 4: TLBCacheUnit = ((TLBCacheData[1] & 0x0000FF00) >> 8); break;
  1966. case 5: TLBCacheUnit = ((TLBCacheData[1] & 0x00FF0000) >> 16); break;
  1967. case 6: TLBCacheUnit = ((TLBCacheData[1] & 0xFF000000) >> 24); break;
  1968. // ecx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
  1969. case 7: TLBCacheUnit = ((TLBCacheData[2] & 0x000000FF) >> 0); break;
  1970. case 8: TLBCacheUnit = ((TLBCacheData[2] & 0x0000FF00) >> 8); break;
  1971. case 9: TLBCacheUnit = ((TLBCacheData[2] & 0x00FF0000) >> 16); break;
  1972. case 10: TLBCacheUnit = ((TLBCacheData[2] & 0xFF000000) >> 24); break;
  1973. // edx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
  1974. case 11: TLBCacheUnit = ((TLBCacheData[3] & 0x000000FF) >> 0); break;
  1975. case 12: TLBCacheUnit = ((TLBCacheData[3] & 0x0000FF00) >> 8); break;
  1976. case 13: TLBCacheUnit = ((TLBCacheData[3] & 0x00FF0000) >> 16); break;
  1977. case 14: TLBCacheUnit = ((TLBCacheData[3] & 0xFF000000) >> 24); break;
  1978. // Default case - an error has occured.
  1979. default: return false;
  1980. }
  1981. // Now process the resulting unit to see what it means....
  1982. switch (TLBCacheUnit)
  1983. {
  1984. case 0x00: break;
  1985. case 0x01: STORE_TLBCACHE_INFO (TLBCode, 4); break;
  1986. case 0x02: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
  1987. case 0x03: STORE_TLBCACHE_INFO (TLBData, 4); break;
  1988. case 0x04: STORE_TLBCACHE_INFO (TLBData, 4096); break;
  1989. case 0x06: STORE_TLBCACHE_INFO (L1Code, 8); break;
  1990. case 0x08: STORE_TLBCACHE_INFO (L1Code, 16); break;
  1991. case 0x0a: STORE_TLBCACHE_INFO (L1Data, 8); break;
  1992. case 0x0c: STORE_TLBCACHE_INFO (L1Data, 16); break;
  1993. case 0x10: STORE_TLBCACHE_INFO (L1Data, 16); break; // <-- FIXME: IA-64 Only
  1994. case 0x15: STORE_TLBCACHE_INFO (L1Code, 16); break; // <-- FIXME: IA-64 Only
  1995. case 0x1a: STORE_TLBCACHE_INFO (L2Unified, 96); break; // <-- FIXME: IA-64 Only
  1996. case 0x22: STORE_TLBCACHE_INFO (L3Unified, 512); break;
  1997. case 0x23: STORE_TLBCACHE_INFO (L3Unified, 1024); break;
  1998. case 0x25: STORE_TLBCACHE_INFO (L3Unified, 2048); break;
  1999. case 0x29: STORE_TLBCACHE_INFO (L3Unified, 4096); break;
  2000. case 0x39: STORE_TLBCACHE_INFO (L2Unified, 128); break;
  2001. case 0x3c: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  2002. case 0x40: STORE_TLBCACHE_INFO (L2Unified, 0); break; // <-- FIXME: No integrated L2 cache (P6 core) or L3 cache (P4 core).
  2003. case 0x41: STORE_TLBCACHE_INFO (L2Unified, 128); break;
  2004. case 0x42: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  2005. case 0x43: STORE_TLBCACHE_INFO (L2Unified, 512); break;
  2006. case 0x44: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
  2007. case 0x45: STORE_TLBCACHE_INFO (L2Unified, 2048); break;
  2008. case 0x50: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
  2009. case 0x51: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
  2010. case 0x52: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
  2011. case 0x5b: STORE_TLBCACHE_INFO (TLBData, 4096); break;
  2012. case 0x5c: STORE_TLBCACHE_INFO (TLBData, 4096); break;
  2013. case 0x5d: STORE_TLBCACHE_INFO (TLBData, 4096); break;
  2014. case 0x66: STORE_TLBCACHE_INFO (L1Data, 8); break;
  2015. case 0x67: STORE_TLBCACHE_INFO (L1Data, 16); break;
  2016. case 0x68: STORE_TLBCACHE_INFO (L1Data, 32); break;
  2017. case 0x70: STORE_TLBCACHE_INFO (L1Trace, 12); break;
  2018. case 0x71: STORE_TLBCACHE_INFO (L1Trace, 16); break;
  2019. case 0x72: STORE_TLBCACHE_INFO (L1Trace, 32); break;
  2020. case 0x77: STORE_TLBCACHE_INFO (L1Code, 16); break; // <-- FIXME: IA-64 Only
  2021. case 0x79: STORE_TLBCACHE_INFO (L2Unified, 128); break;
  2022. case 0x7a: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  2023. case 0x7b: STORE_TLBCACHE_INFO (L2Unified, 512); break;
  2024. case 0x7c: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
  2025. case 0x7e: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  2026. case 0x81: STORE_TLBCACHE_INFO (L2Unified, 128); break;
  2027. case 0x82: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  2028. case 0x83: STORE_TLBCACHE_INFO (L2Unified, 512); break;
  2029. case 0x84: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
  2030. case 0x85: STORE_TLBCACHE_INFO (L2Unified, 2048); break;
  2031. case 0x88: STORE_TLBCACHE_INFO (L3Unified, 2048); break; // <-- FIXME: IA-64 Only
  2032. case 0x89: STORE_TLBCACHE_INFO (L3Unified, 4096); break; // <-- FIXME: IA-64 Only
  2033. case 0x8a: STORE_TLBCACHE_INFO (L3Unified, 8192); break; // <-- FIXME: IA-64 Only
  2034. case 0x8d: STORE_TLBCACHE_INFO (L3Unified, 3096); break; // <-- FIXME: IA-64 Only
  2035. case 0x90: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
  2036. case 0x96: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
  2037. case 0x9b: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
  2038. // Default case - an error has occured.
  2039. default: return false;
  2040. }
  2041. }
  2042. // Increment the TLB pass counter.
  2043. TLBPassCounter ++;
  2044. } while ((TLBCacheData[0] & 0x000000FF) > TLBPassCounter);
  2045. // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
  2046. if ((L1Code == -1) && (L1Data == -1) && (L1Trace == -1))
  2047. {
  2048. this->Features.L1CacheSize = -1;
  2049. }
  2050. else if ((L1Code == -1) && (L1Data == -1) && (L1Trace != -1))
  2051. {
  2052. this->Features.L1CacheSize = L1Trace;
  2053. }
  2054. else if ((L1Code != -1) && (L1Data == -1))
  2055. {
  2056. this->Features.L1CacheSize = L1Code;
  2057. }
  2058. else if ((L1Code == -1) && (L1Data != -1))
  2059. {
  2060. this->Features.L1CacheSize = L1Data;
  2061. }
  2062. else if ((L1Code != -1) && (L1Data != -1))
  2063. {
  2064. this->Features.L1CacheSize = L1Code + L1Data;
  2065. }
  2066. else
  2067. {
  2068. this->Features.L1CacheSize = -1;
  2069. }
  2070. // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
  2071. if (L2Unified == -1)
  2072. {
  2073. this->Features.L2CacheSize = -1;
  2074. }
  2075. else
  2076. {
  2077. this->Features.L2CacheSize = L2Unified;
  2078. }
  2079. // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
  2080. if (L3Unified == -1)
  2081. {
  2082. this->Features.L3CacheSize = -1;
  2083. }
  2084. else
  2085. {
  2086. this->Features.L3CacheSize = L3Unified;
  2087. }
  2088. return true;
  2089. #else
  2090. return false;
  2091. #endif
  2092. }
  2093. /** */
  2094. bool SystemInformationImplementation::RetrieveCPUClockSpeed()
  2095. {
  2096. bool retrieved = false;
  2097. #if defined(_WIN32)
  2098. unsigned int uiRepetitions = 1;
  2099. unsigned int uiMSecPerRepetition = 50;
  2100. __int64 i64Total = 0;
  2101. __int64 i64Overhead = 0;
  2102. // Check if the TSC implementation works at all
  2103. if (this->Features.HasTSC &&
  2104. GetCyclesDifference(SystemInformationImplementation::Delay,
  2105. uiMSecPerRepetition) > 0)
  2106. {
  2107. for (unsigned int nCounter = 0; nCounter < uiRepetitions; nCounter ++)
  2108. {
  2109. i64Total += GetCyclesDifference (SystemInformationImplementation::Delay,
  2110. uiMSecPerRepetition);
  2111. i64Overhead +=
  2112. GetCyclesDifference (SystemInformationImplementation::DelayOverhead,
  2113. uiMSecPerRepetition);
  2114. }
  2115. // Calculate the MHz speed.
  2116. i64Total -= i64Overhead;
  2117. i64Total /= uiRepetitions;
  2118. i64Total /= uiMSecPerRepetition;
  2119. i64Total /= 1000;
  2120. // Save the CPU speed.
  2121. this->CPUSpeedInMHz = (float) i64Total;
  2122. retrieved = true;
  2123. }
  2124. // If RDTSC is not supported, we fallback to trying to read this value
  2125. // from the registry:
  2126. if (!retrieved)
  2127. {
  2128. HKEY hKey = NULL;
  2129. LONG err = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
  2130. L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0,
  2131. KEY_READ, &hKey);
  2132. if (ERROR_SUCCESS == err)
  2133. {
  2134. DWORD dwType = 0;
  2135. DWORD data = 0;
  2136. DWORD dwSize = sizeof(DWORD);
  2137. err = RegQueryValueExW(hKey, L"~MHz", 0,
  2138. &dwType, (LPBYTE) &data, &dwSize);
  2139. if (ERROR_SUCCESS == err)
  2140. {
  2141. this->CPUSpeedInMHz = (float) data;
  2142. retrieved = true;
  2143. }
  2144. RegCloseKey(hKey);
  2145. hKey = NULL;
  2146. }
  2147. }
  2148. #endif
  2149. return retrieved;
  2150. }
  2151. /** */
  2152. bool SystemInformationImplementation::RetrieveClassicalCPUClockSpeed()
  2153. {
  2154. #if USE_ASM_INSTRUCTIONS
  2155. LARGE_INTEGER liStart, liEnd, liCountsPerSecond;
  2156. double dFrequency, dDifference;
  2157. // Attempt to get a starting tick count.
  2158. QueryPerformanceCounter (&liStart);
  2159. __try
  2160. {
  2161. _asm
  2162. {
  2163. mov eax, 0x80000000
  2164. mov ebx, CLASSICAL_CPU_FREQ_LOOP
  2165. Timer_Loop:
  2166. bsf ecx,eax
  2167. dec ebx
  2168. jnz Timer_Loop
  2169. }
  2170. }
  2171. __except(1)
  2172. {
  2173. return false;
  2174. }
  2175. // Attempt to get a starting tick count.
  2176. QueryPerformanceCounter (&liEnd);
  2177. // Get the difference... NB: This is in seconds....
  2178. QueryPerformanceFrequency (&liCountsPerSecond);
  2179. dDifference = (((double) liEnd.QuadPart - (double) liStart.QuadPart) / (double) liCountsPerSecond.QuadPart);
  2180. // Calculate the clock speed.
  2181. if (this->ChipID.Family == 3)
  2182. {
  2183. // 80386 processors.... Loop time is 115 cycles!
  2184. dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 115) / dDifference) / 1000000);
  2185. }
  2186. else if (this->ChipID.Family == 4)
  2187. {
  2188. // 80486 processors.... Loop time is 47 cycles!
  2189. dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 47) / dDifference) / 1000000);
  2190. }
  2191. else if (this->ChipID.Family == 5)
  2192. {
  2193. // Pentium processors.... Loop time is 43 cycles!
  2194. dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 43) / dDifference) / 1000000);
  2195. }
  2196. // Save the clock speed.
  2197. this->Features.CPUSpeed = (int) dFrequency;
  2198. return true;
  2199. #else
  2200. return false;
  2201. #endif
  2202. }
  2203. /** */
  2204. bool SystemInformationImplementation::RetrieveCPUExtendedLevelSupport(int CPULevelToCheck)
  2205. {
  2206. int cpuinfo[4] = { 0, 0, 0, 0 };
  2207. // The extended CPUID is supported by various vendors starting with the following CPU models:
  2208. //
  2209. // Manufacturer & Chip Name | Family Model Revision
  2210. //
  2211. // AMD K6, K6-2 | 5 6 x
  2212. // Cyrix GXm, Cyrix III "Joshua" | 5 4 x
  2213. // IDT C6-2 | 5 8 x
  2214. // VIA Cyrix III | 6 5 x
  2215. // Transmeta Crusoe | 5 x x
  2216. // Intel Pentium 4 | f x x
  2217. //
  2218. // We check to see if a supported processor is present...
  2219. if (this->ChipManufacturer == AMD)
  2220. {
  2221. if (this->ChipID.Family < 5) return false;
  2222. if ((this->ChipID.Family == 5) && (this->ChipID.Model < 6)) return false;
  2223. }
  2224. else if (this->ChipManufacturer == Cyrix)
  2225. {
  2226. if (this->ChipID.Family < 5) return false;
  2227. if ((this->ChipID.Family == 5) && (this->ChipID.Model < 4)) return false;
  2228. if ((this->ChipID.Family == 6) && (this->ChipID.Model < 5)) return false;
  2229. }
  2230. else if (this->ChipManufacturer == IDT)
  2231. {
  2232. if (this->ChipID.Family < 5) return false;
  2233. if ((this->ChipID.Family == 5) && (this->ChipID.Model < 8)) return false;
  2234. }
  2235. else if (this->ChipManufacturer == Transmeta)
  2236. {
  2237. if (this->ChipID.Family < 5) return false;
  2238. }
  2239. else if (this->ChipManufacturer == Intel)
  2240. {
  2241. if (this->ChipID.Family < 0xf)
  2242. {
  2243. return false;
  2244. }
  2245. }
  2246. #if USE_CPUID
  2247. if (!call_cpuid(0x80000000, cpuinfo))
  2248. {
  2249. return false;
  2250. }
  2251. #endif
  2252. // Now we have to check the level wanted vs level returned...
  2253. int nLevelWanted = (CPULevelToCheck & 0x7FFFFFFF);
  2254. int nLevelReturn = (cpuinfo[0] & 0x7FFFFFFF);
  2255. // Check to see if the level provided is supported...
  2256. if (nLevelWanted > nLevelReturn)
  2257. {
  2258. return false;
  2259. }
  2260. return true;
  2261. }
  2262. /** */
  2263. bool SystemInformationImplementation::RetrieveExtendedCPUFeatures()
  2264. {
  2265. // Check that we are not using an Intel processor as it does not support this.
  2266. if (this->ChipManufacturer == Intel)
  2267. {
  2268. return false;
  2269. }
  2270. // Check to see if what we are about to do is supported...
  2271. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000001)))
  2272. {
  2273. return false;
  2274. }
  2275. #if USE_CPUID
  2276. int localCPUExtendedFeatures[4] = { 0, 0, 0, 0 };
  2277. if (!call_cpuid(0x80000001, localCPUExtendedFeatures))
  2278. {
  2279. return false;
  2280. }
  2281. // Retrieve the extended features of CPU present.
  2282. this->Features.ExtendedFeatures.Has3DNow = ((localCPUExtendedFeatures[3] & 0x80000000) != 0); // 3DNow Present --> Bit 31.
  2283. this->Features.ExtendedFeatures.Has3DNowPlus = ((localCPUExtendedFeatures[3] & 0x40000000) != 0); // 3DNow+ Present -- > Bit 30.
  2284. this->Features.ExtendedFeatures.HasSSEMMX = ((localCPUExtendedFeatures[3] & 0x00400000) != 0); // SSE MMX Present --> Bit 22.
  2285. this->Features.ExtendedFeatures.SupportsMP = ((localCPUExtendedFeatures[3] & 0x00080000) != 0); // MP Capable -- > Bit 19.
  2286. // Retrieve AMD specific extended features.
  2287. if (this->ChipManufacturer == AMD)
  2288. {
  2289. this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures[3] & 0x00400000) != 0); // AMD specific: MMX-SSE --> Bit 22
  2290. }
  2291. // Retrieve Cyrix specific extended features.
  2292. if (this->ChipManufacturer == Cyrix)
  2293. {
  2294. this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures[3] & 0x01000000) != 0); // Cyrix specific: Extended MMX --> Bit 24
  2295. }
  2296. return true;
  2297. #else
  2298. return false;
  2299. #endif
  2300. }
  2301. /** */
  2302. bool SystemInformationImplementation::RetrieveProcessorSerialNumber()
  2303. {
  2304. // Check to see if the processor supports the processor serial number.
  2305. if (!this->Features.HasSerial)
  2306. {
  2307. return false;
  2308. }
  2309. #if USE_CPUID
  2310. int SerialNumber[4];
  2311. if (!call_cpuid(3, SerialNumber))
  2312. {
  2313. return false;
  2314. }
  2315. // Process the returned information.
  2316. // ; eax = 3 --> ebx: top 32 bits are the processor signature bits --> NB: Transmeta only ?!?
  2317. // ; ecx: middle 32 bits are the processor signature bits
  2318. // ; edx: bottom 32 bits are the processor signature bits
  2319. char sn[128];
  2320. sprintf (sn, "%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x",
  2321. ((SerialNumber[1] & 0xff000000) >> 24),
  2322. ((SerialNumber[1] & 0x00ff0000) >> 16),
  2323. ((SerialNumber[1] & 0x0000ff00) >> 8),
  2324. ((SerialNumber[1] & 0x000000ff) >> 0),
  2325. ((SerialNumber[2] & 0xff000000) >> 24),
  2326. ((SerialNumber[2] & 0x00ff0000) >> 16),
  2327. ((SerialNumber[2] & 0x0000ff00) >> 8),
  2328. ((SerialNumber[2] & 0x000000ff) >> 0),
  2329. ((SerialNumber[3] & 0xff000000) >> 24),
  2330. ((SerialNumber[3] & 0x00ff0000) >> 16),
  2331. ((SerialNumber[3] & 0x0000ff00) >> 8),
  2332. ((SerialNumber[3] & 0x000000ff) >> 0));
  2333. this->ChipID.SerialNumber = sn;
  2334. return true;
  2335. #else
  2336. return false;
  2337. #endif
  2338. }
  2339. /** */
  2340. bool SystemInformationImplementation::RetrieveCPUPowerManagement()
  2341. {
  2342. // Check to see if what we are about to do is supported...
  2343. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000007)))
  2344. {
  2345. this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID = false;
  2346. this->Features.ExtendedFeatures.PowerManagement.HasVoltageID = false;
  2347. this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode = false;
  2348. return false;
  2349. }
  2350. #if USE_CPUID
  2351. int localCPUPowerManagement[4] = { 0, 0, 0, 0 };
  2352. if (!call_cpuid(0x80000007, localCPUPowerManagement))
  2353. {
  2354. return false;
  2355. }
  2356. // Check for the power management capabilities of the CPU.
  2357. this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode = ((localCPUPowerManagement[3] & 0x00000001) != 0);
  2358. this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID = ((localCPUPowerManagement[3] & 0x00000002) != 0);
  2359. this->Features.ExtendedFeatures.PowerManagement.HasVoltageID = ((localCPUPowerManagement[3] & 0x00000004) != 0);
  2360. return true;
  2361. #else
  2362. return false;
  2363. #endif
  2364. }
  2365. #if USE_CPUID
  2366. // Used only in USE_CPUID implementation below.
  2367. static void SystemInformationStripLeadingSpace(kwsys_stl::string& str)
  2368. {
  2369. // Because some manufacturers have leading white space - we have to post-process the name.
  2370. kwsys_stl::string::size_type pos = str.find_first_not_of(" ");
  2371. if(pos != kwsys_stl::string::npos)
  2372. {
  2373. str = str.substr(pos);
  2374. }
  2375. }
  2376. #endif
  2377. /** */
  2378. bool SystemInformationImplementation::RetrieveExtendedCPUIdentity()
  2379. {
  2380. // Check to see if what we are about to do is supported...
  2381. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000002)))
  2382. return false;
  2383. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000003)))
  2384. return false;
  2385. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000004)))
  2386. return false;
  2387. #if USE_CPUID
  2388. int CPUExtendedIdentity[12];
  2389. if (!call_cpuid(0x80000002, CPUExtendedIdentity))
  2390. {
  2391. return false;
  2392. }
  2393. if (!call_cpuid(0x80000003, CPUExtendedIdentity + 4))
  2394. {
  2395. return false;
  2396. }
  2397. if (!call_cpuid(0x80000004, CPUExtendedIdentity + 8))
  2398. {
  2399. return false;
  2400. }
  2401. // Process the returned information.
  2402. char nbuf[49];
  2403. memcpy (&(nbuf[0]), &(CPUExtendedIdentity[0]), sizeof (int));
  2404. memcpy (&(nbuf[4]), &(CPUExtendedIdentity[1]), sizeof (int));
  2405. memcpy (&(nbuf[8]), &(CPUExtendedIdentity[2]), sizeof (int));
  2406. memcpy (&(nbuf[12]), &(CPUExtendedIdentity[3]), sizeof (int));
  2407. memcpy (&(nbuf[16]), &(CPUExtendedIdentity[4]), sizeof (int));
  2408. memcpy (&(nbuf[20]), &(CPUExtendedIdentity[5]), sizeof (int));
  2409. memcpy (&(nbuf[24]), &(CPUExtendedIdentity[6]), sizeof (int));
  2410. memcpy (&(nbuf[28]), &(CPUExtendedIdentity[7]), sizeof (int));
  2411. memcpy (&(nbuf[32]), &(CPUExtendedIdentity[8]), sizeof (int));
  2412. memcpy (&(nbuf[36]), &(CPUExtendedIdentity[9]), sizeof (int));
  2413. memcpy (&(nbuf[40]), &(CPUExtendedIdentity[10]), sizeof (int));
  2414. memcpy (&(nbuf[44]), &(CPUExtendedIdentity[11]), sizeof (int));
  2415. nbuf[48] = '\0';
  2416. this->ChipID.ProcessorName = nbuf;
  2417. this->ChipID.ModelName = nbuf;
  2418. // Because some manufacturers have leading white space - we have to post-process the name.
  2419. SystemInformationStripLeadingSpace(this->ChipID.ProcessorName);
  2420. return true;
  2421. #else
  2422. return false;
  2423. #endif
  2424. }
  2425. /** */
  2426. bool SystemInformationImplementation::RetrieveClassicalCPUIdentity()
  2427. {
  2428. // Start by decided which manufacturer we are using....
  2429. switch (this->ChipManufacturer)
  2430. {
  2431. case Intel:
  2432. // Check the family / model / revision to determine the CPU ID.
  2433. switch (this->ChipID.Family) {
  2434. case 3:
  2435. this->ChipID.ProcessorName = "Newer i80386 family";
  2436. break;
  2437. case 4:
  2438. switch (this->ChipID.Model) {
  2439. case 0: this->ChipID.ProcessorName = "i80486DX-25/33"; break;
  2440. case 1: this->ChipID.ProcessorName = "i80486DX-50"; break;
  2441. case 2: this->ChipID.ProcessorName = "i80486SX"; break;
  2442. case 3: this->ChipID.ProcessorName = "i80486DX2"; break;
  2443. case 4: this->ChipID.ProcessorName = "i80486SL"; break;
  2444. case 5: this->ChipID.ProcessorName = "i80486SX2"; break;
  2445. case 7: this->ChipID.ProcessorName = "i80486DX2 WriteBack"; break;
  2446. case 8: this->ChipID.ProcessorName = "i80486DX4"; break;
  2447. case 9: this->ChipID.ProcessorName = "i80486DX4 WriteBack"; break;
  2448. default: this->ChipID.ProcessorName = "Unknown 80486 family"; return false;
  2449. }
  2450. break;
  2451. case 5:
  2452. switch (this->ChipID.Model)
  2453. {
  2454. case 0: this->ChipID.ProcessorName = "P5 A-Step"; break;
  2455. case 1: this->ChipID.ProcessorName = "P5"; break;
  2456. case 2: this->ChipID.ProcessorName = "P54C"; break;
  2457. case 3: this->ChipID.ProcessorName = "P24T OverDrive"; break;
  2458. case 4: this->ChipID.ProcessorName = "P55C"; break;
  2459. case 7: this->ChipID.ProcessorName = "P54C"; break;
  2460. case 8: this->ChipID.ProcessorName = "P55C (0.25micron)"; break;
  2461. default: this->ChipID.ProcessorName = "Unknown Pentium family"; return false;
  2462. }
  2463. break;
  2464. case 6:
  2465. switch (this->ChipID.Model)
  2466. {
  2467. case 0: this->ChipID.ProcessorName = "P6 A-Step"; break;
  2468. case 1: this->ChipID.ProcessorName = "P6"; break;
  2469. case 3: this->ChipID.ProcessorName = "Pentium II (0.28 micron)"; break;
  2470. case 5: this->ChipID.ProcessorName = "Pentium II (0.25 micron)"; break;
  2471. case 6: this->ChipID.ProcessorName = "Pentium II With On-Die L2 Cache"; break;
  2472. case 7: this->ChipID.ProcessorName = "Pentium III (0.25 micron)"; break;
  2473. case 8: this->ChipID.ProcessorName = "Pentium III (0.18 micron) With 256 KB On-Die L2 Cache "; break;
  2474. case 0xa: this->ChipID.ProcessorName = "Pentium III (0.18 micron) With 1 Or 2 MB On-Die L2 Cache "; break;
  2475. case 0xb: this->ChipID.ProcessorName = "Pentium III (0.13 micron) With 256 Or 512 KB On-Die L2 Cache "; break;
  2476. case 23: this->ChipID.ProcessorName = "Intel(R) Core(TM)2 Duo CPU T9500 @ 2.60GHz"; break;
  2477. default: this->ChipID.ProcessorName = "Unknown P6 family"; return false;
  2478. }
  2479. break;
  2480. case 7:
  2481. this->ChipID.ProcessorName = "Intel Merced (IA-64)";
  2482. break;
  2483. case 0xf:
  2484. // Check the extended family bits...
  2485. switch (this->ChipID.ExtendedFamily)
  2486. {
  2487. case 0:
  2488. switch (this->ChipID.Model)
  2489. {
  2490. case 0: this->ChipID.ProcessorName = "Pentium IV (0.18 micron)"; break;
  2491. case 1: this->ChipID.ProcessorName = "Pentium IV (0.18 micron)"; break;
  2492. case 2: this->ChipID.ProcessorName = "Pentium IV (0.13 micron)"; break;
  2493. default: this->ChipID.ProcessorName = "Unknown Pentium 4 family"; return false;
  2494. }
  2495. break;
  2496. case 1:
  2497. this->ChipID.ProcessorName = "Intel McKinley (IA-64)";
  2498. break;
  2499. default:
  2500. this->ChipID.ProcessorName = "Pentium";
  2501. }
  2502. break;
  2503. default:
  2504. this->ChipID.ProcessorName = "Unknown Intel family";
  2505. return false;
  2506. }
  2507. break;
  2508. case AMD:
  2509. // Check the family / model / revision to determine the CPU ID.
  2510. switch (this->ChipID.Family)
  2511. {
  2512. case 4:
  2513. switch (this->ChipID.Model)
  2514. {
  2515. case 3: this->ChipID.ProcessorName = "80486DX2"; break;
  2516. case 7: this->ChipID.ProcessorName = "80486DX2 WriteBack"; break;
  2517. case 8: this->ChipID.ProcessorName = "80486DX4"; break;
  2518. case 9: this->ChipID.ProcessorName = "80486DX4 WriteBack"; break;
  2519. case 0xe: this->ChipID.ProcessorName = "5x86"; break;
  2520. case 0xf: this->ChipID.ProcessorName = "5x86WB"; break;
  2521. default: this->ChipID.ProcessorName = "Unknown 80486 family"; return false;
  2522. }
  2523. break;
  2524. case 5:
  2525. switch (this->ChipID.Model)
  2526. {
  2527. case 0: this->ChipID.ProcessorName = "SSA5 (PR75, PR90 = PR100)"; break;
  2528. case 1: this->ChipID.ProcessorName = "5k86 (PR120 = PR133)"; break;
  2529. case 2: this->ChipID.ProcessorName = "5k86 (PR166)"; break;
  2530. case 3: this->ChipID.ProcessorName = "5k86 (PR200)"; break;
  2531. case 6: this->ChipID.ProcessorName = "K6 (0.30 micron)"; break;
  2532. case 7: this->ChipID.ProcessorName = "K6 (0.25 micron)"; break;
  2533. case 8: this->ChipID.ProcessorName = "K6-2"; break;
  2534. case 9: this->ChipID.ProcessorName = "K6-III"; break;
  2535. case 0xd: this->ChipID.ProcessorName = "K6-2+ or K6-III+ (0.18 micron)"; break;
  2536. default: this->ChipID.ProcessorName = "Unknown 80586 family"; return false;
  2537. }
  2538. break;
  2539. case 6:
  2540. switch (this->ChipID.Model)
  2541. {
  2542. case 1: this->ChipID.ProcessorName = "Athlon- (0.25 micron)"; break;
  2543. case 2: this->ChipID.ProcessorName = "Athlon- (0.18 micron)"; break;
  2544. case 3: this->ChipID.ProcessorName = "Duron- (SF core)"; break;
  2545. case 4: this->ChipID.ProcessorName = "Athlon- (Thunderbird core)"; break;
  2546. case 6: this->ChipID.ProcessorName = "Athlon- (Palomino core)"; break;
  2547. case 7: this->ChipID.ProcessorName = "Duron- (Morgan core)"; break;
  2548. case 8:
  2549. if (this->Features.ExtendedFeatures.SupportsMP)
  2550. this->ChipID.ProcessorName = "Athlon - MP (Thoroughbred core)";
  2551. else this->ChipID.ProcessorName = "Athlon - XP (Thoroughbred core)";
  2552. break;
  2553. default: this->ChipID.ProcessorName = "Unknown K7 family"; return false;
  2554. }
  2555. break;
  2556. default:
  2557. this->ChipID.ProcessorName = "Unknown AMD family";
  2558. return false;
  2559. }
  2560. break;
  2561. case Transmeta:
  2562. switch (this->ChipID.Family)
  2563. {
  2564. case 5:
  2565. switch (this->ChipID.Model)
  2566. {
  2567. case 4: this->ChipID.ProcessorName = "Crusoe TM3x00 and TM5x00"; break;
  2568. default: this->ChipID.ProcessorName = "Unknown Crusoe family"; return false;
  2569. }
  2570. break;
  2571. default:
  2572. this->ChipID.ProcessorName = "Unknown Transmeta family";
  2573. return false;
  2574. }
  2575. break;
  2576. case Rise:
  2577. switch (this->ChipID.Family)
  2578. {
  2579. case 5:
  2580. switch (this->ChipID.Model)
  2581. {
  2582. case 0: this->ChipID.ProcessorName = "mP6 (0.25 micron)"; break;
  2583. case 2: this->ChipID.ProcessorName = "mP6 (0.18 micron)"; break;
  2584. default: this->ChipID.ProcessorName = "Unknown Rise family"; return false;
  2585. }
  2586. break;
  2587. default:
  2588. this->ChipID.ProcessorName = "Unknown Rise family";
  2589. return false;
  2590. }
  2591. break;
  2592. case UMC:
  2593. switch (this->ChipID.Family)
  2594. {
  2595. case 4:
  2596. switch (this->ChipID.Model)
  2597. {
  2598. case 1: this->ChipID.ProcessorName = "U5D"; break;
  2599. case 2: this->ChipID.ProcessorName = "U5S"; break;
  2600. default: this->ChipID.ProcessorName = "Unknown UMC family"; return false;
  2601. }
  2602. break;
  2603. default:
  2604. this->ChipID.ProcessorName = "Unknown UMC family";
  2605. return false;
  2606. }
  2607. break;
  2608. case IDT:
  2609. switch (this->ChipID.Family)
  2610. {
  2611. case 5:
  2612. switch (this->ChipID.Model)
  2613. {
  2614. case 4: this->ChipID.ProcessorName = "C6"; break;
  2615. case 8: this->ChipID.ProcessorName = "C2"; break;
  2616. case 9: this->ChipID.ProcessorName = "C3"; break;
  2617. default: this->ChipID.ProcessorName = "Unknown IDT\\Centaur family"; return false;
  2618. }
  2619. break;
  2620. case 6:
  2621. switch (this->ChipID.Model)
  2622. {
  2623. case 6: this->ChipID.ProcessorName = "VIA Cyrix III - Samuel"; break;
  2624. default: this->ChipID.ProcessorName = "Unknown IDT\\Centaur family"; return false;
  2625. }
  2626. break;
  2627. default:
  2628. this->ChipID.ProcessorName = "Unknown IDT\\Centaur family";
  2629. return false;
  2630. }
  2631. break;
  2632. case Cyrix:
  2633. switch (this->ChipID.Family)
  2634. {
  2635. case 4:
  2636. switch (this->ChipID.Model)
  2637. {
  2638. case 4: this->ChipID.ProcessorName = "MediaGX GX = GXm"; break;
  2639. case 9: this->ChipID.ProcessorName = "5x86"; break;
  2640. default: this->ChipID.ProcessorName = "Unknown Cx5x86 family"; return false;
  2641. }
  2642. break;
  2643. case 5:
  2644. switch (this->ChipID.Model)
  2645. {
  2646. case 2: this->ChipID.ProcessorName = "Cx6x86"; break;
  2647. case 4: this->ChipID.ProcessorName = "MediaGX GXm"; break;
  2648. default: this->ChipID.ProcessorName = "Unknown Cx6x86 family"; return false;
  2649. }
  2650. break;
  2651. case 6:
  2652. switch (this->ChipID.Model)
  2653. {
  2654. case 0: this->ChipID.ProcessorName = "6x86MX"; break;
  2655. case 5: this->ChipID.ProcessorName = "Cyrix M2 Core"; break;
  2656. case 6: this->ChipID.ProcessorName = "WinChip C5A Core"; break;
  2657. case 7: this->ChipID.ProcessorName = "WinChip C5B\\C5C Core"; break;
  2658. case 8: this->ChipID.ProcessorName = "WinChip C5C-T Core"; break;
  2659. default: this->ChipID.ProcessorName = "Unknown 6x86MX\\Cyrix III family"; return false;
  2660. }
  2661. break;
  2662. default:
  2663. this->ChipID.ProcessorName = "Unknown Cyrix family";
  2664. return false;
  2665. }
  2666. break;
  2667. case NexGen:
  2668. switch (this->ChipID.Family)
  2669. {
  2670. case 5:
  2671. switch (this->ChipID.Model)
  2672. {
  2673. case 0: this->ChipID.ProcessorName = "Nx586 or Nx586FPU"; break;
  2674. default: this->ChipID.ProcessorName = "Unknown NexGen family"; return false;
  2675. }
  2676. break;
  2677. default:
  2678. this->ChipID.ProcessorName = "Unknown NexGen family";
  2679. return false;
  2680. }
  2681. break;
  2682. case NSC:
  2683. this->ChipID.ProcessorName = "Cx486SLC \\ DLC \\ Cx486S A-Step";
  2684. break;
  2685. case Sun:
  2686. case IBM:
  2687. case Motorola:
  2688. case HP:
  2689. case UnknownManufacturer:
  2690. default:
  2691. this->ChipID.ProcessorName = "Unknown family"; // We cannot identify the processor.
  2692. return false;
  2693. }
  2694. return true;
  2695. }
  2696. /** Extract a value from the CPUInfo file */
  2697. kwsys_stl::string SystemInformationImplementation::ExtractValueFromCpuInfoFile(kwsys_stl::string buffer,const char* word,size_t init)
  2698. {
  2699. size_t pos = buffer.find(word,init);
  2700. if(pos != buffer.npos)
  2701. {
  2702. this->CurrentPositionInFile = pos;
  2703. pos = buffer.find(":",pos);
  2704. size_t pos2 = buffer.find("\n",pos);
  2705. if(pos!=buffer.npos && pos2!=buffer.npos)
  2706. {
  2707. // It may happen that the beginning matches, but this is still not the requested key.
  2708. // An example is looking for "cpu" when "cpu family" comes first. So we check that
  2709. // we have only spaces from here to pos, otherwise we search again.
  2710. for(size_t i=this->CurrentPositionInFile+strlen(word); i < pos; ++i)
  2711. {
  2712. if(buffer[i] != ' ' && buffer[i] != '\t')
  2713. {
  2714. return this->ExtractValueFromCpuInfoFile(buffer, word, pos2);
  2715. }
  2716. }
  2717. return buffer.substr(pos+2,pos2-pos-2);
  2718. }
  2719. }
  2720. this->CurrentPositionInFile = buffer.npos;
  2721. return "";
  2722. }
  2723. /** Query for the cpu status */
  2724. bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
  2725. {
  2726. this->NumberOfLogicalCPU = 0;
  2727. this->NumberOfPhysicalCPU = 0;
  2728. kwsys_stl::string buffer;
  2729. FILE *fd = fopen("/proc/cpuinfo", "r" );
  2730. if ( !fd )
  2731. {
  2732. kwsys_ios::cout << "Problem opening /proc/cpuinfo" << kwsys_ios::endl;
  2733. return false;
  2734. }
  2735. size_t fileSize = 0;
  2736. while(!feof(fd))
  2737. {
  2738. buffer += static_cast<char>(fgetc(fd));
  2739. fileSize++;
  2740. }
  2741. fclose( fd );
  2742. buffer.resize(fileSize-2);
  2743. // Number of logical CPUs (combination of multiple processors, multi-core
  2744. // and hyperthreading)
  2745. size_t pos = buffer.find("processor\t");
  2746. while(pos != buffer.npos)
  2747. {
  2748. this->NumberOfLogicalCPU++;
  2749. pos = buffer.find("processor\t",pos+1);
  2750. }
  2751. #ifdef __linux
  2752. // Find the largest physical id.
  2753. int maxId = -1;
  2754. kwsys_stl::string idc =
  2755. this->ExtractValueFromCpuInfoFile(buffer,"physical id");
  2756. while(this->CurrentPositionInFile != buffer.npos)
  2757. {
  2758. int id = atoi(idc.c_str());
  2759. if(id > maxId)
  2760. {
  2761. maxId=id;
  2762. }
  2763. idc = this->ExtractValueFromCpuInfoFile(buffer,"physical id",
  2764. this->CurrentPositionInFile+1);
  2765. }
  2766. // Physical ids returned by Linux don't distinguish cores.
  2767. // We want to record the total number of cores in this->NumberOfPhysicalCPU
  2768. // (checking only the first proc)
  2769. kwsys_stl::string cores =
  2770. this->ExtractValueFromCpuInfoFile(buffer,"cpu cores");
  2771. int numberOfCoresPerCPU=atoi(cores.c_str());
  2772. if (maxId > 0)
  2773. {
  2774. this->NumberOfPhysicalCPU=static_cast<unsigned int>(
  2775. numberOfCoresPerCPU*(maxId+1));
  2776. }
  2777. else
  2778. {
  2779. // Linux Sparc: get cpu count
  2780. this->NumberOfPhysicalCPU=
  2781. atoi(this->ExtractValueFromCpuInfoFile(buffer,"ncpus active").c_str());
  2782. }
  2783. #else // __CYGWIN__
  2784. // does not have "physical id" entries, neither "cpu cores"
  2785. // this has to be fixed for hyper-threading.
  2786. kwsys_stl::string cpucount =
  2787. this->ExtractValueFromCpuInfoFile(buffer,"cpu count");
  2788. this->NumberOfPhysicalCPU=
  2789. this->NumberOfLogicalCPU = atoi(cpucount.c_str());
  2790. #endif
  2791. // gotta have one, and if this is 0 then we get a / by 0n
  2792. // better to have a bad answer than a crash
  2793. if(this->NumberOfPhysicalCPU <= 0)
  2794. {
  2795. this->NumberOfPhysicalCPU = 1;
  2796. }
  2797. // LogicalProcessorsPerPhysical>1 => hyperthreading.
  2798. this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical=
  2799. this->NumberOfLogicalCPU/this->NumberOfPhysicalCPU;
  2800. // CPU speed (checking only the first processor)
  2801. kwsys_stl::string CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"cpu MHz");
  2802. if(!CPUSpeed.empty())
  2803. {
  2804. this->CPUSpeedInMHz = static_cast<float>(atof(CPUSpeed.c_str()));
  2805. }
  2806. #ifdef __linux
  2807. else
  2808. {
  2809. // Linux Sparc: CPU speed is in Hz and encoded in hexadecimal
  2810. CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"Cpu0ClkTck");
  2811. this->CPUSpeedInMHz = static_cast<float>(
  2812. strtoull(CPUSpeed.c_str(),0,16))/1000000.0f;
  2813. }
  2814. #endif
  2815. // Chip family
  2816. kwsys_stl::string familyStr =
  2817. this->ExtractValueFromCpuInfoFile(buffer,"cpu family");
  2818. if(familyStr.empty())
  2819. {
  2820. familyStr = this->ExtractValueFromCpuInfoFile(buffer,"CPU architecture");
  2821. }
  2822. this->ChipID.Family = atoi(familyStr.c_str());
  2823. // Chip Vendor
  2824. this->ChipID.Vendor = this->ExtractValueFromCpuInfoFile(buffer,"vendor_id");
  2825. this->FindManufacturer(familyStr);
  2826. // second try for setting family
  2827. if (this->ChipID.Family == 0 && this->ChipManufacturer == HP)
  2828. {
  2829. if (familyStr == "PA-RISC 1.1a")
  2830. this->ChipID.Family = 0x11a;
  2831. else if (familyStr == "PA-RISC 2.0")
  2832. this->ChipID.Family = 0x200;
  2833. // If you really get CMake to work on a machine not belonging to
  2834. // any of those families I owe you a dinner if you get it to
  2835. // contribute nightly builds regularly.
  2836. }
  2837. // Chip Model
  2838. this->ChipID.Model = atoi(this->ExtractValueFromCpuInfoFile(buffer,"model").c_str());
  2839. if(!this->RetrieveClassicalCPUIdentity())
  2840. {
  2841. // Some platforms (e.g. PA-RISC) tell us their CPU name here.
  2842. // Note: x86 does not.
  2843. kwsys_stl::string cpuname = this->ExtractValueFromCpuInfoFile(buffer,"cpu");
  2844. if(!cpuname.empty())
  2845. {
  2846. this->ChipID.ProcessorName = cpuname;
  2847. }
  2848. }
  2849. // Chip revision
  2850. kwsys_stl::string cpurev = this->ExtractValueFromCpuInfoFile(buffer,"stepping");
  2851. if(cpurev.empty())
  2852. {
  2853. cpurev = this->ExtractValueFromCpuInfoFile(buffer,"CPU revision");
  2854. }
  2855. this->ChipID.Revision = atoi(cpurev.c_str());
  2856. // Chip Model Name
  2857. this->ChipID.ModelName = this->ExtractValueFromCpuInfoFile(buffer,"model name").c_str();
  2858. // L1 Cache size
  2859. // Different architectures may show different names for the caches.
  2860. // Sum up everything we find.
  2861. kwsys_stl::vector<const char*> cachename;
  2862. cachename.clear();
  2863. cachename.push_back("cache size"); // e.g. x86
  2864. cachename.push_back("I-cache"); // e.g. PA-RISC
  2865. cachename.push_back("D-cache"); // e.g. PA-RISC
  2866. this->Features.L1CacheSize = 0;
  2867. for (size_t index = 0; index < cachename.size(); index ++)
  2868. {
  2869. kwsys_stl::string cacheSize = this->ExtractValueFromCpuInfoFile(buffer,cachename[index]);
  2870. if (!cacheSize.empty())
  2871. {
  2872. pos = cacheSize.find(" KB");
  2873. if(pos!=cacheSize.npos)
  2874. {
  2875. cacheSize = cacheSize.substr(0,pos);
  2876. }
  2877. this->Features.L1CacheSize += atoi(cacheSize.c_str());
  2878. }
  2879. }
  2880. // processor feature flags (probably x86 specific)
  2881. kwsys_stl::string cpuflags = this->ExtractValueFromCpuInfoFile(buffer,"flags");
  2882. if(!cpurev.empty())
  2883. {
  2884. // now we can match every flags as space + flag + space
  2885. cpuflags = " " + cpuflags + " ";
  2886. if ((cpuflags.find(" fpu ")!=kwsys_stl::string::npos))
  2887. {
  2888. this->Features.HasFPU = true;
  2889. }
  2890. if ((cpuflags.find(" tsc ")!=kwsys_stl::string::npos))
  2891. {
  2892. this->Features.HasTSC = true;
  2893. }
  2894. if ((cpuflags.find(" mmx ")!=kwsys_stl::string::npos))
  2895. {
  2896. this->Features.HasMMX = true;
  2897. }
  2898. if ((cpuflags.find(" sse ")!=kwsys_stl::string::npos))
  2899. {
  2900. this->Features.HasSSE = true;
  2901. }
  2902. if ((cpuflags.find(" sse2 ")!=kwsys_stl::string::npos))
  2903. {
  2904. this->Features.HasSSE2 = true;
  2905. }
  2906. if ((cpuflags.find(" apic ")!=kwsys_stl::string::npos))
  2907. {
  2908. this->Features.HasAPIC = true;
  2909. }
  2910. if ((cpuflags.find(" cmov ")!=kwsys_stl::string::npos))
  2911. {
  2912. this->Features.HasCMOV = true;
  2913. }
  2914. if ((cpuflags.find(" mtrr ")!=kwsys_stl::string::npos))
  2915. {
  2916. this->Features.HasMTRR = true;
  2917. }
  2918. if ((cpuflags.find(" acpi ")!=kwsys_stl::string::npos))
  2919. {
  2920. this->Features.HasACPI = true;
  2921. }
  2922. if ((cpuflags.find(" 3dnow ")!=kwsys_stl::string::npos))
  2923. {
  2924. this->Features.ExtendedFeatures.Has3DNow = true;
  2925. }
  2926. }
  2927. return true;
  2928. }
  2929. bool SystemInformationImplementation::QueryProcessorBySysconf()
  2930. {
  2931. #if defined(_SC_NPROC_ONLN) && !defined(_SC_NPROCESSORS_ONLN)
  2932. // IRIX names this slightly different
  2933. # define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
  2934. #endif
  2935. #ifdef _SC_NPROCESSORS_ONLN
  2936. long c = sysconf(_SC_NPROCESSORS_ONLN);
  2937. if (c <= 0)
  2938. {
  2939. return false;
  2940. }
  2941. this->NumberOfPhysicalCPU = static_cast<unsigned int>(c);
  2942. this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
  2943. return true;
  2944. #else
  2945. return false;
  2946. #endif
  2947. }
  2948. bool SystemInformationImplementation::QueryProcessor()
  2949. {
  2950. return this->QueryProcessorBySysconf();
  2951. }
  2952. /**
  2953. Get total system RAM in units of KiB.
  2954. */
  2955. SystemInformation::LongLong
  2956. SystemInformationImplementation::GetHostMemoryTotal()
  2957. {
  2958. #if defined(_WIN32)
  2959. # if defined(_MSC_VER) && _MSC_VER < 1300
  2960. MEMORYSTATUS stat;
  2961. stat.dwLength = sizeof(stat);
  2962. GlobalMemoryStatus(&stat);
  2963. return stat.dwTotalPhys/1024;
  2964. # else
  2965. MEMORYSTATUSEX statex;
  2966. statex.dwLength=sizeof(statex);
  2967. GlobalMemoryStatusEx(&statex);
  2968. return statex.ullTotalPhys/1024;
  2969. # endif
  2970. #elif defined(__linux)
  2971. SystemInformation::LongLong memTotal=0;
  2972. int ierr=GetFieldFromFile("/proc/meminfo","MemTotal:",memTotal);
  2973. if (ierr)
  2974. {
  2975. return -1;
  2976. }
  2977. return memTotal;
  2978. #elif defined(__APPLE__)
  2979. uint64_t mem;
  2980. size_t len = sizeof(mem);
  2981. int ierr=sysctlbyname("hw.memsize", &mem, &len, NULL, 0);
  2982. if (ierr)
  2983. {
  2984. return -1;
  2985. }
  2986. return mem/1024;
  2987. #else
  2988. return 0;
  2989. #endif
  2990. }
  2991. /**
  2992. Get total system RAM in units of KiB. This may differ from the
  2993. host total if a host-wide resource limit is applied.
  2994. */
  2995. SystemInformation::LongLong
  2996. SystemInformationImplementation::GetHostMemoryAvailable(const char *hostLimitEnvVarName)
  2997. {
  2998. SystemInformation::LongLong memTotal=this->GetHostMemoryTotal();
  2999. // the following mechanism is provided for systems that
  3000. // apply resource limits across groups of processes.
  3001. // this is of use on certain SMP systems (eg. SGI UV)
  3002. // where the host has a large amount of ram but a given user's
  3003. // access to it is severly restricted. The system will
  3004. // apply a limit across a set of processes. Units are in KiB.
  3005. if (hostLimitEnvVarName)
  3006. {
  3007. const char *hostLimitEnvVarValue=getenv(hostLimitEnvVarName);
  3008. if (hostLimitEnvVarValue)
  3009. {
  3010. SystemInformation::LongLong hostLimit=atoLongLong(hostLimitEnvVarValue);
  3011. if (hostLimit>0)
  3012. {
  3013. memTotal=min(hostLimit,memTotal);
  3014. }
  3015. }
  3016. }
  3017. return memTotal;
  3018. }
  3019. /**
  3020. Get total system RAM in units of KiB. This may differ from the
  3021. host total if a per-process resource limit is applied.
  3022. */
  3023. SystemInformation::LongLong
  3024. SystemInformationImplementation::GetProcMemoryAvailable(
  3025. const char *hostLimitEnvVarName,
  3026. const char *procLimitEnvVarName)
  3027. {
  3028. SystemInformation::LongLong memAvail
  3029. = this->GetHostMemoryAvailable(hostLimitEnvVarName);
  3030. // the following mechanism is provide for systems where rlimits
  3031. // are not employed. Units are in KiB.
  3032. if (procLimitEnvVarName)
  3033. {
  3034. const char *procLimitEnvVarValue=getenv(procLimitEnvVarName);
  3035. if (procLimitEnvVarValue)
  3036. {
  3037. SystemInformation::LongLong procLimit=atoLongLong(procLimitEnvVarValue);
  3038. if (procLimit>0)
  3039. {
  3040. memAvail=min(procLimit,memAvail);
  3041. }
  3042. }
  3043. }
  3044. #if defined(__linux)
  3045. int ierr;
  3046. ResourceLimitType rlim;
  3047. ierr=GetResourceLimit(RLIMIT_DATA,&rlim);
  3048. if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY))
  3049. {
  3050. memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail);
  3051. }
  3052. ierr=GetResourceLimit(RLIMIT_AS,&rlim);
  3053. if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY))
  3054. {
  3055. memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail);
  3056. }
  3057. #elif defined(__APPLE__)
  3058. struct rlimit rlim;
  3059. int ierr;
  3060. ierr=getrlimit(RLIMIT_DATA,&rlim);
  3061. if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY))
  3062. {
  3063. memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail);
  3064. }
  3065. ierr=getrlimit(RLIMIT_RSS,&rlim);
  3066. if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY))
  3067. {
  3068. memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail);
  3069. }
  3070. #endif
  3071. return memAvail;
  3072. }
  3073. /**
  3074. Get RAM used by all processes in the host, in units of KiB.
  3075. */
  3076. SystemInformation::LongLong
  3077. SystemInformationImplementation::GetHostMemoryUsed()
  3078. {
  3079. #if defined(_WIN32)
  3080. # if defined(_MSC_VER) && _MSC_VER < 1300
  3081. MEMORYSTATUS stat;
  3082. stat.dwLength = sizeof(stat);
  3083. GlobalMemoryStatus(&stat);
  3084. return (stat.dwTotalPhys - stat.dwAvailPhys)/1024;
  3085. # else
  3086. MEMORYSTATUSEX statex;
  3087. statex.dwLength=sizeof(statex);
  3088. GlobalMemoryStatusEx(&statex);
  3089. return (statex.ullTotalPhys - statex.ullAvailPhys)/1024;
  3090. # endif
  3091. #elif defined(__linux)
  3092. const char *names[3]={"MemTotal:","MemFree:",NULL};
  3093. SystemInformation::LongLong values[2]={SystemInformation::LongLong(0)};
  3094. int ierr=GetFieldsFromFile("/proc/meminfo",names,values);
  3095. if (ierr)
  3096. {
  3097. return ierr;
  3098. }
  3099. SystemInformation::LongLong &memTotal=values[0];
  3100. SystemInformation::LongLong &memFree=values[1];
  3101. return memTotal - memFree;
  3102. #elif defined(__APPLE__)
  3103. SystemInformation::LongLong psz=getpagesize();
  3104. if (psz<1)
  3105. {
  3106. return -1;
  3107. }
  3108. const char *names[4]={"Pages active:","Pages inactive:","Pages wired down:",NULL};
  3109. SystemInformation::LongLong values[3]={SystemInformation::LongLong(0)};
  3110. int ierr=GetFieldsFromCommand("vm_stat", names, values);
  3111. if (ierr)
  3112. {
  3113. return -1;
  3114. }
  3115. SystemInformation::LongLong &vmActive=values[0];
  3116. SystemInformation::LongLong &vmInactive=values[1];
  3117. SystemInformation::LongLong &vmWired=values[2];
  3118. return ((vmActive+vmInactive+vmWired)*psz)/1024;
  3119. #else
  3120. return 0;
  3121. #endif
  3122. }
  3123. /**
  3124. Get system RAM used by the process associated with the given
  3125. process id in units of KiB.
  3126. */
  3127. SystemInformation::LongLong
  3128. SystemInformationImplementation::GetProcMemoryUsed()
  3129. {
  3130. #if defined(_WIN32) && defined(KWSYS_SYS_HAS_PSAPI)
  3131. long pid=GetCurrentProcessId();
  3132. HANDLE hProc;
  3133. hProc=OpenProcess(
  3134. PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,
  3135. false,
  3136. pid);
  3137. if (hProc==0)
  3138. {
  3139. return -1;
  3140. }
  3141. PROCESS_MEMORY_COUNTERS pmc;
  3142. int ok=GetProcessMemoryInfo(hProc,&pmc,sizeof(pmc));
  3143. CloseHandle(hProc);
  3144. if (!ok)
  3145. {
  3146. return -2;
  3147. }
  3148. return pmc.WorkingSetSize/1024;
  3149. #elif defined(__linux)
  3150. SystemInformation::LongLong memUsed=0;
  3151. int ierr=GetFieldFromFile("/proc/self/status","VmRSS:",memUsed);
  3152. if (ierr)
  3153. {
  3154. return -1;
  3155. }
  3156. return memUsed;
  3157. #elif defined(__APPLE__)
  3158. SystemInformation::LongLong memUsed=0;
  3159. pid_t pid=getpid();
  3160. kwsys_ios::ostringstream oss;
  3161. oss << "ps -o rss= -p " << pid;
  3162. FILE *file=popen(oss.str().c_str(),"r");
  3163. if (file==0)
  3164. {
  3165. return -1;
  3166. }
  3167. oss.str("");
  3168. while (!feof(file) && !ferror(file))
  3169. {
  3170. char buf[256]={'\0'};
  3171. errno=0;
  3172. size_t nRead=fread(buf,1,256,file);
  3173. if (ferror(file) && (errno==EINTR))
  3174. {
  3175. clearerr(file);
  3176. }
  3177. if (nRead) oss << buf;
  3178. }
  3179. int ierr=ferror(file);
  3180. pclose(file);
  3181. if (ierr)
  3182. {
  3183. return -2;
  3184. }
  3185. kwsys_ios::istringstream iss(oss.str());
  3186. iss >> memUsed;
  3187. return memUsed;
  3188. #else
  3189. return 0;
  3190. #endif
  3191. }
  3192. /**
  3193. Get the process id of the running process.
  3194. */
  3195. SystemInformation::LongLong
  3196. SystemInformationImplementation::GetProcessId()
  3197. {
  3198. #if defined(_WIN32)
  3199. return GetCurrentProcessId();
  3200. #elif defined(__linux) || defined(__APPLE__)
  3201. return getpid();
  3202. #else
  3203. return -1;
  3204. #endif
  3205. }
  3206. /**
  3207. return current program stack in a string
  3208. demangle cxx symbols if possible.
  3209. */
  3210. kwsys_stl::string SystemInformationImplementation::GetProgramStack(
  3211. int firstFrame,
  3212. int wholePath)
  3213. {
  3214. kwsys_stl::string programStack = ""
  3215. #if !defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
  3216. "WARNING: The stack could not be examined "
  3217. "because backtrace is not supported.\n"
  3218. #elif !defined(KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD)
  3219. "WARNING: The stack trace will not use advanced "
  3220. "capabilities because this is a release build.\n"
  3221. #else
  3222. # if !defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
  3223. "WARNING: Function names will not be demangled because "
  3224. "dladdr is not available.\n"
  3225. # endif
  3226. # if !defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
  3227. "WARNING: Function names will not be demangled "
  3228. "because cxxabi is not available.\n"
  3229. # endif
  3230. #endif
  3231. ;
  3232. kwsys_ios::ostringstream oss;
  3233. #if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
  3234. void *stackSymbols[256];
  3235. int nFrames=backtrace(stackSymbols,256);
  3236. for (int i=firstFrame; i<nFrames; ++i)
  3237. {
  3238. SymbolProperties symProps;
  3239. symProps.SetReportPath(wholePath);
  3240. symProps.Initialize(stackSymbols[i]);
  3241. oss << symProps << kwsys_ios::endl;
  3242. }
  3243. #else
  3244. (void)firstFrame;
  3245. (void)wholePath;
  3246. #endif
  3247. programStack += oss.str();
  3248. return programStack;
  3249. }
  3250. /**
  3251. when set print stack trace in response to common signals.
  3252. */
  3253. void SystemInformationImplementation::SetStackTraceOnError(int enable)
  3254. {
  3255. #if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
  3256. static int saOrigValid=0;
  3257. static struct sigaction saABRTOrig;
  3258. static struct sigaction saSEGVOrig;
  3259. static struct sigaction saTERMOrig;
  3260. static struct sigaction saINTOrig;
  3261. static struct sigaction saILLOrig;
  3262. static struct sigaction saBUSOrig;
  3263. static struct sigaction saFPEOrig;
  3264. if (enable && !saOrigValid)
  3265. {
  3266. // save the current actions
  3267. sigaction(SIGABRT,0,&saABRTOrig);
  3268. sigaction(SIGSEGV,0,&saSEGVOrig);
  3269. sigaction(SIGTERM,0,&saTERMOrig);
  3270. sigaction(SIGINT,0,&saINTOrig);
  3271. sigaction(SIGILL,0,&saILLOrig);
  3272. sigaction(SIGBUS,0,&saBUSOrig);
  3273. sigaction(SIGFPE,0,&saFPEOrig);
  3274. // enable read, disable write
  3275. saOrigValid=1;
  3276. // install ours
  3277. struct sigaction sa;
  3278. sa.sa_sigaction=(SigAction)StacktraceSignalHandler;
  3279. sa.sa_flags=SA_SIGINFO|SA_RESETHAND;
  3280. # ifdef SA_RESTART
  3281. sa.sa_flags|=SA_RESTART;
  3282. # endif
  3283. sigemptyset(&sa.sa_mask);
  3284. sigaction(SIGABRT,&sa,0);
  3285. sigaction(SIGSEGV,&sa,0);
  3286. sigaction(SIGTERM,&sa,0);
  3287. sigaction(SIGINT,&sa,0);
  3288. sigaction(SIGILL,&sa,0);
  3289. sigaction(SIGBUS,&sa,0);
  3290. sigaction(SIGFPE,&sa,0);
  3291. }
  3292. else
  3293. if (!enable && saOrigValid)
  3294. {
  3295. // restore previous actions
  3296. sigaction(SIGABRT,&saABRTOrig,0);
  3297. sigaction(SIGSEGV,&saSEGVOrig,0);
  3298. sigaction(SIGTERM,&saTERMOrig,0);
  3299. sigaction(SIGINT,&saINTOrig,0);
  3300. sigaction(SIGILL,&saILLOrig,0);
  3301. sigaction(SIGBUS,&saBUSOrig,0);
  3302. sigaction(SIGFPE,&saFPEOrig,0);
  3303. // enable write, disable read
  3304. saOrigValid=0;
  3305. }
  3306. #else
  3307. // avoid warning C4100
  3308. (void)enable;
  3309. #endif
  3310. }
  3311. bool SystemInformationImplementation::QueryWindowsMemory()
  3312. {
  3313. #if defined(_WIN32)
  3314. # if defined(_MSC_VER) && _MSC_VER < 1300
  3315. MEMORYSTATUS ms;
  3316. unsigned long tv, tp, av, ap;
  3317. ms.dwLength = sizeof(ms);
  3318. GlobalMemoryStatus(&ms);
  3319. # define MEM_VAL(value) dw##value
  3320. # else
  3321. MEMORYSTATUSEX ms;
  3322. DWORDLONG tv, tp, av, ap;
  3323. ms.dwLength = sizeof(ms);
  3324. if (0 == GlobalMemoryStatusEx(&ms))
  3325. {
  3326. return 0;
  3327. }
  3328. # define MEM_VAL(value) ull##value
  3329. # endif
  3330. tv = ms.MEM_VAL(TotalPageFile);
  3331. tp = ms.MEM_VAL(TotalPhys);
  3332. av = ms.MEM_VAL(AvailPageFile);
  3333. ap = ms.MEM_VAL(AvailPhys);
  3334. this->TotalVirtualMemory = tv>>10>>10;
  3335. this->TotalPhysicalMemory = tp>>10>>10;
  3336. this->AvailableVirtualMemory = av>>10>>10;
  3337. this->AvailablePhysicalMemory = ap>>10>>10;
  3338. return true;
  3339. #else
  3340. return false;
  3341. #endif
  3342. }
  3343. bool SystemInformationImplementation::QueryLinuxMemory()
  3344. {
  3345. #if defined(__linux)
  3346. unsigned long tv=0;
  3347. unsigned long tp=0;
  3348. unsigned long av=0;
  3349. unsigned long ap=0;
  3350. char buffer[1024]; // for reading lines
  3351. int linuxMajor = 0;
  3352. int linuxMinor = 0;
  3353. // Find the Linux kernel version first
  3354. struct utsname unameInfo;
  3355. int errorFlag = uname(&unameInfo);
  3356. if( errorFlag!=0 )
  3357. {
  3358. kwsys_ios::cout << "Problem calling uname(): " << strerror(errno) << kwsys_ios::endl;
  3359. return false;
  3360. }
  3361. if( strlen(unameInfo.release)>=3 )
  3362. {
  3363. // release looks like "2.6.3-15mdk-i686-up-4GB"
  3364. char majorChar=unameInfo.release[0];
  3365. char minorChar=unameInfo.release[2];
  3366. if( isdigit(majorChar) )
  3367. {
  3368. linuxMajor=majorChar-'0';
  3369. }
  3370. if( isdigit(minorChar) )
  3371. {
  3372. linuxMinor=minorChar-'0';
  3373. }
  3374. }
  3375. FILE *fd = fopen("/proc/meminfo", "r" );
  3376. if ( !fd )
  3377. {
  3378. kwsys_ios::cout << "Problem opening /proc/meminfo" << kwsys_ios::endl;
  3379. return false;
  3380. }
  3381. if( linuxMajor>=3 || ( (linuxMajor>=2) && (linuxMinor>=6) ) )
  3382. {
  3383. // new /proc/meminfo format since kernel 2.6.x
  3384. // Rigorously, this test should check from the developping version 2.5.x
  3385. // that introduced the new format...
  3386. enum { mMemTotal, mMemFree, mBuffers, mCached, mSwapTotal, mSwapFree };
  3387. const char* format[6] =
  3388. { "MemTotal:%lu kB", "MemFree:%lu kB", "Buffers:%lu kB",
  3389. "Cached:%lu kB", "SwapTotal:%lu kB", "SwapFree:%lu kB" };
  3390. bool have[6] = { false, false, false, false, false, false };
  3391. unsigned long value[6];
  3392. int count = 0;
  3393. while(fgets(buffer, static_cast<int>(sizeof(buffer)), fd))
  3394. {
  3395. for(int i=0; i < 6; ++i)
  3396. {
  3397. if(!have[i] && sscanf(buffer, format[i], &value[i]) == 1)
  3398. {
  3399. have[i] = true;
  3400. ++count;
  3401. }
  3402. }
  3403. }
  3404. if(count == 6)
  3405. {
  3406. this->TotalPhysicalMemory = value[mMemTotal] / 1024;
  3407. this->AvailablePhysicalMemory =
  3408. (value[mMemFree] + value[mBuffers] + value[mCached]) / 1024;
  3409. this->TotalVirtualMemory = value[mSwapTotal] / 1024;
  3410. this->AvailableVirtualMemory = value[mSwapFree] / 1024;
  3411. }
  3412. else
  3413. {
  3414. kwsys_ios::cout << "Problem parsing /proc/meminfo" << kwsys_ios::endl;
  3415. fclose(fd);
  3416. return false;
  3417. }
  3418. }
  3419. else
  3420. {
  3421. // /proc/meminfo format for kernel older than 2.6.x
  3422. unsigned long temp;
  3423. unsigned long cachedMem;
  3424. unsigned long buffersMem;
  3425. // Skip "total: used:..."
  3426. char *r=fgets(buffer, static_cast<int>(sizeof(buffer)), fd);
  3427. int status=0;
  3428. if(r==buffer)
  3429. {
  3430. status+=fscanf(fd, "Mem: %lu %lu %lu %lu %lu %lu\n",
  3431. &tp, &temp, &ap, &temp, &buffersMem, &cachedMem);
  3432. }
  3433. if(status==6)
  3434. {
  3435. status+=fscanf(fd, "Swap: %lu %lu %lu\n", &tv, &temp, &av);
  3436. }
  3437. if(status==9)
  3438. {
  3439. this->TotalVirtualMemory = tv>>10>>10;
  3440. this->TotalPhysicalMemory = tp>>10>>10;
  3441. this->AvailableVirtualMemory = av>>10>>10;
  3442. this->AvailablePhysicalMemory = (ap+buffersMem+cachedMem)>>10>>10;
  3443. }
  3444. else
  3445. {
  3446. kwsys_ios::cout << "Problem parsing /proc/meminfo" << kwsys_ios::endl;
  3447. fclose(fd);
  3448. return false;
  3449. }
  3450. }
  3451. fclose( fd );
  3452. return true;
  3453. #else
  3454. return false;
  3455. #endif
  3456. }
  3457. bool SystemInformationImplementation::QueryCygwinMemory()
  3458. {
  3459. #ifdef __CYGWIN__
  3460. // _SC_PAGE_SIZE does return the mmap() granularity on Cygwin,
  3461. // see http://cygwin.com/ml/cygwin/2006-06/msg00350.html
  3462. // Therefore just use 4096 as the page size of Windows.
  3463. long m = sysconf(_SC_PHYS_PAGES);
  3464. if (m < 0)
  3465. {
  3466. return false;
  3467. }
  3468. this->TotalPhysicalMemory = m >> 8;
  3469. return true;
  3470. #else
  3471. return false;
  3472. #endif
  3473. }
  3474. bool SystemInformationImplementation::QueryAIXMemory()
  3475. {
  3476. #if defined(_AIX) && defined(_SC_AIX_REALMEM)
  3477. long c = sysconf(_SC_AIX_REALMEM);
  3478. if (c <= 0)
  3479. {
  3480. return false;
  3481. }
  3482. this->TotalPhysicalMemory = c / 1024;
  3483. return true;
  3484. #else
  3485. return false;
  3486. #endif
  3487. }
  3488. bool SystemInformationImplementation::QueryMemoryBySysconf()
  3489. {
  3490. #if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
  3491. // Assume the mmap() granularity as returned by _SC_PAGESIZE is also
  3492. // the system page size. The only known system where this isn't true
  3493. // is Cygwin.
  3494. long p = sysconf(_SC_PHYS_PAGES);
  3495. long m = sysconf(_SC_PAGESIZE);
  3496. if (p < 0 || m < 0)
  3497. {
  3498. return false;
  3499. }
  3500. // assume pagesize is a power of 2 and smaller 1 MiB
  3501. size_t pagediv = (1024 * 1024 / m);
  3502. this->TotalPhysicalMemory = p;
  3503. this->TotalPhysicalMemory /= pagediv;
  3504. #if defined(_SC_AVPHYS_PAGES)
  3505. p = sysconf(_SC_AVPHYS_PAGES);
  3506. if (p < 0)
  3507. {
  3508. return false;
  3509. }
  3510. this->AvailablePhysicalMemory = p;
  3511. this->AvailablePhysicalMemory /= pagediv;
  3512. #endif
  3513. return true;
  3514. #else
  3515. return false;
  3516. #endif
  3517. }
  3518. /** Query for the memory status */
  3519. bool SystemInformationImplementation::QueryMemory()
  3520. {
  3521. return this->QueryMemoryBySysconf();
  3522. }
  3523. /** */
  3524. size_t SystemInformationImplementation::GetTotalVirtualMemory()
  3525. {
  3526. return this->TotalVirtualMemory;
  3527. }
  3528. /** */
  3529. size_t SystemInformationImplementation::GetAvailableVirtualMemory()
  3530. {
  3531. return this->AvailableVirtualMemory;
  3532. }
  3533. size_t SystemInformationImplementation::GetTotalPhysicalMemory()
  3534. {
  3535. return this->TotalPhysicalMemory;
  3536. }
  3537. /** */
  3538. size_t SystemInformationImplementation::GetAvailablePhysicalMemory()
  3539. {
  3540. return this->AvailablePhysicalMemory;
  3541. }
  3542. /** Get Cycle differences */
  3543. SystemInformation::LongLong
  3544. SystemInformationImplementation::GetCyclesDifference (DELAY_FUNC DelayFunction,
  3545. unsigned int uiParameter)
  3546. {
  3547. #if defined(_MSC_VER) && (_MSC_VER >= 1400)
  3548. unsigned __int64 stamp1, stamp2;
  3549. stamp1 = __rdtsc();
  3550. DelayFunction(uiParameter);
  3551. stamp2 = __rdtsc();
  3552. return stamp2 - stamp1;
  3553. #elif USE_ASM_INSTRUCTIONS
  3554. unsigned int edx1, eax1;
  3555. unsigned int edx2, eax2;
  3556. // Calculate the frequency of the CPU instructions.
  3557. __try {
  3558. _asm {
  3559. push uiParameter ; push parameter param
  3560. mov ebx, DelayFunction ; store func in ebx
  3561. RDTSC_INSTRUCTION
  3562. mov esi, eax ; esi = eax
  3563. mov edi, edx ; edi = edx
  3564. call ebx ; call the delay functions
  3565. RDTSC_INSTRUCTION
  3566. pop ebx
  3567. mov edx2, edx ; edx2 = edx
  3568. mov eax2, eax ; eax2 = eax
  3569. mov edx1, edi ; edx2 = edi
  3570. mov eax1, esi ; eax2 = esi
  3571. }
  3572. }
  3573. __except(1)
  3574. {
  3575. return -1;
  3576. }
  3577. return ((((__int64) edx2 << 32) + eax2) - (((__int64) edx1 << 32) + eax1));
  3578. #else
  3579. (void)DelayFunction;
  3580. (void)uiParameter;
  3581. return -1;
  3582. #endif
  3583. }
  3584. /** Compute the delay overhead */
  3585. void SystemInformationImplementation::DelayOverhead(unsigned int uiMS)
  3586. {
  3587. #if defined(_WIN32)
  3588. LARGE_INTEGER Frequency, StartCounter, EndCounter;
  3589. __int64 x;
  3590. // Get the frequency of the high performance counter.
  3591. if(!QueryPerformanceFrequency (&Frequency))
  3592. {
  3593. return;
  3594. }
  3595. x = Frequency.QuadPart / 1000 * uiMS;
  3596. // Get the starting position of the counter.
  3597. QueryPerformanceCounter (&StartCounter);
  3598. do {
  3599. // Get the ending position of the counter.
  3600. QueryPerformanceCounter (&EndCounter);
  3601. } while (EndCounter.QuadPart - StartCounter.QuadPart == x);
  3602. #endif
  3603. (void)uiMS;
  3604. }
  3605. /** Return the number of logical CPU per physical CPUs Works only for windows */
  3606. unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void)
  3607. {
  3608. #ifdef __APPLE__
  3609. size_t len = 4;
  3610. int cores_per_package = 0;
  3611. int err = sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, &len, NULL, 0);
  3612. if (err != 0)
  3613. {
  3614. return 1; // That name was not found, default to 1
  3615. }
  3616. return static_cast<unsigned char>(cores_per_package);
  3617. #else
  3618. int Regs[4] = { 0, 0, 0, 0 };
  3619. #if USE_CPUID
  3620. if (!this->IsHyperThreadingSupported())
  3621. {
  3622. return static_cast<unsigned char>(1); // HT not supported
  3623. }
  3624. call_cpuid(1, Regs);
  3625. #endif
  3626. return static_cast<unsigned char> ((Regs[1] & NUM_LOGICAL_BITS) >> 16);
  3627. #endif
  3628. }
  3629. /** Works only for windows */
  3630. bool SystemInformationImplementation::IsHyperThreadingSupported()
  3631. {
  3632. if (this->Features.ExtendedFeatures.SupportsHyperthreading)
  3633. {
  3634. return true;
  3635. }
  3636. #if USE_CPUID
  3637. int Regs[4] = { 0, 0, 0, 0 },
  3638. VendorId[4] = { 0, 0, 0, 0 };
  3639. // Get vendor id string
  3640. if (!call_cpuid(0, VendorId))
  3641. {
  3642. return false;
  3643. }
  3644. // eax contains family processor type
  3645. // edx has info about the availability of hyper-Threading
  3646. if (!call_cpuid(1, Regs))
  3647. {
  3648. return false;
  3649. }
  3650. if (((Regs[0] & FAMILY_ID) == PENTIUM4_ID) || (Regs[0] & EXT_FAMILY_ID))
  3651. {
  3652. if (VendorId[1] == 0x756e6547) // 'uneG'
  3653. {
  3654. if (VendorId[3] == 0x49656e69) // 'Ieni'
  3655. {
  3656. if (VendorId[2] == 0x6c65746e) // 'letn'
  3657. {
  3658. // Genuine Intel with hyper-Threading technology
  3659. this->Features.ExtendedFeatures.SupportsHyperthreading = ((Regs[3] & HT_BIT) != 0);
  3660. return this->Features.ExtendedFeatures.SupportsHyperthreading;
  3661. }
  3662. }
  3663. }
  3664. }
  3665. #endif
  3666. return 0; // Not genuine Intel processor
  3667. }
  3668. /** Return the APIC Id. Works only for windows. */
  3669. unsigned char SystemInformationImplementation::GetAPICId()
  3670. {
  3671. int Regs[4] = { 0, 0, 0, 0 };
  3672. #if USE_CPUID
  3673. if (!this->IsHyperThreadingSupported())
  3674. {
  3675. return static_cast<unsigned char>(-1); // HT not supported
  3676. } // Logical processor = 1
  3677. call_cpuid(1, Regs);
  3678. #endif
  3679. return static_cast<unsigned char>((Regs[1] & INITIAL_APIC_ID_BITS) >> 24);
  3680. }
  3681. /** Count the number of CPUs. Works only on windows. */
  3682. int SystemInformationImplementation::CPUCount()
  3683. {
  3684. #if defined(_WIN32)
  3685. unsigned char StatusFlag = 0;
  3686. SYSTEM_INFO info;
  3687. this->NumberOfPhysicalCPU = 0;
  3688. this->NumberOfLogicalCPU = 0;
  3689. info.dwNumberOfProcessors = 0;
  3690. GetSystemInfo (&info);
  3691. // Number of physical processors in a non-Intel system
  3692. // or in a 32-bit Intel system with Hyper-Threading technology disabled
  3693. this->NumberOfPhysicalCPU = (unsigned char) info.dwNumberOfProcessors;
  3694. if (this->IsHyperThreadingSupported())
  3695. {
  3696. unsigned char HT_Enabled = 0;
  3697. this->NumberOfLogicalCPU = this->LogicalCPUPerPhysicalCPU();
  3698. if (this->NumberOfLogicalCPU >= 1) // >1 Doesn't mean HT is enabled in the BIOS
  3699. {
  3700. HANDLE hCurrentProcessHandle;
  3701. #ifndef _WIN64
  3702. # define DWORD_PTR DWORD
  3703. #endif
  3704. DWORD_PTR dwProcessAffinity;
  3705. DWORD_PTR dwSystemAffinity;
  3706. DWORD dwAffinityMask;
  3707. // Calculate the appropriate shifts and mask based on the
  3708. // number of logical processors.
  3709. unsigned int i = 1;
  3710. unsigned char PHY_ID_MASK = 0xFF;
  3711. //unsigned char PHY_ID_SHIFT = 0;
  3712. while (i < this->NumberOfLogicalCPU)
  3713. {
  3714. i *= 2;
  3715. PHY_ID_MASK <<= 1;
  3716. // PHY_ID_SHIFT++;
  3717. }
  3718. hCurrentProcessHandle = GetCurrentProcess();
  3719. GetProcessAffinityMask(hCurrentProcessHandle, &dwProcessAffinity,
  3720. &dwSystemAffinity);
  3721. // Check if available process affinity mask is equal to the
  3722. // available system affinity mask
  3723. if (dwProcessAffinity != dwSystemAffinity)
  3724. {
  3725. StatusFlag = HT_CANNOT_DETECT;
  3726. this->NumberOfPhysicalCPU = (unsigned char)-1;
  3727. return StatusFlag;
  3728. }
  3729. dwAffinityMask = 1;
  3730. while (dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity)
  3731. {
  3732. // Check if this CPU is available
  3733. if (dwAffinityMask & dwProcessAffinity)
  3734. {
  3735. if (SetProcessAffinityMask(hCurrentProcessHandle,
  3736. dwAffinityMask))
  3737. {
  3738. unsigned char APIC_ID, LOG_ID;
  3739. Sleep(0); // Give OS time to switch CPU
  3740. APIC_ID = GetAPICId();
  3741. LOG_ID = APIC_ID & ~PHY_ID_MASK;
  3742. if (LOG_ID != 0)
  3743. {
  3744. HT_Enabled = 1;
  3745. }
  3746. }
  3747. }
  3748. dwAffinityMask = dwAffinityMask << 1;
  3749. }
  3750. // Reset the processor affinity
  3751. SetProcessAffinityMask(hCurrentProcessHandle, dwProcessAffinity);
  3752. if (this->NumberOfLogicalCPU == 1) // Normal P4 : HT is disabled in hardware
  3753. {
  3754. StatusFlag = HT_DISABLED;
  3755. }
  3756. else
  3757. {
  3758. if (HT_Enabled)
  3759. {
  3760. // Total physical processors in a Hyper-Threading enabled system.
  3761. this->NumberOfPhysicalCPU /= (this->NumberOfLogicalCPU);
  3762. StatusFlag = HT_ENABLED;
  3763. }
  3764. else
  3765. {
  3766. StatusFlag = HT_SUPPORTED_NOT_ENABLED;
  3767. }
  3768. }
  3769. }
  3770. }
  3771. else
  3772. {
  3773. // Processors do not have Hyper-Threading technology
  3774. StatusFlag = HT_NOT_CAPABLE;
  3775. this->NumberOfLogicalCPU = 1;
  3776. }
  3777. return StatusFlag;
  3778. #else
  3779. return 0;
  3780. #endif
  3781. }
  3782. /** Return the number of logical CPUs on the system */
  3783. unsigned int SystemInformationImplementation::GetNumberOfLogicalCPU()
  3784. {
  3785. return this->NumberOfLogicalCPU;
  3786. }
  3787. /** Return the number of physical CPUs on the system */
  3788. unsigned int SystemInformationImplementation::GetNumberOfPhysicalCPU()
  3789. {
  3790. return this->NumberOfPhysicalCPU;
  3791. }
  3792. /** For Mac use sysctlbyname calls to find system info */
  3793. bool SystemInformationImplementation::ParseSysCtl()
  3794. {
  3795. #if defined(__APPLE__)
  3796. char retBuf[128];
  3797. int err = 0;
  3798. uint64_t value = 0;
  3799. size_t len = sizeof(value);
  3800. sysctlbyname("hw.memsize", &value, &len, NULL, 0);
  3801. this->TotalPhysicalMemory = static_cast< size_t >( value/1048576 );
  3802. // Parse values for Mac
  3803. this->AvailablePhysicalMemory = 0;
  3804. vm_statistics_data_t vmstat;
  3805. mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
  3806. if ( host_statistics(mach_host_self(), HOST_VM_INFO,
  3807. (host_info_t) &vmstat, &count) == KERN_SUCCESS )
  3808. {
  3809. len = sizeof(value);
  3810. err = sysctlbyname("hw.pagesize", &value, &len, NULL, 0);
  3811. int64_t available_memory = vmstat.free_count * value;
  3812. this->AvailablePhysicalMemory = static_cast< size_t >( available_memory / 1048576 );
  3813. }
  3814. #ifdef VM_SWAPUSAGE
  3815. // Virtual memory.
  3816. int mib[2] = { CTL_VM, VM_SWAPUSAGE };
  3817. size_t miblen = sizeof(mib) / sizeof(mib[0]);
  3818. struct xsw_usage swap;
  3819. len = sizeof(swap);
  3820. err = sysctl(mib, miblen, &swap, &len, NULL, 0);
  3821. if (err == 0)
  3822. {
  3823. this->AvailableVirtualMemory = static_cast< size_t >( swap.xsu_avail/1048576 );
  3824. this->TotalVirtualMemory = static_cast< size_t >( swap.xsu_total/1048576 );
  3825. }
  3826. #else
  3827. this->AvailableVirtualMemory = 0;
  3828. this->TotalVirtualMemory = 0;
  3829. #endif
  3830. // CPU Info
  3831. len = sizeof(this->NumberOfPhysicalCPU);
  3832. sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len, NULL, 0);
  3833. len = sizeof(this->NumberOfLogicalCPU);
  3834. sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, NULL, 0);
  3835. this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical =
  3836. this->LogicalCPUPerPhysicalCPU();
  3837. len = sizeof(value);
  3838. sysctlbyname("hw.cpufrequency", &value, &len, NULL, 0);
  3839. this->CPUSpeedInMHz = static_cast< float >( value )/ 1000000;
  3840. // Chip family
  3841. len = sizeof(this->ChipID.Family);
  3842. //Seems only the intel chips will have this name so if this fails it is
  3843. //probably a PPC machine
  3844. err = sysctlbyname("machdep.cpu.family",
  3845. &this->ChipID.Family, &len, NULL, 0);
  3846. if (err != 0) // Go back to names we know but are less descriptive
  3847. {
  3848. this->ChipID.Family = 0;
  3849. ::memset(retBuf, 0, 128);
  3850. len = 32;
  3851. err = sysctlbyname("hw.machine", &retBuf, &len, NULL, 0);
  3852. kwsys_stl::string machineBuf(retBuf);
  3853. if (machineBuf.find_first_of("Power") != kwsys_stl::string::npos)
  3854. {
  3855. this->ChipID.Vendor = "IBM";
  3856. len = sizeof(this->ChipID.Family);
  3857. err = sysctlbyname("hw.cputype", &this->ChipID.Family, &len, NULL, 0);
  3858. len = sizeof(this->ChipID.Model);
  3859. err = sysctlbyname("hw.cpusubtype", &this->ChipID.Model, &len, NULL, 0);
  3860. this->FindManufacturer();
  3861. }
  3862. }
  3863. else // Should be an Intel Chip.
  3864. {
  3865. len = sizeof(this->ChipID.Family);
  3866. err =
  3867. sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len, NULL, 0);
  3868. ::memset(retBuf, 0, 128);
  3869. len = 128;
  3870. err = sysctlbyname("machdep.cpu.vendor", retBuf, &len, NULL, 0);
  3871. // Chip Vendor
  3872. this->ChipID.Vendor = retBuf;
  3873. this->FindManufacturer();
  3874. // Chip Model
  3875. len = sizeof(value);
  3876. err = sysctlbyname("machdep.cpu.model", &value, &len, NULL, 0);
  3877. this->ChipID.Model = static_cast< int >( value );
  3878. // Chip Stepping
  3879. len = sizeof(value);
  3880. value = 0;
  3881. err = sysctlbyname("machdep.cpu.stepping", &value, &len, NULL, 0);
  3882. if (!err)
  3883. {
  3884. this->ChipID.Revision = static_cast< int >( value );
  3885. }
  3886. // feature string
  3887. char *buf = 0;
  3888. size_t allocSize = 128;
  3889. err = 0;
  3890. len = 0;
  3891. // sysctlbyname() will return with err==0 && len==0 if the buffer is too small
  3892. while (err == 0 && len == 0)
  3893. {
  3894. delete[] buf;
  3895. allocSize *= 2;
  3896. buf = new char[allocSize];
  3897. if (!buf)
  3898. {
  3899. break;
  3900. }
  3901. buf[0] = ' ';
  3902. len = allocSize - 2; // keep space for leading and trailing space
  3903. err = sysctlbyname("machdep.cpu.features", buf + 1, &len, NULL, 0);
  3904. }
  3905. if (!err && buf && len)
  3906. {
  3907. // now we can match every flags as space + flag + space
  3908. buf[len + 1] = ' ';
  3909. kwsys_stl::string cpuflags(buf, len + 2);
  3910. if ((cpuflags.find(" FPU ")!=kwsys_stl::string::npos))
  3911. {
  3912. this->Features.HasFPU = true;
  3913. }
  3914. if ((cpuflags.find(" TSC ")!=kwsys_stl::string::npos))
  3915. {
  3916. this->Features.HasTSC = true;
  3917. }
  3918. if ((cpuflags.find(" MMX ")!=kwsys_stl::string::npos))
  3919. {
  3920. this->Features.HasMMX = true;
  3921. }
  3922. if ((cpuflags.find(" SSE ")!=kwsys_stl::string::npos))
  3923. {
  3924. this->Features.HasSSE = true;
  3925. }
  3926. if ((cpuflags.find(" SSE2 ")!=kwsys_stl::string::npos))
  3927. {
  3928. this->Features.HasSSE2 = true;
  3929. }
  3930. if ((cpuflags.find(" APIC ")!=kwsys_stl::string::npos))
  3931. {
  3932. this->Features.HasAPIC = true;
  3933. }
  3934. if ((cpuflags.find(" CMOV ")!=kwsys_stl::string::npos))
  3935. {
  3936. this->Features.HasCMOV = true;
  3937. }
  3938. if ((cpuflags.find(" MTRR ")!=kwsys_stl::string::npos))
  3939. {
  3940. this->Features.HasMTRR = true;
  3941. }
  3942. if ((cpuflags.find(" ACPI ")!=kwsys_stl::string::npos))
  3943. {
  3944. this->Features.HasACPI = true;
  3945. }
  3946. }
  3947. delete[] buf;
  3948. }
  3949. // brand string
  3950. ::memset(retBuf, 0, sizeof(retBuf));
  3951. len = sizeof(retBuf);
  3952. err = sysctlbyname("machdep.cpu.brand_string", retBuf, &len, NULL, 0);
  3953. if (!err)
  3954. {
  3955. this->ChipID.ProcessorName = retBuf;
  3956. this->ChipID.ModelName = retBuf;
  3957. }
  3958. // Cache size
  3959. len = sizeof(value);
  3960. err = sysctlbyname("hw.l1icachesize", &value, &len, NULL, 0);
  3961. this->Features.L1CacheSize = static_cast< int >( value );
  3962. len = sizeof(value);
  3963. err = sysctlbyname("hw.l2cachesize", &value, &len, NULL, 0);
  3964. this->Features.L2CacheSize = static_cast< int >( value );
  3965. return true;
  3966. #else
  3967. return false;
  3968. #endif
  3969. }
  3970. /** Extract a value from sysctl command */
  3971. kwsys_stl::string SystemInformationImplementation::ExtractValueFromSysCtl(const char* word)
  3972. {
  3973. size_t pos = this->SysCtlBuffer.find(word);
  3974. if(pos != this->SysCtlBuffer.npos)
  3975. {
  3976. pos = this->SysCtlBuffer.find(": ",pos);
  3977. size_t pos2 = this->SysCtlBuffer.find("\n",pos);
  3978. if(pos!=this->SysCtlBuffer.npos && pos2!=this->SysCtlBuffer.npos)
  3979. {
  3980. return this->SysCtlBuffer.substr(pos+2,pos2-pos-2);
  3981. }
  3982. }
  3983. return "";
  3984. }
  3985. /** Run a given process */
  3986. kwsys_stl::string SystemInformationImplementation::RunProcess(kwsys_stl::vector<const char*> args)
  3987. {
  3988. kwsys_stl::string buffer = "";
  3989. // Run the application
  3990. kwsysProcess* gp = kwsysProcess_New();
  3991. kwsysProcess_SetCommand(gp, &*args.begin());
  3992. kwsysProcess_SetOption(gp,kwsysProcess_Option_HideWindow,1);
  3993. kwsysProcess_Execute(gp);
  3994. char* data = NULL;
  3995. int length;
  3996. double timeout = 255;
  3997. int pipe; // pipe id as returned by kwsysProcess_WaitForData()
  3998. while( ( pipe = kwsysProcess_WaitForData(gp,&data,&length,&timeout),
  3999. (pipe == kwsysProcess_Pipe_STDOUT || pipe == kwsysProcess_Pipe_STDERR) ) ) // wait for 1s
  4000. {
  4001. buffer.append(data, length);
  4002. }
  4003. kwsysProcess_WaitForExit(gp, 0);
  4004. int result = 0;
  4005. switch(kwsysProcess_GetState(gp))
  4006. {
  4007. case kwsysProcess_State_Exited:
  4008. {
  4009. result = kwsysProcess_GetExitValue(gp);
  4010. } break;
  4011. case kwsysProcess_State_Error:
  4012. {
  4013. kwsys_ios::cerr << "Error: Could not run " << args[0] << ":\n";
  4014. kwsys_ios::cerr << kwsysProcess_GetErrorString(gp) << "\n";
  4015. } break;
  4016. case kwsysProcess_State_Exception:
  4017. {
  4018. kwsys_ios::cerr << "Error: " << args[0]
  4019. << " terminated with an exception: "
  4020. << kwsysProcess_GetExceptionString(gp) << "\n";
  4021. } break;
  4022. case kwsysProcess_State_Starting:
  4023. case kwsysProcess_State_Executing:
  4024. case kwsysProcess_State_Expired:
  4025. case kwsysProcess_State_Killed:
  4026. {
  4027. // Should not get here.
  4028. kwsys_ios::cerr << "Unexpected ending state after running " << args[0]
  4029. << kwsys_ios::endl;
  4030. } break;
  4031. }
  4032. kwsysProcess_Delete(gp);
  4033. if(result)
  4034. {
  4035. kwsys_ios::cerr << "Error " << args[0] << " returned :" << result << "\n";
  4036. }
  4037. return buffer;
  4038. }
  4039. kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const char* arguments)
  4040. {
  4041. kwsys_stl::vector<const char*> args;
  4042. args.clear();
  4043. args.push_back("kstat");
  4044. args.push_back("-p");
  4045. kwsys_stl::string command = arguments;
  4046. size_t start = command.npos;
  4047. size_t pos = command.find(' ',0);
  4048. while(pos!=command.npos)
  4049. {
  4050. bool inQuotes = false;
  4051. // Check if we are between quotes
  4052. size_t b0 = command.find('"',0);
  4053. size_t b1 = command.find('"',b0+1);
  4054. while(b0 != command.npos && b1 != command.npos && b1>b0)
  4055. {
  4056. if(pos>b0 && pos<b1)
  4057. {
  4058. inQuotes = true;
  4059. break;
  4060. }
  4061. b0 = command.find('"',b1+1);
  4062. b1 = command.find('"',b0+1);
  4063. }
  4064. if(!inQuotes)
  4065. {
  4066. kwsys_stl::string arg = command.substr(start+1,pos-start-1);
  4067. // Remove the quotes if any
  4068. size_t quotes = arg.find('"');
  4069. while(quotes != arg.npos)
  4070. {
  4071. arg.erase(quotes,1);
  4072. quotes = arg.find('"');
  4073. }
  4074. args.push_back(arg.c_str());
  4075. start = pos;
  4076. }
  4077. pos = command.find(' ',pos+1);
  4078. }
  4079. kwsys_stl::string lastArg = command.substr(start+1,command.size()-start-1);
  4080. args.push_back(lastArg.c_str());
  4081. args.push_back(0);
  4082. kwsys_stl::string buffer = this->RunProcess(args);
  4083. kwsys_stl::string value = "";
  4084. for(size_t i=buffer.size()-1;i>0;i--)
  4085. {
  4086. if(buffer[i] == ' ' || buffer[i] == '\t')
  4087. {
  4088. break;
  4089. }
  4090. if(buffer[i] != '\n' && buffer[i] != '\r')
  4091. {
  4092. kwsys_stl::string val = value;
  4093. value = buffer[i];
  4094. value += val;
  4095. }
  4096. }
  4097. return value;
  4098. }
  4099. /** Querying for system information from Solaris */
  4100. bool SystemInformationImplementation::QuerySolarisMemory()
  4101. {
  4102. #if defined (__SVR4) && defined (__sun)
  4103. // Solaris allows querying this value by sysconf, but if this is
  4104. // a 32 bit process on a 64 bit host the returned memory will be
  4105. // limited to 4GiB. So if this is a 32 bit process or if the sysconf
  4106. // method fails use the kstat interface.
  4107. #if SIZEOF_VOID_P == 8
  4108. if (this->QueryMemoryBySysconf())
  4109. {
  4110. return true;
  4111. }
  4112. #endif
  4113. char* tail;
  4114. unsigned long totalMemory =
  4115. strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail,0);
  4116. this->TotalPhysicalMemory = totalMemory/128;
  4117. return true;
  4118. #else
  4119. return false;
  4120. #endif
  4121. }
  4122. bool SystemInformationImplementation::QuerySolarisProcessor()
  4123. {
  4124. if (!this->QueryProcessorBySysconf())
  4125. {
  4126. return false;
  4127. }
  4128. // Parse values
  4129. this->CPUSpeedInMHz = static_cast<float>(atoi(this->ParseValueFromKStat("-s clock_MHz").c_str()));
  4130. // Chip family
  4131. this->ChipID.Family = 0;
  4132. // Chip Model
  4133. this->ChipID.ProcessorName = this->ParseValueFromKStat("-s cpu_type");
  4134. this->ChipID.Model = 0;
  4135. // Chip Vendor
  4136. if (this->ChipID.ProcessorName != "i386")
  4137. {
  4138. this->ChipID.Vendor = "Sun";
  4139. this->FindManufacturer();
  4140. }
  4141. return true;
  4142. }
  4143. /** Querying for system information from Haiku OS */
  4144. bool SystemInformationImplementation::QueryHaikuInfo()
  4145. {
  4146. #if defined(__HAIKU__)
  4147. // CPU count
  4148. system_info info;
  4149. get_system_info(&info);
  4150. this->NumberOfPhysicalCPU = info.cpu_count;
  4151. // CPU speed
  4152. uint32 topologyNodeCount = 0;
  4153. cpu_topology_node_info* topology = 0;
  4154. get_cpu_topology_info(0, &topologyNodeCount);
  4155. if (topologyNodeCount != 0)
  4156. topology = new cpu_topology_node_info[topologyNodeCount];
  4157. get_cpu_topology_info(topology, &topologyNodeCount);
  4158. for (uint32 i = 0; i < topologyNodeCount; i++) {
  4159. if (topology[i].type == B_TOPOLOGY_CORE) {
  4160. this->CPUSpeedInMHz = topology[i].data.core.default_frequency /
  4161. 1000000.0f;
  4162. break;
  4163. }
  4164. }
  4165. delete[] topology;
  4166. // Physical Memory
  4167. this->TotalPhysicalMemory = (info.max_pages * B_PAGE_SIZE) / (1024 * 1024) ;
  4168. this->AvailablePhysicalMemory = this->TotalPhysicalMemory -
  4169. ((info.used_pages * B_PAGE_SIZE) / (1024 * 1024));
  4170. // NOTE: get_system_info_etc is currently a private call so just set to 0
  4171. // until it becomes public
  4172. this->TotalVirtualMemory = 0;
  4173. this->AvailableVirtualMemory = 0;
  4174. // Retrieve cpuid_info union for cpu 0
  4175. cpuid_info cpu_info;
  4176. get_cpuid(&cpu_info, 0, 0);
  4177. // Chip Vendor
  4178. // Use a temporary buffer so that we can add NULL termination to the string
  4179. char vbuf[13];
  4180. strncpy(vbuf, cpu_info.eax_0.vendor_id, 12);
  4181. vbuf[12] = '\0';
  4182. this->ChipID.Vendor = vbuf;
  4183. this->FindManufacturer();
  4184. // Retrieve cpuid_info union for cpu 0 this time using a register value of 1
  4185. get_cpuid(&cpu_info, 1, 0);
  4186. this->NumberOfLogicalCPU = cpu_info.eax_1.logical_cpus;
  4187. // Chip type
  4188. this->ChipID.Type = cpu_info.eax_1.type;
  4189. // Chip family
  4190. this->ChipID.Family = cpu_info.eax_1.family;
  4191. // Chip Model
  4192. this->ChipID.Model = cpu_info.eax_1.model;
  4193. // Chip Revision
  4194. this->ChipID.Revision = cpu_info.eax_1.stepping;
  4195. // Chip Extended Family
  4196. this->ChipID.ExtendedFamily = cpu_info.eax_1.extended_family;
  4197. // Chip Extended Model
  4198. this->ChipID.ExtendedModel = cpu_info.eax_1.extended_model;
  4199. // Get ChipID.ProcessorName from other information already gathered
  4200. this->RetrieveClassicalCPUIdentity();
  4201. // Cache size
  4202. this->Features.L1CacheSize = 0;
  4203. this->Features.L2CacheSize = 0;
  4204. return true;
  4205. #else
  4206. return false;
  4207. #endif
  4208. }
  4209. bool SystemInformationImplementation::QueryQNXMemory()
  4210. {
  4211. #if defined(__QNX__)
  4212. kwsys_stl::string buffer;
  4213. kwsys_stl::vector<const char*> args;
  4214. args.clear();
  4215. args.push_back("showmem");
  4216. args.push_back("-S");
  4217. args.push_back(0);
  4218. buffer = this->RunProcess(args);
  4219. args.clear();
  4220. size_t pos = buffer.find("System RAM:");
  4221. if (pos == buffer.npos)
  4222. return false;
  4223. pos = buffer.find(":", pos);
  4224. size_t pos2 = buffer.find("M (", pos);
  4225. if (pos2 == buffer.npos)
  4226. return false;
  4227. pos++;
  4228. while (buffer[pos] == ' ')
  4229. pos++;
  4230. this->TotalPhysicalMemory = atoi(buffer.substr(pos, pos2 - pos).c_str());
  4231. return true;
  4232. #endif
  4233. return false;
  4234. }
  4235. bool SystemInformationImplementation::QueryBSDMemory()
  4236. {
  4237. #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
  4238. int ctrl[2] = { CTL_HW, HW_PHYSMEM };
  4239. #if defined(HW_PHYSMEM64)
  4240. int64_t k;
  4241. ctrl[1] = HW_PHYSMEM64;
  4242. #else
  4243. int k;
  4244. #endif
  4245. size_t sz = sizeof(k);
  4246. if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
  4247. {
  4248. return false;
  4249. }
  4250. this->TotalPhysicalMemory = k>>10>>10;
  4251. return true;
  4252. #else
  4253. return false;
  4254. #endif
  4255. }
  4256. bool SystemInformationImplementation::QueryQNXProcessor()
  4257. {
  4258. #if defined(__QNX__)
  4259. // the output on my QNX 6.4.1 looks like this:
  4260. // Processor1: 686 Pentium II Stepping 3 2175MHz FPU
  4261. kwsys_stl::string buffer;
  4262. kwsys_stl::vector<const char*> args;
  4263. args.clear();
  4264. args.push_back("pidin");
  4265. args.push_back("info");
  4266. args.push_back(0);
  4267. buffer = this->RunProcess(args);
  4268. args.clear();
  4269. size_t pos = buffer.find("Processor1:");
  4270. if (pos == buffer.npos)
  4271. return false;
  4272. size_t pos2 = buffer.find("MHz", pos);
  4273. if (pos2 == buffer.npos)
  4274. return false;
  4275. size_t pos3 = pos2;
  4276. while (buffer[pos3] != ' ')
  4277. --pos3;
  4278. this->CPUSpeedInMHz = atoi(buffer.substr(pos3 + 1, pos2 - pos3 - 1).c_str());
  4279. pos2 = buffer.find(" Stepping", pos);
  4280. if (pos2 != buffer.npos)
  4281. {
  4282. pos2 = buffer.find(" ", pos2 + 1);
  4283. if (pos2 != buffer.npos && pos2 < pos3)
  4284. {
  4285. this->ChipID.Revision = atoi(buffer.substr(pos2 + 1, pos3 - pos2).c_str());
  4286. }
  4287. }
  4288. this->NumberOfPhysicalCPU = 0;
  4289. do
  4290. {
  4291. pos = buffer.find("\nProcessor", pos + 1);
  4292. ++this->NumberOfPhysicalCPU;
  4293. } while (pos != buffer.npos);
  4294. this->NumberOfLogicalCPU = 1;
  4295. return true;
  4296. #else
  4297. return false;
  4298. #endif
  4299. }
  4300. bool SystemInformationImplementation::QueryBSDProcessor()
  4301. {
  4302. #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
  4303. int k;
  4304. size_t sz = sizeof(k);
  4305. int ctrl[2] = { CTL_HW, HW_NCPU };
  4306. if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
  4307. {
  4308. return false;
  4309. }
  4310. this->NumberOfPhysicalCPU = k;
  4311. this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
  4312. #if defined(HW_CPUSPEED)
  4313. ctrl[1] = HW_CPUSPEED;
  4314. if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
  4315. {
  4316. return false;
  4317. }
  4318. this->CPUSpeedInMHz = (float) k;
  4319. #endif
  4320. #if defined(CPU_SSE)
  4321. ctrl[0] = CTL_MACHDEP;
  4322. ctrl[1] = CPU_SSE;
  4323. if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
  4324. {
  4325. return false;
  4326. }
  4327. this->Features.HasSSE = (k > 0);
  4328. #endif
  4329. #if defined(CPU_SSE2)
  4330. ctrl[0] = CTL_MACHDEP;
  4331. ctrl[1] = CPU_SSE2;
  4332. if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
  4333. {
  4334. return false;
  4335. }
  4336. this->Features.HasSSE2 = (k > 0);
  4337. #endif
  4338. #if defined(CPU_CPUVENDOR)
  4339. ctrl[0] = CTL_MACHDEP;
  4340. ctrl[1] = CPU_CPUVENDOR;
  4341. char vbuf[25];
  4342. ::memset(vbuf, 0, sizeof(vbuf));
  4343. sz = sizeof(vbuf) - 1;
  4344. if (sysctl(ctrl, 2, vbuf, &sz, NULL, 0) != 0)
  4345. {
  4346. return false;
  4347. }
  4348. this->ChipID.Vendor = vbuf;
  4349. this->FindManufacturer();
  4350. #endif
  4351. return true;
  4352. #else
  4353. return false;
  4354. #endif
  4355. }
  4356. bool SystemInformationImplementation::QueryHPUXMemory()
  4357. {
  4358. #if defined(__hpux)
  4359. unsigned long tv=0;
  4360. unsigned long tp=0;
  4361. unsigned long av=0;
  4362. unsigned long ap=0;
  4363. struct pst_static pst;
  4364. struct pst_dynamic pdy;
  4365. unsigned long ps = 0;
  4366. if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1)
  4367. {
  4368. return false;
  4369. }
  4370. ps = pst.page_size;
  4371. tp = pst.physical_memory *ps;
  4372. tv = (pst.physical_memory + pst.pst_maxmem) * ps;
  4373. if (pstat_getdynamic(&pdy, sizeof(pdy), (size_t) 1, 0) == -1)
  4374. {
  4375. return false;
  4376. }
  4377. ap = tp - pdy.psd_rm * ps;
  4378. av = tv - pdy.psd_vm;
  4379. this->TotalVirtualMemory = tv>>10>>10;
  4380. this->TotalPhysicalMemory = tp>>10>>10;
  4381. this->AvailableVirtualMemory = av>>10>>10;
  4382. this->AvailablePhysicalMemory = ap>>10>>10;
  4383. return true;
  4384. #else
  4385. return false;
  4386. #endif
  4387. }
  4388. bool SystemInformationImplementation::QueryHPUXProcessor()
  4389. {
  4390. #if defined(__hpux)
  4391. # if defined(KWSYS_SYS_HAS_MPCTL_H)
  4392. int c = mpctl(MPC_GETNUMSPUS_SYS, 0, 0);
  4393. if (c <= 0)
  4394. {
  4395. return false;
  4396. }
  4397. this->NumberOfPhysicalCPU = c;
  4398. this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
  4399. long t = sysconf(_SC_CPU_VERSION);
  4400. if (t == -1)
  4401. {
  4402. return false;
  4403. }
  4404. switch (t)
  4405. {
  4406. case CPU_PA_RISC1_0:
  4407. this->ChipID.Vendor = "Hewlett-Packard";
  4408. this->ChipID.Family = 0x100;
  4409. break;
  4410. case CPU_PA_RISC1_1:
  4411. this->ChipID.Vendor = "Hewlett-Packard";
  4412. this->ChipID.Family = 0x110;
  4413. break;
  4414. case CPU_PA_RISC2_0:
  4415. this->ChipID.Vendor = "Hewlett-Packard";
  4416. this->ChipID.Family = 0x200;
  4417. break;
  4418. # if defined(CPU_HP_INTEL_EM_1_0) || defined(CPU_IA64_ARCHREV_0)
  4419. # ifdef CPU_HP_INTEL_EM_1_0
  4420. case CPU_HP_INTEL_EM_1_0:
  4421. # endif
  4422. # ifdef CPU_IA64_ARCHREV_0
  4423. case CPU_IA64_ARCHREV_0:
  4424. # endif
  4425. this->ChipID.Vendor = "GenuineIntel";
  4426. this->Features.HasIA64 = true;
  4427. break;
  4428. # endif
  4429. default:
  4430. return false;
  4431. }
  4432. this->FindManufacturer();
  4433. return true;
  4434. # else
  4435. return false;
  4436. # endif
  4437. #else
  4438. return false;
  4439. #endif
  4440. }
  4441. /** Query the operating system information */
  4442. bool SystemInformationImplementation::QueryOSInformation()
  4443. {
  4444. #if defined(_WIN32)
  4445. this->OSName = "Windows";
  4446. OSVERSIONINFOEXW osvi;
  4447. BOOL bIsWindows64Bit;
  4448. BOOL bOsVersionInfoEx;
  4449. char operatingSystem[256];
  4450. // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
  4451. ZeroMemory (&osvi, sizeof (OSVERSIONINFOEXW));
  4452. osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXW);
  4453. #ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
  4454. # pragma warning (push)
  4455. # ifdef __INTEL_COMPILER
  4456. # pragma warning (disable:1478)
  4457. # else
  4458. # pragma warning (disable:4996)
  4459. # endif
  4460. #endif
  4461. bOsVersionInfoEx = GetVersionExW ((OSVERSIONINFOW*)&osvi);
  4462. if (!bOsVersionInfoEx)
  4463. {
  4464. osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOW);
  4465. if (!GetVersionExW((OSVERSIONINFOW*)&osvi))
  4466. {
  4467. return false;
  4468. }
  4469. }
  4470. #ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
  4471. # pragma warning (pop)
  4472. #endif
  4473. switch (osvi.dwPlatformId)
  4474. {
  4475. case VER_PLATFORM_WIN32_NT:
  4476. // Test for the product.
  4477. if (osvi.dwMajorVersion <= 4)
  4478. {
  4479. this->OSRelease = "NT";
  4480. }
  4481. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
  4482. {
  4483. this->OSRelease = "2000";
  4484. }
  4485. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  4486. {
  4487. this->OSRelease = "XP";
  4488. }
  4489. // XP Professional x64
  4490. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
  4491. {
  4492. this->OSRelease = "XP";
  4493. }
  4494. #ifdef VER_NT_WORKSTATION
  4495. // Test for product type.
  4496. if (bOsVersionInfoEx)
  4497. {
  4498. if (osvi.wProductType == VER_NT_WORKSTATION)
  4499. {
  4500. if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0)
  4501. {
  4502. this->OSRelease = "Vista";
  4503. }
  4504. if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1)
  4505. {
  4506. this->OSRelease = "7";
  4507. }
  4508. // VER_SUITE_PERSONAL may not be defined
  4509. #ifdef VER_SUITE_PERSONAL
  4510. else
  4511. {
  4512. if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
  4513. {
  4514. this->OSRelease += " Personal";
  4515. }
  4516. else
  4517. {
  4518. this->OSRelease += " Professional";
  4519. }
  4520. }
  4521. #endif
  4522. }
  4523. else if (osvi.wProductType == VER_NT_SERVER)
  4524. {
  4525. // Check for .NET Server instead of Windows XP.
  4526. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  4527. {
  4528. this->OSRelease = ".NET";
  4529. }
  4530. // Continue with the type detection.
  4531. if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
  4532. {
  4533. this->OSRelease += " DataCenter Server";
  4534. }
  4535. else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
  4536. {
  4537. this->OSRelease += " Advanced Server";
  4538. }
  4539. else
  4540. {
  4541. this->OSRelease += " Server";
  4542. }
  4543. }
  4544. sprintf (operatingSystem, "%ls (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
  4545. this->OSVersion = operatingSystem;
  4546. }
  4547. else
  4548. #endif // VER_NT_WORKSTATION
  4549. {
  4550. HKEY hKey;
  4551. wchar_t szProductType[80];
  4552. DWORD dwBufLen;
  4553. // Query the registry to retrieve information.
  4554. RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey);
  4555. RegQueryValueExW(hKey, L"ProductType", NULL, NULL, (LPBYTE) szProductType, &dwBufLen);
  4556. RegCloseKey (hKey);
  4557. if (lstrcmpiW(L"WINNT", szProductType) == 0)
  4558. {
  4559. this->OSRelease += " Professional";
  4560. }
  4561. if (lstrcmpiW(L"LANMANNT", szProductType) == 0)
  4562. {
  4563. // Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
  4564. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  4565. {
  4566. this->OSRelease += " Standard Server";
  4567. }
  4568. else
  4569. {
  4570. this->OSRelease += " Server";
  4571. }
  4572. }
  4573. if (lstrcmpiW(L"SERVERNT", szProductType) == 0)
  4574. {
  4575. // Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
  4576. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  4577. {
  4578. this->OSRelease += " Enterprise Server";
  4579. }
  4580. else
  4581. {
  4582. this->OSRelease += " Advanced Server";
  4583. }
  4584. }
  4585. }
  4586. // Display version, service pack (if any), and build number.
  4587. if (osvi.dwMajorVersion <= 4)
  4588. {
  4589. // NB: NT 4.0 and earlier.
  4590. sprintf (operatingSystem, "version %ld.%ld %ls (Build %ld)",
  4591. osvi.dwMajorVersion,
  4592. osvi.dwMinorVersion,
  4593. osvi.szCSDVersion,
  4594. osvi.dwBuildNumber & 0xFFFF);
  4595. this->OSVersion = operatingSystem;
  4596. }
  4597. else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  4598. {
  4599. // Windows XP and .NET server.
  4600. typedef BOOL (CALLBACK* LPFNPROC) (HANDLE, BOOL *);
  4601. HINSTANCE hKernelDLL;
  4602. LPFNPROC DLLProc;
  4603. // Load the Kernel32 DLL.
  4604. hKernelDLL = LoadLibraryW(L"kernel32");
  4605. if (hKernelDLL != NULL) {
  4606. // Only XP and .NET Server support IsWOW64Process so... Load dynamically!
  4607. DLLProc = (LPFNPROC) GetProcAddress (hKernelDLL, "IsWow64Process");
  4608. // If the function address is valid, call the function.
  4609. if (DLLProc != NULL) (DLLProc) (GetCurrentProcess (), &bIsWindows64Bit);
  4610. else bIsWindows64Bit = false;
  4611. // Free the DLL module.
  4612. FreeLibrary (hKernelDLL);
  4613. }
  4614. }
  4615. else
  4616. {
  4617. // Windows 2000 and everything else.
  4618. sprintf (operatingSystem,"%ls (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
  4619. this->OSVersion = operatingSystem;
  4620. }
  4621. break;
  4622. case VER_PLATFORM_WIN32_WINDOWS:
  4623. // Test for the product.
  4624. if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
  4625. {
  4626. this->OSRelease = "95";
  4627. if(osvi.szCSDVersion[1] == 'C')
  4628. {
  4629. this->OSRelease += "OSR 2.5";
  4630. }
  4631. else if(osvi.szCSDVersion[1] == 'B')
  4632. {
  4633. this->OSRelease += "OSR 2";
  4634. }
  4635. }
  4636. if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
  4637. {
  4638. this->OSRelease = "98";
  4639. if (osvi.szCSDVersion[1] == 'A' )
  4640. {
  4641. this->OSRelease += "SE";
  4642. }
  4643. }
  4644. if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
  4645. {
  4646. this->OSRelease = "Me";
  4647. }
  4648. break;
  4649. case VER_PLATFORM_WIN32s:
  4650. this->OSRelease = "Win32s";
  4651. break;
  4652. default:
  4653. this->OSRelease = "Unknown";
  4654. break;
  4655. }
  4656. // Get the hostname
  4657. WORD wVersionRequested;
  4658. WSADATA wsaData;
  4659. char name[255];
  4660. wVersionRequested = MAKEWORD(2,0);
  4661. if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
  4662. {
  4663. gethostname(name,sizeof(name));
  4664. WSACleanup( );
  4665. }
  4666. this->Hostname = name;
  4667. const char* arch = getenv("PROCESSOR_ARCHITECTURE");
  4668. if(arch)
  4669. {
  4670. this->OSPlatform = arch;
  4671. }
  4672. #else
  4673. struct utsname unameInfo;
  4674. int errorFlag = uname(&unameInfo);
  4675. if(errorFlag == 0)
  4676. {
  4677. this->OSName = unameInfo.sysname;
  4678. this->Hostname = unameInfo.nodename;
  4679. this->OSRelease = unameInfo.release;
  4680. this->OSVersion = unameInfo.version;
  4681. this->OSPlatform = unameInfo.machine;
  4682. }
  4683. #ifdef __APPLE__
  4684. this->OSName="Unknown Apple OS";
  4685. this->OSRelease="Unknown product version";
  4686. this->OSVersion="Unknown build version";
  4687. this->CallSwVers("-productName",this->OSName);
  4688. this->CallSwVers("-productVersion",this->OSRelease);
  4689. this->CallSwVers("-buildVersion",this->OSVersion);
  4690. #endif
  4691. #endif
  4692. return true;
  4693. }
  4694. int SystemInformationImplementation::CallSwVers(
  4695. const char *arg,
  4696. kwsys_stl::string &ver)
  4697. {
  4698. #ifdef __APPLE__
  4699. kwsys_stl::vector<const char*> args;
  4700. args.push_back("sw_vers");
  4701. args.push_back(arg);
  4702. args.push_back(0);
  4703. ver = this->RunProcess(args);
  4704. this->TrimNewline(ver);
  4705. #else
  4706. // avoid C4100
  4707. (void)arg;
  4708. (void)ver;
  4709. #endif
  4710. return 0;
  4711. }
  4712. void SystemInformationImplementation::TrimNewline(kwsys_stl::string& output)
  4713. {
  4714. // remove \r
  4715. kwsys_stl::string::size_type pos=0;
  4716. while((pos = output.find("\r", pos)) != kwsys_stl::string::npos)
  4717. {
  4718. output.erase(pos);
  4719. }
  4720. // remove \n
  4721. pos = 0;
  4722. while((pos = output.find("\n", pos)) != kwsys_stl::string::npos)
  4723. {
  4724. output.erase(pos);
  4725. }
  4726. }
  4727. /** Return true if the machine is 64 bits */
  4728. bool SystemInformationImplementation::Is64Bits()
  4729. {
  4730. return (sizeof(void*) == 8);
  4731. }
  4732. } // namespace @KWSYS_NAMESPACE@