libc_windows.go 202 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857
  1. // Copyright 2020 The Libc Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package libc // import "modernc.org/libc"
  5. import (
  6. "errors"
  7. "fmt"
  8. "golang.org/x/sys/windows"
  9. "math"
  10. mbits "math/bits"
  11. "os"
  12. "os/exec"
  13. "os/user"
  14. "path/filepath"
  15. "runtime/debug"
  16. "strings"
  17. "sync"
  18. "sync/atomic"
  19. gotime "time"
  20. "unicode"
  21. "unicode/utf16"
  22. "unsafe"
  23. "github.com/ncruces/go-strftime"
  24. "modernc.org/libc/errno"
  25. "modernc.org/libc/fcntl"
  26. "modernc.org/libc/limits"
  27. "modernc.org/libc/stdio"
  28. "modernc.org/libc/sys/stat"
  29. "modernc.org/libc/sys/types"
  30. "modernc.org/libc/time"
  31. "modernc.org/libc/unistd"
  32. )
  33. // Keep these outside of the var block otherwise go generate will miss them.
  34. var X__imp__environ = EnvironP()
  35. var X__imp__wenviron = uintptr(unsafe.Pointer(&wenviron))
  36. var X_imp___environ = EnvironP()
  37. var X_imp___wenviron = uintptr(unsafe.Pointer(&wenviron))
  38. var X_iob [stdio.X_IOB_ENTRIES]stdio.FILE
  39. var Xin6addr_any [16]byte
  40. var Xtimezone long // extern long timezone;
  41. type Tsize_t = types.Size_t
  42. var (
  43. iobMap = map[uintptr]int32{} // &_iob[fd] -> fd
  44. wenvValid bool
  45. wenviron uintptr // &winEnviron[0]
  46. winEnviron = []uintptr{0}
  47. )
  48. func init() {
  49. for i := range X_iob {
  50. iobMap[uintptr(unsafe.Pointer(&X_iob[i]))] = int32(i)
  51. }
  52. }
  53. func X__p__wenviron(t *TLS) uintptr {
  54. if !wenvValid {
  55. bootWinEnviron(t)
  56. }
  57. return uintptr(unsafe.Pointer(&wenviron))
  58. }
  59. func winGetObject(stream uintptr) interface{} {
  60. if fd, ok := iobMap[stream]; ok {
  61. f, _ := fdToFile(fd)
  62. return f
  63. }
  64. return getObject(stream)
  65. }
  66. type (
  67. syscallErrno = windows.Errno
  68. long = int32
  69. ulong = uint32
  70. )
  71. var (
  72. modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
  73. //--
  74. procAreFileApisANSI = modkernel32.NewProc("AreFileApisANSI")
  75. procCopyFileW = modkernel32.NewProc("CopyFileW")
  76. procCreateEventA = modkernel32.NewProc("CreateEventA")
  77. procCreateEventW = modkernel32.NewProc("CreateEventW")
  78. procCreateFileA = modkernel32.NewProc("CreateFileA")
  79. procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
  80. procCreateFileW = modkernel32.NewProc("CreateFileW")
  81. procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW")
  82. procCreatePipe = modkernel32.NewProc("CreatePipe")
  83. procCreateProcessA = modkernel32.NewProc("CreateProcessA")
  84. procCreateProcessW = modkernel32.NewProc("CreateProcessW")
  85. procCreateThread = modkernel32.NewProc("CreateThread")
  86. procDeleteCriticalSection = modkernel32.NewProc("DeleteCriticalSection")
  87. procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
  88. procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
  89. procEnterCriticalSection = modkernel32.NewProc("EnterCriticalSection")
  90. procFindClose = modkernel32.NewProc("FindClose")
  91. procFindFirstFileExW = modkernel32.NewProc("FindFirstFileExW")
  92. procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
  93. procFindNextFileW = modkernel32.NewProc("FindNextFileW")
  94. procFormatMessageW = modkernel32.NewProc("FormatMessageW")
  95. procGetACP = modkernel32.NewProc("GetACP")
  96. procGetCommState = modkernel32.NewProc("GetCommState")
  97. procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
  98. procGetConsoleCP = modkernel32.NewProc("GetConsoleCP")
  99. procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo")
  100. procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess")
  101. procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
  102. procGetCurrentThread = modkernel32.NewProc("GetCurrentThread")
  103. procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId")
  104. procGetEnvironmentVariableA = modkernel32.NewProc("GetEnvironmentVariableA")
  105. procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW")
  106. procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess")
  107. procGetExitCodeThread = modkernel32.NewProc("GetExitCodeThread")
  108. procGetFileAttributesA = modkernel32.NewProc("GetFileAttributesA")
  109. procGetFileAttributesExA = modkernel32.NewProc("GetFileAttributesExA")
  110. procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
  111. procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle")
  112. procGetFileSize = modkernel32.NewProc("GetFileSize")
  113. procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
  114. procGetLastError = modkernel32.NewProc("GetLastError")
  115. procGetLogicalDriveStringsA = modkernel32.NewProc("GetLogicalDriveStringsA")
  116. procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW")
  117. procGetModuleHandleA = modkernel32.NewProc("GetModuleHandleA")
  118. procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW")
  119. procGetPrivateProfileStringA = modkernel32.NewProc("GetPrivateProfileStringA")
  120. procGetProcAddress = modkernel32.NewProc("GetProcAddress")
  121. procGetProcessHeap = modkernel32.NewProc("GetProcessHeap")
  122. procGetSystemInfo = modkernel32.NewProc("GetSystemInfo")
  123. procGetSystemTime = modkernel32.NewProc("GetSystemTime")
  124. procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
  125. procGetTempFileNameW = modkernel32.NewProc("GetTempFileNameW")
  126. procGetTickCount = modkernel32.NewProc("GetTickCount")
  127. procGetVersionExA = modkernel32.NewProc("GetVersionExA")
  128. procGetVersionExW = modkernel32.NewProc("GetVersionExW")
  129. procGetVolumeInformationA = modkernel32.NewProc("GetVolumeInformationA")
  130. procGetVolumeInformationW = modkernel32.NewProc("GetVolumeInformationW")
  131. procHeapAlloc = modkernel32.NewProc("HeapAlloc")
  132. procHeapFree = modkernel32.NewProc("HeapFree")
  133. procInitializeCriticalSection = modkernel32.NewProc("InitializeCriticalSection")
  134. procLeaveCriticalSection = modkernel32.NewProc("LeaveCriticalSection")
  135. procLockFile = modkernel32.NewProc("LockFile")
  136. procLockFileEx = modkernel32.NewProc("LockFileEx")
  137. procLstrlenW = modkernel32.NewProc("lstrlenW")
  138. procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
  139. procMoveFileW = modkernel32.NewProc("MoveFileW")
  140. procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
  141. procOpenEventA = modkernel32.NewProc("OpenEventA")
  142. procOpenProcessToken = modkernel32.NewProc("OpenProcessToken")
  143. procPeekConsoleInputW = modkernel32.NewProc("PeekConsoleInputW")
  144. procPeekNamedPipe = modkernel32.NewProc("PeekNamedPipe")
  145. procQueryPerformanceCounter = modkernel32.NewProc("QueryPerformanceCounter")
  146. procQueryPerformanceFrequency = modkernel32.NewProc("QueryPerformanceFrequency")
  147. procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
  148. procReadFile = modkernel32.NewProc("ReadFile")
  149. procResetEvent = modkernel32.NewProc("ResetEvent")
  150. procSearchPathW = modkernel32.NewProc("SearchPathW")
  151. procSetConsoleCtrlHandler = modkernel32.NewProc("SetConsoleCtrlHandler")
  152. procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
  153. procSetConsoleTextAttribute = modkernel32.NewProc("SetConsoleTextAttribute")
  154. procSetEvent = modkernel32.NewProc("SetEvent")
  155. procSetFilePointer = modkernel32.NewProc("SetFilePointer")
  156. procSetFileTime = modkernel32.NewProc("SetFileTime")
  157. procSleepEx = modkernel32.NewProc("SleepEx")
  158. procSystemTimeToFileTime = modkernel32.NewProc("SystemTimeToFileTime")
  159. procTerminateThread = modkernel32.NewProc("TerminateThread")
  160. procTryEnterCriticalSection = modkernel32.NewProc("TryEnterCriticalSection")
  161. procUnlockFile = modkernel32.NewProc("UnlockFile")
  162. procUnlockFileEx = modkernel32.NewProc("UnlockFileEx")
  163. procWaitForSingleObjectEx = modkernel32.NewProc("WaitForSingleObjectEx")
  164. procWideCharToMultiByte = modkernel32.NewProc("WideCharToMultiByte")
  165. procWriteConsoleA = modkernel32.NewProc("WriteConsoleA")
  166. procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
  167. procWriteFile = modkernel32.NewProc("WriteFile")
  168. // procSetConsoleCP = modkernel32.NewProc("SetConsoleCP")
  169. // procSetThreadPriority = modkernel32.NewProc("SetThreadPriority")
  170. //--
  171. modadvapi = windows.NewLazySystemDLL("advapi32.dll")
  172. //--
  173. procAccessCheck = modadvapi.NewProc("AccessCheck")
  174. procAddAce = modadvapi.NewProc("AddAce")
  175. procEqualSid = modadvapi.NewProc("EqualSid")
  176. procGetAce = modadvapi.NewProc("GetAce")
  177. procGetAclInformation = modadvapi.NewProc("GetAclInformation")
  178. procGetFileSecurityA = modadvapi.NewProc("GetFileSecurityA")
  179. procGetFileSecurityW = modadvapi.NewProc("GetFileSecurityW")
  180. procGetLengthSid = modadvapi.NewProc("GetLengthSid")
  181. procGetNamedSecurityInfoW = modadvapi.NewProc("GetNamedSecurityInfoW")
  182. procGetSecurityDescriptorDacl = modadvapi.NewProc("GetSecurityDescriptorDacl")
  183. procGetSecurityDescriptorOwner = modadvapi.NewProc("GetSecurityDescriptorOwner")
  184. procGetSidIdentifierAuthority = modadvapi.NewProc("GetSidIdentifierAuthority")
  185. procGetSidLengthRequired = modadvapi.NewProc("GetSidLengthRequired")
  186. procGetSidSubAuthority = modadvapi.NewProc("GetSidSubAuthority")
  187. procGetTokenInformation = modadvapi.NewProc("GetTokenInformation")
  188. procImpersonateSelf = modadvapi.NewProc("ImpersonateSelf")
  189. procInitializeAcl = modadvapi.NewProc("InitializeAcl")
  190. procInitializeSid = modadvapi.NewProc("InitializeSid")
  191. procOpenThreadToken = modadvapi.NewProc("OpenThreadToken")
  192. procRevertToSelf = modadvapi.NewProc("RevertToSelf")
  193. //--
  194. modws2_32 = windows.NewLazySystemDLL("ws2_32.dll")
  195. //--
  196. procWSAStartup = modws2_32.NewProc("WSAStartup")
  197. //--
  198. moduser32 = windows.NewLazySystemDLL("user32.dll")
  199. //--
  200. procCharLowerW = moduser32.NewProc("CharLowerW")
  201. procCreateWindowExW = moduser32.NewProc("CreateWindowExW")
  202. procMsgWaitForMultipleObjectsEx = moduser32.NewProc("MsgWaitForMultipleObjectsEx")
  203. procPeekMessageW = moduser32.NewProc("PeekMessageW")
  204. procRegisterClassW = moduser32.NewProc("RegisterClassW")
  205. procUnregisterClassW = moduser32.NewProc("UnregisterClassW")
  206. procWaitForInputIdle = moduser32.NewProc("WaitForInputIdle")
  207. //--
  208. netapi = windows.NewLazySystemDLL("netapi32.dll")
  209. procNetGetDCName = netapi.NewProc("NetGetDCName")
  210. procNetUserGetInfo = netapi.NewProc("NetUserGetInfo")
  211. userenvapi = windows.NewLazySystemDLL("userenv.dll")
  212. procGetProfilesDirectoryW = userenvapi.NewProc("GetProfilesDirectoryW")
  213. modcrt = windows.NewLazySystemDLL("msvcrt.dll")
  214. procAccess = modcrt.NewProc("_access")
  215. procChmod = modcrt.NewProc("_chmod")
  216. procCtime64 = modcrt.NewProc("ctime64")
  217. procGmtime = modcrt.NewProc("gmtime")
  218. procGmtime32 = modcrt.NewProc("_gmtime32")
  219. procGmtime64 = modcrt.NewProc("_gmtime64")
  220. procStati64 = modcrt.NewProc("_stati64")
  221. procStrftime = modcrt.NewProc("strftime")
  222. procStrnicmp = modcrt.NewProc("_strnicmp")
  223. procStrtod = modcrt.NewProc("strtod")
  224. procTime64 = modcrt.NewProc("time64")
  225. procWcsncpy = modcrt.NewProc("wcsncpy")
  226. procWcsrchr = modcrt.NewProc("wcsrchr")
  227. moducrt = windows.NewLazySystemDLL("ucrtbase.dll")
  228. procFindfirst32 = moducrt.NewProc("_findfirst32")
  229. procFindnext32 = moducrt.NewProc("_findnext32")
  230. procStat64i32 = moducrt.NewProc("_stat64i32")
  231. procWchmod = moducrt.NewProc("_wchmod")
  232. procWfindfirst32 = moducrt.NewProc("_wfindfirst32")
  233. procWfindfirst64i32 = moducrt.NewProc("_wfindfirst64i32")
  234. procWfindnext32 = moducrt.NewProc("_wfindnext32")
  235. procWfindnext64i32 = moducrt.NewProc("_wfindnext64i32")
  236. procWmkdir = moducrt.NewProc("_wmkdir")
  237. procWstat32 = moducrt.NewProc("_wstat32")
  238. procWstat64i32 = moducrt.NewProc("_wstat64i32")
  239. )
  240. var (
  241. threadCallback uintptr
  242. )
  243. func init() {
  244. isWindows = true
  245. threadCallback = windows.NewCallback(ThreadProc)
  246. }
  247. // ---------------------------------
  248. // Windows filehandle-to-fd mapping
  249. // so the lib-c interface contract looks
  250. // like normal fds being passed around
  251. // but we're mapping them back and forth to
  252. // native windows file handles (windows.Handle)
  253. //
  254. var EBADF = errors.New("EBADF")
  255. var w_nextFd int32 = 42
  256. var w_fdLock sync.Mutex
  257. var w_fd_to_file = map[int32]*file{}
  258. type file struct {
  259. _fd int32
  260. hadErr bool
  261. t uintptr
  262. windows.Handle
  263. }
  264. func addFile(hdl windows.Handle, fd int32) uintptr {
  265. var f = file{_fd: fd, Handle: hdl}
  266. w_fdLock.Lock()
  267. defer w_fdLock.Unlock()
  268. w_fd_to_file[fd] = &f
  269. f.t = addObject(&f)
  270. return f.t
  271. }
  272. func remFile(f *file) {
  273. removeObject(f.t)
  274. w_fdLock.Lock()
  275. defer w_fdLock.Unlock()
  276. delete(w_fd_to_file, f._fd)
  277. }
  278. func fdToFile(fd int32) (*file, bool) {
  279. w_fdLock.Lock()
  280. defer w_fdLock.Unlock()
  281. f, ok := w_fd_to_file[fd]
  282. return f, ok
  283. }
  284. // Wrap the windows handle up tied to a unique fd
  285. func wrapFdHandle(hdl windows.Handle) (uintptr, int32) {
  286. newFd := atomic.AddInt32(&w_nextFd, 1)
  287. return addFile(hdl, newFd), newFd
  288. }
  289. func (f *file) err() bool {
  290. return f.hadErr
  291. }
  292. func (f *file) setErr() {
  293. f.hadErr = true
  294. }
  295. func (tls *TLS) SetLastError(_dwErrCode uint32) {
  296. if tls != nil {
  297. tls.lastError = _dwErrCode
  298. }
  299. }
  300. // https://github.com/golang/go/issues/41220
  301. func (tls *TLS) GetLastError() (r uint32) {
  302. if tls == nil {
  303. return 0
  304. }
  305. return tls.lastError
  306. }
  307. // -----------------------------------
  308. // On windows we have to fetch these
  309. //
  310. // stdout, stdin, sterr
  311. //
  312. // Using the windows specific GetStdHandle
  313. // they're mapped to the standard fds (0,1,2)
  314. // Note: it's possible they don't exist
  315. // if the app has been built for a GUI only
  316. // target in windows. If that's the case
  317. // panic seems like the only reasonable option
  318. // ------------------------------
  319. func newFile(t *TLS, fd int32) uintptr {
  320. if fd == unistd.STDIN_FILENO {
  321. h, err := windows.GetStdHandle(windows.STD_INPUT_HANDLE)
  322. if err != nil {
  323. panic("no console")
  324. }
  325. return addFile(h, fd)
  326. }
  327. if fd == unistd.STDOUT_FILENO {
  328. h, err := windows.GetStdHandle(windows.STD_OUTPUT_HANDLE)
  329. if err != nil {
  330. panic("no console")
  331. }
  332. return addFile(h, fd)
  333. }
  334. if fd == unistd.STDERR_FILENO {
  335. h, err := windows.GetStdHandle(windows.STD_ERROR_HANDLE)
  336. if err != nil {
  337. panic("no console")
  338. }
  339. return addFile(h, fd)
  340. }
  341. // should not get here -- unless newFile
  342. // is being used from somewhere we don't know about
  343. // to originate fds.
  344. panic("unknown fd source")
  345. return 0
  346. }
  347. func (f *file) close(t *TLS) int32 {
  348. remFile(f)
  349. err := windows.Close(f.Handle)
  350. if err != nil {
  351. return (-1) // EOF
  352. }
  353. return 0
  354. }
  355. func fwrite(fd int32, b []byte) (int, error) {
  356. if fd == unistd.STDOUT_FILENO {
  357. return write(b)
  358. }
  359. f, ok := fdToFile(fd)
  360. if !ok {
  361. return -1, EBADF
  362. }
  363. if dmesgs {
  364. dmesg("%v: fd %v: %s", origin(1), fd, b)
  365. }
  366. return windows.Write(f.Handle, b)
  367. }
  368. // int fprintf(FILE *stream, const char *format, ...);
  369. func Xfprintf(t *TLS, stream, format, args uintptr) int32 {
  370. if __ccgo_strace {
  371. trc("t=%v args=%v, (%v:)", t, args, origin(2))
  372. }
  373. f, ok := winGetObject(stream).(*file)
  374. if !ok {
  375. t.setErrno(errno.EBADF)
  376. return -1
  377. }
  378. n, _ := fwrite(f._fd, printf(format, args))
  379. return int32(n)
  380. }
  381. // int usleep(useconds_t usec);
  382. func Xusleep(t *TLS, usec types.Useconds_t) int32 {
  383. if __ccgo_strace {
  384. trc("t=%v usec=%v, (%v:)", t, usec, origin(2))
  385. }
  386. gotime.Sleep(gotime.Microsecond * gotime.Duration(usec))
  387. return 0
  388. }
  389. // int getrusage(int who, struct rusage *usage);
  390. func Xgetrusage(t *TLS, who int32, usage uintptr) int32 {
  391. if __ccgo_strace {
  392. trc("t=%v who=%v usage=%v, (%v:)", t, who, usage, origin(2))
  393. }
  394. panic(todo(""))
  395. // if _, _, err := unix.Syscall(unix.SYS_GETRUSAGE, uintptr(who), usage, 0); err != 0 {
  396. // t.setErrno(err)
  397. // return -1
  398. // }
  399. // return 0
  400. }
  401. // int lstat(const char *pathname, struct stat *statbuf);
  402. func Xlstat(t *TLS, pathname, statbuf uintptr) int32 {
  403. if __ccgo_strace {
  404. trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
  405. }
  406. return Xlstat64(t, pathname, statbuf)
  407. }
  408. // int stat(const char *pathname, struct stat *statbuf);
  409. func Xstat(t *TLS, pathname, statbuf uintptr) int32 {
  410. if __ccgo_strace {
  411. trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
  412. }
  413. return Xstat64(t, pathname, statbuf)
  414. }
  415. // int chdir(const char *path);
  416. func Xchdir(t *TLS, path uintptr) int32 {
  417. if __ccgo_strace {
  418. trc("t=%v path=%v, (%v:)", t, path, origin(2))
  419. }
  420. err := windows.Chdir(GoString(path))
  421. if err != nil {
  422. t.setErrno(err)
  423. return -1
  424. }
  425. if dmesgs {
  426. dmesg("%v: %q: ok", origin(1), GoString(path))
  427. }
  428. return 0
  429. }
  430. var localtime time.Tm
  431. // struct tm *localtime(const time_t *timep);
  432. func Xlocaltime(_ *TLS, timep uintptr) uintptr {
  433. loc := getLocalLocation()
  434. ut := *(*time.Time_t)(unsafe.Pointer(timep))
  435. t := gotime.Unix(int64(ut), 0).In(loc)
  436. localtime.Ftm_sec = int32(t.Second())
  437. localtime.Ftm_min = int32(t.Minute())
  438. localtime.Ftm_hour = int32(t.Hour())
  439. localtime.Ftm_mday = int32(t.Day())
  440. localtime.Ftm_mon = int32(t.Month() - 1)
  441. localtime.Ftm_year = int32(t.Year() - 1900)
  442. localtime.Ftm_wday = int32(t.Weekday())
  443. localtime.Ftm_yday = int32(t.YearDay())
  444. localtime.Ftm_isdst = Bool32(isTimeDST(t))
  445. return uintptr(unsafe.Pointer(&localtime))
  446. }
  447. // struct tm *localtime(const time_t *timep);
  448. func X_localtime64(_ *TLS, timep uintptr) uintptr {
  449. return Xlocaltime(nil, timep)
  450. }
  451. // struct tm *localtime_r(const time_t *timep, struct tm *result);
  452. func Xlocaltime_r(_ *TLS, timep, result uintptr) uintptr {
  453. panic(todo(""))
  454. // loc := getLocalLocation()
  455. // ut := *(*unix.Time_t)(unsafe.Pointer(timep))
  456. // t := gotime.Unix(int64(ut), 0).In(loc)
  457. // (*time.Tm)(unsafe.Pointer(result)).Ftm_sec = int32(t.Second())
  458. // (*time.Tm)(unsafe.Pointer(result)).Ftm_min = int32(t.Minute())
  459. // (*time.Tm)(unsafe.Pointer(result)).Ftm_hour = int32(t.Hour())
  460. // (*time.Tm)(unsafe.Pointer(result)).Ftm_mday = int32(t.Day())
  461. // (*time.Tm)(unsafe.Pointer(result)).Ftm_mon = int32(t.Month() - 1)
  462. // (*time.Tm)(unsafe.Pointer(result)).Ftm_year = int32(t.Year() - 1900)
  463. // (*time.Tm)(unsafe.Pointer(result)).Ftm_wday = int32(t.Weekday())
  464. // (*time.Tm)(unsafe.Pointer(result)).Ftm_yday = int32(t.YearDay())
  465. // (*time.Tm)(unsafe.Pointer(result)).Ftm_isdst = Bool32(isTimeDST(t))
  466. // return result
  467. }
  468. // int _wopen(
  469. //
  470. // const wchar_t *filename,
  471. // int oflag [,
  472. // int pmode]
  473. //
  474. // );
  475. func X_wopen(t *TLS, pathname uintptr, flags int32, args uintptr) int32 {
  476. if __ccgo_strace {
  477. trc("t=%v pathname=%v flags=%v args=%v, (%v:)", t, pathname, flags, args, origin(2))
  478. }
  479. var mode types.Mode_t
  480. if args != 0 {
  481. mode = *(*types.Mode_t)(unsafe.Pointer(args))
  482. }
  483. s := goWideString(pathname)
  484. h, err := windows.Open(GoString(pathname), int(flags), uint32(mode))
  485. if err != nil {
  486. if dmesgs {
  487. dmesg("%v: %q %#x: %v", origin(1), s, flags, err)
  488. }
  489. t.setErrno(err)
  490. return 0
  491. }
  492. _, n := wrapFdHandle(h)
  493. if dmesgs {
  494. dmesg("%v: %q flags %#x mode %#o: fd %v", origin(1), s, flags, mode, n)
  495. }
  496. return n
  497. }
  498. // int open(const char *pathname, int flags, ...);
  499. func Xopen(t *TLS, pathname uintptr, flags int32, args uintptr) int32 {
  500. if __ccgo_strace {
  501. trc("t=%v pathname=%v flags=%v args=%v, (%v:)", t, pathname, flags, args, origin(2))
  502. }
  503. return Xopen64(t, pathname, flags, args)
  504. }
  505. // int open(const char *pathname, int flags, ...);
  506. func Xopen64(t *TLS, pathname uintptr, flags int32, cmode uintptr) int32 {
  507. if __ccgo_strace {
  508. trc("t=%v pathname=%v flags=%v cmode=%v, (%v:)", t, pathname, flags, cmode, origin(2))
  509. }
  510. var mode types.Mode_t
  511. if cmode != 0 {
  512. mode = (types.Mode_t)(VaUint32(&cmode))
  513. }
  514. // fdcwd := fcntl.AT_FDCWD
  515. h, err := windows.Open(GoString(pathname), int(flags), uint32(mode))
  516. if err != nil {
  517. if dmesgs {
  518. dmesg("%v: %q %#x: %v", origin(1), GoString(pathname), flags, err)
  519. }
  520. t.setErrno(err)
  521. return -1
  522. }
  523. _, n := wrapFdHandle(h)
  524. if dmesgs {
  525. dmesg("%v: %q flags %#x mode %#o: fd %v", origin(1), GoString(pathname), flags, mode, n)
  526. }
  527. return n
  528. }
  529. // off_t lseek(int fd, off_t offset, int whence);
  530. func Xlseek(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
  531. if __ccgo_strace {
  532. trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
  533. }
  534. return types.Off_t(Xlseek64(t, fd, offset, whence))
  535. }
  536. func whenceStr(whence int32) string {
  537. switch whence {
  538. case windows.FILE_CURRENT:
  539. return "SEEK_CUR"
  540. case windows.FILE_END:
  541. return "SEEK_END"
  542. case windows.FILE_BEGIN:
  543. return "SEEK_SET"
  544. default:
  545. return fmt.Sprintf("whence(%d)", whence)
  546. }
  547. }
  548. var fsyncStatbuf stat.Stat
  549. // int fsync(int fd);
  550. func Xfsync(t *TLS, fd int32) int32 {
  551. if __ccgo_strace {
  552. trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
  553. }
  554. f, ok := fdToFile(fd)
  555. if !ok {
  556. t.setErrno(errno.EBADF)
  557. return -1
  558. }
  559. err := windows.FlushFileBuffers(f.Handle)
  560. if err != nil {
  561. t.setErrno(err)
  562. return -1
  563. }
  564. if dmesgs {
  565. dmesg("%v: %d: ok", origin(1), fd)
  566. }
  567. return 0
  568. }
  569. // long sysconf(int name);
  570. func Xsysconf(t *TLS, name int32) long {
  571. if __ccgo_strace {
  572. trc("t=%v name=%v, (%v:)", t, name, origin(2))
  573. }
  574. panic(todo(""))
  575. // switch name {
  576. // case unistd.X_SC_PAGESIZE:
  577. // return long(unix.Getpagesize())
  578. // }
  579. // panic(todo(""))
  580. }
  581. // int close(int fd);
  582. func Xclose(t *TLS, fd int32) int32 {
  583. if __ccgo_strace {
  584. trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
  585. }
  586. f, ok := fdToFile(fd)
  587. if !ok {
  588. t.setErrno(errno.EBADF)
  589. return -1
  590. }
  591. err := windows.Close(f.Handle)
  592. if err != nil {
  593. t.setErrno(err)
  594. return -1
  595. }
  596. if dmesgs {
  597. dmesg("%v: %d: ok", origin(1), fd)
  598. }
  599. return 0
  600. }
  601. // char *getcwd(char *buf, size_t size);
  602. func Xgetcwd(t *TLS, buf uintptr, size types.Size_t) uintptr {
  603. if __ccgo_strace {
  604. trc("t=%v buf=%v size=%v, (%v:)", t, buf, size, origin(2))
  605. }
  606. b := make([]uint16, size)
  607. n, err := windows.GetCurrentDirectory(uint32(len(b)), &b[0])
  608. if err != nil {
  609. t.setErrno(err)
  610. return 0
  611. }
  612. // to bytes
  613. var wd = []byte(string(utf16.Decode(b[0:n])))
  614. if types.Size_t(len(wd)) > size {
  615. t.setErrno(errno.ERANGE)
  616. return 0
  617. }
  618. copy((*RawMem)(unsafe.Pointer(buf))[:], wd)
  619. (*RawMem)(unsafe.Pointer(buf))[len(wd)] = 0
  620. if dmesgs {
  621. dmesg("%v: %q: ok", origin(1), GoString(buf))
  622. }
  623. return buf
  624. }
  625. // int fstat(int fd, struct stat *statbuf);
  626. func Xfstat(t *TLS, fd int32, statbuf uintptr) int32 {
  627. if __ccgo_strace {
  628. trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
  629. }
  630. return Xfstat64(t, fd, statbuf)
  631. }
  632. // int ftruncate(int fd, off_t length);
  633. func Xftruncate(t *TLS, fd int32, length types.Off_t) int32 {
  634. if __ccgo_strace {
  635. trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
  636. }
  637. return Xftruncate64(t, fd, length)
  638. }
  639. // int fcntl(int fd, int cmd, ... /* arg */ );
  640. func Xfcntl(t *TLS, fd, cmd int32, args uintptr) int32 {
  641. if __ccgo_strace {
  642. trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
  643. }
  644. return Xfcntl64(t, fd, cmd, args)
  645. }
  646. // int _read( // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/read?view=msvc-160
  647. //
  648. // int const fd,
  649. // void * const buffer,
  650. // unsigned const buffer_size
  651. //
  652. // );
  653. func Xread(t *TLS, fd int32, buf uintptr, count uint32) int32 {
  654. if __ccgo_strace {
  655. trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
  656. }
  657. f, ok := fdToFile(fd)
  658. if !ok {
  659. t.setErrno(errno.EBADF)
  660. return -1
  661. }
  662. var obuf = ((*RawMem)(unsafe.Pointer(buf)))[:count]
  663. n, err := windows.Read(f.Handle, obuf)
  664. if err != nil {
  665. t.setErrno(err)
  666. return -1
  667. }
  668. if dmesgs {
  669. // dmesg("%v: %d %#x: %#x\n%s", origin(1), fd, count, n, hex.Dump(GoBytes(buf, int(n))))
  670. dmesg("%v: %d %#x: %#x", origin(1), fd, count, n)
  671. }
  672. return int32(n)
  673. }
  674. func X_read(t *TLS, fd int32, buf uintptr, count uint32) int32 {
  675. if __ccgo_strace {
  676. trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
  677. }
  678. return Xread(t, fd, buf, count)
  679. }
  680. // int _write( // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/write?view=msvc-160
  681. //
  682. // int fd,
  683. // const void *buffer,
  684. // unsigned int count
  685. //
  686. // );
  687. func Xwrite(t *TLS, fd int32, buf uintptr, count uint32) int32 {
  688. if __ccgo_strace {
  689. trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
  690. }
  691. f, ok := fdToFile(fd)
  692. if !ok {
  693. t.setErrno(errno.EBADF)
  694. return -1
  695. }
  696. var obuf = ((*RawMem)(unsafe.Pointer(buf)))[:count]
  697. n, err := windows.Write(f.Handle, obuf)
  698. if err != nil {
  699. if dmesgs {
  700. dmesg("%v: fd %v, count %#x: %v", origin(1), fd, count, err)
  701. }
  702. t.setErrno(err)
  703. return -1
  704. }
  705. if dmesgs {
  706. // dmesg("%v: %d %#x: %#x\n%s", origin(1), fd, count, n, hex.Dump(GoBytes(buf, int(n))))
  707. dmesg("%v: %d %#x: %#x", origin(1), fd, count, n)
  708. }
  709. return int32(n)
  710. }
  711. func X_write(t *TLS, fd int32, buf uintptr, count uint32) int32 {
  712. if __ccgo_strace {
  713. trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
  714. }
  715. return Xwrite(t, fd, buf, count)
  716. }
  717. // int fchmod(int fd, mode_t mode);
  718. func Xfchmod(t *TLS, fd int32, mode types.Mode_t) int32 {
  719. if __ccgo_strace {
  720. trc("t=%v fd=%v mode=%v, (%v:)", t, fd, mode, origin(2))
  721. }
  722. panic(todo(""))
  723. // if _, _, err := unix.Syscall(unix.SYS_FCHMOD, uintptr(fd), uintptr(mode), 0); err != 0 {
  724. // t.setErrno(err)
  725. // return -1
  726. // }
  727. // if dmesgs {
  728. // dmesg("%v: %d %#o: ok", origin(1), fd, mode)
  729. // }
  730. // return 0
  731. }
  732. // // int fchown(int fd, uid_t owner, gid_t group);
  733. // func Xfchown(t *TLS, fd int32, owner types.Uid_t, group types.Gid_t) int32 {
  734. // if _, _, err := unix.Syscall(unix.SYS_FCHOWN, uintptr(fd), uintptr(owner), uintptr(group)); err != 0 {
  735. // t.setErrno(err)
  736. // return -1
  737. // }
  738. //
  739. // return 0
  740. // }
  741. // // uid_t geteuid(void);
  742. // func Xgeteuid(t *TLS) types.Uid_t {
  743. // n, _, _ := unix.Syscall(unix.SYS_GETEUID, 0, 0, 0)
  744. // return types.Uid_t(n)
  745. // }
  746. // int munmap(void *addr, size_t length);
  747. func Xmunmap(t *TLS, addr uintptr, length types.Size_t) int32 {
  748. if __ccgo_strace {
  749. trc("t=%v addr=%v length=%v, (%v:)", t, addr, length, origin(2))
  750. }
  751. panic(todo(""))
  752. // if _, _, err := unix.Syscall(unix.SYS_MUNMAP, addr, uintptr(length), 0); err != 0 {
  753. // t.setErrno(err)
  754. // return -1
  755. // }
  756. // return 0
  757. }
  758. type Timeval = struct {
  759. Ftv_sec int32
  760. Ftv_usec int32
  761. }
  762. // int gettimeofday(struct timeval *tv, struct timezone *tz);
  763. func Xgettimeofday(t *TLS, tv, tz uintptr) int32 {
  764. if __ccgo_strace {
  765. trc("t=%v tz=%v, (%v:)", t, tz, origin(2))
  766. }
  767. if tv == 0 {
  768. return 0
  769. }
  770. // This seems to work as well
  771. // var u64 uint64
  772. // procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&u64)), 0, 0)
  773. // u64 /= 10
  774. // u64 -= 11644473600000000
  775. // (*Timeval)(unsafe.Pointer(tv)).Ftv_sec = int32(u64/1e6)
  776. // (*Timeval)(unsafe.Pointer(tv)).Ftv_usec = int32(u64%1e6)
  777. // return 0
  778. // But let's use the golang.org/x/sys version
  779. windows.Gettimeofday((*windows.Timeval)(unsafe.Pointer(tv)))
  780. return 0
  781. }
  782. type Timespec = struct {
  783. Ftv_sec time.Time_t
  784. Ftv_nsec int32
  785. }
  786. // int clock_gettime(clockid_t clk_id, struct timespec *tp);
  787. func Xclock_gettime(t *TLS, clk_id int32, tp uintptr) int32 {
  788. if __ccgo_strace {
  789. trc("t=%v clk_id=%v tp=%v, (%v:)", t, clk_id, tp, origin(2))
  790. }
  791. var u64 uint64 // [100ns]
  792. procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&u64)), 0, 0)
  793. (*Timespec)(unsafe.Pointer(tp)).Ftv_sec = time.Time_t((u64/10 - 11644473600000000) / 1e6)
  794. (*Timespec)(unsafe.Pointer(tp)).Ftv_nsec = int32((u64 * 100) % 1e9)
  795. return 0
  796. }
  797. // int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
  798. func Xgetsockopt(t *TLS, _ ...interface{}) int32 {
  799. panic(todo(""))
  800. // if _, _, err := unix.Syscall6(unix.SYS_GETSOCKOPT, uintptr(sockfd), uintptr(level), uintptr(optname), optval, optlen, 0); err != 0 {
  801. // t.setErrno(err)
  802. // return -1
  803. // }
  804. // return 0
  805. }
  806. // // int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
  807. func Xsetsockopt(t *TLS, _ ...interface{}) int32 {
  808. panic(todo(""))
  809. }
  810. // int ioctl(int fd, unsigned long request, ...);
  811. func Xioctl(t *TLS, fd int32, request ulong, va uintptr) int32 {
  812. if __ccgo_strace {
  813. trc("t=%v fd=%v request=%v va=%v, (%v:)", t, fd, request, va, origin(2))
  814. }
  815. panic(todo(""))
  816. // var argp uintptr
  817. // if va != 0 {
  818. // argp = VaUintptr(&va)
  819. // }
  820. // n, _, err := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(request), argp)
  821. // if err != 0 {
  822. // t.setErrno(err)
  823. // return -1
  824. // }
  825. // return int32(n)
  826. }
  827. // int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
  828. func Xselect(t *TLS, nfds int32, readfds, writefds, exceptfds, timeout uintptr) int32 {
  829. if __ccgo_strace {
  830. trc("t=%v nfds=%v timeout=%v, (%v:)", t, nfds, timeout, origin(2))
  831. }
  832. panic(todo(""))
  833. // n, err := unix.Select(
  834. // int(nfds),
  835. // (*unix.FdSet)(unsafe.Pointer(readfds)),
  836. // (*unix.FdSet)(unsafe.Pointer(writefds)),
  837. // (*unix.FdSet)(unsafe.Pointer(exceptfds)),
  838. // (*unix.Timeval)(unsafe.Pointer(timeout)),
  839. // )
  840. // if err != nil {
  841. // t.setErrno(err)
  842. // return -1
  843. // }
  844. // return int32(n)
  845. }
  846. // int mkfifo(const char *pathname, mode_t mode);
  847. func Xmkfifo(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
  848. if __ccgo_strace {
  849. trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
  850. }
  851. panic(todo(""))
  852. // if err := unix.Mkfifo(GoString(pathname), mode); err != nil {
  853. // t.setErrno(err)
  854. // return -1
  855. // }
  856. //
  857. // return 0
  858. }
  859. // mode_t umask(mode_t mask);
  860. func Xumask(t *TLS, mask types.Mode_t) types.Mode_t {
  861. if __ccgo_strace {
  862. trc("t=%v mask=%v, (%v:)", t, mask, origin(2))
  863. }
  864. panic(todo(""))
  865. // n, _, _ := unix.Syscall(unix.SYS_UMASK, uintptr(mask), 0, 0)
  866. // return types.Mode_t(n)
  867. }
  868. // int execvp(const char *file, char *const argv[]);
  869. func Xexecvp(t *TLS, file, argv uintptr) int32 {
  870. if __ccgo_strace {
  871. trc("t=%v argv=%v, (%v:)", t, argv, origin(2))
  872. }
  873. panic(todo(""))
  874. // if _, _, err := unix.Syscall(unix.SYS_EXECVE, file, argv, Environ()); err != 0 {
  875. // t.setErrno(err)
  876. // return -1
  877. // }
  878. //
  879. // return 0
  880. }
  881. // pid_t waitpid(pid_t pid, int *wstatus, int options);
  882. func Xwaitpid(t *TLS, pid types.Pid_t, wstatus uintptr, optname int32) types.Pid_t {
  883. if __ccgo_strace {
  884. trc("t=%v pid=%v wstatus=%v optname=%v, (%v:)", t, pid, wstatus, optname, origin(2))
  885. }
  886. panic(todo(""))
  887. // n, _, err := unix.Syscall6(unix.SYS_WAIT4, uintptr(pid), wstatus, uintptr(optname), 0, 0, 0)
  888. // if err != 0 {
  889. // t.setErrno(err)
  890. // return -1
  891. // }
  892. //
  893. // return types.Pid_t(n)
  894. }
  895. // int uname(struct utsname *buf);
  896. func Xuname(t *TLS, buf uintptr) int32 {
  897. if __ccgo_strace {
  898. trc("t=%v buf=%v, (%v:)", t, buf, origin(2))
  899. }
  900. panic(todo(""))
  901. // if _, _, err := unix.Syscall(unix.SYS_UNAME, buf, 0, 0); err != 0 {
  902. // t.setErrno(err)
  903. // return -1
  904. // }
  905. //
  906. // return 0
  907. }
  908. // int getrlimit(int resource, struct rlimit *rlim);
  909. func Xgetrlimit(t *TLS, resource int32, rlim uintptr) int32 {
  910. if __ccgo_strace {
  911. trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
  912. }
  913. return Xgetrlimit64(t, resource, rlim)
  914. }
  915. // int setrlimit(int resource, const struct rlimit *rlim);
  916. func Xsetrlimit(t *TLS, resource int32, rlim uintptr) int32 {
  917. if __ccgo_strace {
  918. trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
  919. }
  920. return Xsetrlimit64(t, resource, rlim)
  921. }
  922. // int setrlimit(int resource, const struct rlimit *rlim);
  923. func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
  924. if __ccgo_strace {
  925. trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
  926. }
  927. panic(todo(""))
  928. // if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
  929. // t.setErrno(err)
  930. // return -1
  931. // }
  932. //
  933. // return 0
  934. }
  935. // // uid_t getuid(void);
  936. // func Xgetuid(t *TLS) types.Uid_t {
  937. // return types.Uid_t(os.Getuid())
  938. // }
  939. // pid_t getpid(void);
  940. func Xgetpid(t *TLS) int32 {
  941. if __ccgo_strace {
  942. trc("t=%v, (%v:)", t, origin(2))
  943. }
  944. return int32(os.Getpid())
  945. }
  946. // int system(const char *command);
  947. func Xsystem(t *TLS, command uintptr) int32 {
  948. if __ccgo_strace {
  949. trc("t=%v command=%v, (%v:)", t, command, origin(2))
  950. }
  951. s := GoString(command)
  952. if command == 0 {
  953. panic(todo(""))
  954. }
  955. cmd := exec.Command("sh", "-c", s)
  956. cmd.Stdout = os.Stdout
  957. cmd.Stderr = os.Stderr
  958. err := cmd.Run()
  959. if err != nil {
  960. ps := err.(*exec.ExitError)
  961. return int32(ps.ExitCode())
  962. }
  963. return 0
  964. }
  965. // var staticGetpwuid pwd.Passwd
  966. //
  967. // func init() {
  968. // atExit = append(atExit, func() { closePasswd(&staticGetpwuid) })
  969. // }
  970. //
  971. // func closePasswd(p *pwd.Passwd) {
  972. // Xfree(nil, p.Fpw_name)
  973. // Xfree(nil, p.Fpw_passwd)
  974. // Xfree(nil, p.Fpw_gecos)
  975. // Xfree(nil, p.Fpw_dir)
  976. // Xfree(nil, p.Fpw_shell)
  977. // *p = pwd.Passwd{}
  978. // }
  979. // struct passwd *getpwuid(uid_t uid);
  980. func Xgetpwuid(t *TLS, uid uint32) uintptr {
  981. if __ccgo_strace {
  982. trc("t=%v uid=%v, (%v:)", t, uid, origin(2))
  983. }
  984. panic(todo(""))
  985. // f, err := os.Open("/etc/passwd")
  986. // if err != nil {
  987. // panic(todo("", err))
  988. // }
  989. //
  990. // defer f.Close()
  991. //
  992. // sid := strconv.Itoa(int(uid))
  993. // sc := bufio.NewScanner(f)
  994. // for sc.Scan() {
  995. // // eg. "root:x:0:0:root:/root:/bin/bash"
  996. // a := strings.Split(sc.Text(), ":")
  997. // if len(a) < 7 {
  998. // panic(todo(""))
  999. // }
  1000. //
  1001. // if a[2] == sid {
  1002. // uid, err := strconv.Atoi(a[2])
  1003. // if err != nil {
  1004. // panic(todo(""))
  1005. // }
  1006. //
  1007. // gid, err := strconv.Atoi(a[3])
  1008. // if err != nil {
  1009. // panic(todo(""))
  1010. // }
  1011. //
  1012. // closePasswd(&staticGetpwuid)
  1013. // gecos := a[4]
  1014. // if strings.Contains(gecos, ",") {
  1015. // a := strings.Split(gecos, ",")
  1016. // gecos = a[0]
  1017. // }
  1018. // initPasswd(t, &staticGetpwuid, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6])
  1019. // return uintptr(unsafe.Pointer(&staticGetpwuid))
  1020. // }
  1021. // }
  1022. //
  1023. // if sc.Err() != nil {
  1024. // panic(todo(""))
  1025. // }
  1026. //
  1027. // return 0
  1028. }
  1029. // func initPasswd(t *TLS, p *pwd.Passwd, name, pwd string, uid, gid uint32, gecos, dir, shell string) {
  1030. // p.Fpw_name = cString(t, name)
  1031. // p.Fpw_passwd = cString(t, pwd)
  1032. // p.Fpw_uid = uid
  1033. // p.Fpw_gid = gid
  1034. // p.Fpw_gecos = cString(t, gecos)
  1035. // p.Fpw_dir = cString(t, dir)
  1036. // p.Fpw_shell = cString(t, shell)
  1037. // }
  1038. // int setvbuf(FILE *stream, char *buf, int mode, size_t size);
  1039. func Xsetvbuf(t *TLS, stream, buf uintptr, mode int32, size types.Size_t) int32 {
  1040. if __ccgo_strace {
  1041. trc("t=%v buf=%v mode=%v size=%v, (%v:)", t, buf, mode, size, origin(2))
  1042. }
  1043. return 0 //TODO
  1044. }
  1045. // int raise(int sig);
  1046. func Xraise(t *TLS, sig int32) int32 {
  1047. if __ccgo_strace {
  1048. trc("t=%v sig=%v, (%v:)", t, sig, origin(2))
  1049. }
  1050. panic(todo(""))
  1051. }
  1052. // int backtrace(void **buffer, int size);
  1053. func Xbacktrace(t *TLS, buf uintptr, size int32) int32 {
  1054. if __ccgo_strace {
  1055. trc("t=%v buf=%v size=%v, (%v:)", t, buf, size, origin(2))
  1056. }
  1057. panic(todo(""))
  1058. }
  1059. // void backtrace_symbols_fd(void *const *buffer, int size, int fd);
  1060. func Xbacktrace_symbols_fd(t *TLS, buffer uintptr, size, fd int32) {
  1061. if __ccgo_strace {
  1062. trc("t=%v buffer=%v fd=%v, (%v:)", t, buffer, fd, origin(2))
  1063. }
  1064. panic(todo(""))
  1065. }
  1066. // int fileno(FILE *stream);
  1067. func Xfileno(t *TLS, stream uintptr) int32 {
  1068. if __ccgo_strace {
  1069. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  1070. }
  1071. if stream == 0 {
  1072. t.setErrno(errno.EBADF)
  1073. return -1
  1074. }
  1075. f, ok := winGetObject(stream).(*file)
  1076. if !ok {
  1077. t.setErrno(errno.EBADF)
  1078. return -1
  1079. }
  1080. return f._fd
  1081. }
  1082. // var staticGetpwnam pwd.Passwd
  1083. //
  1084. // func init() {
  1085. // atExit = append(atExit, func() { closePasswd(&staticGetpwnam) })
  1086. // }
  1087. //
  1088. // // struct passwd *getpwnam(const char *name);
  1089. // func Xgetpwnam(t *TLS, name uintptr) uintptr {
  1090. // f, err := os.Open("/etc/passwd")
  1091. // if err != nil {
  1092. // panic(todo("", err))
  1093. // }
  1094. //
  1095. // defer f.Close()
  1096. //
  1097. // sname := GoString(name)
  1098. // sc := bufio.NewScanner(f)
  1099. // for sc.Scan() {
  1100. // // eg. "root:x:0:0:root:/root:/bin/bash"
  1101. // a := strings.Split(sc.Text(), ":")
  1102. // if len(a) < 7 {
  1103. // panic(todo(""))
  1104. // }
  1105. //
  1106. // if a[0] == sname {
  1107. // uid, err := strconv.Atoi(a[2])
  1108. // if err != nil {
  1109. // panic(todo(""))
  1110. // }
  1111. //
  1112. // gid, err := strconv.Atoi(a[3])
  1113. // if err != nil {
  1114. // panic(todo(""))
  1115. // }
  1116. //
  1117. // closePasswd(&staticGetpwnam)
  1118. // gecos := a[4]
  1119. // if strings.Contains(gecos, ",") {
  1120. // a := strings.Split(gecos, ",")
  1121. // gecos = a[0]
  1122. // }
  1123. // initPasswd(t, &staticGetpwnam, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6])
  1124. // return uintptr(unsafe.Pointer(&staticGetpwnam))
  1125. // }
  1126. // }
  1127. //
  1128. // if sc.Err() != nil {
  1129. // panic(todo(""))
  1130. // }
  1131. //
  1132. // return 0
  1133. // }
  1134. //
  1135. // var staticGetgrnam grp.Group
  1136. //
  1137. // func init() {
  1138. // atExit = append(atExit, func() { closeGroup(&staticGetgrnam) })
  1139. // }
  1140. //
  1141. // // struct group *getgrnam(const char *name);
  1142. // func Xgetgrnam(t *TLS, name uintptr) uintptr {
  1143. // f, err := os.Open("/etc/group")
  1144. // if err != nil {
  1145. // panic(todo(""))
  1146. // }
  1147. //
  1148. // defer f.Close()
  1149. //
  1150. // sname := GoString(name)
  1151. // sc := bufio.NewScanner(f)
  1152. // for sc.Scan() {
  1153. // // eg. "root:x:0:"
  1154. // a := strings.Split(sc.Text(), ":")
  1155. // if len(a) < 4 {
  1156. // panic(todo(""))
  1157. // }
  1158. //
  1159. // if a[0] == sname {
  1160. // closeGroup(&staticGetgrnam)
  1161. // gid, err := strconv.Atoi(a[2])
  1162. // if err != nil {
  1163. // panic(todo(""))
  1164. // }
  1165. //
  1166. // var names []string
  1167. // if a[3] != "" {
  1168. // names = strings.Split(a[3], ",")
  1169. // }
  1170. // initGroup(t, &staticGetgrnam, a[0], a[1], uint32(gid), names)
  1171. // return uintptr(unsafe.Pointer(&staticGetgrnam))
  1172. // }
  1173. // }
  1174. //
  1175. // if sc.Err() != nil {
  1176. // panic(todo(""))
  1177. // }
  1178. //
  1179. // return 0
  1180. // }
  1181. //
  1182. // func closeGroup(p *grp.Group) {
  1183. // Xfree(nil, p.Fgr_name)
  1184. // Xfree(nil, p.Fgr_passwd)
  1185. // if p.Fgr_mem != 0 {
  1186. // panic(todo(""))
  1187. // }
  1188. //
  1189. // *p = grp.Group{}
  1190. // }
  1191. //
  1192. // func initGroup(t *TLS, p *grp.Group, name, pwd string, gid uint32, names []string) {
  1193. // p.Fgr_name = cString(t, name)
  1194. // p.Fgr_passwd = cString(t, pwd)
  1195. // p.Fgr_gid = gid
  1196. // p.Fgr_mem = 0
  1197. // if len(names) != 0 {
  1198. // panic(todo("%q %q %v %q %v", name, pwd, gid, names, len(names)))
  1199. // }
  1200. // }
  1201. //
  1202. // func init() {
  1203. // atExit = append(atExit, func() { closeGroup(&staticGetgrgid) })
  1204. // }
  1205. //
  1206. // var staticGetgrgid grp.Group
  1207. //
  1208. // // struct group *getgrgid(gid_t gid);
  1209. // func Xgetgrgid(t *TLS, gid uint32) uintptr {
  1210. // f, err := os.Open("/etc/group")
  1211. // if err != nil {
  1212. // panic(todo(""))
  1213. // }
  1214. //
  1215. // defer f.Close()
  1216. //
  1217. // sid := strconv.Itoa(int(gid))
  1218. // sc := bufio.NewScanner(f)
  1219. // for sc.Scan() {
  1220. // // eg. "root:x:0:"
  1221. // a := strings.Split(sc.Text(), ":")
  1222. // if len(a) < 4 {
  1223. // panic(todo(""))
  1224. // }
  1225. //
  1226. // if a[2] == sid {
  1227. // closeGroup(&staticGetgrgid)
  1228. // var names []string
  1229. // if a[3] != "" {
  1230. // names = strings.Split(a[3], ",")
  1231. // }
  1232. // initGroup(t, &staticGetgrgid, a[0], a[1], gid, names)
  1233. // return uintptr(unsafe.Pointer(&staticGetgrgid))
  1234. // }
  1235. // }
  1236. //
  1237. // if sc.Err() != nil {
  1238. // panic(todo(""))
  1239. // }
  1240. //
  1241. // return 0
  1242. // }
  1243. // int mkstemps(char *template, int suffixlen);
  1244. func Xmkstemps(t *TLS, template uintptr, suffixlen int32) int32 {
  1245. if __ccgo_strace {
  1246. trc("t=%v template=%v suffixlen=%v, (%v:)", t, template, suffixlen, origin(2))
  1247. }
  1248. return Xmkstemps64(t, template, suffixlen)
  1249. }
  1250. // int mkstemps(char *template, int suffixlen);
  1251. func Xmkstemps64(t *TLS, template uintptr, suffixlen int32) int32 {
  1252. if __ccgo_strace {
  1253. trc("t=%v template=%v suffixlen=%v, (%v:)", t, template, suffixlen, origin(2))
  1254. }
  1255. panic(todo(""))
  1256. // len := uintptr(Xstrlen(t, template))
  1257. // x := template + uintptr(len-6) - uintptr(suffixlen)
  1258. // for i := uintptr(0); i < 6; i++ {
  1259. // if *(*byte)(unsafe.Pointer(x + i)) != 'X' {
  1260. // t.setErrno(errno.EINVAL)
  1261. // return -1
  1262. // }
  1263. // }
  1264. //
  1265. // fd, err := tempFile(template, x)
  1266. // if err != 0 {
  1267. // t.setErrno(err)
  1268. // return -1
  1269. // }
  1270. //
  1271. // return int32(fd)
  1272. }
  1273. // int mkstemp(char *template);
  1274. func Xmkstemp64(t *TLS, template uintptr) int32 {
  1275. if __ccgo_strace {
  1276. trc("t=%v template=%v, (%v:)", t, template, origin(2))
  1277. }
  1278. return Xmkstemps64(t, template, 0)
  1279. }
  1280. // func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err windows.Errno) (r *fts.FTSENT) {
  1281. // var statp uintptr
  1282. // if stat != nil {
  1283. // statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))
  1284. // if statp == 0 {
  1285. // panic("OOM")
  1286. // }
  1287. //
  1288. // *(*unix.Stat_t)(unsafe.Pointer(statp)) = *stat
  1289. // }
  1290. // csp := CString(path)
  1291. // if csp == 0 {
  1292. // panic("OOM")
  1293. // }
  1294. //
  1295. // return &fts.FTSENT{
  1296. // Ffts_info: uint16(info),
  1297. // Ffts_path: csp,
  1298. // Ffts_pathlen: uint16(len(path)),
  1299. // Ffts_statp: statp,
  1300. // Ffts_errno: int32(err),
  1301. // }
  1302. // }
  1303. //
  1304. // func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err windows.Errno) uintptr {
  1305. // p := Xcalloc(t, types.Size_t(unsafe.Sizeof(fts.FTSENT{})))
  1306. // if p == 0 {
  1307. // panic("OOM")
  1308. // }
  1309. //
  1310. // *(*fts.FTSENT)(unsafe.Pointer(p)) = *newFtsent(t, info, path, stat, err)
  1311. // return p
  1312. // }
  1313. //
  1314. // func ftsentClose(t *TLS, p uintptr) {
  1315. // Xfree(t, (*fts.FTSENT)(unsafe.Pointer(p)).Ffts_path)
  1316. // Xfree(t, (*fts.FTSENT)(unsafe.Pointer(p)).Ffts_statp)
  1317. // }
  1318. type ftstream struct {
  1319. s []uintptr
  1320. x int
  1321. }
  1322. // func (f *ftstream) close(t *TLS) {
  1323. // for _, p := range f.s {
  1324. // ftsentClose(t, p)
  1325. // Xfree(t, p)
  1326. // }
  1327. // *f = ftstream{}
  1328. // }
  1329. //
  1330. // // FTS *fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **));
  1331. // func Xfts_open(t *TLS, path_argv uintptr, options int32, compar uintptr) uintptr {
  1332. // return Xfts64_open(t, path_argv, options, compar)
  1333. // }
  1334. // FTS *fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **));
  1335. func Xfts64_open(t *TLS, path_argv uintptr, options int32, compar uintptr) uintptr {
  1336. if __ccgo_strace {
  1337. trc("t=%v path_argv=%v options=%v compar=%v, (%v:)", t, path_argv, options, compar, origin(2))
  1338. }
  1339. panic(todo(""))
  1340. // f := &ftstream{}
  1341. //
  1342. // var walk func(string)
  1343. // walk = func(path string) {
  1344. // var fi os.FileInfo
  1345. // var err error
  1346. // switch {
  1347. // case options&fts.FTS_LOGICAL != 0:
  1348. // fi, err = os.Stat(path)
  1349. // case options&fts.FTS_PHYSICAL != 0:
  1350. // fi, err = os.Lstat(path)
  1351. // default:
  1352. // panic(todo(""))
  1353. // }
  1354. //
  1355. // if err != nil {
  1356. // panic(todo(""))
  1357. // }
  1358. //
  1359. // var statp *unix.Stat_t
  1360. // if options&fts.FTS_NOSTAT == 0 {
  1361. // var stat unix.Stat_t
  1362. // switch {
  1363. // case options&fts.FTS_LOGICAL != 0:
  1364. // if err := unix.Stat(path, &stat); err != nil {
  1365. // panic(todo(""))
  1366. // }
  1367. // case options&fts.FTS_PHYSICAL != 0:
  1368. // if err := unix.Lstat(path, &stat); err != nil {
  1369. // panic(todo(""))
  1370. // }
  1371. // default:
  1372. // panic(todo(""))
  1373. // }
  1374. //
  1375. // statp = &stat
  1376. // }
  1377. //
  1378. // out:
  1379. // switch {
  1380. // case fi.IsDir():
  1381. // f.s = append(f.s, newCFtsent(t, fts.FTS_D, path, statp, 0))
  1382. // g, err := os.Open(path)
  1383. // switch x := err.(type) {
  1384. // case nil:
  1385. // // ok
  1386. // case *os.PathError:
  1387. // f.s = append(f.s, newCFtsent(t, fts.FTS_DNR, path, statp, errno.EACCES))
  1388. // break out
  1389. // default:
  1390. // panic(todo("%q: %v %T", path, x, x))
  1391. // }
  1392. //
  1393. // names, err := g.Readdirnames(-1)
  1394. // g.Close()
  1395. // if err != nil {
  1396. // panic(todo(""))
  1397. // }
  1398. //
  1399. // for _, name := range names {
  1400. // walk(path + "/" + name)
  1401. // if f == nil {
  1402. // break out
  1403. // }
  1404. // }
  1405. //
  1406. // f.s = append(f.s, newCFtsent(t, fts.FTS_DP, path, statp, 0))
  1407. // default:
  1408. // info := fts.FTS_F
  1409. // if fi.Mode()&os.ModeSymlink != 0 {
  1410. // info = fts.FTS_SL
  1411. // }
  1412. // switch {
  1413. // case statp != nil:
  1414. // f.s = append(f.s, newCFtsent(t, info, path, statp, 0))
  1415. // case options&fts.FTS_NOSTAT != 0:
  1416. // f.s = append(f.s, newCFtsent(t, fts.FTS_NSOK, path, nil, 0))
  1417. // default:
  1418. // panic(todo(""))
  1419. // }
  1420. // }
  1421. // }
  1422. //
  1423. // for {
  1424. // p := *(*uintptr)(unsafe.Pointer(path_argv))
  1425. // if p == 0 {
  1426. // if f == nil {
  1427. // return 0
  1428. // }
  1429. //
  1430. // if compar != 0 {
  1431. // panic(todo(""))
  1432. // }
  1433. //
  1434. // return addObject(f)
  1435. // }
  1436. //
  1437. // walk(GoString(p))
  1438. // path_argv += unsafe.Sizeof(uintptr(0))
  1439. // }
  1440. }
  1441. // FTSENT *fts_read(FTS *ftsp);
  1442. func Xfts_read(t *TLS, ftsp uintptr) uintptr {
  1443. if __ccgo_strace {
  1444. trc("t=%v ftsp=%v, (%v:)", t, ftsp, origin(2))
  1445. }
  1446. return Xfts64_read(t, ftsp)
  1447. }
  1448. // FTSENT *fts_read(FTS *ftsp);
  1449. func Xfts64_read(t *TLS, ftsp uintptr) uintptr {
  1450. if __ccgo_strace {
  1451. trc("t=%v ftsp=%v, (%v:)", t, ftsp, origin(2))
  1452. }
  1453. panic(todo(""))
  1454. // f := winGetObject(ftsp).(*ftstream)
  1455. // if f.x == len(f.s) {
  1456. // t.setErrno(0)
  1457. // return 0
  1458. // }
  1459. //
  1460. // r := f.s[f.x]
  1461. // if e := (*fts.FTSENT)(unsafe.Pointer(r)).Ffts_errno; e != 0 {
  1462. // t.setErrno(e)
  1463. // }
  1464. // f.x++
  1465. // return r
  1466. }
  1467. // int fts_close(FTS *ftsp);
  1468. func Xfts_close(t *TLS, ftsp uintptr) int32 {
  1469. if __ccgo_strace {
  1470. trc("t=%v ftsp=%v, (%v:)", t, ftsp, origin(2))
  1471. }
  1472. return Xfts64_close(t, ftsp)
  1473. }
  1474. // int fts_close(FTS *ftsp);
  1475. func Xfts64_close(t *TLS, ftsp uintptr) int32 {
  1476. if __ccgo_strace {
  1477. trc("t=%v ftsp=%v, (%v:)", t, ftsp, origin(2))
  1478. }
  1479. panic(todo(""))
  1480. // winGetObject(ftsp).(*ftstream).close(t)
  1481. // removeObject(ftsp)
  1482. // return 0
  1483. }
  1484. // void tzset (void);
  1485. func Xtzset(t *TLS) {
  1486. if __ccgo_strace {
  1487. trc("t=%v, (%v:)", t, origin(2))
  1488. }
  1489. //TODO
  1490. }
  1491. var strerrorBuf [256]byte
  1492. // char *strerror(int errnum);
  1493. func Xstrerror(t *TLS, errnum int32) uintptr {
  1494. if __ccgo_strace {
  1495. trc("t=%v errnum=%v, (%v:)", t, errnum, origin(2))
  1496. }
  1497. copy((*RawMem)(unsafe.Pointer(&strerrorBuf[0]))[:len(strerrorBuf):len(strerrorBuf)], fmt.Sprintf("errno %d\x00", errnum))
  1498. return uintptr(unsafe.Pointer(&strerrorBuf[0]))
  1499. }
  1500. // void *dlopen(const char *filename, int flags);
  1501. func Xdlopen(t *TLS, filename uintptr, flags int32) uintptr {
  1502. if __ccgo_strace {
  1503. trc("t=%v filename=%v flags=%v, (%v:)", t, filename, flags, origin(2))
  1504. }
  1505. panic(todo(""))
  1506. }
  1507. // char *dlerror(void);
  1508. func Xdlerror(t *TLS) uintptr {
  1509. if __ccgo_strace {
  1510. trc("t=%v, (%v:)", t, origin(2))
  1511. }
  1512. panic(todo(""))
  1513. }
  1514. // int dlclose(void *handle);
  1515. func Xdlclose(t *TLS, handle uintptr) int32 {
  1516. if __ccgo_strace {
  1517. trc("t=%v handle=%v, (%v:)", t, handle, origin(2))
  1518. }
  1519. panic(todo(""))
  1520. }
  1521. // void *dlsym(void *handle, const char *symbol);
  1522. func Xdlsym(t *TLS, handle, symbol uintptr) uintptr {
  1523. if __ccgo_strace {
  1524. trc("t=%v symbol=%v, (%v:)", t, symbol, origin(2))
  1525. }
  1526. panic(todo(""))
  1527. }
  1528. // void perror(const char *s);
  1529. func Xperror(t *TLS, s uintptr) {
  1530. if __ccgo_strace {
  1531. trc("t=%v s=%v, (%v:)", t, s, origin(2))
  1532. }
  1533. panic(todo(""))
  1534. }
  1535. // int pclose(FILE *stream);
  1536. func Xpclose(t *TLS, stream uintptr) int32 {
  1537. if __ccgo_strace {
  1538. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  1539. }
  1540. panic(todo(""))
  1541. }
  1542. var gai_strerrorBuf [100]byte
  1543. // const char *gai_strerror(int errcode);
  1544. func Xgai_strerror(t *TLS, errcode int32) uintptr {
  1545. if __ccgo_strace {
  1546. trc("t=%v errcode=%v, (%v:)", t, errcode, origin(2))
  1547. }
  1548. copy(gai_strerrorBuf[:], fmt.Sprintf("gai error %d\x00", errcode))
  1549. return uintptr(unsafe.Pointer(&gai_strerrorBuf))
  1550. }
  1551. // int tcgetattr(int fd, struct termios *termios_p);
  1552. func Xtcgetattr(t *TLS, fd int32, termios_p uintptr) int32 {
  1553. if __ccgo_strace {
  1554. trc("t=%v fd=%v termios_p=%v, (%v:)", t, fd, termios_p, origin(2))
  1555. }
  1556. panic(todo(""))
  1557. }
  1558. // int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);
  1559. func Xtcsetattr(t *TLS, fd, optional_actions int32, termios_p uintptr) int32 {
  1560. if __ccgo_strace {
  1561. trc("t=%v optional_actions=%v termios_p=%v, (%v:)", t, optional_actions, termios_p, origin(2))
  1562. }
  1563. panic(todo(""))
  1564. }
  1565. // // speed_t cfgetospeed(const struct termios *termios_p);
  1566. // func Xcfgetospeed(t *TLS, termios_p uintptr) termios.Speed_t {
  1567. // panic(todo(""))
  1568. // }
  1569. // int cfsetospeed(struct termios *termios_p, speed_t speed);
  1570. func Xcfsetospeed(t *TLS, termios_p uintptr, speed uint32) int32 {
  1571. if __ccgo_strace {
  1572. trc("t=%v termios_p=%v speed=%v, (%v:)", t, termios_p, speed, origin(2))
  1573. }
  1574. panic(todo(""))
  1575. }
  1576. // int cfsetispeed(struct termios *termios_p, speed_t speed);
  1577. func Xcfsetispeed(t *TLS, termios_p uintptr, speed uint32) int32 {
  1578. if __ccgo_strace {
  1579. trc("t=%v termios_p=%v speed=%v, (%v:)", t, termios_p, speed, origin(2))
  1580. }
  1581. panic(todo(""))
  1582. }
  1583. // pid_t fork(void);
  1584. func Xfork(t *TLS) int32 {
  1585. if __ccgo_strace {
  1586. trc("t=%v, (%v:)", t, origin(2))
  1587. }
  1588. t.setErrno(errno.ENOSYS)
  1589. return -1
  1590. }
  1591. // char *setlocale(int category, const char *locale);
  1592. func Xsetlocale(t *TLS, category int32, locale uintptr) uintptr {
  1593. if __ccgo_strace {
  1594. trc("t=%v category=%v locale=%v, (%v:)", t, category, locale, origin(2))
  1595. }
  1596. return 0 //TODO
  1597. }
  1598. // // char *nl_langinfo(nl_item item);
  1599. // func Xnl_langinfo(t *TLS, item langinfo.Nl_item) uintptr {
  1600. // panic(todo(""))
  1601. // }
  1602. // FILE *popen(const char *command, const char *type);
  1603. func Xpopen(t *TLS, command, type1 uintptr) uintptr {
  1604. if __ccgo_strace {
  1605. trc("t=%v type1=%v, (%v:)", t, type1, origin(2))
  1606. }
  1607. panic(todo(""))
  1608. }
  1609. // char *realpath(const char *path, char *resolved_path);
  1610. func Xrealpath(t *TLS, path, resolved_path uintptr) uintptr {
  1611. if __ccgo_strace {
  1612. trc("t=%v resolved_path=%v, (%v:)", t, resolved_path, origin(2))
  1613. }
  1614. s, err := filepath.EvalSymlinks(GoString(path))
  1615. if err != nil {
  1616. if os.IsNotExist(err) {
  1617. if dmesgs {
  1618. dmesg("%v: %q: %v", origin(1), GoString(path), err)
  1619. }
  1620. t.setErrno(errno.ENOENT)
  1621. return 0
  1622. }
  1623. panic(todo("", err))
  1624. }
  1625. if resolved_path == 0 {
  1626. panic(todo(""))
  1627. }
  1628. if len(s) >= limits.PATH_MAX {
  1629. s = s[:limits.PATH_MAX-1]
  1630. }
  1631. copy((*RawMem)(unsafe.Pointer(resolved_path))[:len(s):len(s)], s)
  1632. (*RawMem)(unsafe.Pointer(resolved_path))[len(s)] = 0
  1633. return resolved_path
  1634. }
  1635. // // char *inet_ntoa(struct in_addr in);
  1636. // func Xinet_ntoa(t *TLS, in1 in.In_addr) uintptr {
  1637. // panic(todo(""))
  1638. // }
  1639. // func X__ccgo_in6addr_anyp(t *TLS) uintptr {
  1640. // return uintptr(unsafe.Pointer(&in6_addr_any))
  1641. // }
  1642. func Xabort(t *TLS) {
  1643. if __ccgo_strace {
  1644. trc("t=%v, (%v:)", t, origin(2))
  1645. }
  1646. panic(todo(""))
  1647. // if dmesgs {
  1648. // dmesg("%v:\n%s", origin(1), debug.Stack())
  1649. // }
  1650. // p := Xmalloc(t, types.Size_t(unsafe.Sizeof(signal.Sigaction{})))
  1651. // if p == 0 {
  1652. // panic("OOM")
  1653. // }
  1654. //
  1655. // *(*signal.Sigaction)(unsafe.Pointer(p)) = signal.Sigaction{
  1656. // F__sigaction_handler: struct{ Fsa_handler signal.X__sighandler_t }{Fsa_handler: signal.SIG_DFL},
  1657. // }
  1658. // Xsigaction(t, signal.SIGABRT, p, 0)
  1659. // Xfree(t, p)
  1660. // unix.Kill(unix.Getpid(), windows.Signal(signal.SIGABRT))
  1661. // panic(todo("unrechable"))
  1662. }
  1663. // int fflush(FILE *stream);
  1664. func Xfflush(t *TLS, stream uintptr) int32 {
  1665. if __ccgo_strace {
  1666. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  1667. }
  1668. f, ok := winGetObject(stream).(*file)
  1669. if !ok {
  1670. t.setErrno(errno.EBADF)
  1671. return -1
  1672. }
  1673. err := windows.FlushFileBuffers(f.Handle)
  1674. if err != nil {
  1675. t.setErrno(err)
  1676. return -1
  1677. }
  1678. return 0
  1679. }
  1680. // size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
  1681. func Xfread(t *TLS, ptr uintptr, size, nmemb types.Size_t, stream uintptr) types.Size_t {
  1682. if __ccgo_strace {
  1683. trc("t=%v ptr=%v nmemb=%v stream=%v, (%v:)", t, ptr, nmemb, stream, origin(2))
  1684. }
  1685. f, ok := winGetObject(stream).(*file)
  1686. if !ok {
  1687. t.setErrno(errno.EBADF)
  1688. return 0
  1689. }
  1690. var sz = size * nmemb
  1691. var obuf = ((*RawMem)(unsafe.Pointer(ptr)))[:sz]
  1692. n, err := windows.Read(f.Handle, obuf)
  1693. if err != nil {
  1694. f.setErr()
  1695. return 0
  1696. }
  1697. if dmesgs {
  1698. // dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), file(stream).fd(), size, nmemb, types.Size_t(m)/size, hex.Dump(GoBytes(ptr, int(m))))
  1699. dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), f._fd, size, nmemb, types.Size_t(n)/size)
  1700. }
  1701. return types.Size_t(n) / size
  1702. }
  1703. // size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
  1704. func Xfwrite(t *TLS, ptr uintptr, size, nmemb types.Size_t, stream uintptr) types.Size_t {
  1705. if __ccgo_strace {
  1706. trc("t=%v ptr=%v nmemb=%v stream=%v, (%v:)", t, ptr, nmemb, stream, origin(2))
  1707. }
  1708. if ptr == 0 || size == 0 {
  1709. return 0
  1710. }
  1711. f, ok := winGetObject(stream).(*file)
  1712. if !ok {
  1713. t.setErrno(errno.EBADF)
  1714. return 0
  1715. }
  1716. var sz = size * nmemb
  1717. var obuf = ((*RawMem)(unsafe.Pointer(ptr)))[:sz]
  1718. n, err := windows.Write(f.Handle, obuf)
  1719. if err != nil {
  1720. f.setErr()
  1721. return 0
  1722. }
  1723. if dmesgs {
  1724. // // dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), file(stream).fd(), size, nmemb, types.Size_t(m)/size, hex.Dump(GoBytes(ptr, int(m))))
  1725. dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), f._fd, size, nmemb, types.Size_t(n)/size)
  1726. }
  1727. return types.Size_t(n) / size
  1728. }
  1729. // int fclose(FILE *stream);
  1730. func Xfclose(t *TLS, stream uintptr) int32 {
  1731. if __ccgo_strace {
  1732. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  1733. }
  1734. f, ok := winGetObject(stream).(*file)
  1735. if !ok {
  1736. t.setErrno(errno.EBADF)
  1737. return -1
  1738. }
  1739. return f.close(t)
  1740. }
  1741. // int fputc(int c, FILE *stream);
  1742. func Xfputc(t *TLS, c int32, stream uintptr) int32 {
  1743. if __ccgo_strace {
  1744. trc("t=%v c=%v stream=%v, (%v:)", t, c, stream, origin(2))
  1745. }
  1746. f, ok := winGetObject(stream).(*file)
  1747. if !ok {
  1748. t.setErrno(errno.EBADF)
  1749. return -1
  1750. }
  1751. if _, err := fwrite(f._fd, []byte{byte(c)}); err != nil {
  1752. return -1
  1753. }
  1754. return int32(byte(c))
  1755. }
  1756. // int fseek(FILE *stream, long offset, int whence);
  1757. func Xfseek(t *TLS, stream uintptr, offset long, whence int32) int32 {
  1758. if __ccgo_strace {
  1759. trc("t=%v stream=%v offset=%v whence=%v, (%v:)", t, stream, offset, whence, origin(2))
  1760. }
  1761. f, ok := winGetObject(stream).(*file)
  1762. if !ok {
  1763. t.setErrno(errno.EBADF)
  1764. return -1
  1765. }
  1766. if n := Xlseek(t, f._fd, types.Off_t(offset), whence); n < 0 {
  1767. if dmesgs {
  1768. dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
  1769. }
  1770. f.setErr()
  1771. return -1
  1772. }
  1773. if dmesgs {
  1774. dmesg("%v: fd %v, off %#x, whence %v: ok", origin(1), f._fd, offset, whenceStr(whence))
  1775. }
  1776. return 0
  1777. }
  1778. // long ftell(FILE *stream);
  1779. func Xftell(t *TLS, stream uintptr) long {
  1780. if __ccgo_strace {
  1781. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  1782. }
  1783. f, ok := winGetObject(stream).(*file)
  1784. if !ok {
  1785. t.setErrno(errno.EBADF)
  1786. return -1
  1787. }
  1788. n := Xlseek(t, f._fd, 0, windows.FILE_CURRENT)
  1789. if n < 0 {
  1790. f.setErr()
  1791. return -1
  1792. }
  1793. if dmesgs {
  1794. dmesg("%v: fd %v, n %#x: ok %#x", origin(1), f._fd, n, long(n))
  1795. }
  1796. return long(n)
  1797. }
  1798. // int ferror(FILE *stream);
  1799. func Xferror(t *TLS, stream uintptr) int32 {
  1800. if __ccgo_strace {
  1801. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  1802. }
  1803. f, ok := winGetObject(stream).(*file)
  1804. if !ok {
  1805. t.setErrno(errno.EBADF)
  1806. return -1
  1807. }
  1808. return Bool32(f.err())
  1809. }
  1810. // int getc(FILE *stream);
  1811. func Xfgetc(t *TLS, stream uintptr) int32 {
  1812. if __ccgo_strace {
  1813. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  1814. }
  1815. f, ok := winGetObject(stream).(*file)
  1816. if !ok {
  1817. t.setErrno(errno.EBADF)
  1818. return stdio.EOF
  1819. }
  1820. var buf [1]byte
  1821. if n, _ := windows.Read(f.Handle, buf[:]); n != 0 {
  1822. return int32(buf[0])
  1823. }
  1824. return stdio.EOF
  1825. }
  1826. // int ungetc(int c, FILE *stream);
  1827. func Xungetc(t *TLS, c int32, stream uintptr) int32 {
  1828. if __ccgo_strace {
  1829. trc("t=%v c=%v stream=%v, (%v:)", t, c, stream, origin(2))
  1830. }
  1831. panic(todo(""))
  1832. }
  1833. // int fscanf(FILE *stream, const char *format, ...);
  1834. func Xfscanf(t *TLS, stream, format, va uintptr) int32 {
  1835. if __ccgo_strace {
  1836. trc("t=%v va=%v, (%v:)", t, va, origin(2))
  1837. }
  1838. panic(todo(""))
  1839. }
  1840. // int fputs(const char *s, FILE *stream);
  1841. func Xfputs(t *TLS, s, stream uintptr) int32 {
  1842. if __ccgo_strace {
  1843. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  1844. }
  1845. f, ok := winGetObject(stream).(*file)
  1846. if !ok {
  1847. t.setErrno(errno.EBADF)
  1848. return -1
  1849. }
  1850. gS := GoString(s)
  1851. if _, err := fwrite(f._fd, []byte(gS)); err != nil {
  1852. return -1
  1853. }
  1854. return 0
  1855. }
  1856. // var getservbynameStaticResult netdb.Servent
  1857. //
  1858. // // struct servent *getservbyname(const char *name, const char *proto);
  1859. // func Xgetservbyname(t *TLS, name, proto uintptr) uintptr {
  1860. // var protoent *gonetdb.Protoent
  1861. // if proto != 0 {
  1862. // protoent = gonetdb.GetProtoByName(GoString(proto))
  1863. // }
  1864. // servent := gonetdb.GetServByName(GoString(name), protoent)
  1865. // if servent == nil {
  1866. // if dmesgs {
  1867. // dmesg("%q %q: nil (protoent %+v)", GoString(name), GoString(proto), protoent)
  1868. // }
  1869. // return 0
  1870. // }
  1871. //
  1872. // Xfree(t, (*netdb.Servent)(unsafe.Pointer(&getservbynameStaticResult)).Fs_name)
  1873. // if v := (*netdb.Servent)(unsafe.Pointer(&getservbynameStaticResult)).Fs_aliases; v != 0 {
  1874. // for {
  1875. // p := *(*uintptr)(unsafe.Pointer(v))
  1876. // if p == 0 {
  1877. // break
  1878. // }
  1879. //
  1880. // Xfree(t, p)
  1881. // v += unsafe.Sizeof(uintptr(0))
  1882. // }
  1883. // Xfree(t, v)
  1884. // }
  1885. // Xfree(t, (*netdb.Servent)(unsafe.Pointer(&getservbynameStaticResult)).Fs_proto)
  1886. // cname, err := CString(servent.Name)
  1887. // if err != nil {
  1888. // getservbynameStaticResult = netdb.Servent{}
  1889. // return 0
  1890. // }
  1891. //
  1892. // var protoname uintptr
  1893. // if protoent != nil {
  1894. // if protoname, err = CString(protoent.Name); err != nil {
  1895. // Xfree(t, cname)
  1896. // getservbynameStaticResult = netdb.Servent{}
  1897. // return 0
  1898. // }
  1899. // }
  1900. // var a []uintptr
  1901. // for _, v := range servent.Aliases {
  1902. // cs, err := CString(v)
  1903. // if err != nil {
  1904. // for _, v := range a {
  1905. // Xfree(t, v)
  1906. // }
  1907. // return 0
  1908. // }
  1909. //
  1910. // a = append(a, cs)
  1911. // }
  1912. // v := Xcalloc(t, types.Size_t(len(a)+1), types.Size_t(unsafe.Sizeof(uintptr(0))))
  1913. // if v == 0 {
  1914. // Xfree(t, cname)
  1915. // Xfree(t, protoname)
  1916. // for _, v := range a {
  1917. // Xfree(t, v)
  1918. // }
  1919. // getservbynameStaticResult = netdb.Servent{}
  1920. // return 0
  1921. // }
  1922. // for _, p := range a {
  1923. // *(*uintptr)(unsafe.Pointer(v)) = p
  1924. // v += unsafe.Sizeof(uintptr(0))
  1925. // }
  1926. //
  1927. // getservbynameStaticResult = netdb.Servent{
  1928. // Fs_name: cname,
  1929. // Fs_aliases: v,
  1930. // Fs_port: int32(servent.Port),
  1931. // Fs_proto: protoname,
  1932. // }
  1933. // return uintptr(unsafe.Pointer(&getservbynameStaticResult))
  1934. // }
  1935. // func Xreaddir64(t *TLS, dir uintptr) uintptr {
  1936. // return Xreaddir(t, dir)
  1937. // }
  1938. // func fcntlCmdStr(cmd int32) string {
  1939. // switch cmd {
  1940. // case fcntl.F_GETOWN:
  1941. // return "F_GETOWN"
  1942. // case fcntl.F_SETLK:
  1943. // return "F_SETLK"
  1944. // case fcntl.F_GETLK:
  1945. // return "F_GETLK"
  1946. // case fcntl.F_SETFD:
  1947. // return "F_SETFD"
  1948. // case fcntl.F_GETFD:
  1949. // return "F_GETFD"
  1950. // default:
  1951. // return fmt.Sprintf("cmd(%d)", cmd)
  1952. // }
  1953. // }
  1954. // _CRTIMP extern int *__cdecl _errno(void); // /usr/share/mingw-w64/include/errno.h:17:
  1955. func X_errno(t *TLS) uintptr {
  1956. if __ccgo_strace {
  1957. trc("t=%v, (%v:)", t, origin(2))
  1958. }
  1959. return t.errnop
  1960. }
  1961. // int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg);
  1962. func X__ms_vfscanf(t *TLS, stream, format, ap uintptr) int32 {
  1963. if __ccgo_strace {
  1964. trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
  1965. }
  1966. panic(todo(""))
  1967. }
  1968. // int vsscanf(const char *str, const char *format, va_list ap);
  1969. func X__ms_vsscanf(t *TLS, str, format, ap uintptr) int32 {
  1970. if __ccgo_strace {
  1971. trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
  1972. }
  1973. panic(todo(""))
  1974. }
  1975. // int vscanf(const char *format, va_list ap);
  1976. func X__ms_vscanf(t *TLS, format, ap uintptr) int32 {
  1977. if __ccgo_strace {
  1978. trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
  1979. }
  1980. panic(todo(""))
  1981. }
  1982. // int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  1983. func X__ms_vsnprintf(t *TLS, str uintptr, size types.Size_t, format, ap uintptr) int32 {
  1984. if __ccgo_strace {
  1985. trc("t=%v str=%v size=%v ap=%v, (%v:)", t, str, size, ap, origin(2))
  1986. }
  1987. return Xvsnprintf(t, str, size, format, ap)
  1988. }
  1989. // int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr;);
  1990. func X__ms_vfwscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
  1991. if __ccgo_strace {
  1992. trc("t=%v stream=%v ap=%v, (%v:)", t, stream, ap, origin(2))
  1993. }
  1994. panic(todo(""))
  1995. }
  1996. // int vwscanf(const wchar_t * restrict format, va_list arg);
  1997. func X__ms_vwscanf(t *TLS, format, ap uintptr) int32 {
  1998. if __ccgo_strace {
  1999. trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
  2000. }
  2001. panic(todo(""))
  2002. }
  2003. // int _vsnwprintf(wchar_t *buffer, size_t count, const wchar_t *format, va_list argptr);
  2004. func X_vsnwprintf(t *TLS, buffer uintptr, count types.Size_t, format, ap uintptr) int32 {
  2005. if __ccgo_strace {
  2006. trc("t=%v buffer=%v count=%v ap=%v, (%v:)", t, buffer, count, ap, origin(2))
  2007. }
  2008. panic(todo(""))
  2009. }
  2010. // int vswscanf(const wchar_t *buffer, const wchar_t *format, va_list arglist);
  2011. func X__ms_vswscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
  2012. if __ccgo_strace {
  2013. trc("t=%v stream=%v ap=%v, (%v:)", t, stream, ap, origin(2))
  2014. }
  2015. panic(todo(""))
  2016. }
  2017. // __acrt_iob_func
  2018. func X__acrt_iob_func(t *TLS, fd uint32) uintptr {
  2019. if __ccgo_strace {
  2020. trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
  2021. }
  2022. f, ok := fdToFile(int32(fd))
  2023. if !ok {
  2024. t.setErrno(EBADF)
  2025. return 0
  2026. }
  2027. return f.t
  2028. }
  2029. // BOOL SetEvent(
  2030. //
  2031. // HANDLE hEvent
  2032. //
  2033. // );
  2034. func XSetEvent(t *TLS, hEvent uintptr) int32 {
  2035. if __ccgo_strace {
  2036. trc("t=%v hEvent=%v, (%v:)", t, hEvent, origin(2))
  2037. }
  2038. r0, _, err := procSetEvent.Call(hEvent, 0, 0)
  2039. if r0 == 0 {
  2040. t.setErrno(err)
  2041. }
  2042. return int32(r0)
  2043. }
  2044. // int _stricmp(
  2045. //
  2046. // const char *string1,
  2047. // const char *string2
  2048. //
  2049. // );
  2050. func X_stricmp(t *TLS, string1, string2 uintptr) int32 {
  2051. if __ccgo_strace {
  2052. trc("t=%v string2=%v, (%v:)", t, string2, origin(2))
  2053. }
  2054. var s1 = strings.ToLower(GoString(string1))
  2055. var s2 = strings.ToLower(GoString(string2))
  2056. return int32(strings.Compare(s1, s2))
  2057. }
  2058. // BOOL HeapFree(
  2059. //
  2060. // HANDLE hHeap,
  2061. // DWORD dwFlags,
  2062. // _Frees_ptr_opt_ LPVOID lpMem
  2063. //
  2064. // );
  2065. func XHeapFree(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) int32 {
  2066. if __ccgo_strace {
  2067. trc("t=%v hHeap=%v dwFlags=%v lpMem=%v, (%v:)", t, hHeap, dwFlags, lpMem, origin(2))
  2068. }
  2069. r0, _, err := procHeapFree.Call(hHeap, uintptr(dwFlags), lpMem)
  2070. if err != windows.NOERROR {
  2071. t.setErrno(err)
  2072. }
  2073. return int32(r0)
  2074. }
  2075. // HANDLE GetProcessHeap();
  2076. func XGetProcessHeap(t *TLS) uintptr {
  2077. if __ccgo_strace {
  2078. trc("t=%v, (%v:)", t, origin(2))
  2079. }
  2080. r0, _, err := procGetProcessHeap.Call(0, 0, 0)
  2081. if r0 == 0 {
  2082. t.setErrno(err)
  2083. }
  2084. return r0
  2085. }
  2086. // LPVOID HeapAlloc(
  2087. //
  2088. // HANDLE hHeap,
  2089. // DWORD dwFlags,
  2090. // SIZE_T dwBytes
  2091. //
  2092. // );
  2093. func XHeapAlloc(t *TLS, hHeap uintptr, dwFlags uint32, dwBytes types.Size_t) uintptr {
  2094. if __ccgo_strace {
  2095. trc("t=%v hHeap=%v dwFlags=%v dwBytes=%v, (%v:)", t, hHeap, dwFlags, dwBytes, origin(2))
  2096. }
  2097. r0, _, err := procHeapAlloc.Call(hHeap, uintptr(dwFlags), uintptr(dwBytes))
  2098. if r0 == 0 {
  2099. t.setErrno(err)
  2100. }
  2101. return r0
  2102. }
  2103. // WCHAR * gai_strerrorW(
  2104. //
  2105. // int ecode
  2106. //
  2107. // );
  2108. func Xgai_strerrorW(t *TLS, _ ...interface{}) uintptr {
  2109. panic(todo(""))
  2110. }
  2111. // servent * getservbyname(
  2112. //
  2113. // const char *name,
  2114. // const char *proto
  2115. //
  2116. // );
  2117. func Xgetservbyname(t *TLS, _ ...interface{}) uintptr {
  2118. panic(todo(""))
  2119. }
  2120. // INT WSAAPI getaddrinfo(
  2121. //
  2122. // PCSTR pNodeName,
  2123. // PCSTR pServiceName,
  2124. // const ADDRINFOA *pHints,
  2125. // PADDRINFOA *ppResult
  2126. //
  2127. // );
  2128. func XWspiapiGetAddrInfo(t *TLS, _ ...interface{}) int32 {
  2129. panic(todo(""))
  2130. }
  2131. // int wcscmp(
  2132. //
  2133. // const wchar_t *string1,
  2134. // const wchar_t *string2
  2135. //
  2136. // );
  2137. func Xwcscmp(t *TLS, string1, string2 uintptr) int32 {
  2138. if __ccgo_strace {
  2139. trc("t=%v string2=%v, (%v:)", t, string2, origin(2))
  2140. }
  2141. var s1 = goWideString(string1)
  2142. var s2 = goWideString(string2)
  2143. return int32(strings.Compare(s1, s2))
  2144. }
  2145. // BOOL IsDebuggerPresent();
  2146. func XIsDebuggerPresent(t *TLS) int32 {
  2147. if __ccgo_strace {
  2148. trc("t=%v, (%v:)", t, origin(2))
  2149. }
  2150. return 0
  2151. }
  2152. func XExitProcess(t *TLS, _ ...interface{}) int32 {
  2153. panic(todo(""))
  2154. }
  2155. // BOOL GetVersionExW(
  2156. //
  2157. // LPOSVERSIONINFOW lpVersionInformation
  2158. //
  2159. // );
  2160. func XGetVersionExW(t *TLS, lpVersionInformation uintptr) int32 {
  2161. if __ccgo_strace {
  2162. trc("t=%v lpVersionInformation=%v, (%v:)", t, lpVersionInformation, origin(2))
  2163. }
  2164. r0, _, err := procGetVersionExW.Call(lpVersionInformation, 0, 0)
  2165. if r0 == 0 {
  2166. t.setErrno(err)
  2167. }
  2168. return int32(r0)
  2169. }
  2170. // BOOL GetVolumeNameForVolumeMountPointW(
  2171. //
  2172. // LPCWSTR lpszVolumeMountPoint,
  2173. // LPWSTR lpszVolumeName,
  2174. // DWORD cchBufferLength
  2175. //
  2176. // );
  2177. func XGetVolumeNameForVolumeMountPointW(t *TLS, _ ...interface{}) int32 {
  2178. panic(todo(""))
  2179. }
  2180. // size_t wcslen(
  2181. //
  2182. // const wchar_t *str
  2183. //
  2184. // );
  2185. func Xwcslen(t *TLS, str uintptr) types.Size_t {
  2186. if __ccgo_strace {
  2187. trc("t=%v str=%v, (%v:)", t, str, origin(2))
  2188. }
  2189. r0, _, _ := procLstrlenW.Call(str, 0, 0)
  2190. return types.Size_t(r0)
  2191. }
  2192. // HANDLE WINAPI GetStdHandle(
  2193. //
  2194. // _In_ DWORD nStdHandle
  2195. //
  2196. // );
  2197. func XGetStdHandle(t *TLS, nStdHandle uint32) uintptr {
  2198. if __ccgo_strace {
  2199. trc("t=%v nStdHandle=%v, (%v:)", t, nStdHandle, origin(2))
  2200. }
  2201. h, err := windows.GetStdHandle(nStdHandle)
  2202. if err != nil {
  2203. panic("no console")
  2204. }
  2205. return uintptr(h)
  2206. }
  2207. // BOOL CloseHandle(
  2208. //
  2209. // HANDLE hObject
  2210. //
  2211. // );
  2212. func XCloseHandle(t *TLS, hObject uintptr) int32 {
  2213. if __ccgo_strace {
  2214. trc("t=%v hObject=%v, (%v:)", t, hObject, origin(2))
  2215. }
  2216. r := windows.CloseHandle(windows.Handle(hObject))
  2217. if r != nil {
  2218. return errno.EINVAL
  2219. }
  2220. return 1
  2221. }
  2222. // DWORD GetLastError();
  2223. func XGetLastError(t *TLS) uint32 {
  2224. if __ccgo_strace {
  2225. trc("t=%v, (%v:)", t, origin(2))
  2226. }
  2227. var rv = *(*int32)(unsafe.Pointer(t.errnop))
  2228. return uint32(rv)
  2229. //r1, _, _ := procGetLastError.Call(0, 0, 0)
  2230. //return uint32(r1)
  2231. }
  2232. // DWORD SetFilePointer(
  2233. //
  2234. // HANDLE hFile,
  2235. // LONG lDistanceToMove,
  2236. // PLONG lpDistanceToMoveHigh,
  2237. // DWORD dwMoveMethod
  2238. //
  2239. // );
  2240. func XSetFilePointer(t *TLS, hFile uintptr, lDistanceToMove long, lpDistanceToMoveHigh uintptr, dwMoveMethod uint32) uint32 {
  2241. if __ccgo_strace {
  2242. trc("t=%v hFile=%v lDistanceToMove=%v lpDistanceToMoveHigh=%v dwMoveMethod=%v, (%v:)", t, hFile, lDistanceToMove, lpDistanceToMoveHigh, dwMoveMethod, origin(2))
  2243. }
  2244. r0, _, e1 := procSetFilePointer.Call(hFile, uintptr(lDistanceToMove), lpDistanceToMoveHigh, uintptr(dwMoveMethod), 0, 0)
  2245. var uOff = uint32(r0)
  2246. if uOff == 0xffffffff {
  2247. if e1 != windows.NOERROR {
  2248. t.setErrno(e1)
  2249. } else {
  2250. t.setErrno(errno.EINVAL)
  2251. }
  2252. }
  2253. return uint32(r0)
  2254. }
  2255. // BOOL SetEndOfFile(
  2256. //
  2257. // HANDLE hFile
  2258. //
  2259. // );
  2260. func XSetEndOfFile(t *TLS, hFile uintptr) int32 {
  2261. if __ccgo_strace {
  2262. trc("t=%v hFile=%v, (%v:)", t, hFile, origin(2))
  2263. }
  2264. err := windows.SetEndOfFile(windows.Handle(hFile))
  2265. if err != nil {
  2266. t.setErrno(err)
  2267. return 0
  2268. }
  2269. return 1
  2270. }
  2271. // BOOL ReadFile(
  2272. //
  2273. // HANDLE hFile,
  2274. // LPVOID lpBuffer,
  2275. // DWORD nNumberOfBytesToRead,
  2276. // LPDWORD lpNumberOfBytesRead,
  2277. // LPOVERLAPPED lpOverlapped
  2278. //
  2279. // );
  2280. func XReadFile(t *TLS, hFile, lpBuffer uintptr, nNumberOfBytesToRead uint32, lpNumberOfBytesRead, lpOverlapped uintptr) int32 {
  2281. if __ccgo_strace {
  2282. trc("t=%v lpBuffer=%v nNumberOfBytesToRead=%v lpOverlapped=%v, (%v:)", t, lpBuffer, nNumberOfBytesToRead, lpOverlapped, origin(2))
  2283. }
  2284. r1, _, e1 := procReadFile.Call(hFile, lpBuffer, uintptr(nNumberOfBytesToRead), uintptr(lpNumberOfBytesRead), uintptr(lpOverlapped), 0)
  2285. if r1 == 0 {
  2286. if e1 != windows.NOERROR {
  2287. t.setErrno(e1)
  2288. } else {
  2289. t.setErrno(errno.EINVAL)
  2290. }
  2291. return 0
  2292. }
  2293. return int32(r1)
  2294. }
  2295. // BOOL WriteFile(
  2296. //
  2297. // HANDLE hFile,
  2298. // LPCVOID lpBuffer,
  2299. // DWORD nNumberOfBytesToWrite,
  2300. // LPDWORD lpNumberOfBytesWritten,
  2301. // LPOVERLAPPED lpOverlapped
  2302. //
  2303. // );
  2304. func XWriteFile(t *TLS, hFile, lpBuffer uintptr, nNumberOfBytesToWrite uint32, lpNumberOfBytesWritten, lpOverlapped uintptr) int32 {
  2305. if __ccgo_strace {
  2306. trc("t=%v lpBuffer=%v nNumberOfBytesToWrite=%v lpOverlapped=%v, (%v:)", t, lpBuffer, nNumberOfBytesToWrite, lpOverlapped, origin(2))
  2307. }
  2308. r1, _, e1 := procWriteFile.Call(hFile, lpBuffer, uintptr(nNumberOfBytesToWrite), lpNumberOfBytesWritten, lpOverlapped, 0)
  2309. if r1 == 0 {
  2310. if e1 != windows.NOERROR {
  2311. t.setErrno(e1)
  2312. } else {
  2313. t.setErrno(errno.EINVAL)
  2314. }
  2315. return 0
  2316. }
  2317. return int32(r1)
  2318. }
  2319. // DWORD GetFileAttributesW(
  2320. //
  2321. // LPCWSTR lpFileName
  2322. //
  2323. // );
  2324. func XGetFileAttributesW(t *TLS, lpFileName uintptr) uint32 {
  2325. if __ccgo_strace {
  2326. trc("t=%v lpFileName=%v, (%v:)", t, lpFileName, origin(2))
  2327. }
  2328. attrs, err := windows.GetFileAttributes((*uint16)(unsafe.Pointer(lpFileName)))
  2329. if attrs == windows.INVALID_FILE_ATTRIBUTES {
  2330. if err != nil {
  2331. t.setErrno(err)
  2332. } else {
  2333. t.setErrno(errno.EINVAL)
  2334. }
  2335. }
  2336. return attrs
  2337. }
  2338. // HANDLE CreateFileW(
  2339. //
  2340. // LPCWSTR lpFileName,
  2341. // DWORD dwDesiredAccess,
  2342. // DWORD dwShareMode,
  2343. // LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  2344. // DWORD dwCreationDisposition,
  2345. // DWORD dwFlagsAndAttributes,
  2346. // HANDLE hTemplateFile
  2347. //
  2348. // );
  2349. func XCreateFileW(t *TLS, lpFileName uintptr, dwDesiredAccess, dwShareMode uint32, lpSecurityAttributes uintptr, dwCreationDisposition, dwFlagsAndAttributes uint32, hTemplateFile uintptr) uintptr {
  2350. if __ccgo_strace {
  2351. trc("t=%v lpFileName=%v dwShareMode=%v lpSecurityAttributes=%v dwFlagsAndAttributes=%v hTemplateFile=%v, (%v:)", t, lpFileName, dwShareMode, lpSecurityAttributes, dwFlagsAndAttributes, hTemplateFile, origin(2))
  2352. }
  2353. r0, _, e1 := procCreateFileW.Call(lpFileName, uintptr(dwDesiredAccess), uintptr(dwShareMode), lpSecurityAttributes,
  2354. uintptr(dwCreationDisposition), uintptr(dwFlagsAndAttributes), hTemplateFile, 0, 0)
  2355. h := windows.Handle(r0)
  2356. if h == windows.InvalidHandle {
  2357. if e1 != windows.NOERROR {
  2358. t.setErrno(e1)
  2359. } else {
  2360. t.setErrno(errno.EINVAL)
  2361. }
  2362. return r0
  2363. }
  2364. return uintptr(h)
  2365. }
  2366. // BOOL DuplicateHandle(
  2367. //
  2368. // HANDLE hSourceProcessHandle,
  2369. // HANDLE hSourceHandle,
  2370. // HANDLE hTargetProcessHandle,
  2371. // LPHANDLE lpTargetHandle,
  2372. // DWORD dwDesiredAccess,
  2373. // BOOL bInheritHandle,
  2374. // DWORD dwOptions
  2375. //
  2376. // );
  2377. func XDuplicateHandle(t *TLS, hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle uintptr, dwDesiredAccess uint32, bInheritHandle int32, dwOptions uint32) int32 {
  2378. if __ccgo_strace {
  2379. trc("t=%v lpTargetHandle=%v dwDesiredAccess=%v bInheritHandle=%v dwOptions=%v, (%v:)", t, lpTargetHandle, dwDesiredAccess, bInheritHandle, dwOptions, origin(2))
  2380. }
  2381. r0, _, err := procDuplicateHandle.Call(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle,
  2382. lpTargetHandle, uintptr(dwDesiredAccess), uintptr(bInheritHandle), uintptr(dwOptions), 0, 0)
  2383. if r0 == 0 {
  2384. t.setErrno(err)
  2385. }
  2386. return int32(r0)
  2387. }
  2388. // HANDLE GetCurrentProcess();
  2389. func XGetCurrentProcess(t *TLS) uintptr {
  2390. if __ccgo_strace {
  2391. trc("t=%v, (%v:)", t, origin(2))
  2392. }
  2393. r0, _, e1 := procGetCurrentProcess.Call(0, 0, 0)
  2394. if r0 == 0 {
  2395. if e1 != windows.NOERROR {
  2396. t.setErrno(e1)
  2397. } else {
  2398. t.setErrno(errno.EINVAL)
  2399. }
  2400. }
  2401. return r0
  2402. }
  2403. // BOOL FlushFileBuffers(
  2404. //
  2405. // HANDLE hFile
  2406. //
  2407. // );
  2408. func XFlushFileBuffers(t *TLS, hFile uintptr) int32 {
  2409. if __ccgo_strace {
  2410. trc("t=%v hFile=%v, (%v:)", t, hFile, origin(2))
  2411. }
  2412. err := windows.FlushFileBuffers(windows.Handle(hFile))
  2413. if err != nil {
  2414. t.setErrno(err)
  2415. return -1
  2416. }
  2417. return 1
  2418. }
  2419. // DWORD GetFileType(
  2420. //
  2421. // HANDLE hFile
  2422. //
  2423. // );
  2424. func XGetFileType(t *TLS, hFile uintptr) uint32 {
  2425. if __ccgo_strace {
  2426. trc("t=%v hFile=%v, (%v:)", t, hFile, origin(2))
  2427. }
  2428. n, err := windows.GetFileType(windows.Handle(hFile))
  2429. if err != nil {
  2430. t.setErrno(err)
  2431. }
  2432. return n
  2433. }
  2434. // BOOL WINAPI GetConsoleMode(
  2435. //
  2436. // _In_ HANDLE hConsoleHandle,
  2437. // _Out_ LPDWORD lpMode
  2438. //
  2439. // );
  2440. func XGetConsoleMode(t *TLS, hConsoleHandle, lpMode uintptr) int32 {
  2441. if __ccgo_strace {
  2442. trc("t=%v lpMode=%v, (%v:)", t, lpMode, origin(2))
  2443. }
  2444. err := windows.GetConsoleMode(windows.Handle(hConsoleHandle), (*uint32)(unsafe.Pointer(lpMode)))
  2445. if err != nil {
  2446. t.setErrno(err)
  2447. return 0
  2448. }
  2449. return 1
  2450. }
  2451. // BOOL GetCommState(
  2452. //
  2453. // HANDLE hFile,
  2454. // LPDCB lpDCB
  2455. //
  2456. // );
  2457. func XGetCommState(t *TLS, hFile, lpDCB uintptr) int32 {
  2458. if __ccgo_strace {
  2459. trc("t=%v lpDCB=%v, (%v:)", t, lpDCB, origin(2))
  2460. }
  2461. r1, _, err := procGetCommState.Call(hFile, lpDCB, 0)
  2462. if r1 == 0 {
  2463. t.setErrno(err)
  2464. return 0
  2465. }
  2466. return int32(r1)
  2467. }
  2468. // int _wcsnicmp(
  2469. //
  2470. // const wchar_t *string1,
  2471. // const wchar_t *string2,
  2472. // size_t count
  2473. //
  2474. // );
  2475. func X_wcsnicmp(t *TLS, string1, string2 uintptr, count types.Size_t) int32 {
  2476. if __ccgo_strace {
  2477. trc("t=%v string2=%v count=%v, (%v:)", t, string2, count, origin(2))
  2478. }
  2479. var s1 = strings.ToLower(goWideString(string1))
  2480. var l1 = len(s1)
  2481. var s2 = strings.ToLower(goWideString(string2))
  2482. var l2 = len(s2)
  2483. // shorter is lesser
  2484. if l1 < l2 {
  2485. return -1
  2486. }
  2487. if l2 > l1 {
  2488. return 1
  2489. }
  2490. // compare at most count
  2491. var cmpLen = count
  2492. if types.Size_t(l1) < cmpLen {
  2493. cmpLen = types.Size_t(l1)
  2494. }
  2495. return int32(strings.Compare(s1[:cmpLen], s2[:cmpLen]))
  2496. }
  2497. // BOOL WINAPI ReadConsole(
  2498. //
  2499. // _In_ HANDLE hConsoleInput,
  2500. // _Out_ LPVOID lpBuffer,
  2501. // _In_ DWORD nNumberOfCharsToRead,
  2502. // _Out_ LPDWORD lpNumberOfCharsRead,
  2503. // _In_opt_ LPVOID pInputControl
  2504. //
  2505. // );
  2506. func XReadConsoleW(t *TLS, hConsoleInput, lpBuffer uintptr, nNumberOfCharsToRead uint32, lpNumberOfCharsRead, pInputControl uintptr) int32 {
  2507. if __ccgo_strace {
  2508. trc("t=%v lpBuffer=%v nNumberOfCharsToRead=%v pInputControl=%v, (%v:)", t, lpBuffer, nNumberOfCharsToRead, pInputControl, origin(2))
  2509. }
  2510. rv, _, err := procReadConsoleW.Call(hConsoleInput,
  2511. lpBuffer, uintptr(nNumberOfCharsToRead), lpNumberOfCharsRead, pInputControl, 0)
  2512. if rv == 0 {
  2513. t.setErrno(err)
  2514. }
  2515. return int32(rv)
  2516. }
  2517. // BOOL WINAPI WriteConsoleW(
  2518. //
  2519. // _In_ HANDLE hConsoleOutput,
  2520. // _In_ const VOID *lpBuffer,
  2521. // _In_ DWORD nNumberOfCharsToWrite,
  2522. // _Out_opt_ LPDWORD lpNumberOfCharsWritten,
  2523. // _Reserved_ LPVOID lpReserved
  2524. //
  2525. // );
  2526. func XWriteConsoleW(t *TLS, hConsoleOutput, lpBuffer uintptr, nNumberOfCharsToWrite uint32, lpNumberOfCharsWritten, lpReserved uintptr) int32 {
  2527. if __ccgo_strace {
  2528. trc("t=%v lpBuffer=%v nNumberOfCharsToWrite=%v lpReserved=%v, (%v:)", t, lpBuffer, nNumberOfCharsToWrite, lpReserved, origin(2))
  2529. }
  2530. rv, _, err := procWriteConsoleW.Call(hConsoleOutput,
  2531. lpBuffer, uintptr(nNumberOfCharsToWrite), lpNumberOfCharsWritten, lpReserved, 0)
  2532. if rv == 0 {
  2533. t.setErrno(err)
  2534. }
  2535. return int32(rv)
  2536. }
  2537. // DWORD WaitForSingleObject(
  2538. //
  2539. // HANDLE hHandle,
  2540. // DWORD dwMilliseconds
  2541. //
  2542. // );
  2543. func XWaitForSingleObject(t *TLS, hHandle uintptr, dwMilliseconds uint32) uint32 {
  2544. if __ccgo_strace {
  2545. trc("t=%v hHandle=%v dwMilliseconds=%v, (%v:)", t, hHandle, dwMilliseconds, origin(2))
  2546. }
  2547. rv, err := windows.WaitForSingleObject(windows.Handle(hHandle), dwMilliseconds)
  2548. if err != nil {
  2549. t.setErrno(err)
  2550. }
  2551. return rv
  2552. }
  2553. // BOOL ResetEvent(
  2554. //
  2555. // HANDLE hEvent
  2556. //
  2557. // );
  2558. func XResetEvent(t *TLS, hEvent uintptr) int32 {
  2559. if __ccgo_strace {
  2560. trc("t=%v hEvent=%v, (%v:)", t, hEvent, origin(2))
  2561. }
  2562. rv, _, err := procResetEvent.Call(hEvent, 0, 0)
  2563. if rv == 0 {
  2564. t.setErrno(err)
  2565. }
  2566. return int32(rv)
  2567. }
  2568. // BOOL WINAPI PeekConsoleInput(
  2569. //
  2570. // _In_ HANDLE hConsoleInput,
  2571. // _Out_ PINPUT_RECORD lpBuffer,
  2572. // _In_ DWORD nLength,
  2573. // _Out_ LPDWORD lpNumberOfEventsRead
  2574. //
  2575. // );
  2576. func XPeekConsoleInputW(t *TLS, hConsoleInput, lpBuffer uintptr, nLength uint32, lpNumberOfEventsRead uintptr) int32 {
  2577. if __ccgo_strace {
  2578. trc("t=%v lpBuffer=%v nLength=%v lpNumberOfEventsRead=%v, (%v:)", t, lpBuffer, nLength, lpNumberOfEventsRead, origin(2))
  2579. }
  2580. r0, _, err := procPeekConsoleInputW.Call(hConsoleInput, lpBuffer, uintptr(nLength), lpNumberOfEventsRead, 0, 0)
  2581. if r0 == 0 {
  2582. t.setErrno(err)
  2583. }
  2584. return int32(r0)
  2585. }
  2586. // int WINAPIV wsprintfA(
  2587. //
  2588. // LPSTR ,
  2589. // LPCSTR ,
  2590. // ...
  2591. //
  2592. // );
  2593. func XwsprintfA(t *TLS, buf, format, args uintptr) int32 {
  2594. if __ccgo_strace {
  2595. trc("t=%v args=%v, (%v:)", t, args, origin(2))
  2596. }
  2597. return Xsprintf(t, buf, format, args)
  2598. }
  2599. // UINT WINAPI GetConsoleCP(void);
  2600. func XGetConsoleCP(t *TLS) uint32 {
  2601. if __ccgo_strace {
  2602. trc("t=%v, (%v:)", t, origin(2))
  2603. }
  2604. r0, _, err := procGetConsoleCP.Call(0, 0, 0)
  2605. if r0 == 0 {
  2606. t.setErrno(err)
  2607. }
  2608. return uint32(r0)
  2609. }
  2610. // UINT WINAPI SetConsoleCP(UNIT);
  2611. //func setConsoleCP(cp uint32) uint32 {
  2612. //
  2613. // r0, _, _ := procSetConsoleCP.Call(uintptr(cp), 0, 0)
  2614. // if r0 == 0 {
  2615. // panic("setcp failed")
  2616. // }
  2617. // return uint32(r0)
  2618. //}
  2619. // HANDLE CreateEventW(
  2620. //
  2621. // LPSECURITY_ATTRIBUTES lpEventAttributes,
  2622. // BOOL bManualReset,
  2623. // BOOL bInitialState,
  2624. // LPCWSTR lpName
  2625. //
  2626. // );
  2627. func XCreateEventW(t *TLS, lpEventAttributes uintptr, bManualReset, bInitialState int32, lpName uintptr) uintptr {
  2628. if __ccgo_strace {
  2629. trc("t=%v lpEventAttributes=%v bInitialState=%v lpName=%v, (%v:)", t, lpEventAttributes, bInitialState, lpName, origin(2))
  2630. }
  2631. r0, _, err := procCreateEventW.Call(lpEventAttributes, uintptr(bManualReset),
  2632. uintptr(bInitialState), lpName, 0, 0)
  2633. if r0 == 0 {
  2634. t.setErrno(err)
  2635. }
  2636. return r0
  2637. }
  2638. type ThreadAdapter struct {
  2639. token uintptr
  2640. tls *TLS
  2641. param uintptr
  2642. threadFunc func(*TLS, uintptr) uint32
  2643. }
  2644. func (ta *ThreadAdapter) run() uintptr {
  2645. r := ta.threadFunc(ta.tls, ta.param)
  2646. ta.tls.Close()
  2647. removeObject(ta.token)
  2648. return uintptr(r)
  2649. }
  2650. func ThreadProc(p uintptr) uintptr {
  2651. adp, ok := winGetObject(p).(*ThreadAdapter)
  2652. if !ok {
  2653. panic("invalid thread")
  2654. }
  2655. return adp.run()
  2656. }
  2657. // HANDLE CreateThread(
  2658. //
  2659. // LPSECURITY_ATTRIBUTES lpThreadAttributes,
  2660. // SIZE_T dwStackSize,
  2661. // LPTHREAD_START_ROUTINE lpStartAddress,
  2662. // __drv_aliasesMem LPVOID lpParameter,
  2663. // DWORD dwCreationFlags,
  2664. // LPDWORD lpThreadId
  2665. //
  2666. // );
  2667. func XCreateThread(t *TLS, lpThreadAttributes uintptr, dwStackSize types.Size_t, lpStartAddress, lpParameter uintptr, dwCreationFlags uint32, lpThreadId uintptr) uintptr {
  2668. if __ccgo_strace {
  2669. trc("t=%v lpThreadAttributes=%v dwStackSize=%v lpParameter=%v dwCreationFlags=%v lpThreadId=%v, (%v:)", t, lpThreadAttributes, dwStackSize, lpParameter, dwCreationFlags, lpThreadId, origin(2))
  2670. }
  2671. f := (*struct{ f func(*TLS, uintptr) uint32 })(unsafe.Pointer(&struct{ uintptr }{lpStartAddress})).f
  2672. var tAdp = ThreadAdapter{threadFunc: f, tls: NewTLS(), param: lpParameter}
  2673. tAdp.token = addObject(&tAdp)
  2674. r0, _, err := procCreateThread.Call(lpThreadAttributes, uintptr(dwStackSize),
  2675. threadCallback, tAdp.token, uintptr(dwCreationFlags), lpThreadId)
  2676. if r0 == 0 {
  2677. t.setErrno(err)
  2678. }
  2679. return r0
  2680. }
  2681. // BOOL SetThreadPriority(
  2682. //
  2683. // HANDLE hThread,
  2684. // int nPriority
  2685. //
  2686. // );
  2687. func XSetThreadPriority(t *TLS, hThread uintptr, nPriority int32) int32 {
  2688. if __ccgo_strace {
  2689. trc("t=%v hThread=%v nPriority=%v, (%v:)", t, hThread, nPriority, origin(2))
  2690. }
  2691. //r0, _, err := procSetThreadPriority.Call(hThread, uintptr(nPriority), 0)
  2692. //if r0 == 0 {
  2693. // t.setErrno(err)
  2694. //}
  2695. //return int32(r0)
  2696. return 1
  2697. }
  2698. // BOOL WINAPI SetConsoleMode(
  2699. //
  2700. // _In_ HANDLE hConsoleHandle,
  2701. // _In_ DWORD dwMode
  2702. //
  2703. // );
  2704. func XSetConsoleMode(t *TLS, hConsoleHandle uintptr, dwMode uint32) int32 {
  2705. if __ccgo_strace {
  2706. trc("t=%v hConsoleHandle=%v dwMode=%v, (%v:)", t, hConsoleHandle, dwMode, origin(2))
  2707. }
  2708. rv, _, err := procSetConsoleMode.Call(hConsoleHandle, uintptr(dwMode), 0)
  2709. if rv == 0 {
  2710. t.setErrno(err)
  2711. }
  2712. return int32(rv)
  2713. }
  2714. func XPurgeComm(t *TLS, _ ...interface{}) int32 {
  2715. panic(todo(""))
  2716. }
  2717. func XClearCommError(t *TLS, _ ...interface{}) int32 {
  2718. panic(todo(""))
  2719. }
  2720. // void DeleteCriticalSection(
  2721. //
  2722. // LPCRITICAL_SECTION lpCriticalSection
  2723. //
  2724. // );
  2725. func XDeleteCriticalSection(t *TLS, lpCriticalSection uintptr) {
  2726. if __ccgo_strace {
  2727. trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
  2728. }
  2729. procDeleteCriticalSection.Call(lpCriticalSection, 0, 0)
  2730. }
  2731. // void EnterCriticalSection(
  2732. //
  2733. // LPCRITICAL_SECTION lpCriticalSection
  2734. //
  2735. // );
  2736. func XEnterCriticalSection(t *TLS, lpCriticalSection uintptr) {
  2737. if __ccgo_strace {
  2738. trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
  2739. }
  2740. procEnterCriticalSection.Call(lpCriticalSection, 0, 0)
  2741. }
  2742. // BOOL TryEnterCriticalSection(
  2743. //
  2744. // LPCRITICAL_SECTION lpCriticalSection
  2745. //
  2746. // );
  2747. func XTryEnterCriticalSection(t *TLS, lpCriticalSection uintptr) (r int32) {
  2748. if __ccgo_strace {
  2749. trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
  2750. }
  2751. r0, _, err := procTryEnterCriticalSection.Call(lpCriticalSection)
  2752. if err != windows.NOERROR {
  2753. t.setErrno(err)
  2754. }
  2755. return int32(r0)
  2756. }
  2757. // void LeaveCriticalSection(
  2758. //
  2759. // LPCRITICAL_SECTION lpCriticalSection
  2760. //
  2761. // );
  2762. func XLeaveCriticalSection(t *TLS, lpCriticalSection uintptr) {
  2763. if __ccgo_strace {
  2764. trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
  2765. }
  2766. procLeaveCriticalSection.Call(lpCriticalSection, 0, 0)
  2767. }
  2768. func XGetOverlappedResult(t *TLS, _ ...interface{}) int32 {
  2769. panic(todo(""))
  2770. }
  2771. func XSetupComm(t *TLS, _ ...interface{}) int32 {
  2772. panic(todo(""))
  2773. }
  2774. func XSetCommTimeouts(t *TLS, _ ...interface{}) int32 {
  2775. panic(todo(""))
  2776. }
  2777. // void InitializeCriticalSection(
  2778. //
  2779. // LPCRITICAL_SECTION lpCriticalSection
  2780. //
  2781. // );
  2782. func XInitializeCriticalSection(t *TLS, lpCriticalSection uintptr) {
  2783. if __ccgo_strace {
  2784. trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
  2785. }
  2786. // InitializeCriticalSection always succeeds, even in low memory situations.
  2787. procInitializeCriticalSection.Call(lpCriticalSection, 0, 0)
  2788. }
  2789. func XBuildCommDCBW(t *TLS, _ ...interface{}) int32 {
  2790. panic(todo(""))
  2791. }
  2792. func XSetCommState(t *TLS, _ ...interface{}) int32 {
  2793. panic(todo(""))
  2794. }
  2795. func XEscapeCommFunction(t *TLS, _ ...interface{}) int32 {
  2796. panic(todo(""))
  2797. }
  2798. func XGetCommModemStatus(t *TLS, _ ...interface{}) int32 {
  2799. panic(todo(""))
  2800. }
  2801. // BOOL MoveFileW(
  2802. //
  2803. // LPCWSTR lpExistingFileName,
  2804. // LPCWSTR lpNewFileName
  2805. //
  2806. // );
  2807. func XMoveFileW(t *TLS, lpExistingFileName, lpNewFileName uintptr) int32 {
  2808. if __ccgo_strace {
  2809. trc("t=%v lpNewFileName=%v, (%v:)", t, lpNewFileName, origin(2))
  2810. }
  2811. r0, _, err := procMoveFileW.Call(lpExistingFileName, lpNewFileName, 0)
  2812. if err != windows.NOERROR {
  2813. t.setErrno(err)
  2814. }
  2815. return int32(r0)
  2816. }
  2817. // DWORD GetFullPathNameW(
  2818. //
  2819. // LPCWSTR lpFileName,
  2820. // DWORD nBufferLength,
  2821. // LPWSTR lpBuffer,
  2822. // LPWSTR *lpFilePart
  2823. //
  2824. // );
  2825. func XGetFullPathNameW(t *TLS, lpFileName uintptr, nBufferLength uint32, lpBuffer, lpFilePart uintptr) uint32 {
  2826. if __ccgo_strace {
  2827. trc("t=%v lpFileName=%v nBufferLength=%v lpFilePart=%v, (%v:)", t, lpFileName, nBufferLength, lpFilePart, origin(2))
  2828. }
  2829. r0, _, e1 := procGetFullPathNameW.Call(lpFileName, uintptr(nBufferLength), uintptr(lpBuffer), uintptr(lpFilePart), 0, 0)
  2830. n := uint32(r0)
  2831. if n == 0 {
  2832. if e1 != windows.NOERROR {
  2833. t.setErrno(e1)
  2834. } else {
  2835. t.setErrno(errno.EINVAL)
  2836. }
  2837. }
  2838. return n
  2839. }
  2840. // __attribute__((dllimport)) LPWSTR CharLowerW(LPWSTR lpsz);
  2841. func XCharLowerW(tls *TLS, _lpsz uintptr) (r uintptr) {
  2842. if __ccgo_strace {
  2843. trc("lpsz=%+v", _lpsz)
  2844. defer func() { trc(`XCharLowerW->%+v`, r) }()
  2845. }
  2846. r0, r1, err := procCharLowerW.Call(_lpsz)
  2847. if err != windows.NOERROR {
  2848. if __ccgo_strace {
  2849. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  2850. }
  2851. tls.SetLastError(uint32(err.(windows.Errno)))
  2852. }
  2853. return r0
  2854. }
  2855. // BOOL CreateDirectoryW(
  2856. //
  2857. // LPCWSTR lpPathName,
  2858. // LPSECURITY_ATTRIBUTES lpSecurityAttributes
  2859. //
  2860. // );
  2861. func XCreateDirectoryW(t *TLS, lpPathName, lpSecurityAttributes uintptr) int32 {
  2862. if __ccgo_strace {
  2863. trc("t=%v lpSecurityAttributes=%v, (%v:)", t, lpSecurityAttributes, origin(2))
  2864. }
  2865. err := windows.CreateDirectory((*uint16)(unsafe.Pointer(lpPathName)),
  2866. (*windows.SecurityAttributes)(unsafe.Pointer(lpSecurityAttributes)))
  2867. if err != nil {
  2868. t.setErrno(err)
  2869. return 0
  2870. }
  2871. return 1
  2872. }
  2873. // BOOL SetFileAttributesW(
  2874. //
  2875. // LPCWSTR lpFileName,
  2876. // DWORD dwFileAttributes
  2877. //
  2878. // );
  2879. func XSetFileAttributesW(t *TLS, lpFileName uintptr, dwFileAttributes uint32) int32 {
  2880. if __ccgo_strace {
  2881. trc("t=%v lpFileName=%v dwFileAttributes=%v, (%v:)", t, lpFileName, dwFileAttributes, origin(2))
  2882. }
  2883. err := windows.SetFileAttributes((*uint16)(unsafe.Pointer(lpFileName)), dwFileAttributes)
  2884. if err != nil {
  2885. t.setErrno(err)
  2886. return 0
  2887. }
  2888. return 1
  2889. }
  2890. // UINT GetTempFileNameW(
  2891. //
  2892. // LPCWSTR lpPathName,
  2893. // LPCWSTR lpPrefixString,
  2894. // UINT uUnique,
  2895. // LPWSTR lpTempFileName
  2896. //
  2897. // );
  2898. func XGetTempFileNameW(t *TLS, lpPathName, lpPrefixString uintptr, uUnique uint32, lpTempFileName uintptr) uint32 {
  2899. if __ccgo_strace {
  2900. trc("t=%v lpPrefixString=%v uUnique=%v lpTempFileName=%v, (%v:)", t, lpPrefixString, uUnique, lpTempFileName, origin(2))
  2901. }
  2902. r0, _, e1 := procGetTempFileNameW.Call(lpPathName, lpPrefixString, uintptr(uUnique), lpTempFileName, 0, 0)
  2903. if r0 == 0 {
  2904. t.setErrno(e1)
  2905. }
  2906. return uint32(r0)
  2907. }
  2908. // BOOL CopyFileW(
  2909. //
  2910. // LPCWSTR lpExistingFileName,
  2911. // LPCWSTR lpNewFileName,
  2912. // BOOL bFailIfExists
  2913. //
  2914. // );
  2915. func XCopyFileW(t *TLS, lpExistingFileName, lpNewFileName uintptr, bFailIfExists int32) int32 {
  2916. if __ccgo_strace {
  2917. trc("t=%v lpNewFileName=%v bFailIfExists=%v, (%v:)", t, lpNewFileName, bFailIfExists, origin(2))
  2918. }
  2919. r0, _, e1 := procCopyFileW.Call(lpExistingFileName, lpNewFileName, uintptr(bFailIfExists))
  2920. if r0 == 0 {
  2921. t.setErrno(e1)
  2922. }
  2923. return int32(r0)
  2924. }
  2925. // BOOL DeleteFileW(
  2926. //
  2927. // LPCWSTR lpFileName
  2928. //
  2929. // );
  2930. func XDeleteFileW(t *TLS, lpFileName uintptr) int32 {
  2931. if __ccgo_strace {
  2932. trc("t=%v lpFileName=%v, (%v:)", t, lpFileName, origin(2))
  2933. }
  2934. err := windows.DeleteFile((*uint16)(unsafe.Pointer(lpFileName)))
  2935. if err != nil {
  2936. t.setErrno(err)
  2937. return 0
  2938. }
  2939. return 1
  2940. }
  2941. // BOOL RemoveDirectoryW(
  2942. //
  2943. // LPCWSTR lpPathName
  2944. //
  2945. // );
  2946. func XRemoveDirectoryW(t *TLS, lpPathName uintptr) int32 {
  2947. if __ccgo_strace {
  2948. trc("t=%v lpPathName=%v, (%v:)", t, lpPathName, origin(2))
  2949. }
  2950. err := windows.RemoveDirectory((*uint16)(unsafe.Pointer(lpPathName)))
  2951. if err != nil {
  2952. t.setErrno(err)
  2953. return 0
  2954. }
  2955. return 1
  2956. }
  2957. // HANDLE FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData);
  2958. func XFindFirstFileW(t *TLS, lpFileName, lpFindFileData uintptr) uintptr {
  2959. if __ccgo_strace {
  2960. trc("t=%v lpFindFileData=%v, (%v:)", t, lpFindFileData, origin(2))
  2961. }
  2962. r0, _, e1 := procFindFirstFileW.Call(lpFileName, lpFindFileData, 0)
  2963. handle := windows.Handle(r0)
  2964. if handle == windows.InvalidHandle {
  2965. if e1 != windows.NOERROR {
  2966. t.setErrno(e1)
  2967. } else {
  2968. t.setErrno(errno.EINVAL)
  2969. }
  2970. }
  2971. return r0
  2972. }
  2973. // HANDLE FindFirstFileExW(
  2974. //
  2975. // LPCWSTR lpFileName,
  2976. // FINDEX_INFO_LEVELS fInfoLevelId,
  2977. // LPVOID lpFindFileData,
  2978. // FINDEX_SEARCH_OPS fSearchOp,
  2979. // LPVOID lpSearchFilter,
  2980. // DWORD dwAdditionalFlags
  2981. //
  2982. // );
  2983. func XFindFirstFileExW(t *TLS, lpFileName uintptr, fInfoLevelId int32, lpFindFileData uintptr, fSearchOp int32, lpSearchFilter uintptr, dwAdditionalFlags uint32) uintptr {
  2984. if __ccgo_strace {
  2985. trc("t=%v lpFileName=%v fInfoLevelId=%v lpFindFileData=%v fSearchOp=%v lpSearchFilter=%v dwAdditionalFlags=%v, (%v:)", t, lpFileName, fInfoLevelId, lpFindFileData, fSearchOp, lpSearchFilter, dwAdditionalFlags, origin(2))
  2986. }
  2987. r0, _, e1 := procFindFirstFileExW.Call(lpFileName, uintptr(fInfoLevelId), lpFindFileData, uintptr(fSearchOp), lpSearchFilter, uintptr(dwAdditionalFlags))
  2988. handle := windows.Handle(r0)
  2989. if handle == windows.InvalidHandle {
  2990. if e1 != windows.NOERROR {
  2991. t.setErrno(e1)
  2992. } else {
  2993. t.setErrno(errno.EINVAL)
  2994. }
  2995. }
  2996. return r0
  2997. }
  2998. // BOOL FindClose(HANDLE hFindFile);
  2999. func XFindClose(t *TLS, hFindFile uintptr) int32 {
  3000. if __ccgo_strace {
  3001. trc("t=%v hFindFile=%v, (%v:)", t, hFindFile, origin(2))
  3002. }
  3003. r0, _, e1 := procFindClose.Call(hFindFile, 0, 0)
  3004. if r0 == 0 {
  3005. if e1 != windows.NOERROR {
  3006. t.setErrno(e1)
  3007. } else {
  3008. t.setErrno(errno.EINVAL)
  3009. }
  3010. }
  3011. return int32(r0)
  3012. }
  3013. // BOOL FindNextFileW(
  3014. //
  3015. // HANDLE hFindFile,
  3016. // LPWIN32_FIND_DATAW lpFindFileData
  3017. //
  3018. // );
  3019. func XFindNextFileW(t *TLS, hFindFile, lpFindFileData uintptr) int32 {
  3020. if __ccgo_strace {
  3021. trc("t=%v lpFindFileData=%v, (%v:)", t, lpFindFileData, origin(2))
  3022. }
  3023. r0, _, e1 := procFindNextFileW.Call(hFindFile, lpFindFileData, 0)
  3024. if r0 == 0 {
  3025. if e1 != windows.NOERROR {
  3026. t.setErrno(e1)
  3027. } else {
  3028. t.setErrno(errno.EINVAL)
  3029. }
  3030. }
  3031. return int32(r0)
  3032. }
  3033. // DWORD GetLogicalDriveStringsA(
  3034. //
  3035. // DWORD nBufferLength,
  3036. // LPSTR lpBuffer
  3037. //
  3038. // );
  3039. func XGetLogicalDriveStringsA(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
  3040. if __ccgo_strace {
  3041. trc("t=%v nBufferLength=%v lpBuffer=%v, (%v:)", t, nBufferLength, lpBuffer, origin(2))
  3042. }
  3043. r0, _, err := procGetLogicalDriveStringsA.Call(uintptr(nBufferLength), lpBuffer, 0)
  3044. if err != windows.NOERROR {
  3045. t.setErrno(err)
  3046. }
  3047. return uint32(r0)
  3048. }
  3049. // BOOL GetVolumeInformationA(
  3050. //
  3051. // LPCSTR lpRootPathName,
  3052. // LPSTR lpVolumeNameBuffer,
  3053. // DWORD nVolumeNameSize,
  3054. // LPDWORD lpVolumeSerialNumber,
  3055. // LPDWORD lpMaximumComponentLength,
  3056. // LPDWORD lpFileSystemFlags,
  3057. // LPSTR lpFileSystemNameBuffer,
  3058. // DWORD nFileSystemNameSize
  3059. //
  3060. // );
  3061. func XGetVolumeInformationA(t *TLS, lpRootPathName, lpVolumeNameBuffer uintptr, nVolumeNameSize uint32, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer uintptr, nFileSystemNameSize uint32) int32 {
  3062. if __ccgo_strace {
  3063. trc("t=%v lpVolumeNameBuffer=%v nVolumeNameSize=%v lpFileSystemNameBuffer=%v nFileSystemNameSize=%v, (%v:)", t, lpVolumeNameBuffer, nVolumeNameSize, lpFileSystemNameBuffer, nFileSystemNameSize, origin(2))
  3064. }
  3065. r0, _, err := procGetVolumeInformationA.Call(lpRootPathName,
  3066. lpVolumeNameBuffer,
  3067. uintptr(nVolumeNameSize),
  3068. lpVolumeSerialNumber,
  3069. lpMaximumComponentLength,
  3070. lpFileSystemFlags,
  3071. lpFileSystemNameBuffer,
  3072. uintptr(nFileSystemNameSize),
  3073. 0,
  3074. )
  3075. if err != windows.NOERROR {
  3076. t.setErrno(err)
  3077. }
  3078. return int32(r0)
  3079. }
  3080. // BOOL CreateHardLinkW(
  3081. //
  3082. // LPCWSTR lpFileName,
  3083. // LPCWSTR lpExistingFileName,
  3084. // LPSECURITY_ATTRIBUTES lpSecurityAttributes
  3085. //
  3086. // );
  3087. func XCreateHardLinkW(t *TLS, lpFileName, lpExistingFileName, lpSecurityAttributes uintptr) int32 {
  3088. if __ccgo_strace {
  3089. trc("t=%v lpSecurityAttributes=%v, (%v:)", t, lpSecurityAttributes, origin(2))
  3090. }
  3091. r0, _, err := procCreateHardLinkW.Call(lpFileName, lpExistingFileName, lpSecurityAttributes)
  3092. if err != windows.NOERROR {
  3093. t.setErrno(err)
  3094. }
  3095. return int32(r0)
  3096. }
  3097. // BOOL DeviceIoControl(
  3098. //
  3099. // HANDLE hDevice,
  3100. // DWORD dwIoControlCode,
  3101. // LPVOID lpInBuffer,
  3102. // DWORD nInBufferSize,
  3103. // LPVOID lpOutBuffer,
  3104. // DWORD nOutBufferSize,
  3105. // LPDWORD lpBytesReturned,
  3106. // LPOVERLAPPED lpOverlapped
  3107. //
  3108. // );
  3109. func XDeviceIoControl(t *TLS, hDevice uintptr, dwIoControlCode uint32, lpInBuffer uintptr, nInBufferSize uint32, lpOutBuffer uintptr, nOutBufferSize uint32, lpBytesReturned, lpOverlapped uintptr) int32 {
  3110. if __ccgo_strace {
  3111. trc("t=%v hDevice=%v dwIoControlCode=%v lpInBuffer=%v nInBufferSize=%v lpOutBuffer=%v nOutBufferSize=%v lpOverlapped=%v, (%v:)", t, hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpOverlapped, origin(2))
  3112. }
  3113. r0, _, err := procDeviceIoControl.Call(hDevice, uintptr(dwIoControlCode), lpInBuffer,
  3114. uintptr(nInBufferSize), lpOutBuffer, uintptr(nOutBufferSize), lpBytesReturned, lpOverlapped, 0)
  3115. if r0 == 0 {
  3116. t.setErrno(err)
  3117. }
  3118. return int32(r0)
  3119. }
  3120. // int wcsncmp(
  3121. //
  3122. // const wchar_t *string1,
  3123. // const wchar_t *string2,
  3124. // size_t count
  3125. //
  3126. // );
  3127. func Xwcsncmp(t *TLS, string1, string2 uintptr, count types.Size_t) int32 {
  3128. if __ccgo_strace {
  3129. trc("t=%v string2=%v count=%v, (%v:)", t, string2, count, origin(2))
  3130. }
  3131. var s1 = goWideString(string1)
  3132. var l1 = len(s1)
  3133. var s2 = goWideString(string2)
  3134. var l2 = len(s2)
  3135. // shorter is lesser
  3136. if l1 < l2 {
  3137. return -1
  3138. }
  3139. if l2 > l1 {
  3140. return 1
  3141. }
  3142. // compare at most count
  3143. var cmpLen = count
  3144. if types.Size_t(l1) < cmpLen {
  3145. cmpLen = types.Size_t(l1)
  3146. }
  3147. return int32(strings.Compare(s1[:cmpLen], s2[:cmpLen]))
  3148. }
  3149. // int MultiByteToWideChar(
  3150. //
  3151. // UINT CodePage,
  3152. // DWORD dwFlags,
  3153. // _In_NLS_string_(cbMultiByte)LPCCH lpMultiByteStr,
  3154. // int cbMultiByte,
  3155. // LPWSTR lpWideCharStr,
  3156. // int cchWideChar
  3157. //
  3158. // );
  3159. func XMultiByteToWideChar(t *TLS, CodePage uint32, dwFlags uint32, lpMultiByteStr uintptr, cbMultiByte int32, lpWideCharStr uintptr, cchWideChar int32) int32 {
  3160. if __ccgo_strace {
  3161. trc("t=%v CodePage=%v dwFlags=%v lpMultiByteStr=%v cbMultiByte=%v lpWideCharStr=%v cchWideChar=%v, (%v:)", t, CodePage, dwFlags, lpMultiByteStr, cbMultiByte, lpWideCharStr, cchWideChar, origin(2))
  3162. }
  3163. r1, _, _ := procMultiByteToWideChar.Call(uintptr(CodePage), uintptr(dwFlags), uintptr(lpMultiByteStr),
  3164. uintptr(cbMultiByte), uintptr(lpWideCharStr), uintptr(cchWideChar))
  3165. return (int32(r1))
  3166. }
  3167. // void OutputDebugStringW(
  3168. //
  3169. // LPCWSTR lpOutputString
  3170. //
  3171. // );
  3172. func XOutputDebugStringW(t *TLS, lpOutputString uintptr) {
  3173. if __ccgo_strace {
  3174. trc("t=%v lpOutputString=%v, (%v:)", t, lpOutputString, origin(2))
  3175. }
  3176. panic(todo(""))
  3177. }
  3178. func XMessageBeep(t *TLS, _ ...interface{}) int32 {
  3179. panic(todo(""))
  3180. }
  3181. //====
  3182. // long _InterlockedCompareExchange(
  3183. //
  3184. // long volatile * Destination,
  3185. // long Exchange,
  3186. // long Comparand
  3187. //
  3188. // );
  3189. func X_InterlockedCompareExchange(t *TLS, Destination uintptr, Exchange, Comparand long) long {
  3190. if __ccgo_strace {
  3191. trc("t=%v Destination=%v Comparand=%v, (%v:)", t, Destination, Comparand, origin(2))
  3192. }
  3193. // The function returns the initial value of the Destination parameter.
  3194. var v = *(*int32)(unsafe.Pointer(Destination))
  3195. _ = atomic.CompareAndSwapInt32((*int32)(unsafe.Pointer(Destination)), Comparand, Exchange)
  3196. return long(v)
  3197. }
  3198. // int rename(const char *oldpath, const char *newpath);
  3199. func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
  3200. if __ccgo_strace {
  3201. trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
  3202. }
  3203. panic(todo(""))
  3204. }
  3205. // BOOL AreFileApisANSI();
  3206. func XAreFileApisANSI(t *TLS) int32 {
  3207. if __ccgo_strace {
  3208. trc("t=%v, (%v:)", t, origin(2))
  3209. }
  3210. r0, _, _ := procAreFileApisANSI.Call(0, 0, 0)
  3211. return int32(r0)
  3212. }
  3213. // HANDLE CreateFileA(
  3214. //
  3215. // LPCSTR lpFileName,
  3216. // DWORD dwDesiredAccess,
  3217. // DWORD dwShareMode,
  3218. // LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  3219. // DWORD dwCreationDisposition,
  3220. // DWORD dwFlagsAndAttributes,
  3221. // HANDLE hTemplateFile
  3222. //
  3223. // );
  3224. func XCreateFileA(t *TLS, lpFileName uintptr, dwDesiredAccess, dwShareMode uint32,
  3225. lpSecurityAttributes uintptr, dwCreationDisposition, dwFlagsAndAttributes uint32, hTemplateFile uintptr) uintptr {
  3226. r0, _, e1 := procCreateFileA.Call(lpFileName, uintptr(dwDesiredAccess), uintptr(dwShareMode), lpSecurityAttributes,
  3227. uintptr(dwCreationDisposition), uintptr(dwFlagsAndAttributes), hTemplateFile, 0, 0)
  3228. h := windows.Handle(r0)
  3229. if h == windows.InvalidHandle {
  3230. if e1 != windows.NOERROR {
  3231. t.setErrno(e1)
  3232. } else {
  3233. t.setErrno(errno.EINVAL)
  3234. }
  3235. return r0
  3236. }
  3237. return uintptr(h)
  3238. }
  3239. // HANDLE CreateFileMappingA(
  3240. //
  3241. // HANDLE hFile,
  3242. // LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
  3243. // DWORD flProtect,
  3244. // DWORD dwMaximumSizeHigh,
  3245. // DWORD dwMaximumSizeLow,
  3246. // LPCSTR lpName
  3247. //
  3248. // );
  3249. func XCreateFileMappingA(t *TLS, hFile, lpFileMappingAttributes uintptr, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow uint32, lpName uintptr) uintptr {
  3250. if __ccgo_strace {
  3251. trc("t=%v lpFileMappingAttributes=%v dwMaximumSizeLow=%v lpName=%v, (%v:)", t, lpFileMappingAttributes, dwMaximumSizeLow, lpName, origin(2))
  3252. }
  3253. panic(todo(""))
  3254. }
  3255. // HANDLE CreateFileMappingW(
  3256. //
  3257. // HANDLE hFile,
  3258. // LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
  3259. // DWORD flProtect,
  3260. // DWORD dwMaximumSizeHigh,
  3261. // DWORD dwMaximumSizeLow,
  3262. // LPCWSTR lpName
  3263. //
  3264. // );
  3265. func XCreateFileMappingW(t *TLS, hFile, lpFileMappingAttributes uintptr, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow uint32, lpName uintptr) uintptr {
  3266. if __ccgo_strace {
  3267. trc("t=%v lpFileMappingAttributes=%v dwMaximumSizeLow=%v lpName=%v, (%v:)", t, lpFileMappingAttributes, dwMaximumSizeLow, lpName, origin(2))
  3268. }
  3269. h, _, e1 := procCreateFileMappingW.Call(hFile, lpFileMappingAttributes, uintptr(flProtect),
  3270. uintptr(dwMaximumSizeHigh), uintptr(dwMaximumSizeLow), lpName)
  3271. if h == 0 {
  3272. if e1 != windows.NOERROR {
  3273. t.setErrno(e1)
  3274. } else {
  3275. t.setErrno(errno.EINVAL)
  3276. }
  3277. }
  3278. return h
  3279. }
  3280. // HANDLE CreateMutexW(
  3281. //
  3282. // LPSECURITY_ATTRIBUTES lpMutexAttributes,
  3283. // BOOL bInitialOwner,
  3284. // LPCWSTR lpName
  3285. //
  3286. // );
  3287. func XCreateMutexW(t *TLS, lpMutexAttributes uintptr, bInitialOwner int32, lpName uintptr) uintptr {
  3288. if __ccgo_strace {
  3289. trc("t=%v lpMutexAttributes=%v bInitialOwner=%v lpName=%v, (%v:)", t, lpMutexAttributes, bInitialOwner, lpName, origin(2))
  3290. }
  3291. panic(todo(""))
  3292. }
  3293. // BOOL DeleteFileA(
  3294. //
  3295. // LPCSTR lpFileName
  3296. //
  3297. // );
  3298. func XDeleteFileA(t *TLS, lpFileName uintptr) int32 {
  3299. if __ccgo_strace {
  3300. trc("t=%v lpFileName=%v, (%v:)", t, lpFileName, origin(2))
  3301. }
  3302. panic(todo(""))
  3303. }
  3304. // DWORD FormatMessageA(
  3305. //
  3306. // DWORD dwFlags,
  3307. // LPCVOID lpSource,
  3308. // DWORD dwMessageId,
  3309. // DWORD dwLanguageId,
  3310. // LPSTR lpBuffer,
  3311. // DWORD nSize,
  3312. // va_list *Arguments
  3313. //
  3314. // );
  3315. func XFormatMessageA(t *TLS, dwFlagsAndAttributes uint32, lpSource uintptr, dwMessageId, dwLanguageId uint32, lpBuffer uintptr, nSize uint32, Arguments uintptr) uint32 {
  3316. if __ccgo_strace {
  3317. trc("t=%v dwFlagsAndAttributes=%v lpSource=%v dwLanguageId=%v lpBuffer=%v nSize=%v Arguments=%v, (%v:)", t, dwFlagsAndAttributes, lpSource, dwLanguageId, lpBuffer, nSize, Arguments, origin(2))
  3318. }
  3319. panic(todo(""))
  3320. }
  3321. // DWORD FormatMessageW(
  3322. //
  3323. // DWORD dwFlags,
  3324. // LPCVOID lpSource,
  3325. // DWORD dwMessageId,
  3326. // DWORD dwLanguageId,
  3327. // LPWSTR lpBuffer,
  3328. // DWORD nSize,
  3329. // va_list *Arguments
  3330. //
  3331. // );
  3332. func XFormatMessageW(t *TLS, dwFlags uint32, lpSource uintptr, dwMessageId, dwLanguageId uint32, lpBuffer uintptr, nSize uint32, Arguments uintptr) uint32 {
  3333. if __ccgo_strace {
  3334. trc("t=%v dwFlags=%v lpSource=%v dwLanguageId=%v lpBuffer=%v nSize=%v Arguments=%v, (%v:)", t, dwFlags, lpSource, dwLanguageId, lpBuffer, nSize, Arguments, origin(2))
  3335. }
  3336. r0, _, e1 := procFormatMessageW.Call(uintptr(dwFlags), lpSource, uintptr(dwMessageId), uintptr(dwLanguageId),
  3337. lpBuffer, uintptr(nSize), Arguments, 0, 0)
  3338. n := uint32(r0)
  3339. if n == 0 {
  3340. if e1 != windows.NOERROR {
  3341. t.setErrno(e1)
  3342. } else {
  3343. t.setErrno(errno.EINVAL)
  3344. }
  3345. }
  3346. return n
  3347. }
  3348. // BOOL FreeLibrary(HMODULE hLibModule);
  3349. func XFreeLibrary(t *TLS, hLibModule uintptr) int32 {
  3350. if __ccgo_strace {
  3351. trc("t=%v hLibModule=%v, (%v:)", t, hLibModule, origin(2))
  3352. }
  3353. panic(todo(""))
  3354. }
  3355. // DWORD GetCurrentProcessId();
  3356. func XGetCurrentProcessId(t *TLS) uint32 {
  3357. if __ccgo_strace {
  3358. trc("t=%v, (%v:)", t, origin(2))
  3359. }
  3360. r0, _, _ := procGetCurrentProcessId.Call(0, 0, 0)
  3361. pid := uint32(r0)
  3362. return pid
  3363. }
  3364. // BOOL GetDiskFreeSpaceA(
  3365. //
  3366. // LPCSTR lpRootPathName,
  3367. // LPDWORD lpSectorsPerCluster,
  3368. // LPDWORD lpBytesPerSector,
  3369. // LPDWORD lpNumberOfFreeClusters,
  3370. // LPDWORD lpTotalNumberOfClusters
  3371. //
  3372. // );
  3373. func XGetDiskFreeSpaceA(t *TLS, lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters uintptr) int32 {
  3374. if __ccgo_strace {
  3375. trc("t=%v lpTotalNumberOfClusters=%v, (%v:)", t, lpTotalNumberOfClusters, origin(2))
  3376. }
  3377. panic(todo(""))
  3378. }
  3379. // BOOL GetDiskFreeSpaceW(
  3380. //
  3381. // LPCWSTR lpRootPathName,
  3382. // LPDWORD lpSectorsPerCluster,
  3383. // LPDWORD lpBytesPerSector,
  3384. // LPDWORD lpNumberOfFreeClusters,
  3385. // LPDWORD lpTotalNumberOfClusters
  3386. //
  3387. // );
  3388. func XGetDiskFreeSpaceW(t *TLS, lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters uintptr) int32 {
  3389. if __ccgo_strace {
  3390. trc("t=%v lpTotalNumberOfClusters=%v, (%v:)", t, lpTotalNumberOfClusters, origin(2))
  3391. }
  3392. panic(todo(""))
  3393. }
  3394. // DWORD GetFileAttributesA(
  3395. //
  3396. // LPCSTR lpFileName
  3397. //
  3398. // );
  3399. func XGetFileAttributesA(t *TLS, lpFileName uintptr) uint32 {
  3400. if __ccgo_strace {
  3401. trc("t=%v lpFileName=%v, (%v:)", t, lpFileName, origin(2))
  3402. }
  3403. r0, _, err := procGetFileAttributesA.Call(lpFileName, 0, 0)
  3404. if err != windows.NOERROR {
  3405. t.setErrno(err)
  3406. }
  3407. return uint32(r0)
  3408. }
  3409. // BOOL GetFileAttributesExW(
  3410. //
  3411. // LPCWSTR lpFileName,
  3412. // GET_FILEEX_INFO_LEVELS fInfoLevelId,
  3413. // LPVOID lpFileInformation
  3414. //
  3415. // );
  3416. func XGetFileAttributesExW(t *TLS, lpFileName uintptr, fInfoLevelId int32, lpFileInformation uintptr) int32 {
  3417. if __ccgo_strace {
  3418. trc("t=%v lpFileName=%v fInfoLevelId=%v lpFileInformation=%v, (%v:)", t, lpFileName, fInfoLevelId, lpFileInformation, origin(2))
  3419. }
  3420. r1, _, e1 := procGetFileAttributesExW.Call(lpFileName, uintptr(fInfoLevelId), lpFileInformation)
  3421. if r1 == 0 {
  3422. if e1 != windows.NOERROR {
  3423. t.setErrno(e1)
  3424. } else {
  3425. t.setErrno(errno.EINVAL)
  3426. }
  3427. return 0
  3428. }
  3429. return int32(r1)
  3430. }
  3431. // DWORD GetFileSize(
  3432. //
  3433. // HANDLE hFile,
  3434. // LPDWORD lpFileSizeHigh
  3435. //
  3436. // );
  3437. func XGetFileSize(t *TLS, hFile, lpFileSizeHigh uintptr) uint32 {
  3438. if __ccgo_strace {
  3439. trc("t=%v lpFileSizeHigh=%v, (%v:)", t, lpFileSizeHigh, origin(2))
  3440. }
  3441. r1, _, e1 := procGetFileSize.Call(hFile, lpFileSizeHigh, 0)
  3442. if r1 == math.MaxUint32 {
  3443. if lpFileSizeHigh == 0 {
  3444. // If the function fails and lpFileSizeHigh is NULL, the return value is INVALID_FILE_SIZE.
  3445. // Note that if the return value is INVALID_FILE_SIZE (0xffffffff),
  3446. // an application must call GetLastError to determine whether the function has succeeded or failed.
  3447. t.setErrno(e1)
  3448. return math.MaxUint32
  3449. } else {
  3450. // If the function fails and lpFileSizeHigh is non-NULL, the return value is INVALID_FILE_SIZE
  3451. // and GetLastError will return a value other than NO_ERROR.
  3452. t.setErrno(e1)
  3453. return math.MaxUint32
  3454. }
  3455. }
  3456. return uint32(r1)
  3457. }
  3458. // DWORD GetFullPathNameA(
  3459. //
  3460. // LPCSTR lpFileName,
  3461. // DWORD nBufferLength,
  3462. // LPSTR lpBuffer,
  3463. // LPSTR *lpFilePart
  3464. //
  3465. // );
  3466. func XGetFullPathNameA(t *TLS, lpFileName uintptr, nBufferLength uint32, lpBuffer, lpFilePart uintptr) uint32 {
  3467. if __ccgo_strace {
  3468. trc("t=%v lpFileName=%v nBufferLength=%v lpFilePart=%v, (%v:)", t, lpFileName, nBufferLength, lpFilePart, origin(2))
  3469. }
  3470. panic(todo(""))
  3471. }
  3472. // FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName);
  3473. func XGetProcAddress(t *TLS, hModule, lpProcName uintptr) uintptr {
  3474. if __ccgo_strace {
  3475. trc("t=%v lpProcName=%v, (%v:)", t, lpProcName, origin(2))
  3476. }
  3477. return 0
  3478. //panic(todo(GoString(lpProcName)))
  3479. //
  3480. //r0, _, err := procGetProcAddress.Call(hModule, lpProcName, 0)
  3481. //if r0 == 0 {
  3482. // t.setErrno(err)
  3483. //}
  3484. //return r0
  3485. }
  3486. // NTSYSAPI NTSTATUS RtlGetVersion( // ntdll.dll
  3487. //
  3488. // PRTL_OSVERSIONINFOW lpVersionInformation
  3489. //
  3490. // );
  3491. func XRtlGetVersion(t *TLS, lpVersionInformation uintptr) uintptr {
  3492. if __ccgo_strace {
  3493. trc("t=%v lpVersionInformation=%v, (%v:)", t, lpVersionInformation, origin(2))
  3494. }
  3495. panic(todo(""))
  3496. }
  3497. // void GetSystemInfo(
  3498. //
  3499. // LPSYSTEM_INFO lpSystemInfo
  3500. //
  3501. // );
  3502. func XGetSystemInfo(t *TLS, lpSystemInfo uintptr) {
  3503. if __ccgo_strace {
  3504. trc("t=%v lpSystemInfo=%v, (%v:)", t, lpSystemInfo, origin(2))
  3505. }
  3506. procGetSystemInfo.Call(lpSystemInfo, 0, 0)
  3507. }
  3508. // void GetSystemTime(LPSYSTEMTIME lpSystemTime);
  3509. func XGetSystemTime(t *TLS, lpSystemTime uintptr) {
  3510. if __ccgo_strace {
  3511. trc("t=%v lpSystemTime=%v, (%v:)", t, lpSystemTime, origin(2))
  3512. }
  3513. procGetSystemTime.Call(lpSystemTime, 0, 0)
  3514. }
  3515. // void GetSystemTimeAsFileTime(
  3516. //
  3517. // LPFILETIME lpSystemTimeAsFileTime
  3518. //
  3519. // );
  3520. func XGetSystemTimeAsFileTime(t *TLS, lpSystemTimeAsFileTime uintptr) {
  3521. if __ccgo_strace {
  3522. trc("t=%v lpSystemTimeAsFileTime=%v, (%v:)", t, lpSystemTimeAsFileTime, origin(2))
  3523. }
  3524. procGetSystemTimeAsFileTime.Call(lpSystemTimeAsFileTime, 0, 0)
  3525. }
  3526. // DWORD GetTempPathA(
  3527. //
  3528. // DWORD nBufferLength,
  3529. // LPSTR lpBuffer
  3530. //
  3531. // );
  3532. func XGetTempPathA(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
  3533. if __ccgo_strace {
  3534. trc("t=%v nBufferLength=%v lpBuffer=%v, (%v:)", t, nBufferLength, lpBuffer, origin(2))
  3535. }
  3536. panic(todo(""))
  3537. }
  3538. // DWORD GetTempPathW(
  3539. //
  3540. // DWORD nBufferLength,
  3541. // LPWSTR lpBuffer
  3542. //
  3543. // );
  3544. func XGetTempPathW(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
  3545. if __ccgo_strace {
  3546. trc("t=%v nBufferLength=%v lpBuffer=%v, (%v:)", t, nBufferLength, lpBuffer, origin(2))
  3547. }
  3548. rv, err := windows.GetTempPath(nBufferLength, (*uint16)(unsafe.Pointer(lpBuffer)))
  3549. if err != nil {
  3550. t.setErrno(err)
  3551. }
  3552. return rv
  3553. }
  3554. // DWORD GetTickCount();
  3555. func XGetTickCount(t *TLS) uint32 {
  3556. if __ccgo_strace {
  3557. trc("t=%v, (%v:)", t, origin(2))
  3558. }
  3559. r0, _, _ := procGetTickCount.Call(0, 0, 0)
  3560. return uint32(r0)
  3561. }
  3562. // BOOL GetVersionExA(
  3563. //
  3564. // LPOSVERSIONINFOA lpVersionInformation
  3565. //
  3566. // );
  3567. func XGetVersionExA(t *TLS, lpVersionInformation uintptr) int32 {
  3568. if __ccgo_strace {
  3569. trc("t=%v lpVersionInformation=%v, (%v:)", t, lpVersionInformation, origin(2))
  3570. }
  3571. r0, _, err := procGetVersionExA.Call(lpVersionInformation, 0, 0)
  3572. if r0 == 0 {
  3573. t.setErrno(err)
  3574. }
  3575. return int32(r0)
  3576. }
  3577. // HANDLE HeapCreate(
  3578. //
  3579. // DWORD flOptions,
  3580. // SIZE_T dwInitialSize,
  3581. // SIZE_T dwMaximumSize
  3582. //
  3583. // );
  3584. func XHeapCreate(t *TLS, flOptions uint32, dwInitialSize, dwMaximumSize types.Size_t) uintptr {
  3585. if __ccgo_strace {
  3586. trc("t=%v flOptions=%v dwMaximumSize=%v, (%v:)", t, flOptions, dwMaximumSize, origin(2))
  3587. }
  3588. panic(todo(""))
  3589. }
  3590. // BOOL HeapDestroy(
  3591. //
  3592. // HANDLE hHeap
  3593. //
  3594. // );
  3595. func XHeapDestroy(t *TLS, hHeap uintptr) int32 {
  3596. if __ccgo_strace {
  3597. trc("t=%v hHeap=%v, (%v:)", t, hHeap, origin(2))
  3598. }
  3599. panic(todo(""))
  3600. }
  3601. // LPVOID HeapReAlloc(
  3602. //
  3603. // HANDLE hHeap,
  3604. // DWORD dwFlags,
  3605. // _Frees_ptr_opt_ LPVOID lpMem,
  3606. // SIZE_T dwBytes
  3607. //
  3608. // );
  3609. func XHeapReAlloc(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr, dwBytes types.Size_t) uintptr {
  3610. if __ccgo_strace {
  3611. trc("t=%v hHeap=%v dwFlags=%v lpMem=%v dwBytes=%v, (%v:)", t, hHeap, dwFlags, lpMem, dwBytes, origin(2))
  3612. }
  3613. panic(todo(""))
  3614. }
  3615. // SIZE_T HeapSize(
  3616. //
  3617. // HANDLE hHeap,
  3618. // DWORD dwFlags,
  3619. // LPCVOID lpMem
  3620. //
  3621. // );
  3622. func XHeapSize(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) types.Size_t {
  3623. if __ccgo_strace {
  3624. trc("t=%v hHeap=%v dwFlags=%v lpMem=%v, (%v:)", t, hHeap, dwFlags, lpMem, origin(2))
  3625. }
  3626. panic(todo(""))
  3627. }
  3628. // BOOL HeapValidate(
  3629. //
  3630. // HANDLE hHeap,
  3631. // DWORD dwFlags,
  3632. // LPCVOID lpMem
  3633. //
  3634. // );
  3635. func XHeapValidate(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) int32 {
  3636. if __ccgo_strace {
  3637. trc("t=%v hHeap=%v dwFlags=%v lpMem=%v, (%v:)", t, hHeap, dwFlags, lpMem, origin(2))
  3638. }
  3639. panic(todo(""))
  3640. }
  3641. // SIZE_T HeapCompact(
  3642. //
  3643. // HANDLE hHeap,
  3644. // DWORD dwFlags
  3645. //
  3646. // );
  3647. func XHeapCompact(t *TLS, hHeap uintptr, dwFlags uint32) types.Size_t {
  3648. if __ccgo_strace {
  3649. trc("t=%v hHeap=%v dwFlags=%v, (%v:)", t, hHeap, dwFlags, origin(2))
  3650. }
  3651. panic(todo(""))
  3652. }
  3653. // HMODULE LoadLibraryA(LPCSTR lpLibFileName);
  3654. func XLoadLibraryA(t *TLS, lpLibFileName uintptr) uintptr {
  3655. if __ccgo_strace {
  3656. trc("t=%v lpLibFileName=%v, (%v:)", t, lpLibFileName, origin(2))
  3657. }
  3658. panic(todo(""))
  3659. }
  3660. // HMODULE LoadLibraryW(
  3661. //
  3662. // LPCWSTR lpLibFileName
  3663. //
  3664. // );
  3665. func XLoadLibraryW(t *TLS, lpLibFileName uintptr) uintptr {
  3666. if __ccgo_strace {
  3667. trc("t=%v lpLibFileName=%v, (%v:)", t, lpLibFileName, origin(2))
  3668. }
  3669. panic(todo(""))
  3670. }
  3671. // HLOCAL LocalFree(
  3672. //
  3673. // HLOCAL hMem
  3674. //
  3675. // );
  3676. func XLocalFree(t *TLS, hMem uintptr) uintptr {
  3677. if __ccgo_strace {
  3678. trc("t=%v hMem=%v, (%v:)", t, hMem, origin(2))
  3679. }
  3680. h, err := windows.LocalFree(windows.Handle(hMem))
  3681. if h != 0 {
  3682. if err != nil {
  3683. t.setErrno(err)
  3684. } else {
  3685. t.setErrno(errno.EINVAL)
  3686. }
  3687. return uintptr(h)
  3688. }
  3689. return 0
  3690. }
  3691. // BOOL LockFile(
  3692. //
  3693. // HANDLE hFile,
  3694. // DWORD dwFileOffsetLow,
  3695. // DWORD dwFileOffsetHigh,
  3696. // DWORD nNumberOfBytesToLockLow,
  3697. // DWORD nNumberOfBytesToLockHigh
  3698. //
  3699. // );
  3700. func XLockFile(t *TLS, hFile uintptr, dwFileOffsetLow, dwFileOffsetHigh, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh uint32) int32 {
  3701. if __ccgo_strace {
  3702. trc("t=%v hFile=%v nNumberOfBytesToLockHigh=%v, (%v:)", t, hFile, nNumberOfBytesToLockHigh, origin(2))
  3703. }
  3704. r1, _, e1 := procLockFile.Call(hFile, uintptr(dwFileOffsetLow), uintptr(dwFileOffsetHigh), uintptr(nNumberOfBytesToLockLow), uintptr(nNumberOfBytesToLockHigh), 0)
  3705. if r1 == 0 {
  3706. if e1 != windows.NOERROR {
  3707. t.setErrno(e1)
  3708. } else {
  3709. t.setErrno(errno.EINVAL)
  3710. }
  3711. return 0
  3712. }
  3713. return int32(r1)
  3714. }
  3715. // BOOL LockFileEx(
  3716. //
  3717. // HANDLE hFile,
  3718. // DWORD dwFlags,
  3719. // DWORD dwReserved,
  3720. // DWORD nNumberOfBytesToLockLow,
  3721. // DWORD nNumberOfBytesToLockHigh,
  3722. // LPOVERLAPPED lpOverlapped
  3723. //
  3724. // );
  3725. func XLockFileEx(t *TLS, hFile uintptr, dwFlags, dwReserved, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh uint32, lpOverlapped uintptr) int32 {
  3726. if __ccgo_strace {
  3727. trc("t=%v hFile=%v nNumberOfBytesToLockHigh=%v lpOverlapped=%v, (%v:)", t, hFile, nNumberOfBytesToLockHigh, lpOverlapped, origin(2))
  3728. }
  3729. r1, _, e1 := procLockFileEx.Call(hFile, uintptr(dwFlags), uintptr(dwReserved), uintptr(nNumberOfBytesToLockLow), uintptr(nNumberOfBytesToLockHigh), lpOverlapped)
  3730. if r1 == 0 {
  3731. if e1 != windows.NOERROR {
  3732. t.setErrno(e1)
  3733. } else {
  3734. t.setErrno(errno.EINVAL)
  3735. }
  3736. return 0
  3737. }
  3738. return int32(r1)
  3739. }
  3740. // LPVOID MapViewOfFile(
  3741. //
  3742. // HANDLE hFileMappingObject,
  3743. // DWORD dwDesiredAccess,
  3744. // DWORD dwFileOffsetHigh,
  3745. // DWORD dwFileOffsetLow,
  3746. // SIZE_T dwNumberOfBytesToMap
  3747. //
  3748. // );
  3749. func XMapViewOfFile(t *TLS, hFileMappingObject uintptr, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow uint32, dwNumberOfBytesToMap types.Size_t) uintptr {
  3750. if __ccgo_strace {
  3751. trc("t=%v hFileMappingObject=%v dwFileOffsetLow=%v dwNumberOfBytesToMap=%v, (%v:)", t, hFileMappingObject, dwFileOffsetLow, dwNumberOfBytesToMap, origin(2))
  3752. }
  3753. h, _, e1 := procMapViewOfFile.Call(hFileMappingObject, uintptr(dwDesiredAccess),
  3754. uintptr(dwFileOffsetHigh), uintptr(dwFileOffsetLow), uintptr(dwNumberOfBytesToMap), 0)
  3755. if h == 0 {
  3756. if e1 != windows.NOERROR {
  3757. t.setErrno(e1)
  3758. } else {
  3759. t.setErrno(errno.EINVAL)
  3760. }
  3761. }
  3762. return h
  3763. }
  3764. // BOOL QueryPerformanceCounter(
  3765. //
  3766. // LARGE_INTEGER *lpPerformanceCount
  3767. //
  3768. // );
  3769. func XQueryPerformanceCounter(t *TLS, lpPerformanceCount uintptr) int32 {
  3770. if __ccgo_strace {
  3771. trc("t=%v lpPerformanceCount=%v, (%v:)", t, lpPerformanceCount, origin(2))
  3772. }
  3773. r0, _, _ := procQueryPerformanceCounter.Call(lpPerformanceCount, 0, 0)
  3774. return int32(r0)
  3775. }
  3776. // void Sleep(
  3777. //
  3778. // DWORD dwMilliseconds
  3779. //
  3780. // );
  3781. func XSleep(t *TLS, dwMilliseconds uint32) {
  3782. if __ccgo_strace {
  3783. trc("t=%v dwMilliseconds=%v, (%v:)", t, dwMilliseconds, origin(2))
  3784. }
  3785. gotime.Sleep(gotime.Duration(dwMilliseconds) * gotime.Millisecond)
  3786. }
  3787. // BOOL SystemTimeToFileTime(const SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime);
  3788. func XSystemTimeToFileTime(t *TLS, lpSystemTime, lpFileTime uintptr) int32 {
  3789. if __ccgo_strace {
  3790. trc("t=%v lpFileTime=%v, (%v:)", t, lpFileTime, origin(2))
  3791. }
  3792. r0, _, _ := procSystemTimeToFileTime.Call(lpSystemTime, lpFileTime, 0)
  3793. return int32(r0)
  3794. }
  3795. // BOOL UnlockFile(
  3796. //
  3797. // HANDLE hFile,
  3798. // DWORD dwFileOffsetLow,
  3799. // DWORD dwFileOffsetHigh,
  3800. // DWORD nNumberOfBytesToUnlockLow,
  3801. // DWORD nNumberOfBytesToUnlockHigh
  3802. //
  3803. // );
  3804. func XUnlockFile(t *TLS, hFile uintptr, dwFileOffsetLow, dwFileOffsetHigh, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh uint32) int32 {
  3805. if __ccgo_strace {
  3806. trc("t=%v hFile=%v nNumberOfBytesToUnlockHigh=%v, (%v:)", t, hFile, nNumberOfBytesToUnlockHigh, origin(2))
  3807. }
  3808. r1, _, e1 := procUnlockFile.Call(hFile, uintptr(dwFileOffsetLow), uintptr(dwFileOffsetHigh), uintptr(nNumberOfBytesToUnlockLow), uintptr(nNumberOfBytesToUnlockHigh), 0)
  3809. if r1 == 0 {
  3810. if e1 != windows.NOERROR {
  3811. t.setErrno(e1)
  3812. } else {
  3813. t.setErrno(errno.EINVAL)
  3814. }
  3815. return 0
  3816. }
  3817. return int32(r1)
  3818. }
  3819. // BOOL UnlockFileEx(
  3820. //
  3821. // HANDLE hFile,
  3822. // DWORD dwReserved,
  3823. // DWORD nNumberOfBytesToUnlockLow,
  3824. // DWORD nNumberOfBytesToUnlockHigh,
  3825. // LPOVERLAPPED lpOverlapped
  3826. //
  3827. // );
  3828. func XUnlockFileEx(t *TLS, hFile uintptr, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh uint32, lpOverlapped uintptr) int32 {
  3829. if __ccgo_strace {
  3830. trc("t=%v hFile=%v nNumberOfBytesToUnlockHigh=%v lpOverlapped=%v, (%v:)", t, hFile, nNumberOfBytesToUnlockHigh, lpOverlapped, origin(2))
  3831. }
  3832. r1, _, e1 := procUnlockFileEx.Call(hFile, uintptr(dwReserved), uintptr(nNumberOfBytesToUnlockLow), uintptr(nNumberOfBytesToUnlockHigh), lpOverlapped, 0)
  3833. if r1 == 0 {
  3834. if e1 != windows.NOERROR {
  3835. t.setErrno(e1)
  3836. } else {
  3837. t.setErrno(errno.EINVAL)
  3838. }
  3839. return 0
  3840. }
  3841. return int32(r1)
  3842. }
  3843. // BOOL UnmapViewOfFile(
  3844. //
  3845. // LPCVOID lpBaseAddress
  3846. //
  3847. // );
  3848. func XUnmapViewOfFile(t *TLS, lpBaseAddress uintptr) int32 {
  3849. if __ccgo_strace {
  3850. trc("t=%v lpBaseAddress=%v, (%v:)", t, lpBaseAddress, origin(2))
  3851. }
  3852. err := windows.UnmapViewOfFile(lpBaseAddress)
  3853. if err != nil {
  3854. t.setErrno(err)
  3855. return 0
  3856. }
  3857. return 1
  3858. }
  3859. // int WideCharToMultiByte(
  3860. //
  3861. // UINT CodePage,
  3862. // DWORD dwFlags,
  3863. // _In_NLS_string_(cchWideChar)LPCWCH lpWideCharStr,
  3864. // int cchWideChar,
  3865. // LPSTR lpMultiByteStr,
  3866. // int cbMultiByte,
  3867. // LPCCH lpDefaultChar,
  3868. // LPBOOL lpUsedDefaultChar
  3869. //
  3870. // );
  3871. func XWideCharToMultiByte(t *TLS, CodePage uint32, dwFlags uint32, lpWideCharStr uintptr, cchWideChar int32, lpMultiByteStr uintptr, cbMultiByte int32, lpDefaultChar, lpUsedDefaultChar uintptr) int32 {
  3872. if __ccgo_strace {
  3873. trc("t=%v CodePage=%v dwFlags=%v lpWideCharStr=%v cchWideChar=%v lpMultiByteStr=%v cbMultiByte=%v lpUsedDefaultChar=%v, (%v:)", t, CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpUsedDefaultChar, origin(2))
  3874. }
  3875. r1, _, _ := procWideCharToMultiByte.Call(uintptr(CodePage), uintptr(dwFlags), lpWideCharStr,
  3876. uintptr(cchWideChar), lpMultiByteStr, uintptr(cbMultiByte),
  3877. lpDefaultChar, lpUsedDefaultChar, 0)
  3878. return (int32(r1))
  3879. }
  3880. // void OutputDebugStringA(
  3881. //
  3882. // LPCSTR lpOutputString
  3883. //
  3884. // )
  3885. func XOutputDebugStringA(t *TLS, lpOutputString uintptr) {
  3886. if __ccgo_strace {
  3887. trc("t=%v lpOutputString=%v, (%v:)", t, lpOutputString, origin(2))
  3888. }
  3889. panic(todo(""))
  3890. }
  3891. // BOOL FlushViewOfFile(
  3892. //
  3893. // LPCVOID lpBaseAddress,
  3894. // SIZE_T dwNumberOfBytesToFlush
  3895. //
  3896. // );
  3897. func XFlushViewOfFile(t *TLS, lpBaseAddress uintptr, dwNumberOfBytesToFlush types.Size_t) int32 {
  3898. if __ccgo_strace {
  3899. trc("t=%v lpBaseAddress=%v dwNumberOfBytesToFlush=%v, (%v:)", t, lpBaseAddress, dwNumberOfBytesToFlush, origin(2))
  3900. }
  3901. err := windows.FlushViewOfFile(lpBaseAddress, uintptr(dwNumberOfBytesToFlush))
  3902. if err != nil {
  3903. t.setErrno(err)
  3904. return 0
  3905. }
  3906. return 1
  3907. }
  3908. type _ino_t = uint16 /* types.h:43:24 */
  3909. type _dev_t = uint32 /* types.h:51:22 */
  3910. type _stat64 = struct {
  3911. Fst_dev _dev_t
  3912. Fst_ino _ino_t
  3913. Fst_mode uint16
  3914. Fst_nlink int16
  3915. Fst_uid int16
  3916. Fst_gid int16
  3917. _ [2]byte
  3918. Fst_rdev _dev_t
  3919. _ [4]byte
  3920. Fst_size int64
  3921. Fst_atime int64
  3922. Fst_mtime int64
  3923. Fst_ctime int64
  3924. } /* _mingw_stat64.h:83:3 */
  3925. var (
  3926. Windows_Tick int64 = 10000000
  3927. SecToUnixEpoch int64 = 11644473600
  3928. )
  3929. func WindowsTickToUnixSeconds(windowsTicks int64) int64 {
  3930. return (windowsTicks/Windows_Tick - SecToUnixEpoch)
  3931. }
  3932. // int _stat64(const char *path, struct __stat64 *buffer);
  3933. func X_stat64(t *TLS, path, buffer uintptr) int32 {
  3934. if __ccgo_strace {
  3935. trc("t=%v buffer=%v, (%v:)", t, buffer, origin(2))
  3936. }
  3937. var fa windows.Win32FileAttributeData
  3938. r1, _, e1 := procGetFileAttributesExA.Call(path, windows.GetFileExInfoStandard, (uintptr)(unsafe.Pointer(&fa)))
  3939. if r1 == 0 {
  3940. if e1 != windows.NOERROR {
  3941. t.setErrno(e1)
  3942. } else {
  3943. t.setErrno(errno.EINVAL)
  3944. }
  3945. return -1
  3946. }
  3947. var bStat64 = (*_stat64)(unsafe.Pointer(buffer))
  3948. var accessTime = int64(fa.LastAccessTime.HighDateTime)<<32 + int64(fa.LastAccessTime.LowDateTime)
  3949. bStat64.Fst_atime = WindowsTickToUnixSeconds(accessTime)
  3950. var modTime = int64(fa.LastWriteTime.HighDateTime)<<32 + int64(fa.LastWriteTime.LowDateTime)
  3951. bStat64.Fst_mtime = WindowsTickToUnixSeconds(modTime)
  3952. var crTime = int64(fa.CreationTime.HighDateTime)<<32 + int64(fa.CreationTime.LowDateTime)
  3953. bStat64.Fst_ctime = WindowsTickToUnixSeconds(crTime)
  3954. var fSz = int64(fa.FileSizeHigh)<<32 + int64(fa.FileSizeLow)
  3955. bStat64.Fst_size = fSz
  3956. bStat64.Fst_mode = WindowsAttrbiutesToStat(fa.FileAttributes)
  3957. return 0
  3958. }
  3959. func WindowsAttrbiutesToStat(fa uint32) uint16 {
  3960. var src_mode = fa & 0xff
  3961. var st_mode uint16
  3962. if (src_mode & windows.FILE_ATTRIBUTE_DIRECTORY) != 0 {
  3963. st_mode = windows.S_IFDIR
  3964. } else {
  3965. st_mode = windows.S_IFREG
  3966. }
  3967. if src_mode&windows.FILE_ATTRIBUTE_READONLY != 0 {
  3968. st_mode = st_mode | windows.S_IRUSR
  3969. } else {
  3970. st_mode = st_mode | windows.S_IRUSR | windows.S_IWUSR
  3971. }
  3972. // fill group fields
  3973. st_mode = st_mode | (st_mode&0x700)>>3
  3974. st_mode = st_mode | (st_mode&0x700)>>6
  3975. return st_mode
  3976. }
  3977. // int _chsize(
  3978. //
  3979. // int fd,
  3980. // long size
  3981. //
  3982. // );
  3983. func X_chsize(t *TLS, fd int32, size long) int32 {
  3984. if __ccgo_strace {
  3985. trc("t=%v fd=%v size=%v, (%v:)", t, fd, size, origin(2))
  3986. }
  3987. f, ok := fdToFile(fd)
  3988. if !ok {
  3989. t.setErrno(EBADF)
  3990. return -1
  3991. }
  3992. err := windows.Ftruncate(f.Handle, int64(size))
  3993. if err != nil {
  3994. t.setErrno(err)
  3995. return -1
  3996. }
  3997. return 0
  3998. }
  3999. // int _snprintf(char *str, size_t size, const char *format, ...);
  4000. func X_snprintf(t *TLS, str uintptr, size types.Size_t, format, args uintptr) int32 {
  4001. if __ccgo_strace {
  4002. trc("t=%v str=%v size=%v args=%v, (%v:)", t, str, size, args, origin(2))
  4003. }
  4004. return Xsnprintf(t, str, size, format, args)
  4005. }
  4006. const wErr_ERROR_INSUFFICIENT_BUFFER = 122
  4007. func win32FindDataToFileInfo(t *TLS, fdata *stat.X_finddata64i32_t, wfd *windows.Win32finddata) int32 {
  4008. // t64 = 64-bit time value
  4009. var accessTime = int64(wfd.LastAccessTime.HighDateTime)<<32 + int64(wfd.LastAccessTime.LowDateTime)
  4010. fdata.Ftime_access = WindowsTickToUnixSeconds(accessTime)
  4011. var modTime = int64(wfd.LastWriteTime.HighDateTime)<<32 + int64(wfd.LastWriteTime.LowDateTime)
  4012. fdata.Ftime_write = WindowsTickToUnixSeconds(modTime)
  4013. var crTime = int64(wfd.CreationTime.HighDateTime)<<32 + int64(wfd.CreationTime.LowDateTime)
  4014. fdata.Ftime_create = WindowsTickToUnixSeconds(crTime)
  4015. // i32 = 32-bit size
  4016. fdata.Fsize = wfd.FileSizeLow
  4017. fdata.Fattrib = wfd.FileAttributes
  4018. var cp = XGetConsoleCP(t)
  4019. var wcFn = (uintptr)(unsafe.Pointer(&wfd.FileName[0]))
  4020. var mbcsFn = (uintptr)(unsafe.Pointer(&fdata.Fname[0]))
  4021. rv := XWideCharToMultiByte(t, cp, 0, wcFn, -1, mbcsFn, 260, 0, 0)
  4022. if rv == wErr_ERROR_INSUFFICIENT_BUFFER {
  4023. t.setErrno(errno.ENOMEM)
  4024. return -1
  4025. }
  4026. return 0
  4027. }
  4028. // intptr_t _findfirst64i32(
  4029. //
  4030. // const char *filespec,
  4031. // struct _finddata64i32_t *fileinfo
  4032. //
  4033. // );
  4034. func X_findfirst64i32(t *TLS, filespec, fileinfo uintptr) types.Intptr_t {
  4035. if __ccgo_strace {
  4036. trc("t=%v fileinfo=%v, (%v:)", t, fileinfo, origin(2))
  4037. }
  4038. // Note: this is the 'narrow' character findfirst -- expects output
  4039. // as mbcs -- conversion below -- via ToFileInfo
  4040. var gsFileSpec = GoString(filespec)
  4041. namep, err := windows.UTF16PtrFromString(gsFileSpec)
  4042. if err != nil {
  4043. t.setErrno(err)
  4044. return types.Intptr_t(-1)
  4045. }
  4046. var fdata = (*stat.X_finddata64i32_t)(unsafe.Pointer(fileinfo))
  4047. var wfd windows.Win32finddata
  4048. h, err := windows.FindFirstFile((*uint16)(unsafe.Pointer(namep)), &wfd)
  4049. if err != nil {
  4050. t.setErrno(err)
  4051. return types.Intptr_t(-1)
  4052. }
  4053. rv := win32FindDataToFileInfo(t, fdata, &wfd)
  4054. if rv != 0 {
  4055. if h != 0 {
  4056. windows.FindClose(h)
  4057. }
  4058. return types.Intptr_t(-1)
  4059. }
  4060. return types.Intptr_t(h)
  4061. }
  4062. // int _findnext64i32(
  4063. //
  4064. // intptr_t handle,
  4065. // struct _finddata64i32_t *fileinfo
  4066. //
  4067. // );
  4068. func X_findnext64i32(t *TLS, handle types.Intptr_t, fileinfo uintptr) int32 {
  4069. if __ccgo_strace {
  4070. trc("t=%v handle=%v fileinfo=%v, (%v:)", t, handle, fileinfo, origin(2))
  4071. }
  4072. var fdata = (*stat.X_finddata64i32_t)(unsafe.Pointer(fileinfo))
  4073. var wfd windows.Win32finddata
  4074. err := windows.FindNextFile(windows.Handle(handle), &wfd)
  4075. if err != nil {
  4076. t.setErrno(err)
  4077. return -1
  4078. }
  4079. rv := win32FindDataToFileInfo(t, fdata, &wfd)
  4080. if rv != 0 {
  4081. return -1
  4082. }
  4083. return 0
  4084. }
  4085. // int _findclose(
  4086. //
  4087. // intptr_t handle
  4088. //
  4089. // );
  4090. func X_findclose(t *TLS, handle types.Intptr_t) int32 {
  4091. if __ccgo_strace {
  4092. trc("t=%v handle=%v, (%v:)", t, handle, origin(2))
  4093. }
  4094. err := windows.FindClose(windows.Handle(handle))
  4095. if err != nil {
  4096. t.setErrno(err)
  4097. return -1
  4098. }
  4099. return 0
  4100. }
  4101. // DWORD GetEnvironmentVariableA(
  4102. //
  4103. // LPCSTR lpName,
  4104. // LPSTR lpBuffer,
  4105. // DWORD nSize
  4106. //
  4107. // );
  4108. func XGetEnvironmentVariableA(t *TLS, lpName, lpBuffer uintptr, nSize uint32) uint32 {
  4109. if __ccgo_strace {
  4110. trc("t=%v lpBuffer=%v nSize=%v, (%v:)", t, lpBuffer, nSize, origin(2))
  4111. }
  4112. r0, _, e1 := procGetEnvironmentVariableA.Call(lpName, lpBuffer, uintptr(nSize))
  4113. n := uint32(r0)
  4114. if n == 0 {
  4115. if e1 != windows.NOERROR {
  4116. t.setErrno(e1)
  4117. } else {
  4118. t.setErrno(errno.EINVAL)
  4119. }
  4120. }
  4121. return n
  4122. }
  4123. // int _fstat64(
  4124. //
  4125. // int fd,
  4126. // struct __stat64 *buffer
  4127. //
  4128. // );
  4129. func X_fstat64(t *TLS, fd int32, buffer uintptr) int32 {
  4130. if __ccgo_strace {
  4131. trc("t=%v fd=%v buffer=%v, (%v:)", t, fd, buffer, origin(2))
  4132. }
  4133. f, ok := fdToFile(fd)
  4134. if !ok {
  4135. t.setErrno(EBADF)
  4136. return -1
  4137. }
  4138. var d windows.ByHandleFileInformation
  4139. err := windows.GetFileInformationByHandle(f.Handle, &d)
  4140. if err != nil {
  4141. t.setErrno(EBADF)
  4142. return -1
  4143. }
  4144. var bStat64 = (*_stat64)(unsafe.Pointer(buffer))
  4145. var accessTime = int64(d.LastAccessTime.HighDateTime)<<32 + int64(d.LastAccessTime.LowDateTime)
  4146. bStat64.Fst_atime = WindowsTickToUnixSeconds(accessTime)
  4147. var modTime = int64(d.LastWriteTime.HighDateTime)<<32 + int64(d.LastWriteTime.LowDateTime)
  4148. bStat64.Fst_mtime = WindowsTickToUnixSeconds(modTime)
  4149. var crTime = int64(d.CreationTime.HighDateTime)<<32 + int64(d.CreationTime.LowDateTime)
  4150. bStat64.Fst_ctime = WindowsTickToUnixSeconds(crTime)
  4151. var fSz = int64(d.FileSizeHigh)<<32 + int64(d.FileSizeLow)
  4152. bStat64.Fst_size = fSz
  4153. bStat64.Fst_mode = WindowsAttrbiutesToStat(d.FileAttributes)
  4154. return 0
  4155. }
  4156. // HANDLE CreateEventA(
  4157. //
  4158. // LPSECURITY_ATTRIBUTES lpEventAttributes,
  4159. // BOOL bManualReset,
  4160. // BOOL bInitialState,
  4161. // LPCSTR lpName
  4162. //
  4163. // );
  4164. func XCreateEventA(t *TLS, lpEventAttributes uintptr, bManualReset, bInitialState int32, lpName uintptr) uintptr {
  4165. if __ccgo_strace {
  4166. trc("t=%v lpEventAttributes=%v bInitialState=%v lpName=%v, (%v:)", t, lpEventAttributes, bInitialState, lpName, origin(2))
  4167. }
  4168. r0, _, err := procCreateEventA.Call(lpEventAttributes, uintptr(bManualReset),
  4169. uintptr(bInitialState), lpName, 0, 0)
  4170. if r0 == 0 {
  4171. t.setErrno(err)
  4172. }
  4173. return r0
  4174. }
  4175. // BOOL WINAPI CancelSynchronousIo(
  4176. //
  4177. // _In_ HANDLE hThread
  4178. //
  4179. // );
  4180. func XCancelSynchronousIo(t *TLS, hThread uintptr) int32 {
  4181. if __ccgo_strace {
  4182. trc("t=%v hThread=%v, (%v:)", t, hThread, origin(2))
  4183. }
  4184. panic(todo(""))
  4185. }
  4186. func X_endthreadex(t *TLS, _ ...interface{}) {
  4187. // NOOP
  4188. }
  4189. // The calling convention for beginthread is cdecl -- but in this
  4190. // case we're just intercepting it and sending it through CreateThread which expects stdcall
  4191. // and gets that via the go callback. This is safe because the thread is calling into go
  4192. // not a cdecl function which would expect the stack setup of cdecl.
  4193. func X_beginthread(t *TLS, procAddr uintptr, stack_sz uint32, args uintptr) int32 {
  4194. if __ccgo_strace {
  4195. trc("t=%v procAddr=%v stack_sz=%v args=%v, (%v:)", t, procAddr, stack_sz, args, origin(2))
  4196. }
  4197. f := (*struct{ f func(*TLS, uintptr) uint32 })(unsafe.Pointer(&struct{ uintptr }{procAddr})).f
  4198. var tAdp = ThreadAdapter{threadFunc: f, tls: NewTLS(), param: args}
  4199. tAdp.token = addObject(&tAdp)
  4200. r0, _, err := procCreateThread.Call(0, uintptr(stack_sz),
  4201. threadCallback, tAdp.token, 0, 0)
  4202. if r0 == 0 {
  4203. t.setErrno(err)
  4204. }
  4205. return int32(r0)
  4206. }
  4207. // uintptr_t _beginthreadex( // NATIVE CODE
  4208. //
  4209. // void *security,
  4210. // unsigned stack_size,
  4211. // unsigned ( __stdcall *start_address )( void * ),
  4212. // void *arglist,
  4213. // unsigned initflag,
  4214. // unsigned *thrdaddr
  4215. //
  4216. // );
  4217. func X_beginthreadex(t *TLS, _ uintptr, stack_sz uint32, procAddr uintptr, args uintptr, initf uint32, thAddr uintptr) int32 {
  4218. f := (*struct{ f func(*TLS, uintptr) uint32 })(unsafe.Pointer(&struct{ uintptr }{procAddr})).f
  4219. var tAdp = ThreadAdapter{threadFunc: f, tls: NewTLS(), param: args}
  4220. tAdp.token = addObject(&tAdp)
  4221. r0, _, err := procCreateThread.Call(0, uintptr(stack_sz),
  4222. threadCallback, tAdp.token, uintptr(initf), thAddr)
  4223. if r0 == 0 {
  4224. t.setErrno(err)
  4225. }
  4226. return int32(r0)
  4227. }
  4228. // DWORD GetCurrentThreadId();
  4229. func XGetCurrentThreadId(t *TLS) uint32 {
  4230. if __ccgo_strace {
  4231. trc("t=%v, (%v:)", t, origin(2))
  4232. }
  4233. r0, _, _ := procGetCurrentThreadId.Call(0, 0, 0)
  4234. return uint32(r0)
  4235. //return uint32(t.ID)
  4236. }
  4237. // BOOL GetExitCodeThread(
  4238. //
  4239. // HANDLE hThread,
  4240. // LPDWORD lpExitCode
  4241. //
  4242. // );
  4243. func XGetExitCodeThread(t *TLS, hThread, lpExitCode uintptr) int32 {
  4244. if __ccgo_strace {
  4245. trc("t=%v lpExitCode=%v, (%v:)", t, lpExitCode, origin(2))
  4246. }
  4247. r0, _, _ := procGetExitCodeThread.Call(hThread, lpExitCode, 0)
  4248. return int32(r0)
  4249. }
  4250. // DWORD WaitForSingleObjectEx(
  4251. //
  4252. // HANDLE hHandle,
  4253. // DWORD dwMilliseconds,
  4254. // BOOL bAlertable
  4255. //
  4256. // );
  4257. func XWaitForSingleObjectEx(t *TLS, hHandle uintptr, dwMilliseconds uint32, bAlertable int32) uint32 {
  4258. if __ccgo_strace {
  4259. trc("t=%v hHandle=%v dwMilliseconds=%v bAlertable=%v, (%v:)", t, hHandle, dwMilliseconds, bAlertable, origin(2))
  4260. }
  4261. rv, _, _ := procWaitForSingleObjectEx.Call(hHandle, uintptr(dwMilliseconds), uintptr(bAlertable))
  4262. return uint32(rv)
  4263. }
  4264. // DWORD MsgWaitForMultipleObjectsEx(
  4265. //
  4266. // DWORD nCount,
  4267. // const HANDLE *pHandles,
  4268. // DWORD dwMilliseconds,
  4269. // DWORD dwWakeMask,
  4270. // DWORD dwFlags
  4271. //
  4272. // );
  4273. func XMsgWaitForMultipleObjectsEx(t *TLS, nCount uint32, pHandles uintptr, dwMilliseconds, dwWakeMask, dwFlags uint32) uint32 {
  4274. if __ccgo_strace {
  4275. trc("t=%v nCount=%v pHandles=%v dwFlags=%v, (%v:)", t, nCount, pHandles, dwFlags, origin(2))
  4276. }
  4277. r0, _, err := procMsgWaitForMultipleObjectsEx.Call(uintptr(nCount),
  4278. pHandles,
  4279. uintptr(dwMilliseconds),
  4280. uintptr(dwWakeMask),
  4281. uintptr(dwFlags),
  4282. 0,
  4283. )
  4284. if err != windows.NOERROR {
  4285. t.setErrno(err)
  4286. }
  4287. return uint32(r0)
  4288. }
  4289. func XMessageBoxW(t *TLS, _ ...interface{}) int32 {
  4290. panic(todo(""))
  4291. }
  4292. // DWORD GetModuleFileNameW(
  4293. //
  4294. // HMODULE hModule,
  4295. // LPWSTR lpFileName,
  4296. // DWORD nSize
  4297. //
  4298. // );
  4299. func XGetModuleFileNameW(t *TLS, hModule, lpFileName uintptr, nSize uint32) uint32 {
  4300. if __ccgo_strace {
  4301. trc("t=%v lpFileName=%v nSize=%v, (%v:)", t, lpFileName, nSize, origin(2))
  4302. }
  4303. r0, _, err := procGetModuleFileNameW.Call(hModule, lpFileName, uintptr(nSize))
  4304. if r0 == 0 {
  4305. t.setErrno(err)
  4306. }
  4307. return uint32(r0)
  4308. }
  4309. // NET_API_STATUS NET_API_FUNCTION NetGetDCName(
  4310. //
  4311. // LPCWSTR ServerName,
  4312. // LPCWSTR DomainName,
  4313. // LPBYTE *Buffer
  4314. //
  4315. // );
  4316. func XNetGetDCName(t *TLS, ServerName, DomainName, Buffer uintptr) int32 {
  4317. if __ccgo_strace {
  4318. trc("t=%v Buffer=%v, (%v:)", t, Buffer, origin(2))
  4319. }
  4320. r0, _, err := procNetGetDCName.Call(ServerName, DomainName, Buffer)
  4321. if err != windows.NOERROR {
  4322. t.setErrno(err)
  4323. }
  4324. return int32(r0)
  4325. }
  4326. // NET_API_STATUS NET_API_FUNCTION NetUserGetInfo(
  4327. //
  4328. // LPCWSTR servername,
  4329. // LPCWSTR username,
  4330. // DWORD level,
  4331. // LPBYTE *bufptr
  4332. //
  4333. // );
  4334. func XNetUserGetInfo(t *TLS, servername, username uintptr, level uint32, bufptr uintptr) uint32 {
  4335. if __ccgo_strace {
  4336. trc("t=%v username=%v level=%v bufptr=%v, (%v:)", t, username, level, bufptr, origin(2))
  4337. }
  4338. r0, _, err := procNetUserGetInfo.Call(servername,
  4339. username,
  4340. uintptr(level),
  4341. bufptr,
  4342. 0,
  4343. 0,
  4344. )
  4345. if err != windows.NOERROR {
  4346. t.setErrno(err)
  4347. }
  4348. return uint32(r0)
  4349. }
  4350. func XlstrlenW(t *TLS, _ ...interface{}) int32 {
  4351. panic(todo(""))
  4352. }
  4353. // USERENVAPI BOOL GetProfilesDirectoryW(
  4354. //
  4355. // [out] LPWSTR lpProfileDir,
  4356. // [in, out] LPDWORD lpcchSize
  4357. //
  4358. // );
  4359. func XGetProfilesDirectoryW(t *TLS, lpProfileDir, lpcchSize uintptr) int32 {
  4360. if __ccgo_strace {
  4361. trc("t=%v lpcchSize=%v, (%v:)", t, lpcchSize, origin(2))
  4362. }
  4363. r0, _, err := procGetProfilesDirectoryW.Call(lpProfileDir, lpcchSize, 0)
  4364. if err != windows.NOERROR {
  4365. t.setErrno(err)
  4366. }
  4367. return int32(r0)
  4368. }
  4369. func XNetApiBufferFree(t *TLS, _ ...interface{}) int32 {
  4370. panic(todo(""))
  4371. }
  4372. // DWORD GetPrivateProfileStringA(
  4373. //
  4374. // LPCSTR lpAppName,
  4375. // LPCSTR lpKeyName,
  4376. // LPCSTR lpDefault,
  4377. // LPSTR lpReturnedString,
  4378. // DWORD nSize,
  4379. // LPCSTR lpFileName
  4380. //
  4381. // );
  4382. func XGetPrivateProfileStringA(t *TLS, lpAppName, lpKeyName, lpDefault, lpReturnedString uintptr, nSize uint32, lpFileName uintptr) uint32 {
  4383. if __ccgo_strace {
  4384. trc("t=%v lpReturnedString=%v nSize=%v lpFileName=%v, (%v:)", t, lpReturnedString, nSize, lpFileName, origin(2))
  4385. }
  4386. r0, _, err := procGetPrivateProfileStringA.Call(lpAppName,
  4387. lpKeyName,
  4388. lpDefault,
  4389. lpReturnedString,
  4390. uintptr(nSize),
  4391. lpFileName,
  4392. )
  4393. if err != windows.NOERROR {
  4394. t.setErrno(0x02)
  4395. }
  4396. return uint32(r0)
  4397. }
  4398. func XGetWindowsDirectoryA(t *TLS, _ ...interface{}) int32 {
  4399. panic(todo(""))
  4400. }
  4401. // BOOL GetFileSecurityW(
  4402. //
  4403. // LPCSTR lpFileName,
  4404. // SECURITY_INFORMATION RequestedInformation,
  4405. // PSECURITY_DESCRIPTOR pSecurityDescriptor,
  4406. // DWORD nLength,
  4407. // LPDWORD lpnLengthNeeded
  4408. //
  4409. // );
  4410. func XGetFileSecurityW(t *TLS, lpFileName uintptr, RequestedInformation uint32, pSecurityDescriptor uintptr, nLength uint32, lpnLengthNeeded uintptr) int32 {
  4411. if __ccgo_strace {
  4412. trc("t=%v lpFileName=%v RequestedInformation=%v pSecurityDescriptor=%v nLength=%v lpnLengthNeeded=%v, (%v:)", t, lpFileName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded, origin(2))
  4413. }
  4414. r0, _, err := procGetFileSecurityW.Call(lpFileName, uintptr(RequestedInformation), pSecurityDescriptor, uintptr(nLength), lpnLengthNeeded, 0)
  4415. if err != windows.NOERROR {
  4416. t.setErrno(err)
  4417. }
  4418. return int32(r0)
  4419. }
  4420. // BOOL GetSecurityDescriptorOwner(
  4421. //
  4422. // PSECURITY_DESCRIPTOR pSecurityDescriptor,
  4423. // PSID *pOwner,
  4424. // LPBOOL lpbOwnerDefaulted
  4425. //
  4426. // );
  4427. func XGetSecurityDescriptorOwner(t *TLS, pSecurityDescriptor, pOwner, lpbOwnerDefaulted uintptr) int32 {
  4428. if __ccgo_strace {
  4429. trc("t=%v lpbOwnerDefaulted=%v, (%v:)", t, lpbOwnerDefaulted, origin(2))
  4430. }
  4431. r0, _, err := procGetSecurityDescriptorOwner.Call(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
  4432. if err != windows.NOERROR {
  4433. t.setErrno(err)
  4434. }
  4435. return int32(r0)
  4436. }
  4437. // PSID_IDENTIFIER_AUTHORITY GetSidIdentifierAuthority(
  4438. //
  4439. // PSID pSid
  4440. //
  4441. // );
  4442. func XGetSidIdentifierAuthority(t *TLS, pSid uintptr) uintptr {
  4443. if __ccgo_strace {
  4444. trc("t=%v pSid=%v, (%v:)", t, pSid, origin(2))
  4445. }
  4446. r0, _, err := procGetSidIdentifierAuthority.Call(pSid, 0, 0)
  4447. if err != windows.NOERROR {
  4448. t.setErrno(err)
  4449. }
  4450. return r0
  4451. }
  4452. // BOOL ImpersonateSelf(
  4453. //
  4454. // SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
  4455. //
  4456. // );
  4457. func XImpersonateSelf(t *TLS, ImpersonationLevel int32) int32 {
  4458. if __ccgo_strace {
  4459. trc("t=%v ImpersonationLevel=%v, (%v:)", t, ImpersonationLevel, origin(2))
  4460. }
  4461. r0, _, err := procImpersonateSelf.Call(uintptr(ImpersonationLevel), 0, 0)
  4462. if err != windows.NOERROR {
  4463. t.setErrno(err)
  4464. }
  4465. return int32(r0)
  4466. }
  4467. // BOOL OpenThreadToken(
  4468. //
  4469. // HANDLE ThreadHandle,
  4470. // DWORD DesiredAccess,
  4471. // BOOL OpenAsSelf,
  4472. // PHANDLE TokenHandle
  4473. //
  4474. // );
  4475. func XOpenThreadToken(t *TLS, ThreadHandle uintptr, DesiredAccess uint32, OpenAsSelf int32, TokenHandle uintptr) int32 {
  4476. if __ccgo_strace {
  4477. trc("t=%v ThreadHandle=%v DesiredAccess=%v OpenAsSelf=%v TokenHandle=%v, (%v:)", t, ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle, origin(2))
  4478. }
  4479. r0, _, err := procOpenThreadToken.Call(ThreadHandle, uintptr(DesiredAccess), uintptr(OpenAsSelf), TokenHandle, 0, 0)
  4480. if err != windows.NOERROR {
  4481. t.setErrno(err)
  4482. }
  4483. return int32(r0)
  4484. }
  4485. // HANDLE GetCurrentThread();
  4486. func XGetCurrentThread(t *TLS) uintptr {
  4487. if __ccgo_strace {
  4488. trc("t=%v, (%v:)", t, origin(2))
  4489. }
  4490. r0, _, err := procGetCurrentThread.Call(0, 0, 0)
  4491. if err != windows.NOERROR {
  4492. t.setErrno(err)
  4493. }
  4494. return r0
  4495. }
  4496. // BOOL RevertToSelf();
  4497. func XRevertToSelf(t *TLS) int32 {
  4498. if __ccgo_strace {
  4499. trc("t=%v, (%v:)", t, origin(2))
  4500. }
  4501. r0, _, err := procRevertToSelf.Call(0, 0, 0)
  4502. if err != windows.NOERROR {
  4503. t.setErrno(err)
  4504. }
  4505. return int32(r0)
  4506. }
  4507. // BOOL AccessCheck(
  4508. //
  4509. // PSECURITY_DESCRIPTOR pSecurityDescriptor,
  4510. // HANDLE ClientToken,
  4511. // DWORD DesiredAccess,
  4512. // PGENERIC_MAPPING GenericMapping,
  4513. // PPRIVILEGE_SET PrivilegeSet,
  4514. // LPDWORD PrivilegeSetLength,
  4515. // LPDWORD GrantedAccess,
  4516. // LPBOOL AccessStatus
  4517. //
  4518. // );
  4519. func XAccessCheck(t *TLS, pSecurityDescriptor, ClientToken uintptr, DesiredAccess uint32, GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, AccessStatus uintptr) int32 {
  4520. if __ccgo_strace {
  4521. trc("t=%v ClientToken=%v DesiredAccess=%v AccessStatus=%v, (%v:)", t, ClientToken, DesiredAccess, AccessStatus, origin(2))
  4522. }
  4523. r0, _, err := procAccessCheck.Call(pSecurityDescriptor,
  4524. ClientToken,
  4525. uintptr(DesiredAccess),
  4526. GenericMapping,
  4527. PrivilegeSet,
  4528. PrivilegeSetLength,
  4529. GrantedAccess,
  4530. AccessStatus,
  4531. 0,
  4532. )
  4533. if err != windows.NOERROR {
  4534. t.setErrno(err)
  4535. }
  4536. return int32(r0)
  4537. }
  4538. // int _wcsicmp(
  4539. //
  4540. // const wchar_t *string1,
  4541. // const wchar_t *string2
  4542. //
  4543. // );
  4544. func Xwcsicmp(t *TLS, string1, string2 uintptr) int32 {
  4545. if __ccgo_strace {
  4546. trc("t=%v string2=%v, (%v:)", t, string2, origin(2))
  4547. }
  4548. var s1 = strings.ToLower(goWideString(string1))
  4549. var s2 = strings.ToLower(goWideString(string2))
  4550. return int32(strings.Compare(s1, s2))
  4551. }
  4552. // BOOL SetCurrentDirectoryW(
  4553. //
  4554. // LPCTSTR lpPathName
  4555. //
  4556. // );
  4557. func XSetCurrentDirectoryW(t *TLS, lpPathName uintptr) int32 {
  4558. if __ccgo_strace {
  4559. trc("t=%v lpPathName=%v, (%v:)", t, lpPathName, origin(2))
  4560. }
  4561. err := windows.SetCurrentDirectory((*uint16)(unsafe.Pointer(lpPathName)))
  4562. if err != nil {
  4563. t.setErrno(err)
  4564. return 0
  4565. }
  4566. return 1
  4567. }
  4568. // DWORD GetCurrentDirectory(
  4569. //
  4570. // DWORD nBufferLength,
  4571. // LPWTSTR lpBuffer
  4572. //
  4573. // );
  4574. func XGetCurrentDirectoryW(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
  4575. if __ccgo_strace {
  4576. trc("t=%v nBufferLength=%v lpBuffer=%v, (%v:)", t, nBufferLength, lpBuffer, origin(2))
  4577. }
  4578. n, err := windows.GetCurrentDirectory(nBufferLength, (*uint16)(unsafe.Pointer(lpBuffer)))
  4579. if err != nil {
  4580. t.setErrno(err)
  4581. }
  4582. return n
  4583. }
  4584. // BOOL GetFileInformationByHandle(
  4585. //
  4586. // HANDLE hFile,
  4587. // LPBY_HANDLE_FILE_INFORMATION lpFileInformation
  4588. //
  4589. // );
  4590. func XGetFileInformationByHandle(t *TLS, hFile, lpFileInformation uintptr) int32 {
  4591. if __ccgo_strace {
  4592. trc("t=%v lpFileInformation=%v, (%v:)", t, lpFileInformation, origin(2))
  4593. }
  4594. r1, _, e1 := procGetFileInformationByHandle.Call(hFile, lpFileInformation, 0)
  4595. if r1 == 0 {
  4596. if e1 != windows.NOERROR {
  4597. t.setErrno(e1)
  4598. } else {
  4599. t.setErrno(errno.EINVAL)
  4600. }
  4601. }
  4602. return int32(r1)
  4603. }
  4604. // BOOL GetVolumeInformationW(
  4605. //
  4606. // LPCWSTR lpRootPathName,
  4607. // LPWSTR lpVolumeNameBuffer,
  4608. // DWORD nVolumeNameSize,
  4609. // LPDWORD lpVolumeSerialNumber,
  4610. // LPDWORD lpMaximumComponentLength,
  4611. // LPDWORD lpFileSystemFlags,
  4612. // LPWSTR lpFileSystemNameBuffer,
  4613. // DWORD nFileSystemNameSize
  4614. //
  4615. // );
  4616. func XGetVolumeInformationW(t *TLS, lpRootPathName, lpVolumeNameBuffer uintptr, nVolumeNameSize uint32, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer uintptr, nFileSystemNameSize uint32) int32 {
  4617. if __ccgo_strace {
  4618. trc("t=%v lpVolumeNameBuffer=%v nVolumeNameSize=%v lpFileSystemNameBuffer=%v nFileSystemNameSize=%v, (%v:)", t, lpVolumeNameBuffer, nVolumeNameSize, lpFileSystemNameBuffer, nFileSystemNameSize, origin(2))
  4619. }
  4620. r0, _, err := procGetVolumeInformationW.Call(lpRootPathName,
  4621. lpVolumeNameBuffer,
  4622. uintptr(nVolumeNameSize),
  4623. lpVolumeSerialNumber,
  4624. lpMaximumComponentLength,
  4625. lpFileSystemFlags,
  4626. lpFileSystemNameBuffer,
  4627. uintptr(nFileSystemNameSize),
  4628. 0,
  4629. )
  4630. if err != windows.NOERROR {
  4631. t.setErrno(err)
  4632. }
  4633. return int32(r0)
  4634. }
  4635. // wchar_t *wcschr(
  4636. //
  4637. // const wchar_t *str,
  4638. // wchar_t c
  4639. //
  4640. // );
  4641. func Xwcschr(t *TLS, str uintptr, c wchar_t) uintptr {
  4642. if __ccgo_strace {
  4643. trc("t=%v str=%v c=%v, (%v:)", t, str, c, origin(2))
  4644. }
  4645. var source = str
  4646. for {
  4647. var buf = *(*uint16)(unsafe.Pointer(source))
  4648. if buf == 0 {
  4649. return 0
  4650. }
  4651. if buf == c {
  4652. return source
  4653. }
  4654. // wchar_t = 2 bytes
  4655. source++
  4656. source++
  4657. }
  4658. }
  4659. // BOOL SetFileTime(
  4660. //
  4661. // HANDLE hFile,
  4662. // const FILETIME *lpCreationTime,
  4663. // const FILETIME *lpLastAccessTime,
  4664. // const FILETIME *lpLastWriteTime
  4665. //
  4666. // );
  4667. func XSetFileTime(t *TLS, _hFile uintptr, _lpCreationTime, _lpLastAccessTime, _lpLastWriteTime uintptr) (r int32) {
  4668. if __ccgo_strace {
  4669. trc("hFile=%+v lpCreationTime=%+v lpLastAccessTime=%+v lpLastWriteTime=%+v", _hFile, _lpCreationTime, _lpLastAccessTime, _lpLastWriteTime)
  4670. defer func() { trc(`XSetFileTime->%+v`, r) }()
  4671. }
  4672. r0, r1, err := procSetFileTime.Call(_hFile, _lpCreationTime, _lpLastAccessTime, _lpLastWriteTime)
  4673. if err != windows.NOERROR {
  4674. if __ccgo_strace {
  4675. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  4676. }
  4677. t.SetLastError(uint32(err.(windows.Errno)))
  4678. }
  4679. return int32(r0)
  4680. }
  4681. // __attribute__((dllimport)) DWORD GetNamedSecurityInfoW (LPCWSTR pObjectName, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner, PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl, PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
  4682. func XGetNamedSecurityInfoW(tls *TLS, _pObjectName uintptr, _ObjectType int32, _SecurityInfo uint32, _ppsidOwner uintptr, _ppsidGroup uintptr, _ppDacl uintptr, _ppSacl uintptr, _ppSecurityDescriptor uintptr) (r uint32) {
  4683. if __ccgo_strace {
  4684. trc("pObjectName=%+v ObjectType=%+v SecurityInfo=%+v ppsidOwner=%+v ppsidGroup=%+v ppDacl=%+v ppSacl=%+v ppSecurityDescriptor=%+v", _pObjectName, _ObjectType, _SecurityInfo, _ppsidOwner, _ppsidGroup, _ppDacl, _ppSacl, _ppSecurityDescriptor)
  4685. defer func() { trc(`XGetNamedSecurityInfoW->%+v`, r) }()
  4686. }
  4687. r0, r1, err := procGetNamedSecurityInfoW.Call(_pObjectName, uintptr(_ObjectType), uintptr(_SecurityInfo), _ppsidOwner, _ppsidGroup, _ppDacl, _ppSacl, _ppSecurityDescriptor)
  4688. if err != windows.NOERROR {
  4689. if __ccgo_strace {
  4690. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  4691. }
  4692. tls.SetLastError(uint32(err.(windows.Errno)))
  4693. }
  4694. return uint32(r0)
  4695. }
  4696. // __attribute__((dllimport)) WINBOOL OpenProcessToken (HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);
  4697. func XOpenProcessToken(tls *TLS, _ProcessHandle uintptr, _DesiredAccess uint32, _TokenHandle uintptr) (r int32) {
  4698. if __ccgo_strace {
  4699. trc("ProcessHandle=%+v DesiredAccess=%+v TokenHandle=%+v", _ProcessHandle, _DesiredAccess, _TokenHandle)
  4700. defer func() { trc(`XOpenProcessToken->%+v`, r) }()
  4701. }
  4702. r0, r1, err := procOpenProcessToken.Call(_ProcessHandle, uintptr(_DesiredAccess), _TokenHandle)
  4703. if err != windows.NOERROR {
  4704. if __ccgo_strace {
  4705. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  4706. }
  4707. tls.SetLastError(uint32(err.(windows.Errno)))
  4708. }
  4709. return int32(r0)
  4710. }
  4711. // __attribute__((dllimport)) WINBOOL GetTokenInformation (HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength);
  4712. func XGetTokenInformation(tls *TLS, _TokenHandle uintptr, _TokenInformationClass int32, _TokenInformation uintptr, _TokenInformationLength uint32, _ReturnLength uintptr) (r int32) {
  4713. if __ccgo_strace {
  4714. trc("TokenHandle=%+v TokenInformationClass=%+v TokenInformation=%+v TokenInformationLength=%+v ReturnLength=%+v", _TokenHandle, _TokenInformationClass, _TokenInformation, _TokenInformationLength, _ReturnLength)
  4715. defer func() { trc(`XGetTokenInformation->%+v`, r) }()
  4716. }
  4717. r0, r1, err := procGetTokenInformation.Call(_TokenHandle, uintptr(_TokenInformationClass), _TokenInformation, uintptr(_TokenInformationLength), _ReturnLength)
  4718. if err != windows.NOERROR {
  4719. if __ccgo_strace {
  4720. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  4721. }
  4722. tls.SetLastError(uint32(err.(windows.Errno)))
  4723. }
  4724. return int32(r0)
  4725. }
  4726. // __attribute__((dllimport)) WINBOOL EqualSid (PSID pSid1, PSID pSid2);
  4727. func XEqualSid(tls *TLS, _pSid1 uintptr, _pSid2 uintptr) (r int32) {
  4728. if __ccgo_strace {
  4729. trc("pSid1=%+v pSid2=%+v", _pSid1, _pSid2)
  4730. defer func() { trc(`XEqualSid->%+v`, r) }()
  4731. }
  4732. r0, r1, err := procEqualSid.Call(_pSid1, _pSid2)
  4733. if err != windows.NOERROR {
  4734. if __ccgo_strace {
  4735. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  4736. }
  4737. tls.SetLastError(uint32(err.(windows.Errno)))
  4738. }
  4739. return int32(r0)
  4740. }
  4741. // int WSAStartup(
  4742. //
  4743. // WORD wVersionRequired,
  4744. // LPWSADATA lpWSAData
  4745. //
  4746. // );
  4747. func XWSAStartup(t *TLS, wVersionRequired uint16, lpWSAData uintptr) int32 {
  4748. if __ccgo_strace {
  4749. trc("t=%v wVersionRequired=%v lpWSAData=%v, (%v:)", t, wVersionRequired, lpWSAData, origin(2))
  4750. }
  4751. r0, _, _ := procWSAStartup.Call(uintptr(wVersionRequired), lpWSAData, 0)
  4752. if r0 != 0 {
  4753. t.setErrno(r0)
  4754. }
  4755. return int32(r0)
  4756. }
  4757. // HMODULE GetModuleHandleA(LPCSTR lpModuleName);
  4758. func XGetModuleHandleA(t *TLS, lpModuleName uintptr) uintptr {
  4759. if __ccgo_strace {
  4760. trc("t=%v lpModuleName=%v, (%v:)", t, lpModuleName, origin(2))
  4761. }
  4762. r0, _, err := procGetModuleHandleA.Call(lpModuleName, 0, 0)
  4763. if r0 == 0 {
  4764. t.setErrno(err)
  4765. }
  4766. return r0
  4767. }
  4768. // HMODULE GetModuleHandleW(
  4769. //
  4770. // LPCWSTR lpModuleName
  4771. //
  4772. // );
  4773. func XGetModuleHandleW(t *TLS, lpModuleName uintptr) uintptr {
  4774. if __ccgo_strace {
  4775. trc("t=%v lpModuleName=%v, (%v:)", t, lpModuleName, origin(2))
  4776. }
  4777. r0, _, err := procGetModuleHandleW.Call(lpModuleName, 0, 0)
  4778. if r0 == 0 {
  4779. t.setErrno(err)
  4780. }
  4781. return r0
  4782. }
  4783. // DWORD GetEnvironmentVariableW(
  4784. //
  4785. // LPCWSTR lpName,
  4786. // LPWSTR lpBuffer,
  4787. // DWORD nSize
  4788. //
  4789. // );
  4790. func XGetEnvironmentVariableW(t *TLS, lpName, lpBuffer uintptr, nSize uint32) uint32 {
  4791. if __ccgo_strace {
  4792. trc("t=%v lpBuffer=%v nSize=%v, (%v:)", t, lpBuffer, nSize, origin(2))
  4793. }
  4794. r0, _, e1 := procGetEnvironmentVariableW.Call(lpName, lpBuffer, uintptr(nSize))
  4795. n := uint32(r0)
  4796. if n == 0 {
  4797. if e1 != windows.NOERROR {
  4798. t.setErrno(e1)
  4799. } else {
  4800. t.setErrno(errno.EINVAL)
  4801. }
  4802. }
  4803. return n
  4804. }
  4805. // int lstrcmpiA(
  4806. //
  4807. // LPCSTR lpString1,
  4808. // LPCSTR lpString2
  4809. //
  4810. // );
  4811. func XlstrcmpiA(t *TLS, lpString1, lpString2 uintptr) int32 {
  4812. if __ccgo_strace {
  4813. trc("t=%v lpString2=%v, (%v:)", t, lpString2, origin(2))
  4814. }
  4815. var s1 = strings.ToLower(GoString(lpString1))
  4816. var s2 = strings.ToLower(GoString(lpString2))
  4817. return int32(strings.Compare(s1, s2))
  4818. }
  4819. func XGetModuleFileNameA(t *TLS, _ ...interface{}) int32 {
  4820. panic(todo(""))
  4821. }
  4822. // UINT GetACP();
  4823. func XGetACP(t *TLS) uint32 {
  4824. if __ccgo_strace {
  4825. trc("t=%v, (%v:)", t, origin(2))
  4826. }
  4827. r0, _, _ := procGetACP.Call(0, 0, 0)
  4828. return uint32(r0)
  4829. }
  4830. // BOOL GetUserNameW(
  4831. //
  4832. // LPWSTR lpBuffer,
  4833. // LPDWORD pcbBuffer
  4834. //
  4835. // );
  4836. func XGetUserNameW(t *TLS, lpBuffer, pcbBuffer uintptr) int32 {
  4837. if __ccgo_strace {
  4838. trc("t=%v pcbBuffer=%v, (%v:)", t, pcbBuffer, origin(2))
  4839. }
  4840. u, err := user.Current()
  4841. if err != nil {
  4842. panic(todo(""))
  4843. return 0
  4844. }
  4845. wcnt := *(*uint16)(unsafe.Pointer(pcbBuffer))
  4846. s := utf16.Encode([]rune(u.Username))
  4847. if len(s)+1 > int(wcnt) {
  4848. panic(todo(""))
  4849. }
  4850. *(*uint16)(unsafe.Pointer(pcbBuffer)) = uint16(len(s) + 1)
  4851. for _, v := range s {
  4852. *(*uint16)(unsafe.Pointer(lpBuffer)) = v
  4853. lpBuffer += 2
  4854. }
  4855. return 1
  4856. }
  4857. // HMODULE LoadLibraryExW(
  4858. //
  4859. // LPCWSTR lpLibFileName,
  4860. // HANDLE hFile,
  4861. // DWORD dwFlags
  4862. //
  4863. // );
  4864. func XLoadLibraryExW(t *TLS, lpLibFileName, hFile uintptr, dwFlags uint32) uintptr {
  4865. if __ccgo_strace {
  4866. trc("t=%v hFile=%v dwFlags=%v, (%v:)", t, hFile, dwFlags, origin(2))
  4867. }
  4868. return 0 // If the function fails, the return value is NULL.
  4869. }
  4870. // wchar_t *wcscpy(
  4871. //
  4872. // wchar_t *strDestination,
  4873. // const wchar_t *strSource
  4874. //
  4875. // );
  4876. func Xwcscpy(t *TLS, strDestination, strSource uintptr) uintptr {
  4877. if __ccgo_strace {
  4878. trc("t=%v strSource=%v, (%v:)", t, strSource, origin(2))
  4879. }
  4880. if strSource == 0 {
  4881. return 0
  4882. }
  4883. d := strDestination
  4884. for {
  4885. c := *(*uint16)(unsafe.Pointer(strSource))
  4886. strSource += 2
  4887. *(*uint16)(unsafe.Pointer(d)) = c
  4888. d += 2
  4889. if c == 0 {
  4890. return strDestination
  4891. }
  4892. }
  4893. }
  4894. func XwsprintfW(t *TLS, _ ...interface{}) int32 {
  4895. panic(todo(""))
  4896. }
  4897. // ATOM RegisterClassW(
  4898. //
  4899. // const WNDCLASSW *lpWndClass
  4900. //
  4901. // );
  4902. func XRegisterClassW(t *TLS, lpWndClass uintptr) int32 {
  4903. if __ccgo_strace {
  4904. trc("t=%v lpWndClass=%v, (%v:)", t, lpWndClass, origin(2))
  4905. }
  4906. r0, _, err := procRegisterClassW.Call(lpWndClass, 0, 0)
  4907. if r0 == 0 {
  4908. t.setErrno(err)
  4909. }
  4910. return int32(r0)
  4911. }
  4912. func XKillTimer(t *TLS, _ ...interface{}) int32 {
  4913. panic(todo(""))
  4914. }
  4915. func XDestroyWindow(t *TLS, _ ...interface{}) int32 {
  4916. panic(todo(""))
  4917. }
  4918. // BOOL UnregisterClassW(
  4919. //
  4920. // LPCWSTR lpClassName,
  4921. // HINSTANCE hInstance
  4922. //
  4923. // );
  4924. func XUnregisterClassW(t *TLS, lpClassName, hInstance uintptr) int32 {
  4925. if __ccgo_strace {
  4926. trc("t=%v hInstance=%v, (%v:)", t, hInstance, origin(2))
  4927. }
  4928. r0, _, err := procUnregisterClassW.Call(lpClassName, hInstance, 0)
  4929. if r0 == 0 {
  4930. t.setErrno(err)
  4931. }
  4932. return int32(r0)
  4933. }
  4934. func XPostMessageW(t *TLS, _ ...interface{}) int32 {
  4935. panic(todo(""))
  4936. }
  4937. func XSetTimer(t *TLS, _ ...interface{}) int32 {
  4938. panic(todo(""))
  4939. }
  4940. // HWND CreateWindowExW(
  4941. //
  4942. // DWORD dwExStyle,
  4943. // LPCWSTR lpClassName,
  4944. // LPCWSTR lpWindowName,
  4945. // DWORD dwStyle,
  4946. // int X,
  4947. // int Y,
  4948. // int nWidth,
  4949. // int nHeight,
  4950. // HWND hWndParent,
  4951. // HMENU hMenu,
  4952. // HINSTANCE hInstance,
  4953. // LPVOID lpParam
  4954. //
  4955. // );
  4956. func XCreateWindowExW(t *TLS, dwExStyle uint32, lpClassName, lpWindowName uintptr, dwStyle uint32, x, y, nWidth, nHeight int32, hWndParent, hMenu, hInstance, lpParam uintptr) uintptr {
  4957. if __ccgo_strace {
  4958. trc("t=%v dwExStyle=%v lpWindowName=%v dwStyle=%v nHeight=%v lpParam=%v, (%v:)", t, dwExStyle, lpWindowName, dwStyle, nHeight, lpParam, origin(2))
  4959. }
  4960. r0, _, err := procCreateWindowExW.Call(
  4961. uintptr(dwExStyle),
  4962. lpClassName,
  4963. lpWindowName,
  4964. uintptr(dwStyle),
  4965. uintptr(x),
  4966. uintptr(y),
  4967. uintptr(nWidth),
  4968. uintptr(nHeight),
  4969. hWndParent,
  4970. hMenu,
  4971. hInstance,
  4972. lpParam,
  4973. )
  4974. if err != windows.NOERROR {
  4975. t.setErrno(err)
  4976. }
  4977. return r0
  4978. }
  4979. // BOOL PeekMessageW(
  4980. //
  4981. // LPMSG lpMsg,
  4982. // HWND hWnd,
  4983. // UINT wMsgFilterMin,
  4984. // UINT wMsgFilterMax,
  4985. // UINT wRemoveMsg
  4986. //
  4987. // );
  4988. func XPeekMessageW(t *TLS, lpMsg, hWnd uintptr, wMsgFilterMin, wMsgFilterMax, wRemoveMsg uint32) int32 {
  4989. if __ccgo_strace {
  4990. trc("t=%v hWnd=%v wRemoveMsg=%v, (%v:)", t, hWnd, wRemoveMsg, origin(2))
  4991. }
  4992. r0, _, err := procPeekMessageW.Call(lpMsg,
  4993. hWnd,
  4994. uintptr(wMsgFilterMin),
  4995. uintptr(wMsgFilterMax),
  4996. uintptr(wRemoveMsg),
  4997. 0,
  4998. )
  4999. if err != windows.NOERROR {
  5000. t.setErrno(err)
  5001. }
  5002. return int32(r0)
  5003. }
  5004. func XGetMessageW(t *TLS, _ ...interface{}) int32 {
  5005. panic(todo(""))
  5006. }
  5007. func XPostQuitMessage(t *TLS, _ ...interface{}) int32 {
  5008. panic(todo(""))
  5009. }
  5010. func XTranslateMessage(t *TLS, _ ...interface{}) int32 {
  5011. panic(todo(""))
  5012. }
  5013. func XDispatchMessageW(t *TLS, _ ...interface{}) int32 {
  5014. panic(todo(""))
  5015. }
  5016. // DWORD SleepEx(
  5017. //
  5018. // DWORD dwMilliseconds,
  5019. // BOOL bAlertable
  5020. //
  5021. // );
  5022. func XSleepEx(t *TLS, dwMilliseconds uint32, bAlertable int32) uint32 {
  5023. if __ccgo_strace {
  5024. trc("t=%v dwMilliseconds=%v bAlertable=%v, (%v:)", t, dwMilliseconds, bAlertable, origin(2))
  5025. }
  5026. r0, _, _ := procSleepEx.Call(uintptr(dwMilliseconds), uintptr(bAlertable), 0)
  5027. return uint32(r0)
  5028. }
  5029. // BOOL CreatePipe(
  5030. //
  5031. // PHANDLE hReadPipe,
  5032. // PHANDLE hWritePipe,
  5033. // LPSECURITY_ATTRIBUTES lpPipeAttributes,
  5034. // DWORD nSize
  5035. //
  5036. // );
  5037. func XCreatePipe(t *TLS, hReadPipe, hWritePipe, lpPipeAttributes uintptr, nSize uint32) int32 {
  5038. if __ccgo_strace {
  5039. trc("t=%v lpPipeAttributes=%v nSize=%v, (%v:)", t, lpPipeAttributes, nSize, origin(2))
  5040. }
  5041. r0, _, err := procCreatePipe.Call(hReadPipe, hWritePipe, lpPipeAttributes, uintptr(nSize), 0, 0)
  5042. if r0 == 0 {
  5043. t.setErrno(err)
  5044. }
  5045. return int32(r0)
  5046. }
  5047. // BOOL CreateProcessW(
  5048. //
  5049. // LPCWSTR lpApplicationName,
  5050. // LPWSTR lpCommandLine,
  5051. // LPSECURITY_ATTRIBUTES lpProcessAttributes,
  5052. // LPSECURITY_ATTRIBUTES lpThreadAttributes,
  5053. // BOOL bInheritHandles,
  5054. // DWORD dwCreationFlags,
  5055. // LPVOID lpEnvironment,
  5056. // LPCWSTR lpCurrentDirectory,
  5057. // LPSTARTUPINFOW lpStartupInfo,
  5058. // LPPROCESS_INFORMATION lpProcessInformation
  5059. //
  5060. // );
  5061. func XCreateProcessW(t *TLS, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes uintptr, bInheritHandles int32, dwCreationFlags uint32,
  5062. lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation uintptr) int32 {
  5063. r1, _, e1 := procCreateProcessW.Call(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes,
  5064. uintptr(bInheritHandles), uintptr(dwCreationFlags), lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, 0, 0)
  5065. if r1 == 0 {
  5066. if e1 != windows.NOERROR {
  5067. t.setErrno(e1)
  5068. } else {
  5069. t.setErrno(errno.EINVAL)
  5070. }
  5071. }
  5072. return int32(r1)
  5073. }
  5074. // DWORD WaitForInputIdle(
  5075. //
  5076. // HANDLE hProcess,
  5077. // DWORD dwMilliseconds
  5078. //
  5079. // );
  5080. func XWaitForInputIdle(t *TLS, hProcess uintptr, dwMilliseconds uint32) int32 {
  5081. if __ccgo_strace {
  5082. trc("t=%v hProcess=%v dwMilliseconds=%v, (%v:)", t, hProcess, dwMilliseconds, origin(2))
  5083. }
  5084. r0, _, _ := procWaitForInputIdle.Call(hProcess, uintptr(dwMilliseconds), 0)
  5085. return int32(r0)
  5086. }
  5087. // DWORD SearchPathW(
  5088. //
  5089. // LPCWSTR lpPath,
  5090. // LPCWSTR lpFileName,
  5091. // LPCWSTR lpExtension,
  5092. // DWORD nBufferLength,
  5093. // LPWSTR lpBuffer,
  5094. // LPWSTR *lpFilePart
  5095. //
  5096. // );
  5097. func XSearchPathW(t *TLS, lpPath, lpFileName, lpExtension uintptr, nBufferLength uint32, lpBuffer, lpFilePart uintptr) int32 {
  5098. if __ccgo_strace {
  5099. trc("t=%v lpExtension=%v nBufferLength=%v lpFilePart=%v, (%v:)", t, lpExtension, nBufferLength, lpFilePart, origin(2))
  5100. }
  5101. r0, _, err := procSearchPathW.Call(lpPath, lpFileName, lpExtension, uintptr(nBufferLength), lpBuffer, lpFilePart)
  5102. if r0 == 0 {
  5103. t.setErrno(err)
  5104. }
  5105. return int32(r0)
  5106. }
  5107. func XGetShortPathNameW(t *TLS, _ ...interface{}) int32 {
  5108. panic(todo(""))
  5109. }
  5110. // BOOL GetExitCodeProcess(
  5111. //
  5112. // HANDLE hProcess,
  5113. // LPDWORD lpExitCode
  5114. //
  5115. // );
  5116. func XGetExitCodeProcess(t *TLS, hProcess, lpExitCode uintptr) int32 {
  5117. if __ccgo_strace {
  5118. trc("t=%v lpExitCode=%v, (%v:)", t, lpExitCode, origin(2))
  5119. }
  5120. r0, _, err := procGetExitCodeProcess.Call(hProcess, lpExitCode, 0)
  5121. if r0 == 0 {
  5122. t.setErrno(err)
  5123. }
  5124. return int32(r0)
  5125. }
  5126. // BOOL PeekNamedPipe(
  5127. //
  5128. // HANDLE hNamedPipe,
  5129. // LPVOID lpBuffer,
  5130. // DWORD nBufferSize,
  5131. // LPDWORD lpBytesRead,
  5132. // LPDWORD lpTotalBytesAvail,
  5133. // LPDWORD lpBytesLeftThisMessage
  5134. //
  5135. // );
  5136. func XPeekNamedPipe(t *TLS, hNamedPipe, lpBuffer uintptr, nBufferSize uint32, lpBytesRead, lpTotalBytesAvail, lpBytesLeftThisMessage uintptr) int32 {
  5137. if __ccgo_strace {
  5138. trc("t=%v lpBuffer=%v nBufferSize=%v lpBytesLeftThisMessage=%v, (%v:)", t, lpBuffer, nBufferSize, lpBytesLeftThisMessage, origin(2))
  5139. }
  5140. r0, _, err := procPeekNamedPipe.Call(hNamedPipe, lpBuffer, uintptr(nBufferSize), lpBytesRead, lpTotalBytesAvail, lpBytesLeftThisMessage)
  5141. if r0 == 0 {
  5142. t.setErrno(err)
  5143. }
  5144. return int32(r0)
  5145. }
  5146. // long _InterlockedExchange(
  5147. //
  5148. // long volatile * Target,
  5149. // long Value
  5150. //
  5151. // );
  5152. func X_InterlockedExchange(t *TLS, Target uintptr, Value long) long {
  5153. if __ccgo_strace {
  5154. trc("t=%v Target=%v Value=%v, (%v:)", t, Target, Value, origin(2))
  5155. }
  5156. old := atomic.SwapInt32((*int32)(unsafe.Pointer(Target)), Value)
  5157. return old
  5158. }
  5159. // BOOL TerminateThread(
  5160. //
  5161. // [in, out] HANDLE hThread,
  5162. // [in] DWORD dwExitCode
  5163. //
  5164. // );
  5165. func XTerminateThread(t *TLS, hThread uintptr, dwExitCode uint32) int32 {
  5166. if __ccgo_strace {
  5167. trc("t=%v hThread=%v dwExitCode=%v, (%v:)", t, hThread, dwExitCode, origin(2))
  5168. }
  5169. r0, _, err := procTerminateThread.Call(hThread, uintptr(dwExitCode), 0)
  5170. if err != windows.NOERROR {
  5171. t.setErrno(err)
  5172. }
  5173. return int32(r0)
  5174. }
  5175. // BOOL GetComputerNameW(
  5176. //
  5177. // LPWSTR lpBuffer,
  5178. // LPDWORD nSize
  5179. //
  5180. // );
  5181. func XGetComputerNameW(t *TLS, lpBuffer, nSize uintptr) int32 {
  5182. if __ccgo_strace {
  5183. trc("t=%v nSize=%v, (%v:)", t, nSize, origin(2))
  5184. }
  5185. panic(todo(""))
  5186. }
  5187. func Xgethostname(t *TLS, _ ...interface{}) int32 {
  5188. panic(todo(""))
  5189. }
  5190. func XSendMessageW(t *TLS, _ ...interface{}) int32 {
  5191. panic(todo(""))
  5192. }
  5193. func XWSAGetLastError(t *TLS, _ ...interface{}) int32 {
  5194. panic(todo(""))
  5195. }
  5196. func Xclosesocket(t *TLS, _ ...interface{}) int32 {
  5197. panic(todo(""))
  5198. }
  5199. func XWspiapiFreeAddrInfo(t *TLS, _ ...interface{}) int32 {
  5200. panic(todo(""))
  5201. }
  5202. func XWspiapiGetNameInfo(t *TLS, _ ...interface{}) int32 {
  5203. panic(todo(""))
  5204. }
  5205. func XIN6_ADDR_EQUAL(t *TLS, _ ...interface{}) int32 {
  5206. panic(todo(""))
  5207. }
  5208. func X__ccgo_in6addr_anyp(t *TLS, _ ...interface{}) int32 {
  5209. panic(todo(""))
  5210. }
  5211. func XIN6_IS_ADDR_V4MAPPED(t *TLS, _ ...interface{}) int32 {
  5212. panic(todo(""))
  5213. }
  5214. func XSetHandleInformation(t *TLS, _ ...interface{}) int32 {
  5215. panic(todo(""))
  5216. }
  5217. func Xioctlsocket(t *TLS, _ ...interface{}) int32 {
  5218. panic(todo(""))
  5219. }
  5220. func XGetWindowLongPtrW(t *TLS, _ ...interface{}) int32 {
  5221. panic(todo(""))
  5222. }
  5223. func XSetWindowLongPtrW(t *TLS, _ ...interface{}) int32 {
  5224. panic(todo(""))
  5225. }
  5226. func XWSAAsyncSelect(t *TLS, _ ...interface{}) int32 {
  5227. panic(todo(""))
  5228. }
  5229. func Xinet_ntoa(t *TLS, _ ...interface{}) uintptr {
  5230. panic(todo(""))
  5231. }
  5232. func X_controlfp(t *TLS, _ ...interface{}) uint32 {
  5233. panic(todo(""))
  5234. }
  5235. // BOOL QueryPerformanceFrequency(
  5236. //
  5237. // LARGE_INTEGER *lpFrequency
  5238. //
  5239. // );
  5240. func XQueryPerformanceFrequency(t *TLS, lpFrequency uintptr) int32 {
  5241. if __ccgo_strace {
  5242. trc("t=%v lpFrequency=%v, (%v:)", t, lpFrequency, origin(2))
  5243. }
  5244. r1, _, err := procQueryPerformanceFrequency.Call(lpFrequency, 0, 0)
  5245. if r1 == 0 {
  5246. t.setErrno(err)
  5247. return 0
  5248. }
  5249. return int32(r1)
  5250. }
  5251. func inDST(t gotime.Time) bool {
  5252. jan1st := gotime.Date(t.Year(), 1, 1, 0, 0, 0, 0, t.Location()) // January 1st is always outside DST window
  5253. _, off1 := t.Zone()
  5254. _, off2 := jan1st.Zone()
  5255. return off1 != off2
  5256. }
  5257. // void _ftime( struct _timeb *timeptr );
  5258. func X_ftime(t *TLS, timeptr uintptr) {
  5259. if __ccgo_strace {
  5260. trc("t=%v timeptr=%v, (%v:)", t, timeptr, origin(2))
  5261. }
  5262. var tm = gotime.Now()
  5263. var tPtr = (*time.X__timeb64)(unsafe.Pointer(timeptr))
  5264. tPtr.Ftime = tm.Unix()
  5265. tPtr.Fmillitm = uint16(gotime.Duration(tm.Nanosecond()) / gotime.Millisecond)
  5266. if inDST(tm) {
  5267. tPtr.Fdstflag = 1
  5268. }
  5269. _, offset := tm.Zone()
  5270. tPtr.Ftimezone = int16(offset)
  5271. }
  5272. func XDdeInitializeW(t *TLS, _ ...interface{}) uint32 {
  5273. panic(todo(""))
  5274. }
  5275. func XDdeCreateStringHandleW(t *TLS, _ ...interface{}) uintptr {
  5276. panic(todo(""))
  5277. }
  5278. func XDdeNameService(t *TLS, _ ...interface{}) int32 {
  5279. panic(todo(""))
  5280. }
  5281. func X_snwprintf(t *TLS, _ ...interface{}) int32 {
  5282. panic(todo(""))
  5283. }
  5284. func XDdeQueryStringW(t *TLS, _ ...interface{}) int32 {
  5285. panic(todo(""))
  5286. }
  5287. // int _wcsicmp(
  5288. //
  5289. // const wchar_t *string1,
  5290. // const wchar_t *string2
  5291. //
  5292. // );
  5293. func X_wcsicmp(t *TLS, string1, string2 uintptr) int32 {
  5294. if __ccgo_strace {
  5295. trc("t=%v string2=%v, (%v:)", t, string2, origin(2))
  5296. }
  5297. return Xwcsicmp(t, string1, string2)
  5298. }
  5299. func XDdeCreateDataHandle(t *TLS, _ ...interface{}) uintptr {
  5300. panic(todo(""))
  5301. }
  5302. func XDdeAccessData(t *TLS, _ ...interface{}) uintptr {
  5303. panic(todo(""))
  5304. }
  5305. func XDdeUnaccessData(t *TLS, _ ...interface{}) int32 {
  5306. panic(todo(""))
  5307. }
  5308. func XDdeUninitialize(t *TLS, _ ...interface{}) int32 {
  5309. panic(todo(""))
  5310. }
  5311. func XDdeConnect(t *TLS, _ ...interface{}) uintptr {
  5312. panic(todo(""))
  5313. }
  5314. func XDdeFreeStringHandle(t *TLS, _ ...interface{}) int32 {
  5315. panic(todo(""))
  5316. }
  5317. func XRegisterClassExW(t *TLS, _ ...interface{}) int32 {
  5318. panic(todo(""))
  5319. }
  5320. func XGlobalGetAtomNameW(t *TLS, _ ...interface{}) int32 {
  5321. panic(todo(""))
  5322. }
  5323. func XGlobalAddAtomW(t *TLS, _ ...interface{}) uint16 {
  5324. panic(todo(""))
  5325. }
  5326. func XEnumWindows(t *TLS, _ ...interface{}) int32 {
  5327. panic(todo(""))
  5328. }
  5329. func XIsWindow(t *TLS, _ ...interface{}) int32 {
  5330. panic(todo(""))
  5331. }
  5332. func XGlobalDeleteAtom(t *TLS, _ ...interface{}) int32 {
  5333. panic(todo(""))
  5334. }
  5335. func XDdeGetLastError(t *TLS, _ ...interface{}) uint32 {
  5336. panic(todo(""))
  5337. }
  5338. // HDDEDATA DdeClientTransaction(
  5339. //
  5340. // LPBYTE pData,
  5341. // DWORD cbData,
  5342. // HCONV hConv,
  5343. // HSZ hszItem,
  5344. // UINT wFmt,
  5345. // UINT wType,
  5346. // DWORD dwTimeout,
  5347. // LPDWORD pdwResult
  5348. //
  5349. // );
  5350. func XDdeClientTransaction(t *TLS, pData uintptr, cbData uint32, hConv uintptr, hszItem uintptr, wFmt, wType, dwTimeout uint32, pdwResult uintptr) uintptr {
  5351. if __ccgo_strace {
  5352. trc("t=%v pData=%v cbData=%v hConv=%v hszItem=%v dwTimeout=%v pdwResult=%v, (%v:)", t, pData, cbData, hConv, hszItem, dwTimeout, pdwResult, origin(2))
  5353. }
  5354. panic(todo(""))
  5355. }
  5356. func XDdeAbandonTransaction(t *TLS, _ ...interface{}) int32 {
  5357. panic(todo(""))
  5358. }
  5359. func XDdeFreeDataHandle(t *TLS, _ ...interface{}) int32 {
  5360. panic(todo(""))
  5361. }
  5362. func XDdeGetData(t *TLS, _ ...interface{}) int32 {
  5363. panic(todo(""))
  5364. }
  5365. func XDdeDisconnect(t *TLS, _ ...interface{}) int32 {
  5366. panic(todo(""))
  5367. }
  5368. func XRegCloseKey(t *TLS, _ ...interface{}) int32 {
  5369. panic(todo(""))
  5370. }
  5371. func XRegDeleteValueW(t *TLS, _ ...interface{}) int32 {
  5372. panic(todo(""))
  5373. }
  5374. func XRegEnumKeyExW(t *TLS, _ ...interface{}) int32 {
  5375. panic(todo(""))
  5376. }
  5377. func XRegQueryValueExW(t *TLS, _ ...interface{}) int32 {
  5378. panic(todo(""))
  5379. }
  5380. func XRegEnumValueW(t *TLS, _ ...interface{}) int32 {
  5381. panic(todo(""))
  5382. }
  5383. func XRegConnectRegistryW(t *TLS, _ ...interface{}) int32 {
  5384. panic(todo(""))
  5385. }
  5386. func XRegCreateKeyExW(t *TLS, _ ...interface{}) int32 {
  5387. panic(todo(""))
  5388. }
  5389. func XRegOpenKeyExW(t *TLS, _ ...interface{}) int32 {
  5390. panic(todo(""))
  5391. }
  5392. func XRegDeleteKeyW(t *TLS, _ ...interface{}) int32 {
  5393. panic(todo(""))
  5394. }
  5395. func XRegSetValueExW(t *TLS, _ ...interface{}) int32 {
  5396. panic(todo(""))
  5397. }
  5398. // int _vsnwprintf(
  5399. //
  5400. // wchar_t *buffer,
  5401. // size_t count,
  5402. // const wchar_t *format,
  5403. // va_list argptr
  5404. //
  5405. // );
  5406. func X__mingw_vsnwprintf(t *TLS, buffer uintptr, count types.Size_t, format, va uintptr) int32 {
  5407. if __ccgo_strace {
  5408. trc("t=%v buffer=%v count=%v va=%v, (%v:)", t, buffer, count, va, origin(2))
  5409. }
  5410. panic(todo(""))
  5411. }
  5412. // int vprintf(const char *format, va_list ap);
  5413. func X__mingw_vprintf(t *TLS, s, ap uintptr) int32 {
  5414. if __ccgo_strace {
  5415. trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
  5416. }
  5417. return Xvprintf(t, s, ap)
  5418. }
  5419. // int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg);
  5420. func X__mingw_vfscanf(t *TLS, stream, format, ap uintptr) int32 {
  5421. if __ccgo_strace {
  5422. trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
  5423. }
  5424. panic(todo(""))
  5425. }
  5426. // int vsscanf(const char *str, const char *format, va_list ap);
  5427. func X__mingw_vsscanf(t *TLS, str, format, ap uintptr) int32 {
  5428. if __ccgo_strace {
  5429. trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
  5430. }
  5431. return Xsscanf(t, str, format, ap)
  5432. }
  5433. // int vfprintf(FILE * restrict stream, const char * restrict format, va_list arg);
  5434. func X__mingw_vfprintf(t *TLS, f uintptr, format, va uintptr) int32 {
  5435. if __ccgo_strace {
  5436. trc("t=%v f=%v va=%v, (%v:)", t, f, va, origin(2))
  5437. }
  5438. return Xvfprintf(t, f, format, va)
  5439. }
  5440. // int vsprintf(char * restrict s, const char * restrict format, va_list arg);
  5441. func X__mingw_vsprintf(t *TLS, s, format, ap uintptr) int32 {
  5442. if __ccgo_strace {
  5443. trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
  5444. }
  5445. return Xvsprintf(t, s, format, ap)
  5446. }
  5447. // int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  5448. func X__mingw_vsnprintf(t *TLS, str uintptr, size types.Size_t, format, ap uintptr) int32 {
  5449. if __ccgo_strace {
  5450. trc("t=%v str=%v size=%v ap=%v, (%v:)", t, str, size, ap, origin(2))
  5451. }
  5452. return Xvsnprintf(t, str, size, format, ap)
  5453. }
  5454. // int putchar(int char)
  5455. func X_putchar(t *TLS, c int32) int32 {
  5456. if __ccgo_strace {
  5457. trc("t=%v c=%v, (%v:)", t, c, origin(2))
  5458. }
  5459. if _, err := fwrite(unistd.STDOUT_FILENO, []byte{byte(c)}); err != nil {
  5460. return -1
  5461. }
  5462. return int32(byte(c))
  5463. }
  5464. // int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr;);
  5465. func X__mingw_vfwscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
  5466. if __ccgo_strace {
  5467. trc("t=%v stream=%v ap=%v, (%v:)", t, stream, ap, origin(2))
  5468. }
  5469. panic(todo(""))
  5470. }
  5471. // int vswscanf(const wchar_t *buffer, const wchar_t *format, va_list arglist);
  5472. func X__mingw_vswscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
  5473. if __ccgo_strace {
  5474. trc("t=%v stream=%v ap=%v, (%v:)", t, stream, ap, origin(2))
  5475. }
  5476. panic(todo(""))
  5477. }
  5478. // int vfwprintf(FILE * restrict stream, const wchar_t * restrict format, va_list arg);
  5479. func X__mingw_vfwprintf(t *TLS, stream, format, ap uintptr) int32 {
  5480. if __ccgo_strace {
  5481. trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
  5482. }
  5483. panic(todo(""))
  5484. }
  5485. // int putchar(int c);
  5486. func Xputchar(t *TLS, c int32) int32 {
  5487. if __ccgo_strace {
  5488. trc("t=%v c=%v, (%v:)", t, c, origin(2))
  5489. }
  5490. panic(todo(""))
  5491. }
  5492. // void _assert(
  5493. //
  5494. // char const* message,
  5495. // char const* filename,
  5496. // unsigned line
  5497. //
  5498. // );
  5499. func X_assert(t *TLS, message, filename uintptr, line uint32) {
  5500. if __ccgo_strace {
  5501. trc("t=%v filename=%v line=%v, (%v:)", t, filename, line, origin(2))
  5502. }
  5503. panic(todo(""))
  5504. }
  5505. // char *strdup(const char *s);
  5506. func X_strdup(t *TLS, s uintptr) uintptr {
  5507. if __ccgo_strace {
  5508. trc("t=%v s=%v, (%v:)", t, s, origin(2))
  5509. }
  5510. panic(todo(""))
  5511. }
  5512. // int _access(
  5513. //
  5514. // const char *path,
  5515. // int mode
  5516. //
  5517. // );
  5518. func X_access(t *TLS, pathname uintptr, mode int32) int32 {
  5519. if __ccgo_strace {
  5520. trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
  5521. }
  5522. var path = GoString(pathname)
  5523. info, err := os.Stat(path)
  5524. if err != nil {
  5525. // doesn't exist
  5526. return errno.ENOENT
  5527. }
  5528. switch mode {
  5529. case 0:
  5530. // exists
  5531. return 0
  5532. case 2:
  5533. // write-only
  5534. // Check if the user bit is enabled in file permission
  5535. if info.Mode().Perm()&(1<<(uint(7))) == 1 {
  5536. // write-able
  5537. return 0
  5538. }
  5539. case 4:
  5540. // read-only
  5541. // Check if the user bit is enabled in file permission
  5542. if info.Mode().Perm()&(1<<(uint(7))) == 0 {
  5543. // not set, so read-only
  5544. return 0
  5545. }
  5546. case 6:
  5547. // r/w
  5548. if info.Mode().Perm()&(1<<(uint(7))) == 1 {
  5549. // write-able
  5550. return 0
  5551. }
  5552. }
  5553. return errno.EACCES
  5554. }
  5555. // BOOL WINAPI SetConsoleCtrlHandler(
  5556. //
  5557. // _In_opt_ PHANDLER_ROUTINE HandlerRoutine,
  5558. // _In_ BOOL Add
  5559. //
  5560. // );
  5561. func XSetConsoleCtrlHandler(t *TLS, HandlerRoutine uintptr, Add int32) int32 {
  5562. if __ccgo_strace {
  5563. trc("t=%v HandlerRoutine=%v Add=%v, (%v:)", t, HandlerRoutine, Add, origin(2))
  5564. }
  5565. //var fcc = &struct {
  5566. // f func(*TLS, uint32) int32
  5567. //}{}
  5568. //fcc = (*struct{ f func(*TLS, uint32) int32 })(unsafe.Pointer(HandlerRoutine))
  5569. //var hdlr = fcc.f
  5570. //
  5571. //_, _, err := procSetConsoleCtrlHandler.Call(
  5572. //windows.NewCallback(func(controlType uint) uint {
  5573. // return uint( hdlr(t, uint32(controlType)) )
  5574. // }), 1)
  5575. //
  5576. //if err != nil {
  5577. // panic("failed: SetConsoleCtrlHandler")
  5578. //}
  5579. return 0
  5580. }
  5581. // DebugBreak
  5582. func XDebugBreak(t *TLS) {
  5583. if __ccgo_strace {
  5584. trc("t=%v, (%v:)", t, origin(2))
  5585. }
  5586. panic(todo(""))
  5587. }
  5588. // int _isatty( int fd );
  5589. func X_isatty(t *TLS, fd int32) int32 {
  5590. if __ccgo_strace {
  5591. trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
  5592. }
  5593. f, ok := fdToFile(fd)
  5594. if !ok {
  5595. t.setErrno(errno.EBADF)
  5596. return 0
  5597. }
  5598. if fd == unistd.STDOUT_FILENO ||
  5599. fd == unistd.STDIN_FILENO ||
  5600. fd == unistd.STDERR_FILENO {
  5601. var mode uint32
  5602. err := windows.GetConsoleMode(f.Handle, &mode)
  5603. if err != nil {
  5604. t.setErrno(errno.EINVAL)
  5605. return 0
  5606. }
  5607. // is console
  5608. return 1
  5609. }
  5610. return 0
  5611. }
  5612. // BOOL WINAPI SetConsoleTextAttribute(
  5613. //
  5614. // _In_ HANDLE hConsoleOutput,
  5615. // _In_ WORD wAttributes
  5616. //
  5617. // );
  5618. func XSetConsoleTextAttribute(t *TLS, hConsoleOutput uintptr, wAttributes uint16) int32 {
  5619. if __ccgo_strace {
  5620. trc("t=%v hConsoleOutput=%v wAttributes=%v, (%v:)", t, hConsoleOutput, wAttributes, origin(2))
  5621. }
  5622. r1, _, _ := procSetConsoleTextAttribute.Call(hConsoleOutput, uintptr(wAttributes), 0)
  5623. return int32(r1)
  5624. }
  5625. // BOOL WINAPI GetConsoleScreenBufferInfo(
  5626. //
  5627. // _In_ HANDLE hConsoleOutput,
  5628. // _Out_ PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
  5629. //
  5630. // );
  5631. func XGetConsoleScreenBufferInfo(t *TLS, hConsoleOutput, lpConsoleScreenBufferInfo uintptr) int32 {
  5632. if __ccgo_strace {
  5633. trc("t=%v lpConsoleScreenBufferInfo=%v, (%v:)", t, lpConsoleScreenBufferInfo, origin(2))
  5634. }
  5635. r1, _, _ := procGetConsoleScreenBufferInfo.Call(hConsoleOutput, lpConsoleScreenBufferInfo, 0)
  5636. return int32(r1)
  5637. }
  5638. // FILE *_popen(
  5639. //
  5640. // const char *command,
  5641. // const char *mode
  5642. //
  5643. // );
  5644. func X_popen(t *TLS, command, mode uintptr) uintptr {
  5645. if __ccgo_strace {
  5646. trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
  5647. }
  5648. panic(todo(""))
  5649. }
  5650. // int _wunlink(
  5651. //
  5652. // const wchar_t *filename
  5653. //
  5654. // );
  5655. func X_wunlink(t *TLS, filename uintptr) int32 {
  5656. if __ccgo_strace {
  5657. trc("t=%v filename=%v, (%v:)", t, filename, origin(2))
  5658. }
  5659. panic(todo(""))
  5660. }
  5661. func Xclosedir(tls *TLS, dir uintptr) int32 {
  5662. if __ccgo_strace {
  5663. trc("tls=%v dir=%v, (%v:)", tls, dir, origin(2))
  5664. }
  5665. panic(todo(""))
  5666. }
  5667. func Xopendir(tls *TLS, name uintptr) uintptr {
  5668. if __ccgo_strace {
  5669. trc("tls=%v name=%v, (%v:)", tls, name, origin(2))
  5670. }
  5671. panic(todo(""))
  5672. }
  5673. func Xreaddir(tls *TLS, dir uintptr) uintptr {
  5674. if __ccgo_strace {
  5675. trc("tls=%v dir=%v, (%v:)", tls, dir, origin(2))
  5676. }
  5677. panic(todo(""))
  5678. }
  5679. // int _unlink(
  5680. //
  5681. // const char *filename
  5682. //
  5683. // );
  5684. func X_unlink(t *TLS, filename uintptr) int32 {
  5685. if __ccgo_strace {
  5686. trc("t=%v filename=%v, (%v:)", t, filename, origin(2))
  5687. }
  5688. panic(todo(""))
  5689. }
  5690. // int pclose(FILE *stream);
  5691. func X_pclose(t *TLS, stream uintptr) int32 {
  5692. if __ccgo_strace {
  5693. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  5694. }
  5695. panic(todo(""))
  5696. }
  5697. // int setmode (int fd, int mode);
  5698. func Xsetmode(t *TLS, fd, mode int32) int32 {
  5699. if __ccgo_strace {
  5700. trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
  5701. }
  5702. return X_setmode(t, fd, mode)
  5703. }
  5704. // int _setmode (int fd, int mode);
  5705. func X_setmode(t *TLS, fd, mode int32) int32 {
  5706. if __ccgo_strace {
  5707. trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
  5708. }
  5709. _, ok := fdToFile(fd)
  5710. if !ok {
  5711. t.setErrno(errno.EBADF)
  5712. return -1
  5713. }
  5714. // we're always in binary mode.
  5715. // at least for now.
  5716. if mode == fcntl.O_BINARY {
  5717. return fcntl.O_BINARY
  5718. } else {
  5719. t.setErrno(errno.EINVAL)
  5720. return -1
  5721. }
  5722. }
  5723. // int _mkdir(const char *dirname);
  5724. func X_mkdir(t *TLS, dirname uintptr) int32 {
  5725. if __ccgo_strace {
  5726. trc("t=%v dirname=%v, (%v:)", t, dirname, origin(2))
  5727. }
  5728. panic(todo(""))
  5729. }
  5730. // int _chmod( const char *filename, int pmode );
  5731. func X_chmod(t *TLS, filename uintptr, pmode int32) int32 {
  5732. if __ccgo_strace {
  5733. trc("t=%v filename=%v pmode=%v, (%v:)", t, filename, pmode, origin(2))
  5734. }
  5735. panic(todo(""))
  5736. }
  5737. // int _fileno(FILE *stream);
  5738. func X_fileno(t *TLS, stream uintptr) int32 {
  5739. if __ccgo_strace {
  5740. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  5741. }
  5742. f, ok := winGetObject(stream).(*file)
  5743. if !ok {
  5744. t.setErrno(errno.EBADF)
  5745. return -1
  5746. }
  5747. return f._fd
  5748. }
  5749. // void rewind(FILE *stream);
  5750. func Xrewind(t *TLS, stream uintptr) {
  5751. if __ccgo_strace {
  5752. trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
  5753. }
  5754. Xfseek(t, stream, 0, unistd.SEEK_SET)
  5755. }
  5756. // __atomic_load_n
  5757. func X__atomic_load_n(t *TLS) {
  5758. if __ccgo_strace {
  5759. trc("t=%v, (%v:)", t, origin(2))
  5760. }
  5761. panic(todo(""))
  5762. }
  5763. // __atomic_store_n
  5764. func X__atomic_store_n(t *TLS, _ ...interface{}) int32 {
  5765. panic(todo(""))
  5766. }
  5767. // __builtin_add_overflow
  5768. func X__builtin_add_overflow(t *TLS) {
  5769. if __ccgo_strace {
  5770. trc("t=%v, (%v:)", t, origin(2))
  5771. }
  5772. panic(todo(""))
  5773. }
  5774. // __builtin_mul_overflow
  5775. func X__builtin_mul_overflow(t *TLS) {
  5776. if __ccgo_strace {
  5777. trc("t=%v, (%v:)", t, origin(2))
  5778. }
  5779. panic(todo(""))
  5780. }
  5781. // __builtin_sub_overflow
  5782. func X__builtin_sub_overflow(t *TLS) {
  5783. if __ccgo_strace {
  5784. trc("t=%v, (%v:)", t, origin(2))
  5785. }
  5786. panic(todo(""))
  5787. }
  5788. func goWideBytes(p uintptr, n int) []uint16 {
  5789. b := GoBytes(p, 2*n)
  5790. var w []uint16
  5791. for i := 0; i < len(b); i += 2 {
  5792. w = append(w, *(*uint16)(unsafe.Pointer(&b[i])))
  5793. }
  5794. return w
  5795. }
  5796. // This version does include the zero terminator in the returned Go string.
  5797. func goWideString(p uintptr) string {
  5798. if p == 0 {
  5799. return ""
  5800. }
  5801. var w []uint16
  5802. var raw = (*RawMem)(unsafe.Pointer(p))
  5803. var i = 0
  5804. for {
  5805. wc := *(*uint16)(unsafe.Pointer(&raw[i]))
  5806. w = append(w, wc)
  5807. // append until U0000
  5808. if wc == 0 {
  5809. break
  5810. }
  5811. i = i + 2
  5812. }
  5813. s := utf16.Decode(w)
  5814. return string(s)
  5815. }
  5816. func goWideStringN(p uintptr, n int) string {
  5817. panic(todo(""))
  5818. }
  5819. // This version does not include the zero terminator in the returned Go string.
  5820. func goWideStringNZ(p uintptr) string {
  5821. if p == 0 {
  5822. return ""
  5823. }
  5824. var w []uint16
  5825. var raw = (*RawMem)(unsafe.Pointer(p))
  5826. var i = 0
  5827. for {
  5828. wc := *(*uint16)(unsafe.Pointer(&raw[i]))
  5829. if wc == 0 {
  5830. break
  5831. }
  5832. w = append(w, wc)
  5833. i = i + 2
  5834. }
  5835. s := utf16.Decode(w)
  5836. return string(s)
  5837. }
  5838. // LPWSTR GetCommandLineW();
  5839. func XGetCommandLineW(t *TLS) uintptr {
  5840. if __ccgo_strace {
  5841. trc("t=%v, (%v:)", t, origin(2))
  5842. }
  5843. return uintptr(unsafe.Pointer(windows.GetCommandLine()))
  5844. }
  5845. // BOOL AddAccessDeniedAce(
  5846. //
  5847. // PACL pAcl,
  5848. // DWORD dwAceRevision,
  5849. // DWORD AccessMask,
  5850. // PSID pSid
  5851. //
  5852. // );
  5853. func XAddAccessDeniedAce(t *TLS, pAcl uintptr, dwAceRevision, AccessMask uint32, pSid uintptr) int32 {
  5854. if __ccgo_strace {
  5855. trc("t=%v pAcl=%v AccessMask=%v pSid=%v, (%v:)", t, pAcl, AccessMask, pSid, origin(2))
  5856. }
  5857. panic(todo(""))
  5858. }
  5859. // __attribute__((dllimport)) WINBOOL AddAce (PACL pAcl, DWORD dwAceRevision, DWORD dwStartingAceIndex, LPVOID pAceList, DWORD nAceListLength);
  5860. func XAddAce(tls *TLS, _pAcl uintptr, _dwAceRevision uint32, _dwStartingAceIndex uint32, _pAceList uintptr, _nAceListLength uint32) (r uint32) {
  5861. if __ccgo_strace {
  5862. trc("pAcl=%+v dwAceRevision=%+v dwStartingAceIndex=%+v pAceList=%+v nAceListLength=%+v", _pAcl, _dwAceRevision, _dwStartingAceIndex, _pAceList, _nAceListLength)
  5863. defer func() { trc(`XAddAce->%+v`, r) }()
  5864. }
  5865. r0, r1, err := procAddAce.Call(_pAcl, uintptr(_dwAceRevision), uintptr(_dwStartingAceIndex), _pAceList, uintptr(_nAceListLength))
  5866. if err != windows.NOERROR {
  5867. if __ccgo_strace {
  5868. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  5869. }
  5870. tls.SetLastError(uint32(err.(windows.Errno)))
  5871. }
  5872. return uint32(r0)
  5873. }
  5874. // __attribute__((dllimport)) WINBOOL GetAce (PACL pAcl, DWORD dwAceIndex, LPVOID *pAce);
  5875. func XGetAce(tls *TLS, _pAcl uintptr, _dwAceIndex uint32, _pAce uintptr) (r int32) {
  5876. if __ccgo_strace {
  5877. trc("pAcl=%+v dwAceIndex=%+v pAce=%+v", _pAcl, _dwAceIndex, _pAce)
  5878. defer func() { trc(`XGetAce->%+v`, r) }()
  5879. }
  5880. r0, r1, err := procGetAce.Call(_pAcl, uintptr(_dwAceIndex), _pAce)
  5881. if err != windows.NOERROR {
  5882. if __ccgo_strace {
  5883. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  5884. }
  5885. tls.SetLastError(uint32(err.(windows.Errno)))
  5886. }
  5887. return int32(r0)
  5888. }
  5889. // BOOL GetAclInformation(
  5890. //
  5891. // PACL pAcl,
  5892. // LPVOID pAclInformation,
  5893. // DWORD nAclInformationLength,
  5894. // ACL_INFORMATION_CLASS dwAclInformationClass
  5895. //
  5896. // );
  5897. func XGetAclInformation(t *TLS, pAcl, pAclInformation uintptr, nAclInformationLength uint32, dwAclInformationClass int32) int32 {
  5898. if __ccgo_strace {
  5899. trc("t=%v pAclInformation=%v dwAclInformationClass=%v, (%v:)", t, pAclInformation, dwAclInformationClass, origin(2))
  5900. }
  5901. r0, _, err := procGetAclInformation.Call(pAclInformation,
  5902. pAclInformation,
  5903. uintptr(nAclInformationLength),
  5904. uintptr(dwAclInformationClass),
  5905. 0,
  5906. 0,
  5907. )
  5908. if err != windows.NOERROR {
  5909. t.setErrno(err)
  5910. }
  5911. return int32(r0)
  5912. }
  5913. // BOOL GetFileSecurityA(
  5914. //
  5915. // LPCSTR lpFileName,
  5916. // SECURITY_INFORMATION RequestedInformation,
  5917. // PSECURITY_DESCRIPTOR pSecurityDescriptor,
  5918. // DWORD nLength,
  5919. // LPDWORD lpnLengthNeeded
  5920. //
  5921. // );
  5922. func XGetFileSecurityA(t *TLS, lpFileName uintptr, RequestedInformation uint32, pSecurityDescriptor uintptr, nLength uint32, lpnLengthNeeded uintptr) int32 {
  5923. if __ccgo_strace {
  5924. trc("t=%v lpFileName=%v RequestedInformation=%v pSecurityDescriptor=%v nLength=%v lpnLengthNeeded=%v, (%v:)", t, lpFileName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded, origin(2))
  5925. }
  5926. r0, _, err := procGetFileSecurityA.Call(lpFileName,
  5927. uintptr(RequestedInformation),
  5928. pSecurityDescriptor,
  5929. uintptr(nLength),
  5930. lpnLengthNeeded,
  5931. 0,
  5932. )
  5933. if err != windows.NOERROR {
  5934. t.setErrno(err)
  5935. }
  5936. return int32(r0)
  5937. }
  5938. // __attribute__((dllimport)) DWORD GetLengthSid (PSID pSid);
  5939. func XGetLengthSid(tls *TLS, _pSid uintptr) (r uint32) {
  5940. if __ccgo_strace {
  5941. trc("pSid=%+v", _pSid)
  5942. defer func() { trc(`XGetLengthSid->%+v`, r) }()
  5943. }
  5944. r0, r1, err := procGetLengthSid.Call(_pSid)
  5945. if err != windows.NOERROR {
  5946. if __ccgo_strace {
  5947. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  5948. }
  5949. tls.SetLastError(uint32(err.(windows.Errno)))
  5950. }
  5951. return uint32(r0)
  5952. }
  5953. // BOOL GetSecurityDescriptorDacl(
  5954. //
  5955. // PSECURITY_DESCRIPTOR pSecurityDescriptor,
  5956. // LPBOOL lpbDaclPresent,
  5957. // PACL *pDacl,
  5958. // LPBOOL lpbDaclDefaulted
  5959. //
  5960. // );
  5961. func XGetSecurityDescriptorDacl(t *TLS, pSecurityDescriptor, lpbDaclPresent, pDacl, lpbDaclDefaulted uintptr) int32 {
  5962. if __ccgo_strace {
  5963. trc("t=%v lpbDaclDefaulted=%v, (%v:)", t, lpbDaclDefaulted, origin(2))
  5964. }
  5965. r0, _, err := procGetSecurityDescriptorDacl.Call(pSecurityDescriptor,
  5966. lpbDaclPresent,
  5967. pDacl,
  5968. lpbDaclDefaulted,
  5969. 0,
  5970. 0,
  5971. )
  5972. if err != windows.NOERROR {
  5973. t.setErrno(err)
  5974. }
  5975. return int32(r0)
  5976. }
  5977. // DWORD GetSidLengthRequired(
  5978. //
  5979. // UCHAR nSubAuthorityCount
  5980. //
  5981. // );
  5982. func XGetSidLengthRequired(t *TLS, nSubAuthorityCount uint8) int32 {
  5983. if __ccgo_strace {
  5984. trc("t=%v nSubAuthorityCount=%v, (%v:)", t, nSubAuthorityCount, origin(2))
  5985. }
  5986. r0, _, err := procGetSidLengthRequired.Call(uintptr(nSubAuthorityCount), 0, 0)
  5987. if err != windows.NOERROR {
  5988. t.setErrno(err)
  5989. }
  5990. return int32(r0)
  5991. }
  5992. // PDWORD GetSidSubAuthority(
  5993. //
  5994. // PSID pSid,
  5995. // DWORD nSubAuthority
  5996. //
  5997. // );
  5998. func XGetSidSubAuthority(t *TLS, pSid uintptr, nSubAuthority uint32) uintptr {
  5999. if __ccgo_strace {
  6000. trc("t=%v pSid=%v nSubAuthority=%v, (%v:)", t, pSid, nSubAuthority, origin(2))
  6001. }
  6002. r0, _, err := procGetSidSubAuthority.Call(pSid, uintptr(nSubAuthority), 0)
  6003. if err != windows.NOERROR {
  6004. t.setErrno(err)
  6005. }
  6006. return r0
  6007. }
  6008. // __attribute__((dllimport)) WINBOOL InitializeAcl (PACL pAcl, DWORD nAclLength, DWORD dwAclRevision);
  6009. func XInitializeAcl(tls *TLS, _pAcl uintptr, _nAclLength uint32, _dwAclRevision uint32) (r int32) {
  6010. if __ccgo_strace {
  6011. trc("pAcl=%+v nAclLength=%+v dwAclRevision=%+v", _pAcl, _nAclLength, _dwAclRevision)
  6012. defer func() { trc(`XInitializeAcl->%+v`, r) }()
  6013. }
  6014. r0, r1, err := procInitializeAcl.Call(_pAcl, uintptr(_nAclLength), uintptr(_dwAclRevision))
  6015. if err != windows.NOERROR {
  6016. if __ccgo_strace {
  6017. trc(`r0=%v r1=%v err=%v`, r0, r1, err)
  6018. }
  6019. tls.SetLastError(uint32(err.(windows.Errno)))
  6020. }
  6021. return int32(r0)
  6022. }
  6023. // BOOL InitializeSid(
  6024. //
  6025. // PSID Sid,
  6026. // PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
  6027. // BYTE nSubAuthorityCount
  6028. //
  6029. // );
  6030. func XInitializeSid(t *TLS, Sid, pIdentifierAuthority uintptr, nSubAuthorityCount uint8) int32 {
  6031. if __ccgo_strace {
  6032. trc("t=%v pIdentifierAuthority=%v nSubAuthorityCount=%v, (%v:)", t, pIdentifierAuthority, nSubAuthorityCount, origin(2))
  6033. }
  6034. r0, _, err := procInitializeSid.Call(Sid, pIdentifierAuthority, uintptr(nSubAuthorityCount))
  6035. if err != windows.NOERROR {
  6036. t.setErrno(err)
  6037. }
  6038. return int32(r0)
  6039. }
  6040. // VOID RaiseException(
  6041. //
  6042. // DWORD dwExceptionCode,
  6043. // DWORD dwExceptionFlags,
  6044. // DWORD nNumberOfArguments,
  6045. // const ULONG_PTR *lpArguments
  6046. //
  6047. // );
  6048. func XRaiseException(t *TLS, dwExceptionCode, dwExceptionFlags, nNumberOfArguments uint32, lpArguments uintptr) {
  6049. if __ccgo_strace {
  6050. trc("t=%v nNumberOfArguments=%v lpArguments=%v, (%v:)", t, nNumberOfArguments, lpArguments, origin(2))
  6051. }
  6052. panic(todo(""))
  6053. }
  6054. // UINT SetErrorMode(
  6055. //
  6056. // UINT uMode
  6057. //
  6058. // );
  6059. func XSetErrorMode(t *TLS, uMode uint32) int32 {
  6060. if __ccgo_strace {
  6061. trc("t=%v uMode=%v, (%v:)", t, uMode, origin(2))
  6062. }
  6063. panic(todo(""))
  6064. }
  6065. // DWORD SetNamedSecurityInfoA(
  6066. //
  6067. // LPSTR pObjectName,
  6068. // SE_OBJECT_TYPE ObjectType,
  6069. // SECURITY_INFORMATION SecurityInfo,
  6070. // PSID psidOwner,
  6071. // PSID psidGroup,
  6072. // PACL pDacl,
  6073. // PACL pSacl
  6074. //
  6075. // );
  6076. func XSetNamedSecurityInfoA(t *TLS, pObjectName uintptr, ObjectType int32, SecurityInfo uint32, psidOwner, psidGroup, pDacl, pSacl uintptr) uint32 {
  6077. if __ccgo_strace {
  6078. trc("t=%v pObjectName=%v SecurityInfo=%v pSacl=%v, (%v:)", t, pObjectName, SecurityInfo, pSacl, origin(2))
  6079. }
  6080. panic(todo(""))
  6081. }
  6082. // BOOL CreateProcessA(
  6083. //
  6084. // LPCSTR lpApplicationName,
  6085. // LPSTR lpCommandLine,
  6086. // LPSECURITY_ATTRIBUTES lpProcessAttributes,
  6087. // LPSECURITY_ATTRIBUTES lpThreadAttributes,
  6088. // BOOL bInheritHandles,
  6089. // DWORD dwCreationFlags,
  6090. // LPVOID lpEnvironment,
  6091. // LPCSTR lpCurrentDirectory,
  6092. // LPSTARTUPINFOA lpStartupInfo,
  6093. // LPPROCESS_INFORMATION lpProcessInformation
  6094. //
  6095. // );
  6096. func XCreateProcessA(t *TLS, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes uintptr, bInheritHandles int32,
  6097. dwCreationFlags uint32, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation uintptr) int32 {
  6098. r1, _, err := procCreateProcessA.Call(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes,
  6099. uintptr(bInheritHandles), uintptr(dwCreationFlags), lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, 0, 0)
  6100. if r1 == 0 {
  6101. if err != windows.NOERROR {
  6102. t.setErrno(err)
  6103. } else {
  6104. t.setErrno(errno.EINVAL)
  6105. }
  6106. }
  6107. return int32(r1)
  6108. }
  6109. // unsigned int _set_abort_behavior(
  6110. //
  6111. // unsigned int flags,
  6112. // unsigned int mask
  6113. //
  6114. // );
  6115. func X_set_abort_behavior(t *TLS, _ ...interface{}) uint32 {
  6116. panic(todo(""))
  6117. }
  6118. // HANDLE OpenEventA(
  6119. //
  6120. // DWORD dwDesiredAccess,
  6121. // BOOL bInheritHandle,
  6122. // LPCSTR lpName
  6123. //
  6124. // );
  6125. func XOpenEventA(t *TLS, dwDesiredAccess uint32, bInheritHandle uint32, lpName uintptr) uintptr {
  6126. if __ccgo_strace {
  6127. trc("t=%v dwDesiredAccess=%v bInheritHandle=%v lpName=%v, (%v:)", t, dwDesiredAccess, bInheritHandle, lpName, origin(2))
  6128. }
  6129. r0, _, err := procOpenEventA.Call(uintptr(dwDesiredAccess), uintptr(bInheritHandle), lpName)
  6130. if r0 == 0 {
  6131. t.setErrno(err)
  6132. }
  6133. return r0
  6134. }
  6135. // size_t _msize(
  6136. //
  6137. // void *memblock
  6138. //
  6139. // );
  6140. func X_msize(t *TLS, memblock uintptr) types.Size_t {
  6141. if __ccgo_strace {
  6142. trc("t=%v memblock=%v, (%v:)", t, memblock, origin(2))
  6143. }
  6144. return types.Size_t(UsableSize(memblock))
  6145. }
  6146. // unsigned long _byteswap_ulong ( unsigned long val );
  6147. func X_byteswap_ulong(t *TLS, val ulong) ulong {
  6148. if __ccgo_strace {
  6149. trc("t=%v val=%v, (%v:)", t, val, origin(2))
  6150. }
  6151. return X__builtin_bswap32(t, val)
  6152. }
  6153. // unsigned __int64 _byteswap_uint64 ( unsigned __int64 val );
  6154. func X_byteswap_uint64(t *TLS, val uint64) uint64 {
  6155. if __ccgo_strace {
  6156. trc("t=%v val=%v, (%v:)", t, val, origin(2))
  6157. }
  6158. return X__builtin_bswap64(t, val)
  6159. }
  6160. // int _commit(
  6161. //
  6162. // int fd
  6163. //
  6164. // );
  6165. func X_commit(t *TLS, fd int32) int32 {
  6166. if __ccgo_strace {
  6167. trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
  6168. }
  6169. return Xfsync(t, fd)
  6170. }
  6171. // int _stati64(
  6172. //
  6173. // const char *path,
  6174. // struct _stati64 *buffer
  6175. //
  6176. // );
  6177. func X_stati64(t *TLS, path, buffer uintptr) int32 {
  6178. if __ccgo_strace {
  6179. trc("t=%v path=%v buffer=%v, (%v:)", t, path, buffer, origin(2))
  6180. }
  6181. r0, _, err := procStati64.Call(uintptr(path), uintptr(buffer))
  6182. if err != windows.NOERROR {
  6183. t.setErrno(err)
  6184. }
  6185. return int32(r0)
  6186. }
  6187. // int _fstati64(int fd, struct _stati64 *buffer);
  6188. func X_fstati64(t *TLS, fd int32, buffer uintptr) int32 {
  6189. return X_fstat64(t, fd, buffer)
  6190. }
  6191. // int _findnext32(
  6192. //
  6193. // intptr_t handle,
  6194. // struct _finddata32_t *fileinfo
  6195. //
  6196. // );
  6197. func X_findnext32(t *TLS, handle types.Intptr_t, buffer uintptr) int32 {
  6198. if __ccgo_strace {
  6199. trc("t=%v handle=%v buffer=%v, (%v:)", t, handle, buffer, origin(2))
  6200. }
  6201. r0, _, err := procFindnext32.Call(uintptr(handle), buffer)
  6202. if err != windows.NOERROR {
  6203. t.setErrno(err)
  6204. }
  6205. return int32(r0)
  6206. }
  6207. // intptr_t _findfirst32(
  6208. //
  6209. // const char *filespec,
  6210. // struct _finddata32_t *fileinfo
  6211. //
  6212. // );
  6213. func X_findfirst32(t *TLS, filespec, fileinfo uintptr) types.Intptr_t {
  6214. if __ccgo_strace {
  6215. trc("t=%v fileinfo=%v, (%v:)", t, fileinfo, origin(2))
  6216. }
  6217. r0, _, err := procFindfirst32.Call(filespec, fileinfo)
  6218. if err != windows.NOERROR {
  6219. t.setErrno(err)
  6220. }
  6221. return types.Intptr_t(r0)
  6222. }
  6223. /*-
  6224. * Copyright (c) 1990 The Regents of the University of California.
  6225. * All rights reserved.
  6226. *
  6227. * Redistribution and use in source and binary forms, with or without
  6228. * modification, are permitted provided that the following conditions
  6229. * are met:
  6230. * 1. Redistributions of source code must retain the above copyright
  6231. * notice, this list of conditions and the following disclaimer.
  6232. * 2. Redistributions in binary form must reproduce the above copyright
  6233. * notice, this list of conditions and the following disclaimer in the
  6234. * documentation and/or other materials provided with the distribution.
  6235. * 3. Neither the name of the University nor the names of its contributors
  6236. * may be used to endorse or promote products derived from this software
  6237. * without specific prior written permission.
  6238. *
  6239. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  6240. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  6241. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  6242. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  6243. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  6244. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  6245. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  6246. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  6247. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  6248. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  6249. * SUCH DAMAGE.
  6250. */
  6251. // long strtol(const char *nptr, char **endptr, int base);
  6252. func Xstrtol(t *TLS, nptr, endptr uintptr, base int32) long {
  6253. if __ccgo_strace {
  6254. trc("t=%v endptr=%v base=%v, (%v:)", t, endptr, base, origin(2))
  6255. }
  6256. var s uintptr = nptr
  6257. var acc ulong
  6258. var c byte
  6259. var cutoff ulong
  6260. var neg int32
  6261. var any int32
  6262. var cutlim int32
  6263. /*
  6264. * Skip white space and pick up leading +/- sign if any.
  6265. * If base is 0, allow 0x for hex and 0 for octal, else
  6266. * assume decimal; if base is already 16, allow 0x.
  6267. */
  6268. for {
  6269. c = *(*byte)(unsafe.Pointer(s))
  6270. PostIncUintptr(&s, 1)
  6271. var sp = strings.TrimSpace(string(c))
  6272. if len(sp) > 0 {
  6273. break
  6274. }
  6275. }
  6276. if c == '-' {
  6277. neg = 1
  6278. c = *(*byte)(unsafe.Pointer(s))
  6279. PostIncUintptr(&s, 1)
  6280. } else if c == '+' {
  6281. c = *(*byte)(unsafe.Pointer(s))
  6282. PostIncUintptr(&s, 1)
  6283. }
  6284. sp := *(*byte)(unsafe.Pointer(s))
  6285. if (base == 0 || base == 16) &&
  6286. c == '0' && (sp == 'x' || sp == 'X') {
  6287. PostIncUintptr(&s, 1)
  6288. c = *(*byte)(unsafe.Pointer(s)) //s[1];
  6289. PostIncUintptr(&s, 1)
  6290. base = 16
  6291. }
  6292. if base == 0 {
  6293. if c == '0' {
  6294. base = 0
  6295. } else {
  6296. base = 10
  6297. }
  6298. }
  6299. /*
  6300. * Compute the cutoff value between legal numbers and illegal
  6301. * numbers. That is the largest legal value, divided by the
  6302. * base. An input number that is greater than this value, if
  6303. * followed by a legal input character, is too big. One that
  6304. * is equal to this value may be valid or not; the limit
  6305. * between valid and invalid numbers is then based on the last
  6306. * digit. For instance, if the range for longs is
  6307. * [-2147483648..2147483647] and the input base is 10,
  6308. * cutoff will be set to 214748364 and cutlim to either
  6309. * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
  6310. * a value > 214748364, or equal but the next digit is > 7 (or 8),
  6311. * the number is too big, and we will return a range error.
  6312. *
  6313. * Set any if any `digits' consumed; make it negative to indicate
  6314. * overflow.
  6315. */
  6316. var ULONG_MAX ulong = 0xFFFFFFFF
  6317. var LONG_MAX long = long(ULONG_MAX >> 1)
  6318. var LONG_MIN long = ^LONG_MAX
  6319. if neg == 1 {
  6320. cutoff = ulong(-1 * LONG_MIN)
  6321. } else {
  6322. cutoff = ulong(LONG_MAX)
  6323. }
  6324. cutlim = int32(cutoff % ulong(base))
  6325. cutoff = cutoff / ulong(base)
  6326. acc = 0
  6327. any = 0
  6328. for {
  6329. var cs = string(c)
  6330. if unicode.IsDigit([]rune(cs)[0]) {
  6331. c -= '0'
  6332. } else if unicode.IsLetter([]rune(cs)[0]) {
  6333. if unicode.IsUpper([]rune(cs)[0]) {
  6334. c -= 'A' - 10
  6335. } else {
  6336. c -= 'a' - 10
  6337. }
  6338. } else {
  6339. break
  6340. }
  6341. if int32(c) >= base {
  6342. break
  6343. }
  6344. if any < 0 || acc > cutoff || (acc == cutoff && int32(c) > cutlim) {
  6345. any = -1
  6346. } else {
  6347. any = 1
  6348. acc *= ulong(base)
  6349. acc += ulong(c)
  6350. }
  6351. c = *(*byte)(unsafe.Pointer(s))
  6352. PostIncUintptr(&s, 1)
  6353. }
  6354. if any < 0 {
  6355. if neg == 1 {
  6356. acc = ulong(LONG_MIN)
  6357. } else {
  6358. acc = ulong(LONG_MAX)
  6359. }
  6360. t.setErrno(errno.ERANGE)
  6361. } else if neg == 1 {
  6362. acc = -acc
  6363. }
  6364. if endptr != 0 {
  6365. if any == 1 {
  6366. PostDecUintptr(&s, 1)
  6367. AssignPtrUintptr(endptr, s)
  6368. } else {
  6369. AssignPtrUintptr(endptr, nptr)
  6370. }
  6371. }
  6372. return long(acc)
  6373. }
  6374. // unsigned long int strtoul(const char *nptr, char **endptr, int base);
  6375. func Xstrtoul(t *TLS, nptr, endptr uintptr, base int32) ulong {
  6376. if __ccgo_strace {
  6377. trc("t=%v endptr=%v base=%v, (%v:)", t, endptr, base, origin(2))
  6378. }
  6379. var s uintptr = nptr
  6380. var acc ulong
  6381. var c byte
  6382. var cutoff ulong
  6383. var neg int32
  6384. var any int32
  6385. var cutlim int32
  6386. /*
  6387. * Skip white space and pick up leading +/- sign if any.
  6388. * If base is 0, allow 0x for hex and 0 for octal, else
  6389. * assume decimal; if base is already 16, allow 0x.
  6390. */
  6391. for {
  6392. c = *(*byte)(unsafe.Pointer(s))
  6393. PostIncUintptr(&s, 1)
  6394. var sp = strings.TrimSpace(string(c))
  6395. if len(sp) > 0 {
  6396. break
  6397. }
  6398. }
  6399. if c == '-' {
  6400. neg = 1
  6401. c = *(*byte)(unsafe.Pointer(s))
  6402. PostIncUintptr(&s, 1)
  6403. } else if c == '+' {
  6404. c = *(*byte)(unsafe.Pointer(s))
  6405. PostIncUintptr(&s, 1)
  6406. }
  6407. sp := *(*byte)(unsafe.Pointer(s))
  6408. if (base == 0 || base == 16) &&
  6409. c == '0' && (sp == 'x' || sp == 'X') {
  6410. PostIncUintptr(&s, 1)
  6411. c = *(*byte)(unsafe.Pointer(s)) //s[1];
  6412. PostIncUintptr(&s, 1)
  6413. base = 16
  6414. }
  6415. if base == 0 {
  6416. if c == '0' {
  6417. base = 0
  6418. } else {
  6419. base = 10
  6420. }
  6421. }
  6422. var ULONG_MAX ulong = 0xFFFFFFFF
  6423. cutoff = ULONG_MAX / ulong(base)
  6424. cutlim = int32(ULONG_MAX % ulong(base))
  6425. acc = 0
  6426. any = 0
  6427. for {
  6428. var cs = string(c)
  6429. if unicode.IsDigit([]rune(cs)[0]) {
  6430. c -= '0'
  6431. } else if unicode.IsLetter([]rune(cs)[0]) {
  6432. if unicode.IsUpper([]rune(cs)[0]) {
  6433. c -= 'A' - 10
  6434. } else {
  6435. c -= 'a' - 10
  6436. }
  6437. } else {
  6438. break
  6439. }
  6440. if int32(c) >= base {
  6441. break
  6442. }
  6443. if any < 0 || acc > cutoff || (acc == cutoff && int32(c) > cutlim) {
  6444. any = -1
  6445. } else {
  6446. any = 1
  6447. acc *= ulong(base)
  6448. acc += ulong(c)
  6449. }
  6450. c = *(*byte)(unsafe.Pointer(s))
  6451. PostIncUintptr(&s, 1)
  6452. }
  6453. if any < 0 {
  6454. acc = ULONG_MAX
  6455. t.setErrno(errno.ERANGE)
  6456. } else if neg == 1 {
  6457. acc = -acc
  6458. }
  6459. if endptr != 0 {
  6460. if any == 1 {
  6461. PostDecUintptr(&s, 1)
  6462. AssignPtrUintptr(endptr, s)
  6463. } else {
  6464. AssignPtrUintptr(endptr, nptr)
  6465. }
  6466. }
  6467. return acc
  6468. }
  6469. // int __isoc99_sscanf(const char *str, const char *format, ...);
  6470. func X__isoc99_sscanf(t *TLS, str, format, va uintptr) int32 {
  6471. if __ccgo_strace {
  6472. trc("t=%v va=%v, (%v:)", t, va, origin(2))
  6473. }
  6474. r := scanf(strings.NewReader(GoString(str)), format, va)
  6475. // if dmesgs {
  6476. // dmesg("%v: %q %q: %d", origin(1), GoString(str), GoString(format), r)
  6477. // }
  6478. return r
  6479. }
  6480. // int sscanf(const char *str, const char *format, ...);
  6481. func Xsscanf(t *TLS, str, format, va uintptr) int32 {
  6482. if __ccgo_strace {
  6483. trc("t=%v va=%v, (%v:)", t, va, origin(2))
  6484. }
  6485. r := scanf(strings.NewReader(GoString(str)), format, va)
  6486. // if dmesgs {
  6487. // dmesg("%v: %q %q: %d", origin(1), GoString(str), GoString(format), r)
  6488. // }
  6489. return r
  6490. }
  6491. var _toint4 = Float64FromInt32(1) / Float64FromFloat64(2.220446049250313e-16)
  6492. func Xrint(tls *TLS, x float64) float64 {
  6493. if __ccgo_strace {
  6494. trc("tls=%v x=%v, (%v:)", tls, x, origin(2))
  6495. }
  6496. bp := tls.Alloc(16)
  6497. defer tls.Free(16)
  6498. var e, s int32
  6499. var y Tdouble_t
  6500. var v1 float64
  6501. var _ /* u at bp+0 */ struct {
  6502. Fi [0]Tuint64_t
  6503. Ff float64
  6504. }
  6505. _, _, _, _ = e, s, y, v1
  6506. *(*struct {
  6507. Fi [0]Tuint64_t
  6508. Ff float64
  6509. })(unsafe.Pointer(bp)) = struct {
  6510. Fi [0]Tuint64_t
  6511. Ff float64
  6512. }{}
  6513. *(*float64)(unsafe.Pointer(bp)) = x
  6514. e = Int32FromUint64(*(*Tuint64_t)(unsafe.Pointer(bp)) >> int32(52) & uint64(0x7ff))
  6515. s = Int32FromUint64(*(*Tuint64_t)(unsafe.Pointer(bp)) >> int32(63))
  6516. if e >= Int32FromInt32(0x3ff)+Int32FromInt32(52) {
  6517. return x
  6518. }
  6519. if s != 0 {
  6520. y = x - _toint4 + _toint4
  6521. } else {
  6522. y = x + _toint4 - _toint4
  6523. }
  6524. if y == Float64FromInt32(0) {
  6525. if s != 0 {
  6526. v1 = -Float64FromFloat64(0)
  6527. } else {
  6528. v1 = Float64FromInt32(0)
  6529. }
  6530. return v1
  6531. }
  6532. return y
  6533. }
  6534. // FILE *fdopen(int fd, const char *mode);
  6535. func Xfdopen(t *TLS, fd int32, mode uintptr) uintptr {
  6536. if __ccgo_strace {
  6537. trc("t=%v fd=%v mode=%v, (%v:)", t, fd, mode, origin(2))
  6538. }
  6539. panic(todo(""))
  6540. }
  6541. // struct tm *_gmtime64( const __time64_t *sourceTime );
  6542. func X_gmtime64(t *TLS, sourceTime uintptr) uintptr {
  6543. if __ccgo_strace {
  6544. trc("t=%v sourceTime=%v, (%v:)", t, sourceTime, origin(2))
  6545. }
  6546. r0, _, err := procGmtime64.Call(uintptr(sourceTime))
  6547. if err != windows.NOERROR {
  6548. t.setErrno(err)
  6549. }
  6550. return uintptr(r0)
  6551. }
  6552. // __time64_t _mktime64(struct tm *timeptr);
  6553. func X_mktime64(t *TLS, timeptr uintptr) time.X__time64_t {
  6554. if __ccgo_strace {
  6555. trc("t=%v timeptr=%v, (%v:)", t, timeptr, origin(2))
  6556. }
  6557. return time.X__time64_t(Xmktime(t, timeptr))
  6558. }
  6559. // char * gai_strerrorA(int ecode);
  6560. func Xgai_strerrorA(t *TLS, ecode int32) uintptr {
  6561. if __ccgo_strace {
  6562. trc("t=%v ecode=%v, (%v:)", t, ecode, origin(2))
  6563. }
  6564. panic(todo(""))
  6565. }
  6566. // https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/crt/sys/timeb.h#L69
  6567. //
  6568. // struct __timeb64 {
  6569. // __time64_t time;
  6570. // unsigned short millitm;
  6571. // short timezone;
  6572. // short dstflag;
  6573. // };
  6574. type __timeb64 struct {
  6575. time types.X__time64_t
  6576. millitm uint32
  6577. timezone int16
  6578. dstflag int16
  6579. }
  6580. // void _ftime64( struct __timeb64 *timeptr );
  6581. func X_ftime64(t *TLS, timeptr uintptr) {
  6582. if __ccgo_strace {
  6583. trc("t=%v timeptr=%v, (%v:)", t, timeptr, origin(2))
  6584. }
  6585. tm := gotime.Now()
  6586. (*__timeb64)(unsafe.Pointer(timeptr)).time = types.X__time64_t(tm.Unix())
  6587. //TODO When Go 1.16 is no more supported
  6588. // (*__timeb64)(unsafe.Pointer(timeptr)).millitm = uint32(tm.UnixMilli() % 1000)
  6589. (*__timeb64)(unsafe.Pointer(timeptr)).millitm = uint32(int64(tm.Nanosecond()) / 1e6)
  6590. }
  6591. func X__ccgo_getMutexType(tls *TLS, m uintptr) int32 { /* pthread_mutex_lock.c:3:5: */
  6592. if __ccgo_strace {
  6593. trc("tls=%v m=%v, (%v:)", tls, m, origin(2))
  6594. }
  6595. return *(*int32)(unsafe.Pointer(m)) & 15
  6596. }
  6597. func X__ccgo_pthreadAttrGetDetachState(tls *TLS, a uintptr) int32 { /* pthread_attr_get.c:3:5: */
  6598. if __ccgo_strace {
  6599. trc("tls=%v a=%v, (%v:)", tls, a, origin(2))
  6600. }
  6601. return *(*int32)(unsafe.Pointer(a))
  6602. }
  6603. func X__ccgo_pthreadMutexattrGettype(tls *TLS, a uintptr) int32 { /* pthread_attr_get.c:93:5: */
  6604. if __ccgo_strace {
  6605. trc("tls=%v a=%v, (%v:)", tls, a, origin(2))
  6606. }
  6607. return *(*int32)(unsafe.Pointer(a)) & int32(3)
  6608. }
  6609. func Xchmod(t *TLS, pathname uintptr, mode int32) int32 {
  6610. r0, _, err := procChmod.Call(pathname, uintptr(mode))
  6611. if err != windows.NOERROR {
  6612. t.setErrno(err)
  6613. }
  6614. return int32(r0)
  6615. }
  6616. // typedef enum _COMPUTER_NAME_FORMAT {
  6617. // ComputerNameNetBIOS,
  6618. // ComputerNameDnsHostname,
  6619. // ComputerNameDnsDomain,
  6620. // ComputerNameDnsFullyQualified,
  6621. // ComputerNamePhysicalNetBIOS,
  6622. // ComputerNamePhysicalDnsHostname,
  6623. // ComputerNamePhysicalDnsDomain,
  6624. // ComputerNamePhysicalDnsFullyQualified,
  6625. // ComputerNameMax
  6626. // } COMPUTER_NAME_FORMAT;
  6627. // BOOL GetComputerNameExW(
  6628. //
  6629. // [in] COMPUTER_NAME_FORMAT NameType,
  6630. // [out] LPWSTR lpBuffer,
  6631. // [in, out] LPDWORD nSize
  6632. //
  6633. // );
  6634. func XGetComputerNameExW(t *TLS, nameType int32, lpBuffer, nSize uintptr) int32 {
  6635. if __ccgo_strace {
  6636. trc("t=%v nameType=%v nSize=%v, (%v:)", t, nameType, nSize, origin(2))
  6637. }
  6638. r0, _, err := procGetComputerNameExW.Call(uintptr(nameType), lpBuffer, nSize)
  6639. if err != windows.NOERROR {
  6640. t.setErrno(err)
  6641. }
  6642. return int32(r0)
  6643. }
  6644. // double _copysign(
  6645. //
  6646. // double x,
  6647. // double y
  6648. //
  6649. // );
  6650. func X_copysign(t *TLS, x, y float64) float64 {
  6651. if __ccgo_strace {
  6652. trc("t=%v y=%v, (%v:)", t, y, origin(2))
  6653. }
  6654. return Xcopysign(t, x, y)
  6655. }
  6656. // int _wtoi(
  6657. //
  6658. // const wchar_t *str
  6659. //
  6660. // );
  6661. func X_wtoi(t *TLS, str uintptr) int32 {
  6662. if __ccgo_strace {
  6663. trc("t=%v str=%v, (%v:)", t, str, origin(2))
  6664. }
  6665. panic(todo(""))
  6666. }
  6667. func allocW(t *TLS, v string) (r uintptr) {
  6668. s := utf16.Encode([]rune(v))
  6669. p := Xcalloc(t, types.Size_t(len(s)+1), 2)
  6670. if p == 0 {
  6671. panic(todo(""))
  6672. }
  6673. r = p
  6674. for _, v := range s {
  6675. *(*uint16)(unsafe.Pointer(p)) = v
  6676. p += 2
  6677. }
  6678. return r
  6679. }
  6680. // wchar_t *_wgetenv(
  6681. //
  6682. // const wchar_t *varname
  6683. //
  6684. // );
  6685. func X_wgetenv(t *TLS, varname uintptr) uintptr {
  6686. if __ccgo_strace {
  6687. trc("t=%v varname=%v, (%v:)", t, varname, origin(2))
  6688. }
  6689. if !wenvValid {
  6690. bootWinEnviron(t)
  6691. }
  6692. k := strings.ToLower(goWideStringNZ(varname))
  6693. for _, v := range winEnviron[:len(winEnviron)-1] {
  6694. s := strings.ToLower(goWideStringNZ(v))
  6695. x := strings.IndexByte(s, '=')
  6696. if s[:x] == k {
  6697. // trc("%v: %q -> %q", origin(1), goWideStringNZ(varname), goWideStringNZ(v))
  6698. return v
  6699. }
  6700. }
  6701. // trc("%v: %q -> %q", origin(1), goWideStringNZ(varname), "")
  6702. return 0
  6703. }
  6704. // int _wputenv(
  6705. //
  6706. // const wchar_t *envstring
  6707. //
  6708. // );
  6709. func X_wputenv(t *TLS, envstring uintptr) int32 {
  6710. if __ccgo_strace {
  6711. trc("t=%v envstring=%v, (%v:)", t, envstring, origin(2))
  6712. }
  6713. if !wenvValid {
  6714. bootWinEnviron(t)
  6715. }
  6716. s0 := goWideStringNZ(envstring)
  6717. s := strings.ToLower(s0)
  6718. x := strings.IndexByte(s, '=')
  6719. k := s[:x]
  6720. for i, v := range winEnviron[:len(winEnviron)-1] {
  6721. s2 := strings.ToLower(goWideStringNZ(v))
  6722. x := strings.IndexByte(s2, '=')
  6723. if s2[:x] == k {
  6724. Xfree(t, v)
  6725. winEnviron[i] = allocW(t, s0)
  6726. return 0
  6727. }
  6728. }
  6729. np := allocW(t, s0)
  6730. winEnviron = winEnviron[:len(winEnviron)-1]
  6731. winEnviron = append(winEnviron, np, 0)
  6732. wenviron = uintptr(unsafe.Pointer(&winEnviron[0]))
  6733. return 0
  6734. }
  6735. func bootWinEnviron(t *TLS) {
  6736. winEnviron = winEnviron[:0]
  6737. p := Environ()
  6738. for {
  6739. q := *(*uintptr)(unsafe.Pointer(p))
  6740. p += unsafe.Sizeof(uintptr(0))
  6741. if q == 0 {
  6742. break
  6743. }
  6744. s := GoString(q)
  6745. // trc("%v: %q", origin(1), s)
  6746. r := allocW(t, s)
  6747. winEnviron = append(winEnviron, r)
  6748. }
  6749. wenviron = uintptr(unsafe.Pointer(&winEnviron[0]))
  6750. wenvValid = true
  6751. }
  6752. func Xfabsl(t *TLS, x float64) float64 {
  6753. if __ccgo_strace {
  6754. trc("t=%v x=%v, (%v:)", t, x, origin(2))
  6755. }
  6756. return math.Abs(x)
  6757. }
  6758. func X__stdio_common_vfprintf(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6759. func X__stdio_common_vfprintf_p(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6760. func X__stdio_common_vfprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6761. func X__stdio_common_vfscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6762. func X__stdio_common_vfwprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6763. func X__stdio_common_vfwscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6764. func X__stdio_common_vsnprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6765. func X__stdio_common_vsnwprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6766. func X__stdio_common_vsprintf(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6767. func X__stdio_common_vsprintf_p(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6768. func X__stdio_common_vsprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6769. func X__stdio_common_vsscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6770. func X__stdio_common_vswprintf(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6771. func X__stdio_common_vswprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6772. func X__stdio_common_vswscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
  6773. func X_lseeki64(t *TLS, fd int32, offset int64, whence int32) int64 {
  6774. if __ccgo_strace {
  6775. trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
  6776. }
  6777. f, ok := fdToFile(fd)
  6778. if !ok {
  6779. t.setErrno(errno.EBADF)
  6780. return -1
  6781. }
  6782. n, err := windows.Seek(f.Handle, offset, int(whence))
  6783. if err != nil {
  6784. if dmesgs {
  6785. dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
  6786. }
  6787. t.setErrno(err)
  6788. return -1
  6789. }
  6790. if dmesgs {
  6791. dmesg("%v: fd %v, off %#x, whence %v: ok", origin(1), f._fd, offset, whenceStr(whence))
  6792. }
  6793. return n
  6794. }
  6795. func Xislower(tls *TLS, c int32) int32 { /* islower.c:4:5: */
  6796. if __ccgo_strace {
  6797. trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
  6798. }
  6799. return Bool32(uint32(c)-uint32('a') < uint32(26))
  6800. }
  6801. func Xisupper(tls *TLS, c int32) int32 { /* isupper.c:4:5: */
  6802. if __ccgo_strace {
  6803. trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
  6804. }
  6805. return Bool32(uint32(c)-uint32('A') < uint32(26))
  6806. }
  6807. // int access(const char *pathname, int mode);
  6808. func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
  6809. if __ccgo_strace {
  6810. trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
  6811. }
  6812. r0, _, err := procAccess.Call(uintptr(pathname), uintptr(mode))
  6813. if err != windows.NOERROR {
  6814. t.setErrno(err)
  6815. }
  6816. return int32(r0)
  6817. }
  6818. // int _vscprintf(const char *format, va_list argptr);
  6819. func X_vscprintf(t *TLS, format uintptr, argptr uintptr) int32 {
  6820. if __ccgo_strace {
  6821. trc("t=%v format=%v argptr=%v, (%v:)", t, format, argptr, origin(2))
  6822. }
  6823. return int32(len(printf(format, argptr)))
  6824. }
  6825. // int _stat32i64(const char *path, struct _stat32i64 *buffer);
  6826. func X_stat64i32(t *TLS, path uintptr, buffer uintptr) int32 {
  6827. if __ccgo_strace {
  6828. trc("t=%v path=%v buffer=%v, (%v:)", t, path, buffer, origin(2))
  6829. }
  6830. r0, _, err := procStat64i32.Call(uintptr(path), uintptr(buffer))
  6831. if err != windows.NOERROR {
  6832. t.setErrno(err)
  6833. }
  6834. return int32(r0)
  6835. }
  6836. func AtomicLoadNUint8(ptr uintptr, memorder int32) uint8 {
  6837. return byte(a_load_8(ptr))
  6838. }
  6839. // struct tm *gmtime( const time_t *sourceTime );
  6840. // func Xgmtime(t *TLS, sourceTime uintptr) uintptr {
  6841. // if __ccgo_strace {
  6842. // trc("t=%v sourceTime=%v, (%v:)", t, sourceTime, origin(2))
  6843. // }
  6844. // r0, _, err := procGmtime.Call(uintptr(sourceTime))
  6845. // if err != windows.NOERROR {
  6846. // t.setErrno(err)
  6847. // }
  6848. // return uintptr(r0)
  6849. // }
  6850. var _tm time.Tm
  6851. // /tmp/libc/musl-master/src/time/gmtime.c:4:11:
  6852. func Xgmtime(tls *TLS, t uintptr) (r uintptr) { // /tmp/libc/musl-master/src/time/gmtime.c:7:2:
  6853. if __ccgo_strace {
  6854. trc("tls=%v t=%v, (%v:)", tls, t, origin(2))
  6855. defer func() { trc("-> %v", r) }()
  6856. }
  6857. r = Xgmtime_r(tls, t, uintptr(unsafe.Pointer(&_tm)))
  6858. return r
  6859. }
  6860. var _days_in_month = [12]int8{
  6861. 0: int8(31),
  6862. 1: int8(30),
  6863. 2: int8(31),
  6864. 3: int8(30),
  6865. 4: int8(31),
  6866. 5: int8(31),
  6867. 6: int8(30),
  6868. 7: int8(31),
  6869. 8: int8(30),
  6870. 9: int8(31),
  6871. 10: int8(31),
  6872. 11: int8(29),
  6873. }
  6874. var x___utc = [4]int8{'U', 'T', 'C'}
  6875. func Xgmtime_r(tls *TLS, t uintptr, tm uintptr) (r uintptr) {
  6876. if __ccgo_strace {
  6877. trc("tls=%v t=%v tm=%v, (%v:)", tls, t, tm, origin(2))
  6878. defer func() { trc("-> %v", r) }()
  6879. }
  6880. if x___secs_to_tm(tls, int64(*(*time.Time_t)(unsafe.Pointer(t))), tm) < 0 {
  6881. *(*int32)(unsafe.Pointer(X__errno_location(tls))) = int32(errno.EOVERFLOW)
  6882. return uintptr(0)
  6883. }
  6884. (*time.Tm)(unsafe.Pointer(tm)).Ftm_isdst = 0
  6885. return tm
  6886. }
  6887. func x___secs_to_tm(tls *TLS, t int64, tm uintptr) (r int32) {
  6888. var c_cycles, leap, months, q_cycles, qc_cycles, remdays, remsecs, remyears, wday, yday int32
  6889. var days, secs, years int64
  6890. _, _, _, _, _, _, _, _, _, _, _, _, _ = c_cycles, days, leap, months, q_cycles, qc_cycles, remdays, remsecs, remyears, secs, wday, yday, years
  6891. /* Reject time_t values whose year would overflow int */
  6892. if t < int64(-Int32FromInt32(1)-Int32FromInt32(0x7fffffff))*Int64FromInt64(31622400) || t > Int64FromInt32(limits.INT_MAX)*Int64FromInt64(31622400) {
  6893. return -int32(1)
  6894. }
  6895. secs = t - (Int64FromInt64(946684800) + int64(Int32FromInt32(86400)*(Int32FromInt32(31)+Int32FromInt32(29))))
  6896. days = secs / int64(86400)
  6897. remsecs = int32(secs % int64(86400))
  6898. if remsecs < 0 {
  6899. remsecs += int32(86400)
  6900. days--
  6901. }
  6902. wday = int32((int64(3) + days) % int64(7))
  6903. if wday < 0 {
  6904. wday += int32(7)
  6905. }
  6906. qc_cycles = int32(days / int64(Int32FromInt32(365)*Int32FromInt32(400)+Int32FromInt32(97)))
  6907. remdays = int32(days % int64(Int32FromInt32(365)*Int32FromInt32(400)+Int32FromInt32(97)))
  6908. if remdays < 0 {
  6909. remdays += Int32FromInt32(365)*Int32FromInt32(400) + Int32FromInt32(97)
  6910. qc_cycles--
  6911. }
  6912. c_cycles = remdays / (Int32FromInt32(365)*Int32FromInt32(100) + Int32FromInt32(24))
  6913. if c_cycles == int32(4) {
  6914. c_cycles--
  6915. }
  6916. remdays -= c_cycles * (Int32FromInt32(365)*Int32FromInt32(100) + Int32FromInt32(24))
  6917. q_cycles = remdays / (Int32FromInt32(365)*Int32FromInt32(4) + Int32FromInt32(1))
  6918. if q_cycles == int32(25) {
  6919. q_cycles--
  6920. }
  6921. remdays -= q_cycles * (Int32FromInt32(365)*Int32FromInt32(4) + Int32FromInt32(1))
  6922. remyears = remdays / int32(365)
  6923. if remyears == int32(4) {
  6924. remyears--
  6925. }
  6926. remdays -= remyears * int32(365)
  6927. leap = BoolInt32(!(remyears != 0) && (q_cycles != 0 || !(c_cycles != 0)))
  6928. yday = remdays + int32(31) + int32(28) + leap
  6929. if yday >= int32(365)+leap {
  6930. yday -= int32(365) + leap
  6931. }
  6932. years = int64(remyears+int32(4)*q_cycles+int32(100)*c_cycles) + int64(400)*int64(int64(qc_cycles))
  6933. months = 0
  6934. for {
  6935. if !(int32(_days_in_month[months]) <= remdays) {
  6936. break
  6937. }
  6938. remdays -= int32(_days_in_month[months])
  6939. goto _1
  6940. _1:
  6941. months++
  6942. }
  6943. if months >= int32(10) {
  6944. months -= int32(12)
  6945. years++
  6946. }
  6947. if years+int64(100) > int64(limits.INT_MAX) || years+int64(100) < int64(-Int32FromInt32(1)-Int32FromInt32(0x7fffffff)) {
  6948. return -int32(1)
  6949. }
  6950. (*time.Tm)(unsafe.Pointer(tm)).Ftm_year = int32(years + int64(100))
  6951. (*time.Tm)(unsafe.Pointer(tm)).Ftm_mon = months + int32(2)
  6952. (*time.Tm)(unsafe.Pointer(tm)).Ftm_mday = remdays + int32(1)
  6953. (*time.Tm)(unsafe.Pointer(tm)).Ftm_wday = wday
  6954. (*time.Tm)(unsafe.Pointer(tm)).Ftm_yday = yday
  6955. (*time.Tm)(unsafe.Pointer(tm)).Ftm_hour = remsecs / int32(3600)
  6956. (*time.Tm)(unsafe.Pointer(tm)).Ftm_min = remsecs / int32(60) % int32(60)
  6957. (*time.Tm)(unsafe.Pointer(tm)).Ftm_sec = remsecs % int32(60)
  6958. return 0
  6959. }
  6960. // size_t strftime(
  6961. //
  6962. // char *strDest,
  6963. // size_t maxsize,
  6964. // const char *format,
  6965. // const struct tm *timeptr
  6966. //
  6967. // );
  6968. func Xstrftime(tls *TLS, s uintptr, n size_t, f uintptr, tm uintptr) (r size_t) {
  6969. if __ccgo_strace {
  6970. trc("tls=%v s=%v n=%v f=%v tm=%v, (%v:)", tls, s, n, f, tm, origin(2))
  6971. defer func() { trc("-> %v", r) }()
  6972. }
  6973. tt := gotime.Date(
  6974. int((*time.Tm)(unsafe.Pointer(tm)).Ftm_year+1900),
  6975. gotime.Month((*time.Tm)(unsafe.Pointer(tm)).Ftm_mon+1),
  6976. int((*time.Tm)(unsafe.Pointer(tm)).Ftm_mday),
  6977. int((*time.Tm)(unsafe.Pointer(tm)).Ftm_hour),
  6978. int((*time.Tm)(unsafe.Pointer(tm)).Ftm_min),
  6979. int((*time.Tm)(unsafe.Pointer(tm)).Ftm_sec),
  6980. 0,
  6981. gotime.UTC,
  6982. )
  6983. fmt := GoString(f)
  6984. var result string
  6985. if fmt != "" {
  6986. result = strftime.Format(fmt, tt)
  6987. }
  6988. switch r = size_t(len(result)); {
  6989. case r > n:
  6990. r = 0
  6991. default:
  6992. copy((*RawMem)(unsafe.Pointer(s))[:r:r], result)
  6993. *(*byte)(unsafe.Pointer(s + uintptr(r))) = 0
  6994. }
  6995. return r
  6996. }
  6997. func X__mingw_strtod(t *TLS, s uintptr, p uintptr) float64 {
  6998. return Xstrtod(t, s, p)
  6999. }
  7000. func Xstrtod(t *TLS, s uintptr, p uintptr) float64 {
  7001. if __ccgo_strace {
  7002. trc("tls=%v s=%v p=%v, (%v:)", t, s, p, origin(2))
  7003. }
  7004. r0, _, err := procStrtod.Call(uintptr(s), uintptr(p))
  7005. if err != windows.NOERROR {
  7006. t.setErrno(err)
  7007. }
  7008. return math.Float64frombits(uint64(r0))
  7009. }
  7010. // int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  7011. func X_vsnprintf(t *TLS, str uintptr, size types.Size_t, format, ap uintptr) int32 {
  7012. if __ccgo_strace {
  7013. trc("t=%v str=%v size=%v ap=%v, (%v:)", t, str, size, ap, origin(2))
  7014. }
  7015. return Xvsnprintf(t, str, size, format, ap)
  7016. }
  7017. func X__ccgo_SyscallFP() {
  7018. s := fmt.Sprintf("%s\nTODO syscall: function pointer", debug.Stack())
  7019. panic(s)
  7020. }
  7021. func CreateThread(t *TLS, lpThreadAttributes uintptr, dwStackSize types.Size_t, lpStartAddress, lpParameter uintptr, dwCreationFlags uint32, lpThreadId uintptr) uintptr {
  7022. return XCreateThread(t, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId)
  7023. }
  7024. // wchar_t *wcsncpy(wchar_t *strDest, const wchar_t *strSource, size_t count);
  7025. func Xwcsncpy(t *TLS, strDest, strSource uintptr, count types.Size_t) uintptr {
  7026. r0, _, err := procWcsncpy.Call(strDest, strSource, uintptr(count))
  7027. if err != windows.NOERROR {
  7028. t.setErrno(err)
  7029. }
  7030. return r0
  7031. }
  7032. // wchar_t *wcsrchr(const wchar_t *str, wchar_t c);
  7033. func Xwcsrchr(t *TLS, str uintptr, c types.Wchar_t) uintptr {
  7034. r0, _, err := procWcsrchr.Call(str, uintptr(c))
  7035. if err != windows.NOERROR {
  7036. t.setErrno(err)
  7037. }
  7038. return r0
  7039. }
  7040. // __attribute__ ((__dllimport__)) char * __attribute__((__cdecl__)) _ctime64(const __time64_t *_Time);
  7041. func X_ctime64(tls *TLS, __Time uintptr) (r uintptr) {
  7042. if __ccgo_strace {
  7043. trc("_Time=%+v", __Time)
  7044. defer func() { trc(`X_ctime64->%+v`, r) }()
  7045. }
  7046. r0, _, err := procCtime64.Call(__Time)
  7047. if err != windows.NOERROR {
  7048. tls.setErrno(int32(err.(windows.Errno)))
  7049. }
  7050. return uintptr(r0)
  7051. }
  7052. // __attribute__ ((__dllimport__)) __time64_t __attribute__((__cdecl__)) _time64(__time64_t *_Time);
  7053. func X_time64(tls *TLS, __Time uintptr) (r int64) {
  7054. if __ccgo_strace {
  7055. trc("_Time=%+v", __Time)
  7056. defer func() { trc(`X_time64->%+v`, r) }()
  7057. }
  7058. r0, _, err := procTime64.Call(__Time)
  7059. if err != windows.NOERROR {
  7060. tls.setErrno(int32(err.(windows.Errno)))
  7061. }
  7062. return int64(r0)
  7063. }
  7064. // __attribute__ ((__dllimport__)) int __attribute__((__cdecl__)) _strnicmp(const char *_Str1,const char *_Str2,size_t _MaxCount);
  7065. func X_strnicmp(tls *TLS, __Str1 uintptr, __Str2 uintptr, __MaxCount types.Size_t) (r int32) {
  7066. if __ccgo_strace {
  7067. trc("_Str1=%+v _Str2=%+v _MaxCount=%+v", __Str1, __Str2, __MaxCount)
  7068. defer func() { trc(`X_strnicmp->%+v`, r) }()
  7069. }
  7070. r0, _, err := procStrnicmp.Call(__Str1, __Str2, uintptr(__MaxCount))
  7071. if err != windows.NOERROR {
  7072. tls.setErrno(int32(err.(windows.Errno)))
  7073. }
  7074. return int32(r0)
  7075. }
  7076. func X__builtin_ctz(t *TLS, n uint32) int32 {
  7077. return int32(mbits.TrailingZeros32(n))
  7078. }
  7079. // intptr_t _wfindfirst64i32(const wchar_t *filespec, struct _wfinddata64i32_t *fileinfo);
  7080. func X_wfindfirst64i32(tls *TLS, filespec, fileinfo uintptr) (r types.Intptr_t) {
  7081. r0, _, err := procWfindfirst64i32.Call(filespec, fileinfo)
  7082. if err != windows.NOERROR {
  7083. tls.setErrno(int32(err.(windows.Errno)))
  7084. }
  7085. return types.Intptr_t(r0)
  7086. }
  7087. // int _wfindnext64i32(intptr_t handle, struct _wfinddata64i32_t *fileinfo);
  7088. func X_wfindnext64i32(tls *TLS, handle types.Intptr_t, fileinfo uintptr) (r int32) {
  7089. r0, _, err := procWfindnext64i32.Call(uintptr(handle), fileinfo)
  7090. if err != windows.NOERROR {
  7091. tls.setErrno(int32(err.(windows.Errno)))
  7092. }
  7093. return int32(r0)
  7094. }
  7095. // int _wchmod( const wchar_t *filename, int pmode );
  7096. func X_wchmod(tls *TLS, filename uintptr, pmode int32) (r int32) {
  7097. r0, _, err := procWchmod.Call(filename, uintptr(pmode))
  7098. if err != windows.NOERROR {
  7099. tls.setErrno(int32(err.(windows.Errno)))
  7100. }
  7101. return int32(r0)
  7102. }
  7103. // int _wmkdir(const wchar_t *dirname);
  7104. func X_wmkdir(tls *TLS, dirname uintptr) (r int32) {
  7105. r0, _, err := procWmkdir.Call(dirname)
  7106. if err != windows.NOERROR {
  7107. tls.setErrno(int32(err.(windows.Errno)))
  7108. }
  7109. return int32(r0)
  7110. }
  7111. // int _wstat64i32(const wchar_t *path, struct _stat64i32 *buffer);
  7112. func X_wstat64i32(tls *TLS, path, buffer uintptr) (r int32) {
  7113. r0, _, err := procWstat64i32.Call(path, buffer)
  7114. if err != windows.NOERROR {
  7115. tls.setErrno(int32(err.(windows.Errno)))
  7116. }
  7117. return int32(r0)
  7118. }
  7119. // intptr_t _wfindfirst32(const wchar_t *filespec, struct _wfinddata32_t *fileinfo);
  7120. func X_wfindfirst32(tls *TLS, filespec, fileinfo uintptr) (r types.Intptr_t) {
  7121. r0, _, err := procWfindfirst32.Call(filespec, fileinfo)
  7122. if err != windows.NOERROR {
  7123. tls.setErrno(int32(err.(windows.Errno)))
  7124. }
  7125. return types.Intptr_t(r0)
  7126. }
  7127. // int _wfindnext32(intptr_t handle, struct _wfinddata32_t *fileinfo);
  7128. func X_wfindnext32(tls *TLS, handle types.Intptr_t, fileinfo uintptr) (r int32) {
  7129. r0, _, err := procWfindnext32.Call(uintptr(handle), fileinfo)
  7130. if err != windows.NOERROR {
  7131. tls.setErrno(int32(err.(windows.Errno)))
  7132. }
  7133. return int32(r0)
  7134. }
  7135. // int _wstat32(const wchar_t *path, struct __stat32 *buffer);
  7136. func X_wstat32(tls *TLS, path, buffer uintptr) (r int32) {
  7137. r0, _, err := procWstat32.Call(path, buffer)
  7138. if err != windows.NOERROR {
  7139. tls.setErrno(int32(err.(windows.Errno)))
  7140. }
  7141. return int32(r0)
  7142. }