2
0

strace.c 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193
  1. #include "qemu/osdep.h"
  2. #include <sys/ipc.h>
  3. #include <sys/msg.h>
  4. #include <sys/sem.h>
  5. #include <sys/shm.h>
  6. #include <sys/select.h>
  7. #include <sys/mount.h>
  8. #include <arpa/inet.h>
  9. #include <netinet/in.h>
  10. #include <netinet/tcp.h>
  11. #include <netinet/udp.h>
  12. #include <linux/if_packet.h>
  13. #include <linux/in6.h>
  14. #include <linux/netlink.h>
  15. #include <sched.h>
  16. #include "qemu.h"
  17. #include "user-internals.h"
  18. #include "strace.h"
  19. #include "signal-common.h"
  20. #include "target_mman.h"
  21. struct syscallname {
  22. int nr;
  23. const char *name;
  24. const char *format;
  25. void (*call)(CPUArchState *, const struct syscallname *,
  26. abi_long, abi_long, abi_long,
  27. abi_long, abi_long, abi_long);
  28. void (*result)(CPUArchState *, const struct syscallname *, abi_long,
  29. abi_long, abi_long, abi_long,
  30. abi_long, abi_long, abi_long);
  31. };
  32. /*
  33. * It is possible that target doesn't have syscall that uses
  34. * following flags but we don't want the compiler to warn
  35. * us about them being unused. Same applies to utility print
  36. * functions. It is ok to keep them while not used.
  37. */
  38. #define UNUSED __attribute__ ((unused))
  39. /*
  40. * Structure used to translate flag values into strings. This is
  41. * similar that is in the actual strace tool.
  42. */
  43. struct flags {
  44. abi_long f_value; /* flag */
  45. const char *f_string; /* stringified flag */
  46. };
  47. /* common flags for all architectures */
  48. #define FLAG_GENERIC(name) { name, #name }
  49. /* target specific flags (syscall_defs.h has TARGET_<flag>) */
  50. #define FLAG_TARGET(name) { TARGET_ ## name, #name }
  51. /* end of flags array */
  52. #define FLAG_END { 0, NULL }
  53. /* Structure used to translate enumerated values into strings */
  54. struct enums {
  55. abi_long e_value; /* enum value */
  56. const char *e_string; /* stringified enum */
  57. };
  58. /* common enums for all architectures */
  59. #define ENUM_GENERIC(name) { name, #name }
  60. /* target specific enums */
  61. #define ENUM_TARGET(name) { TARGET_ ## name, #name }
  62. /* end of enums array */
  63. #define ENUM_END { 0, NULL }
  64. UNUSED static const char *get_comma(int);
  65. UNUSED static void print_pointer(abi_long, int);
  66. UNUSED static void print_flags(const struct flags *, abi_long, int);
  67. UNUSED static void print_enums(const struct enums *, abi_long, int);
  68. UNUSED static void print_at_dirfd(abi_long, int);
  69. UNUSED static void print_file_mode(abi_long, int);
  70. UNUSED static void print_open_flags(abi_long, int);
  71. UNUSED static void print_syscall_prologue(const struct syscallname *);
  72. UNUSED static void print_syscall_epilogue(const struct syscallname *);
  73. UNUSED static void print_string(abi_long, int);
  74. UNUSED static void print_buf(abi_long addr, abi_long len, int last);
  75. UNUSED static void print_raw_param(const char *, abi_long, int);
  76. UNUSED static void print_raw_param64(const char *, long long, int last);
  77. UNUSED static void print_timeval(abi_ulong, int);
  78. UNUSED static void print_timespec(abi_ulong, int);
  79. UNUSED static void print_timespec64(abi_ulong, int);
  80. UNUSED static void print_timezone(abi_ulong, int);
  81. UNUSED static void print_itimerval(abi_ulong, int);
  82. UNUSED static void print_number(abi_long, int);
  83. UNUSED static void print_signal(abi_ulong, int);
  84. UNUSED static void print_sockaddr(abi_ulong, abi_long, int);
  85. UNUSED static void print_socket_domain(int domain);
  86. UNUSED static void print_socket_type(int type);
  87. UNUSED static void print_socket_protocol(int domain, int type, int protocol);
  88. /*
  89. * Utility functions
  90. */
  91. static void
  92. print_ipc_cmd(int cmd)
  93. {
  94. #define output_cmd(val) \
  95. if( cmd == val ) { \
  96. qemu_log(#val); \
  97. return; \
  98. }
  99. cmd &= 0xff;
  100. /* General IPC commands */
  101. output_cmd( IPC_RMID );
  102. output_cmd( IPC_SET );
  103. output_cmd( IPC_STAT );
  104. output_cmd( IPC_INFO );
  105. /* msgctl() commands */
  106. output_cmd( MSG_STAT );
  107. output_cmd( MSG_INFO );
  108. /* shmctl() commands */
  109. output_cmd( SHM_LOCK );
  110. output_cmd( SHM_UNLOCK );
  111. output_cmd( SHM_STAT );
  112. output_cmd( SHM_INFO );
  113. /* semctl() commands */
  114. output_cmd( GETPID );
  115. output_cmd( GETVAL );
  116. output_cmd( GETALL );
  117. output_cmd( GETNCNT );
  118. output_cmd( GETZCNT );
  119. output_cmd( SETVAL );
  120. output_cmd( SETALL );
  121. output_cmd( SEM_STAT );
  122. output_cmd( SEM_INFO );
  123. output_cmd( IPC_RMID );
  124. output_cmd( IPC_RMID );
  125. output_cmd( IPC_RMID );
  126. output_cmd( IPC_RMID );
  127. output_cmd( IPC_RMID );
  128. output_cmd( IPC_RMID );
  129. output_cmd( IPC_RMID );
  130. output_cmd( IPC_RMID );
  131. output_cmd( IPC_RMID );
  132. /* Some value we don't recognize */
  133. qemu_log("%d", cmd);
  134. }
  135. static const char * const target_signal_name[] = {
  136. #define MAKE_SIG_ENTRY(sig) [TARGET_##sig] = #sig,
  137. MAKE_SIGNAL_LIST
  138. #undef MAKE_SIG_ENTRY
  139. };
  140. static void
  141. print_signal(abi_ulong arg, int last)
  142. {
  143. const char *signal_name = NULL;
  144. if (arg < ARRAY_SIZE(target_signal_name)) {
  145. signal_name = target_signal_name[arg];
  146. }
  147. if (signal_name == NULL) {
  148. print_raw_param("%ld", arg, last);
  149. return;
  150. }
  151. qemu_log("%s%s", signal_name, get_comma(last));
  152. }
  153. static void print_si_code(int arg)
  154. {
  155. const char *codename = NULL;
  156. switch (arg) {
  157. case SI_USER:
  158. codename = "SI_USER";
  159. break;
  160. case SI_KERNEL:
  161. codename = "SI_KERNEL";
  162. break;
  163. case SI_QUEUE:
  164. codename = "SI_QUEUE";
  165. break;
  166. case SI_TIMER:
  167. codename = "SI_TIMER";
  168. break;
  169. case SI_MESGQ:
  170. codename = "SI_MESGQ";
  171. break;
  172. case SI_ASYNCIO:
  173. codename = "SI_ASYNCIO";
  174. break;
  175. case SI_SIGIO:
  176. codename = "SI_SIGIO";
  177. break;
  178. case SI_TKILL:
  179. codename = "SI_TKILL";
  180. break;
  181. default:
  182. qemu_log("%d", arg);
  183. return;
  184. }
  185. qemu_log("%s", codename);
  186. }
  187. static void get_target_siginfo(target_siginfo_t *tinfo,
  188. const target_siginfo_t *info)
  189. {
  190. abi_ulong sival_ptr;
  191. int sig;
  192. int si_errno;
  193. int si_code;
  194. int si_type;
  195. __get_user(sig, &info->si_signo);
  196. __get_user(si_errno, &tinfo->si_errno);
  197. __get_user(si_code, &info->si_code);
  198. tinfo->si_signo = sig;
  199. tinfo->si_errno = si_errno;
  200. tinfo->si_code = si_code;
  201. /* Ensure we don't leak random junk to the guest later */
  202. memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
  203. /* This is awkward, because we have to use a combination of
  204. * the si_code and si_signo to figure out which of the union's
  205. * members are valid. (Within the host kernel it is always possible
  206. * to tell, but the kernel carefully avoids giving userspace the
  207. * high 16 bits of si_code, so we don't have the information to
  208. * do this the easy way...) We therefore make our best guess,
  209. * bearing in mind that a guest can spoof most of the si_codes
  210. * via rt_sigqueueinfo() if it likes.
  211. *
  212. * Once we have made our guess, we record it in the top 16 bits of
  213. * the si_code, so that print_siginfo() later can use it.
  214. * print_siginfo() will strip these top bits out before printing
  215. * the si_code.
  216. */
  217. switch (si_code) {
  218. case SI_USER:
  219. case SI_TKILL:
  220. case SI_KERNEL:
  221. /* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
  222. * These are the only unspoofable si_code values.
  223. */
  224. __get_user(tinfo->_sifields._kill._pid, &info->_sifields._kill._pid);
  225. __get_user(tinfo->_sifields._kill._uid, &info->_sifields._kill._uid);
  226. si_type = QEMU_SI_KILL;
  227. break;
  228. default:
  229. /* Everything else is spoofable. Make best guess based on signal */
  230. switch (sig) {
  231. case TARGET_SIGCHLD:
  232. __get_user(tinfo->_sifields._sigchld._pid,
  233. &info->_sifields._sigchld._pid);
  234. __get_user(tinfo->_sifields._sigchld._uid,
  235. &info->_sifields._sigchld._uid);
  236. __get_user(tinfo->_sifields._sigchld._status,
  237. &info->_sifields._sigchld._status);
  238. __get_user(tinfo->_sifields._sigchld._utime,
  239. &info->_sifields._sigchld._utime);
  240. __get_user(tinfo->_sifields._sigchld._stime,
  241. &info->_sifields._sigchld._stime);
  242. si_type = QEMU_SI_CHLD;
  243. break;
  244. case TARGET_SIGIO:
  245. __get_user(tinfo->_sifields._sigpoll._band,
  246. &info->_sifields._sigpoll._band);
  247. __get_user(tinfo->_sifields._sigpoll._fd,
  248. &info->_sifields._sigpoll._fd);
  249. si_type = QEMU_SI_POLL;
  250. break;
  251. default:
  252. /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
  253. __get_user(tinfo->_sifields._rt._pid, &info->_sifields._rt._pid);
  254. __get_user(tinfo->_sifields._rt._uid, &info->_sifields._rt._uid);
  255. /* XXX: potential problem if 64 bit */
  256. __get_user(sival_ptr, &info->_sifields._rt._sigval.sival_ptr);
  257. tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr;
  258. si_type = QEMU_SI_RT;
  259. break;
  260. }
  261. break;
  262. }
  263. tinfo->si_code = deposit32(si_code, 16, 16, si_type);
  264. }
  265. static void print_siginfo(const target_siginfo_t *tinfo)
  266. {
  267. /* Print a target_siginfo_t in the format desired for printing
  268. * signals being taken. We assume the target_siginfo_t is in the
  269. * internal form where the top 16 bits of si_code indicate which
  270. * part of the union is valid, rather than in the guest-visible
  271. * form where the bottom 16 bits are sign-extended into the top 16.
  272. */
  273. int si_type = extract32(tinfo->si_code, 16, 16);
  274. int si_code = sextract32(tinfo->si_code, 0, 16);
  275. qemu_log("{si_signo=");
  276. print_signal(tinfo->si_signo, 1);
  277. qemu_log(", si_code=");
  278. print_si_code(si_code);
  279. switch (si_type) {
  280. case QEMU_SI_KILL:
  281. qemu_log(", si_pid=%u, si_uid=%u",
  282. (unsigned int)tinfo->_sifields._kill._pid,
  283. (unsigned int)tinfo->_sifields._kill._uid);
  284. break;
  285. case QEMU_SI_TIMER:
  286. qemu_log(", si_timer1=%u, si_timer2=%u",
  287. tinfo->_sifields._timer._timer1,
  288. tinfo->_sifields._timer._timer2);
  289. break;
  290. case QEMU_SI_POLL:
  291. qemu_log(", si_band=%d, si_fd=%d",
  292. tinfo->_sifields._sigpoll._band,
  293. tinfo->_sifields._sigpoll._fd);
  294. break;
  295. case QEMU_SI_FAULT:
  296. qemu_log(", si_addr=");
  297. print_pointer(tinfo->_sifields._sigfault._addr, 1);
  298. break;
  299. case QEMU_SI_CHLD:
  300. qemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
  301. ", si_utime=" TARGET_ABI_FMT_ld
  302. ", si_stime=" TARGET_ABI_FMT_ld,
  303. (unsigned int)(tinfo->_sifields._sigchld._pid),
  304. (unsigned int)(tinfo->_sifields._sigchld._uid),
  305. tinfo->_sifields._sigchld._status,
  306. tinfo->_sifields._sigchld._utime,
  307. tinfo->_sifields._sigchld._stime);
  308. break;
  309. case QEMU_SI_RT:
  310. qemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
  311. (unsigned int)tinfo->_sifields._rt._pid,
  312. (unsigned int)tinfo->_sifields._rt._uid,
  313. tinfo->_sifields._rt._sigval.sival_ptr);
  314. break;
  315. default:
  316. g_assert_not_reached();
  317. }
  318. qemu_log("}");
  319. }
  320. static void
  321. print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
  322. {
  323. struct target_sockaddr *sa;
  324. int i;
  325. int sa_family;
  326. sa = lock_user(VERIFY_READ, addr, addrlen, 1);
  327. if (sa) {
  328. sa_family = tswap16(sa->sa_family);
  329. switch (sa_family) {
  330. case AF_UNIX: {
  331. struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
  332. int i;
  333. qemu_log("{sun_family=AF_UNIX,sun_path=\"");
  334. for (i = 0; i < addrlen -
  335. offsetof(struct target_sockaddr_un, sun_path) &&
  336. un->sun_path[i]; i++) {
  337. qemu_log("%c", un->sun_path[i]);
  338. }
  339. qemu_log("\"}");
  340. break;
  341. }
  342. case AF_INET: {
  343. struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
  344. uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
  345. qemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
  346. ntohs(in->sin_port));
  347. qemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
  348. c[0], c[1], c[2], c[3]);
  349. qemu_log("}");
  350. break;
  351. }
  352. case AF_PACKET: {
  353. struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
  354. uint8_t *c = (uint8_t *)&ll->sll_addr;
  355. qemu_log("{sll_family=AF_PACKET,"
  356. "sll_protocol=htons(0x%04x),if%d,pkttype=",
  357. ntohs(ll->sll_protocol), ll->sll_ifindex);
  358. switch (ll->sll_pkttype) {
  359. case PACKET_HOST:
  360. qemu_log("PACKET_HOST");
  361. break;
  362. case PACKET_BROADCAST:
  363. qemu_log("PACKET_BROADCAST");
  364. break;
  365. case PACKET_MULTICAST:
  366. qemu_log("PACKET_MULTICAST");
  367. break;
  368. case PACKET_OTHERHOST:
  369. qemu_log("PACKET_OTHERHOST");
  370. break;
  371. case PACKET_OUTGOING:
  372. qemu_log("PACKET_OUTGOING");
  373. break;
  374. default:
  375. qemu_log("%d", ll->sll_pkttype);
  376. break;
  377. }
  378. qemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
  379. c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
  380. qemu_log("}");
  381. break;
  382. }
  383. case AF_NETLINK: {
  384. struct target_sockaddr_nl *nl = (struct target_sockaddr_nl *)sa;
  385. qemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u}",
  386. tswap32(nl->nl_pid), tswap32(nl->nl_groups));
  387. break;
  388. }
  389. default:
  390. qemu_log("{sa_family=%d, sa_data={", sa->sa_family);
  391. for (i = 0; i < 13; i++) {
  392. qemu_log("%02x, ", sa->sa_data[i]);
  393. }
  394. qemu_log("%02x}", sa->sa_data[i]);
  395. qemu_log("}");
  396. break;
  397. }
  398. unlock_user(sa, addr, 0);
  399. } else {
  400. print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
  401. }
  402. qemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
  403. }
  404. static void
  405. print_socket_domain(int domain)
  406. {
  407. switch (domain) {
  408. case PF_UNIX:
  409. qemu_log("PF_UNIX");
  410. break;
  411. case PF_INET:
  412. qemu_log("PF_INET");
  413. break;
  414. case PF_NETLINK:
  415. qemu_log("PF_NETLINK");
  416. break;
  417. case PF_PACKET:
  418. qemu_log("PF_PACKET");
  419. break;
  420. default:
  421. qemu_log("%d", domain);
  422. break;
  423. }
  424. }
  425. static void
  426. print_socket_type(int type)
  427. {
  428. switch (type & TARGET_SOCK_TYPE_MASK) {
  429. case TARGET_SOCK_DGRAM:
  430. qemu_log("SOCK_DGRAM");
  431. break;
  432. case TARGET_SOCK_STREAM:
  433. qemu_log("SOCK_STREAM");
  434. break;
  435. case TARGET_SOCK_RAW:
  436. qemu_log("SOCK_RAW");
  437. break;
  438. case TARGET_SOCK_RDM:
  439. qemu_log("SOCK_RDM");
  440. break;
  441. case TARGET_SOCK_SEQPACKET:
  442. qemu_log("SOCK_SEQPACKET");
  443. break;
  444. case TARGET_SOCK_PACKET:
  445. qemu_log("SOCK_PACKET");
  446. break;
  447. }
  448. if (type & TARGET_SOCK_CLOEXEC) {
  449. qemu_log("|SOCK_CLOEXEC");
  450. }
  451. if (type & TARGET_SOCK_NONBLOCK) {
  452. qemu_log("|SOCK_NONBLOCK");
  453. }
  454. }
  455. static void
  456. print_socket_protocol(int domain, int type, int protocol)
  457. {
  458. if (domain == AF_PACKET ||
  459. (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
  460. switch (protocol) {
  461. case 0x0003:
  462. qemu_log("ETH_P_ALL");
  463. break;
  464. default:
  465. qemu_log("%d", protocol);
  466. }
  467. return;
  468. }
  469. if (domain == PF_NETLINK) {
  470. switch (protocol) {
  471. case NETLINK_ROUTE:
  472. qemu_log("NETLINK_ROUTE");
  473. break;
  474. case NETLINK_UNUSED:
  475. qemu_log("NETLINK_UNUSED");
  476. break;
  477. case NETLINK_USERSOCK:
  478. qemu_log("NETLINK_USERSOCK");
  479. break;
  480. case NETLINK_FIREWALL:
  481. qemu_log("NETLINK_FIREWALL");
  482. break;
  483. case NETLINK_SOCK_DIAG:
  484. qemu_log("NETLINK_SOCK_DIAG");
  485. break;
  486. case NETLINK_NFLOG:
  487. qemu_log("NETLINK_NFLOG");
  488. break;
  489. case NETLINK_XFRM:
  490. qemu_log("NETLINK_XFRM");
  491. break;
  492. case NETLINK_SELINUX:
  493. qemu_log("NETLINK_SELINUX");
  494. break;
  495. case NETLINK_ISCSI:
  496. qemu_log("NETLINK_ISCSI");
  497. break;
  498. case NETLINK_AUDIT:
  499. qemu_log("NETLINK_AUDIT");
  500. break;
  501. case NETLINK_FIB_LOOKUP:
  502. qemu_log("NETLINK_FIB_LOOKUP");
  503. break;
  504. case NETLINK_CONNECTOR:
  505. qemu_log("NETLINK_CONNECTOR");
  506. break;
  507. case NETLINK_NETFILTER:
  508. qemu_log("NETLINK_NETFILTER");
  509. break;
  510. case NETLINK_IP6_FW:
  511. qemu_log("NETLINK_IP6_FW");
  512. break;
  513. case NETLINK_DNRTMSG:
  514. qemu_log("NETLINK_DNRTMSG");
  515. break;
  516. case NETLINK_KOBJECT_UEVENT:
  517. qemu_log("NETLINK_KOBJECT_UEVENT");
  518. break;
  519. case NETLINK_GENERIC:
  520. qemu_log("NETLINK_GENERIC");
  521. break;
  522. case NETLINK_SCSITRANSPORT:
  523. qemu_log("NETLINK_SCSITRANSPORT");
  524. break;
  525. case NETLINK_ECRYPTFS:
  526. qemu_log("NETLINK_ECRYPTFS");
  527. break;
  528. case NETLINK_RDMA:
  529. qemu_log("NETLINK_RDMA");
  530. break;
  531. case NETLINK_CRYPTO:
  532. qemu_log("NETLINK_CRYPTO");
  533. break;
  534. case NETLINK_SMC:
  535. qemu_log("NETLINK_SMC");
  536. break;
  537. default:
  538. qemu_log("%d", protocol);
  539. break;
  540. }
  541. return;
  542. }
  543. switch (protocol) {
  544. case IPPROTO_IP:
  545. qemu_log("IPPROTO_IP");
  546. break;
  547. case IPPROTO_TCP:
  548. qemu_log("IPPROTO_TCP");
  549. break;
  550. case IPPROTO_UDP:
  551. qemu_log("IPPROTO_UDP");
  552. break;
  553. case IPPROTO_RAW:
  554. qemu_log("IPPROTO_RAW");
  555. break;
  556. default:
  557. qemu_log("%d", protocol);
  558. break;
  559. }
  560. }
  561. #ifdef TARGET_NR__newselect
  562. static void
  563. print_fdset(int n, abi_ulong target_fds_addr)
  564. {
  565. int i;
  566. int first = 1;
  567. qemu_log("[");
  568. if( target_fds_addr ) {
  569. abi_long *target_fds;
  570. target_fds = lock_user(VERIFY_READ,
  571. target_fds_addr,
  572. sizeof(*target_fds)*(n / TARGET_ABI_BITS + 1),
  573. 1);
  574. if (!target_fds)
  575. return;
  576. for (i=n; i>=0; i--) {
  577. if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >>
  578. (i & (TARGET_ABI_BITS - 1))) & 1) {
  579. qemu_log("%s%d", get_comma(first), i);
  580. first = 0;
  581. }
  582. }
  583. unlock_user(target_fds, target_fds_addr, 0);
  584. }
  585. qemu_log("]");
  586. }
  587. #endif
  588. /*
  589. * Sysycall specific output functions
  590. */
  591. /* select */
  592. #ifdef TARGET_NR__newselect
  593. static void
  594. print_newselect(CPUArchState *cpu_env, const struct syscallname *name,
  595. abi_long arg1, abi_long arg2, abi_long arg3,
  596. abi_long arg4, abi_long arg5, abi_long arg6)
  597. {
  598. print_syscall_prologue(name);
  599. print_fdset(arg1, arg2);
  600. qemu_log(",");
  601. print_fdset(arg1, arg3);
  602. qemu_log(",");
  603. print_fdset(arg1, arg4);
  604. qemu_log(",");
  605. print_timeval(arg5, 1);
  606. print_syscall_epilogue(name);
  607. }
  608. #endif
  609. #ifdef TARGET_NR_semctl
  610. static void
  611. print_semctl(CPUArchState *cpu_env, const struct syscallname *name,
  612. abi_long arg1, abi_long arg2, abi_long arg3,
  613. abi_long arg4, abi_long arg5, abi_long arg6)
  614. {
  615. qemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
  616. name->name, arg1, arg2);
  617. print_ipc_cmd(arg3);
  618. qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
  619. }
  620. #endif
  621. #ifdef TARGET_NR_ipc
  622. static void
  623. print_ipc(CPUArchState *cpu_env, const struct syscallname *name,
  624. abi_long arg1, abi_long arg2, abi_long arg3,
  625. abi_long arg4, abi_long arg5, abi_long arg6)
  626. {
  627. switch(arg1) {
  628. case IPCOP_semctl:
  629. qemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
  630. arg1, arg2);
  631. print_ipc_cmd(arg3);
  632. qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
  633. break;
  634. default:
  635. qemu_log(("%s("
  636. TARGET_ABI_FMT_ld ","
  637. TARGET_ABI_FMT_ld ","
  638. TARGET_ABI_FMT_ld ","
  639. TARGET_ABI_FMT_ld
  640. ")"),
  641. name->name, arg1, arg2, arg3, arg4);
  642. }
  643. }
  644. #endif
  645. /*
  646. * Variants for the return value output function
  647. */
  648. static bool
  649. print_syscall_err(abi_long ret)
  650. {
  651. const char *errstr;
  652. qemu_log(" = ");
  653. if (is_error(ret)) {
  654. errstr = target_strerror(-ret);
  655. if (errstr) {
  656. qemu_log("-1 errno=%d (%s)", (int)-ret, errstr);
  657. return true;
  658. }
  659. }
  660. return false;
  661. }
  662. static void
  663. print_syscall_ret_addr(CPUArchState *cpu_env, const struct syscallname *name,
  664. abi_long ret, abi_long arg0, abi_long arg1,
  665. abi_long arg2, abi_long arg3, abi_long arg4,
  666. abi_long arg5)
  667. {
  668. if (!print_syscall_err(ret)) {
  669. qemu_log("0x" TARGET_ABI_FMT_lx, ret);
  670. }
  671. qemu_log("\n");
  672. }
  673. #if 0 /* currently unused */
  674. static void
  675. print_syscall_ret_raw(struct syscallname *name, abi_long ret)
  676. {
  677. qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
  678. }
  679. #endif
  680. #ifdef TARGET_NR__newselect
  681. static void
  682. print_syscall_ret_newselect(CPUArchState *cpu_env, const struct syscallname *name,
  683. abi_long ret, abi_long arg0, abi_long arg1,
  684. abi_long arg2, abi_long arg3, abi_long arg4,
  685. abi_long arg5)
  686. {
  687. if (!print_syscall_err(ret)) {
  688. qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
  689. print_fdset(arg0, arg1);
  690. qemu_log(",");
  691. print_fdset(arg0, arg2);
  692. qemu_log(",");
  693. print_fdset(arg0, arg3);
  694. qemu_log(",");
  695. print_timeval(arg4, 1);
  696. qemu_log(")");
  697. }
  698. qemu_log("\n");
  699. }
  700. #endif
  701. /* special meanings of adjtimex()' non-negative return values */
  702. #define TARGET_TIME_OK 0 /* clock synchronized, no leap second */
  703. #define TARGET_TIME_INS 1 /* insert leap second */
  704. #define TARGET_TIME_DEL 2 /* delete leap second */
  705. #define TARGET_TIME_OOP 3 /* leap second in progress */
  706. #define TARGET_TIME_WAIT 4 /* leap second has occurred */
  707. #define TARGET_TIME_ERROR 5 /* clock not synchronized */
  708. #ifdef TARGET_NR_adjtimex
  709. static void
  710. print_syscall_ret_adjtimex(CPUArchState *cpu_env, const struct syscallname *name,
  711. abi_long ret, abi_long arg0, abi_long arg1,
  712. abi_long arg2, abi_long arg3, abi_long arg4,
  713. abi_long arg5)
  714. {
  715. if (!print_syscall_err(ret)) {
  716. qemu_log(TARGET_ABI_FMT_ld, ret);
  717. switch (ret) {
  718. case TARGET_TIME_OK:
  719. qemu_log(" TIME_OK (clock synchronized, no leap second)");
  720. break;
  721. case TARGET_TIME_INS:
  722. qemu_log(" TIME_INS (insert leap second)");
  723. break;
  724. case TARGET_TIME_DEL:
  725. qemu_log(" TIME_DEL (delete leap second)");
  726. break;
  727. case TARGET_TIME_OOP:
  728. qemu_log(" TIME_OOP (leap second in progress)");
  729. break;
  730. case TARGET_TIME_WAIT:
  731. qemu_log(" TIME_WAIT (leap second has occurred)");
  732. break;
  733. case TARGET_TIME_ERROR:
  734. qemu_log(" TIME_ERROR (clock not synchronized)");
  735. break;
  736. }
  737. }
  738. qemu_log("\n");
  739. }
  740. #endif
  741. #if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
  742. static void
  743. print_syscall_ret_clock_gettime(CPUArchState *cpu_env, const struct syscallname *name,
  744. abi_long ret, abi_long arg0, abi_long arg1,
  745. abi_long arg2, abi_long arg3, abi_long arg4,
  746. abi_long arg5)
  747. {
  748. if (!print_syscall_err(ret)) {
  749. qemu_log(TARGET_ABI_FMT_ld, ret);
  750. qemu_log(" (");
  751. print_timespec(arg1, 1);
  752. qemu_log(")");
  753. }
  754. qemu_log("\n");
  755. }
  756. #define print_syscall_ret_clock_getres print_syscall_ret_clock_gettime
  757. #endif
  758. #if defined(TARGET_NR_clock_gettime64)
  759. static void
  760. print_syscall_ret_clock_gettime64(CPUArchState *cpu_env, const struct syscallname *name,
  761. abi_long ret, abi_long arg0, abi_long arg1,
  762. abi_long arg2, abi_long arg3, abi_long arg4,
  763. abi_long arg5)
  764. {
  765. if (!print_syscall_err(ret)) {
  766. qemu_log(TARGET_ABI_FMT_ld, ret);
  767. qemu_log(" (");
  768. print_timespec64(arg1, 1);
  769. qemu_log(")");
  770. }
  771. qemu_log("\n");
  772. }
  773. #endif
  774. #ifdef TARGET_NR_gettimeofday
  775. static void
  776. print_syscall_ret_gettimeofday(CPUArchState *cpu_env, const struct syscallname *name,
  777. abi_long ret, abi_long arg0, abi_long arg1,
  778. abi_long arg2, abi_long arg3, abi_long arg4,
  779. abi_long arg5)
  780. {
  781. if (!print_syscall_err(ret)) {
  782. qemu_log(TARGET_ABI_FMT_ld, ret);
  783. qemu_log(" (");
  784. print_timeval(arg0, 0);
  785. print_timezone(arg1, 1);
  786. qemu_log(")");
  787. }
  788. qemu_log("\n");
  789. }
  790. #endif
  791. #ifdef TARGET_NR_getitimer
  792. static void
  793. print_syscall_ret_getitimer(CPUArchState *cpu_env, const struct syscallname *name,
  794. abi_long ret, abi_long arg0, abi_long arg1,
  795. abi_long arg2, abi_long arg3, abi_long arg4,
  796. abi_long arg5)
  797. {
  798. if (!print_syscall_err(ret)) {
  799. qemu_log(TARGET_ABI_FMT_ld, ret);
  800. qemu_log(" (");
  801. print_itimerval(arg1, 1);
  802. qemu_log(")");
  803. }
  804. qemu_log("\n");
  805. }
  806. #endif
  807. #ifdef TARGET_NR_getitimer
  808. static void
  809. print_syscall_ret_setitimer(CPUArchState *cpu_env, const struct syscallname *name,
  810. abi_long ret, abi_long arg0, abi_long arg1,
  811. abi_long arg2, abi_long arg3, abi_long arg4,
  812. abi_long arg5)
  813. {
  814. if (!print_syscall_err(ret)) {
  815. qemu_log(TARGET_ABI_FMT_ld, ret);
  816. qemu_log(" (old_value = ");
  817. print_itimerval(arg2, 1);
  818. qemu_log(")");
  819. }
  820. qemu_log("\n");
  821. }
  822. #endif
  823. #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr) \
  824. || defined(TARGGET_NR_flistxattr)
  825. static void
  826. print_syscall_ret_listxattr(CPUArchState *cpu_env, const struct syscallname *name,
  827. abi_long ret, abi_long arg0, abi_long arg1,
  828. abi_long arg2, abi_long arg3, abi_long arg4,
  829. abi_long arg5)
  830. {
  831. if (!print_syscall_err(ret)) {
  832. qemu_log(TARGET_ABI_FMT_ld, ret);
  833. qemu_log(" (list = ");
  834. if (arg1 != 0) {
  835. abi_long attr = arg1;
  836. while (ret) {
  837. if (attr != arg1) {
  838. qemu_log(",");
  839. }
  840. print_string(attr, 1);
  841. ret -= target_strlen(attr) + 1;
  842. attr += target_strlen(attr) + 1;
  843. }
  844. } else {
  845. qemu_log("NULL");
  846. }
  847. qemu_log(")");
  848. }
  849. qemu_log("\n");
  850. }
  851. #define print_syscall_ret_llistxattr print_syscall_ret_listxattr
  852. #define print_syscall_ret_flistxattr print_syscall_ret_listxattr
  853. #endif
  854. #ifdef TARGET_NR_ioctl
  855. static void
  856. print_syscall_ret_ioctl(CPUArchState *cpu_env, const struct syscallname *name,
  857. abi_long ret, abi_long arg0, abi_long arg1,
  858. abi_long arg2, abi_long arg3, abi_long arg4,
  859. abi_long arg5)
  860. {
  861. if (!print_syscall_err(ret)) {
  862. qemu_log(TARGET_ABI_FMT_ld, ret);
  863. const IOCTLEntry *ie;
  864. const argtype *arg_type;
  865. void *argptr;
  866. int target_size;
  867. for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
  868. if (ie->target_cmd == arg1) {
  869. break;
  870. }
  871. }
  872. if (ie->target_cmd == arg1 &&
  873. (ie->access == IOC_R || ie->access == IOC_RW)) {
  874. arg_type = ie->arg_type;
  875. qemu_log(" (");
  876. arg_type++;
  877. target_size = thunk_type_size(arg_type, 0);
  878. argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
  879. if (argptr) {
  880. thunk_print(argptr, arg_type);
  881. unlock_user(argptr, arg2, target_size);
  882. } else {
  883. print_pointer(arg2, 1);
  884. }
  885. qemu_log(")");
  886. }
  887. }
  888. qemu_log("\n");
  889. }
  890. #endif
  891. UNUSED static const struct flags access_flags[] = {
  892. FLAG_GENERIC(F_OK),
  893. FLAG_GENERIC(R_OK),
  894. FLAG_GENERIC(W_OK),
  895. FLAG_GENERIC(X_OK),
  896. FLAG_END,
  897. };
  898. UNUSED static const struct flags at_file_flags[] = {
  899. #ifdef AT_EACCESS
  900. FLAG_GENERIC(AT_EACCESS),
  901. #endif
  902. #ifdef AT_SYMLINK_NOFOLLOW
  903. FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
  904. #endif
  905. FLAG_END,
  906. };
  907. UNUSED static const struct flags unlinkat_flags[] = {
  908. #ifdef AT_REMOVEDIR
  909. FLAG_GENERIC(AT_REMOVEDIR),
  910. #endif
  911. FLAG_END,
  912. };
  913. UNUSED static const struct flags mode_flags[] = {
  914. FLAG_GENERIC(S_IFSOCK),
  915. FLAG_GENERIC(S_IFLNK),
  916. FLAG_GENERIC(S_IFREG),
  917. FLAG_GENERIC(S_IFBLK),
  918. FLAG_GENERIC(S_IFDIR),
  919. FLAG_GENERIC(S_IFCHR),
  920. FLAG_GENERIC(S_IFIFO),
  921. FLAG_END,
  922. };
  923. UNUSED static const struct flags open_access_flags[] = {
  924. FLAG_TARGET(O_RDONLY),
  925. FLAG_TARGET(O_WRONLY),
  926. FLAG_TARGET(O_RDWR),
  927. FLAG_END,
  928. };
  929. UNUSED static const struct flags open_flags[] = {
  930. FLAG_TARGET(O_APPEND),
  931. FLAG_TARGET(O_CREAT),
  932. FLAG_TARGET(O_DIRECTORY),
  933. FLAG_TARGET(O_EXCL),
  934. FLAG_TARGET(O_LARGEFILE),
  935. FLAG_TARGET(O_NOCTTY),
  936. FLAG_TARGET(O_NOFOLLOW),
  937. FLAG_TARGET(O_NONBLOCK), /* also O_NDELAY */
  938. FLAG_TARGET(O_DSYNC),
  939. FLAG_TARGET(__O_SYNC),
  940. FLAG_TARGET(O_TRUNC),
  941. #ifdef O_DIRECT
  942. FLAG_TARGET(O_DIRECT),
  943. #endif
  944. #ifdef O_NOATIME
  945. FLAG_TARGET(O_NOATIME),
  946. #endif
  947. #ifdef O_CLOEXEC
  948. FLAG_TARGET(O_CLOEXEC),
  949. #endif
  950. #ifdef O_PATH
  951. FLAG_TARGET(O_PATH),
  952. #endif
  953. #ifdef O_TMPFILE
  954. FLAG_TARGET(O_TMPFILE),
  955. FLAG_TARGET(__O_TMPFILE),
  956. #endif
  957. FLAG_END,
  958. };
  959. UNUSED static const struct flags mount_flags[] = {
  960. #ifdef MS_BIND
  961. FLAG_GENERIC(MS_BIND),
  962. #endif
  963. #ifdef MS_DIRSYNC
  964. FLAG_GENERIC(MS_DIRSYNC),
  965. #endif
  966. FLAG_GENERIC(MS_MANDLOCK),
  967. #ifdef MS_MOVE
  968. FLAG_GENERIC(MS_MOVE),
  969. #endif
  970. FLAG_GENERIC(MS_NOATIME),
  971. FLAG_GENERIC(MS_NODEV),
  972. FLAG_GENERIC(MS_NODIRATIME),
  973. FLAG_GENERIC(MS_NOEXEC),
  974. FLAG_GENERIC(MS_NOSUID),
  975. FLAG_GENERIC(MS_RDONLY),
  976. #ifdef MS_RELATIME
  977. FLAG_GENERIC(MS_RELATIME),
  978. #endif
  979. FLAG_GENERIC(MS_REMOUNT),
  980. FLAG_GENERIC(MS_SYNCHRONOUS),
  981. FLAG_END,
  982. };
  983. UNUSED static const struct flags umount2_flags[] = {
  984. #ifdef MNT_FORCE
  985. FLAG_GENERIC(MNT_FORCE),
  986. #endif
  987. #ifdef MNT_DETACH
  988. FLAG_GENERIC(MNT_DETACH),
  989. #endif
  990. #ifdef MNT_EXPIRE
  991. FLAG_GENERIC(MNT_EXPIRE),
  992. #endif
  993. FLAG_END,
  994. };
  995. UNUSED static const struct flags mmap_prot_flags[] = {
  996. FLAG_GENERIC(PROT_NONE),
  997. FLAG_GENERIC(PROT_EXEC),
  998. FLAG_GENERIC(PROT_READ),
  999. FLAG_GENERIC(PROT_WRITE),
  1000. FLAG_TARGET(PROT_SEM),
  1001. FLAG_GENERIC(PROT_GROWSDOWN),
  1002. FLAG_GENERIC(PROT_GROWSUP),
  1003. FLAG_END,
  1004. };
  1005. UNUSED static const struct flags mmap_flags[] = {
  1006. FLAG_TARGET(MAP_SHARED),
  1007. FLAG_TARGET(MAP_PRIVATE),
  1008. FLAG_TARGET(MAP_ANONYMOUS),
  1009. FLAG_TARGET(MAP_DENYWRITE),
  1010. FLAG_TARGET(MAP_FIXED),
  1011. FLAG_TARGET(MAP_GROWSDOWN),
  1012. FLAG_TARGET(MAP_EXECUTABLE),
  1013. #ifdef MAP_LOCKED
  1014. FLAG_TARGET(MAP_LOCKED),
  1015. #endif
  1016. #ifdef MAP_NONBLOCK
  1017. FLAG_TARGET(MAP_NONBLOCK),
  1018. #endif
  1019. FLAG_TARGET(MAP_NORESERVE),
  1020. #ifdef MAP_POPULATE
  1021. FLAG_TARGET(MAP_POPULATE),
  1022. #endif
  1023. #ifdef TARGET_MAP_UNINITIALIZED
  1024. FLAG_TARGET(MAP_UNINITIALIZED),
  1025. #endif
  1026. FLAG_TARGET(MAP_HUGETLB),
  1027. FLAG_TARGET(MAP_STACK),
  1028. FLAG_END,
  1029. };
  1030. #ifndef CLONE_PIDFD
  1031. # define CLONE_PIDFD 0x00001000
  1032. #endif
  1033. UNUSED static const struct flags clone_flags[] = {
  1034. FLAG_GENERIC(CLONE_VM),
  1035. FLAG_GENERIC(CLONE_FS),
  1036. FLAG_GENERIC(CLONE_FILES),
  1037. FLAG_GENERIC(CLONE_SIGHAND),
  1038. FLAG_GENERIC(CLONE_PIDFD),
  1039. FLAG_GENERIC(CLONE_PTRACE),
  1040. FLAG_GENERIC(CLONE_VFORK),
  1041. FLAG_GENERIC(CLONE_PARENT),
  1042. FLAG_GENERIC(CLONE_THREAD),
  1043. FLAG_GENERIC(CLONE_NEWNS),
  1044. FLAG_GENERIC(CLONE_SYSVSEM),
  1045. FLAG_GENERIC(CLONE_SETTLS),
  1046. FLAG_GENERIC(CLONE_PARENT_SETTID),
  1047. FLAG_GENERIC(CLONE_CHILD_CLEARTID),
  1048. FLAG_GENERIC(CLONE_DETACHED),
  1049. FLAG_GENERIC(CLONE_UNTRACED),
  1050. FLAG_GENERIC(CLONE_CHILD_SETTID),
  1051. #if defined(CLONE_NEWUTS)
  1052. FLAG_GENERIC(CLONE_NEWUTS),
  1053. #endif
  1054. #if defined(CLONE_NEWIPC)
  1055. FLAG_GENERIC(CLONE_NEWIPC),
  1056. #endif
  1057. #if defined(CLONE_NEWUSER)
  1058. FLAG_GENERIC(CLONE_NEWUSER),
  1059. #endif
  1060. #if defined(CLONE_NEWPID)
  1061. FLAG_GENERIC(CLONE_NEWPID),
  1062. #endif
  1063. #if defined(CLONE_NEWNET)
  1064. FLAG_GENERIC(CLONE_NEWNET),
  1065. #endif
  1066. #if defined(CLONE_NEWCGROUP)
  1067. FLAG_GENERIC(CLONE_NEWCGROUP),
  1068. #endif
  1069. #if defined(CLONE_NEWTIME)
  1070. FLAG_GENERIC(CLONE_NEWTIME),
  1071. #endif
  1072. #if defined(CLONE_IO)
  1073. FLAG_GENERIC(CLONE_IO),
  1074. #endif
  1075. FLAG_END,
  1076. };
  1077. UNUSED static const struct flags execveat_flags[] = {
  1078. #ifdef AT_EMPTY_PATH
  1079. FLAG_GENERIC(AT_EMPTY_PATH),
  1080. #endif
  1081. #ifdef AT_SYMLINK_NOFOLLOW
  1082. FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
  1083. #endif
  1084. FLAG_END,
  1085. };
  1086. UNUSED static const struct flags msg_flags[] = {
  1087. /* send */
  1088. FLAG_GENERIC(MSG_CONFIRM),
  1089. FLAG_GENERIC(MSG_DONTROUTE),
  1090. FLAG_GENERIC(MSG_DONTWAIT),
  1091. FLAG_GENERIC(MSG_EOR),
  1092. FLAG_GENERIC(MSG_MORE),
  1093. FLAG_GENERIC(MSG_NOSIGNAL),
  1094. FLAG_GENERIC(MSG_OOB),
  1095. /* recv */
  1096. FLAG_GENERIC(MSG_CMSG_CLOEXEC),
  1097. FLAG_GENERIC(MSG_ERRQUEUE),
  1098. FLAG_GENERIC(MSG_PEEK),
  1099. FLAG_GENERIC(MSG_TRUNC),
  1100. FLAG_GENERIC(MSG_WAITALL),
  1101. /* recvmsg */
  1102. FLAG_GENERIC(MSG_CTRUNC),
  1103. FLAG_END,
  1104. };
  1105. UNUSED static const struct flags statx_flags[] = {
  1106. #ifdef AT_EMPTY_PATH
  1107. FLAG_GENERIC(AT_EMPTY_PATH),
  1108. #endif
  1109. #ifdef AT_NO_AUTOMOUNT
  1110. FLAG_GENERIC(AT_NO_AUTOMOUNT),
  1111. #endif
  1112. #ifdef AT_SYMLINK_NOFOLLOW
  1113. FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
  1114. #endif
  1115. #ifdef AT_STATX_SYNC_AS_STAT
  1116. FLAG_GENERIC(AT_STATX_SYNC_AS_STAT),
  1117. #endif
  1118. #ifdef AT_STATX_FORCE_SYNC
  1119. FLAG_GENERIC(AT_STATX_FORCE_SYNC),
  1120. #endif
  1121. #ifdef AT_STATX_DONT_SYNC
  1122. FLAG_GENERIC(AT_STATX_DONT_SYNC),
  1123. #endif
  1124. FLAG_END,
  1125. };
  1126. UNUSED static const struct flags statx_mask[] = {
  1127. /* This must come first, because it includes everything. */
  1128. #ifdef STATX_ALL
  1129. FLAG_GENERIC(STATX_ALL),
  1130. #endif
  1131. /* This must come second; it includes everything except STATX_BTIME. */
  1132. #ifdef STATX_BASIC_STATS
  1133. FLAG_GENERIC(STATX_BASIC_STATS),
  1134. #endif
  1135. #ifdef STATX_TYPE
  1136. FLAG_GENERIC(STATX_TYPE),
  1137. #endif
  1138. #ifdef STATX_MODE
  1139. FLAG_GENERIC(STATX_MODE),
  1140. #endif
  1141. #ifdef STATX_NLINK
  1142. FLAG_GENERIC(STATX_NLINK),
  1143. #endif
  1144. #ifdef STATX_UID
  1145. FLAG_GENERIC(STATX_UID),
  1146. #endif
  1147. #ifdef STATX_GID
  1148. FLAG_GENERIC(STATX_GID),
  1149. #endif
  1150. #ifdef STATX_ATIME
  1151. FLAG_GENERIC(STATX_ATIME),
  1152. #endif
  1153. #ifdef STATX_MTIME
  1154. FLAG_GENERIC(STATX_MTIME),
  1155. #endif
  1156. #ifdef STATX_CTIME
  1157. FLAG_GENERIC(STATX_CTIME),
  1158. #endif
  1159. #ifdef STATX_INO
  1160. FLAG_GENERIC(STATX_INO),
  1161. #endif
  1162. #ifdef STATX_SIZE
  1163. FLAG_GENERIC(STATX_SIZE),
  1164. #endif
  1165. #ifdef STATX_BLOCKS
  1166. FLAG_GENERIC(STATX_BLOCKS),
  1167. #endif
  1168. #ifdef STATX_BTIME
  1169. FLAG_GENERIC(STATX_BTIME),
  1170. #endif
  1171. FLAG_END,
  1172. };
  1173. UNUSED static const struct flags falloc_flags[] = {
  1174. FLAG_GENERIC(FALLOC_FL_KEEP_SIZE),
  1175. FLAG_GENERIC(FALLOC_FL_PUNCH_HOLE),
  1176. #ifdef FALLOC_FL_NO_HIDE_STALE
  1177. FLAG_GENERIC(FALLOC_FL_NO_HIDE_STALE),
  1178. #endif
  1179. #ifdef FALLOC_FL_COLLAPSE_RANGE
  1180. FLAG_GENERIC(FALLOC_FL_COLLAPSE_RANGE),
  1181. #endif
  1182. #ifdef FALLOC_FL_ZERO_RANGE
  1183. FLAG_GENERIC(FALLOC_FL_ZERO_RANGE),
  1184. #endif
  1185. #ifdef FALLOC_FL_INSERT_RANGE
  1186. FLAG_GENERIC(FALLOC_FL_INSERT_RANGE),
  1187. #endif
  1188. #ifdef FALLOC_FL_UNSHARE_RANGE
  1189. FLAG_GENERIC(FALLOC_FL_UNSHARE_RANGE),
  1190. #endif
  1191. };
  1192. UNUSED static const struct flags termios_iflags[] = {
  1193. FLAG_TARGET(IGNBRK),
  1194. FLAG_TARGET(BRKINT),
  1195. FLAG_TARGET(IGNPAR),
  1196. FLAG_TARGET(PARMRK),
  1197. FLAG_TARGET(INPCK),
  1198. FLAG_TARGET(ISTRIP),
  1199. FLAG_TARGET(INLCR),
  1200. FLAG_TARGET(IGNCR),
  1201. FLAG_TARGET(ICRNL),
  1202. FLAG_TARGET(IUCLC),
  1203. FLAG_TARGET(IXON),
  1204. FLAG_TARGET(IXANY),
  1205. FLAG_TARGET(IXOFF),
  1206. FLAG_TARGET(IMAXBEL),
  1207. FLAG_TARGET(IUTF8),
  1208. FLAG_END,
  1209. };
  1210. UNUSED static const struct flags termios_oflags[] = {
  1211. FLAG_TARGET(OPOST),
  1212. FLAG_TARGET(OLCUC),
  1213. FLAG_TARGET(ONLCR),
  1214. FLAG_TARGET(OCRNL),
  1215. FLAG_TARGET(ONOCR),
  1216. FLAG_TARGET(ONLRET),
  1217. FLAG_TARGET(OFILL),
  1218. FLAG_TARGET(OFDEL),
  1219. FLAG_END,
  1220. };
  1221. UNUSED static struct enums termios_oflags_NLDLY[] = {
  1222. ENUM_TARGET(NL0),
  1223. ENUM_TARGET(NL1),
  1224. ENUM_END,
  1225. };
  1226. UNUSED static struct enums termios_oflags_CRDLY[] = {
  1227. ENUM_TARGET(CR0),
  1228. ENUM_TARGET(CR1),
  1229. ENUM_TARGET(CR2),
  1230. ENUM_TARGET(CR3),
  1231. ENUM_END,
  1232. };
  1233. UNUSED static struct enums termios_oflags_TABDLY[] = {
  1234. ENUM_TARGET(TAB0),
  1235. ENUM_TARGET(TAB1),
  1236. ENUM_TARGET(TAB2),
  1237. ENUM_TARGET(TAB3),
  1238. ENUM_END,
  1239. };
  1240. UNUSED static struct enums termios_oflags_VTDLY[] = {
  1241. ENUM_TARGET(VT0),
  1242. ENUM_TARGET(VT1),
  1243. ENUM_END,
  1244. };
  1245. UNUSED static struct enums termios_oflags_FFDLY[] = {
  1246. ENUM_TARGET(FF0),
  1247. ENUM_TARGET(FF1),
  1248. ENUM_END,
  1249. };
  1250. UNUSED static struct enums termios_oflags_BSDLY[] = {
  1251. ENUM_TARGET(BS0),
  1252. ENUM_TARGET(BS1),
  1253. ENUM_END,
  1254. };
  1255. UNUSED static struct enums termios_cflags_CBAUD[] = {
  1256. ENUM_TARGET(B0),
  1257. ENUM_TARGET(B50),
  1258. ENUM_TARGET(B75),
  1259. ENUM_TARGET(B110),
  1260. ENUM_TARGET(B134),
  1261. ENUM_TARGET(B150),
  1262. ENUM_TARGET(B200),
  1263. ENUM_TARGET(B300),
  1264. ENUM_TARGET(B600),
  1265. ENUM_TARGET(B1200),
  1266. ENUM_TARGET(B1800),
  1267. ENUM_TARGET(B2400),
  1268. ENUM_TARGET(B4800),
  1269. ENUM_TARGET(B9600),
  1270. ENUM_TARGET(B19200),
  1271. ENUM_TARGET(B38400),
  1272. ENUM_TARGET(B57600),
  1273. ENUM_TARGET(B115200),
  1274. ENUM_TARGET(B230400),
  1275. ENUM_TARGET(B460800),
  1276. ENUM_END,
  1277. };
  1278. UNUSED static struct enums termios_cflags_CSIZE[] = {
  1279. ENUM_TARGET(CS5),
  1280. ENUM_TARGET(CS6),
  1281. ENUM_TARGET(CS7),
  1282. ENUM_TARGET(CS8),
  1283. ENUM_END,
  1284. };
  1285. UNUSED static const struct flags termios_cflags[] = {
  1286. FLAG_TARGET(CSTOPB),
  1287. FLAG_TARGET(CREAD),
  1288. FLAG_TARGET(PARENB),
  1289. FLAG_TARGET(PARODD),
  1290. FLAG_TARGET(HUPCL),
  1291. FLAG_TARGET(CLOCAL),
  1292. FLAG_TARGET(CRTSCTS),
  1293. FLAG_END,
  1294. };
  1295. UNUSED static const struct flags termios_lflags[] = {
  1296. FLAG_TARGET(ISIG),
  1297. FLAG_TARGET(ICANON),
  1298. FLAG_TARGET(XCASE),
  1299. FLAG_TARGET(ECHO),
  1300. FLAG_TARGET(ECHOE),
  1301. FLAG_TARGET(ECHOK),
  1302. FLAG_TARGET(ECHONL),
  1303. FLAG_TARGET(NOFLSH),
  1304. FLAG_TARGET(TOSTOP),
  1305. FLAG_TARGET(ECHOCTL),
  1306. FLAG_TARGET(ECHOPRT),
  1307. FLAG_TARGET(ECHOKE),
  1308. FLAG_TARGET(FLUSHO),
  1309. FLAG_TARGET(PENDIN),
  1310. FLAG_TARGET(IEXTEN),
  1311. FLAG_TARGET(EXTPROC),
  1312. FLAG_END,
  1313. };
  1314. #ifdef TARGET_NR_mlockall
  1315. static const struct flags mlockall_flags[] = {
  1316. FLAG_TARGET(MCL_CURRENT),
  1317. FLAG_TARGET(MCL_FUTURE),
  1318. #ifdef MCL_ONFAULT
  1319. FLAG_TARGET(MCL_ONFAULT),
  1320. #endif
  1321. FLAG_END,
  1322. };
  1323. #endif
  1324. /* IDs of the various system clocks */
  1325. #define TARGET_CLOCK_REALTIME 0
  1326. #define TARGET_CLOCK_MONOTONIC 1
  1327. #define TARGET_CLOCK_PROCESS_CPUTIME_ID 2
  1328. #define TARGET_CLOCK_THREAD_CPUTIME_ID 3
  1329. #define TARGET_CLOCK_MONOTONIC_RAW 4
  1330. #define TARGET_CLOCK_REALTIME_COARSE 5
  1331. #define TARGET_CLOCK_MONOTONIC_COARSE 6
  1332. #define TARGET_CLOCK_BOOTTIME 7
  1333. #define TARGET_CLOCK_REALTIME_ALARM 8
  1334. #define TARGET_CLOCK_BOOTTIME_ALARM 9
  1335. #define TARGET_CLOCK_SGI_CYCLE 10
  1336. #define TARGET_CLOCK_TAI 11
  1337. UNUSED static struct enums clockids[] = {
  1338. ENUM_TARGET(CLOCK_REALTIME),
  1339. ENUM_TARGET(CLOCK_MONOTONIC),
  1340. ENUM_TARGET(CLOCK_PROCESS_CPUTIME_ID),
  1341. ENUM_TARGET(CLOCK_THREAD_CPUTIME_ID),
  1342. ENUM_TARGET(CLOCK_MONOTONIC_RAW),
  1343. ENUM_TARGET(CLOCK_REALTIME_COARSE),
  1344. ENUM_TARGET(CLOCK_MONOTONIC_COARSE),
  1345. ENUM_TARGET(CLOCK_BOOTTIME),
  1346. ENUM_TARGET(CLOCK_REALTIME_ALARM),
  1347. ENUM_TARGET(CLOCK_BOOTTIME_ALARM),
  1348. ENUM_TARGET(CLOCK_SGI_CYCLE),
  1349. ENUM_TARGET(CLOCK_TAI),
  1350. ENUM_END,
  1351. };
  1352. UNUSED static struct enums itimer_types[] = {
  1353. ENUM_GENERIC(ITIMER_REAL),
  1354. ENUM_GENERIC(ITIMER_VIRTUAL),
  1355. ENUM_GENERIC(ITIMER_PROF),
  1356. ENUM_END,
  1357. };
  1358. /*
  1359. * print_xxx utility functions. These are used to print syscall
  1360. * parameters in certain format. All of these have parameter
  1361. * named 'last'. This parameter is used to add comma to output
  1362. * when last == 0.
  1363. */
  1364. static const char *
  1365. get_comma(int last)
  1366. {
  1367. return ((last) ? "" : ",");
  1368. }
  1369. static void
  1370. print_flags(const struct flags *f, abi_long flags, int last)
  1371. {
  1372. const char *sep = "";
  1373. int n;
  1374. if ((flags == 0) && (f->f_value == 0)) {
  1375. qemu_log("%s%s", f->f_string, get_comma(last));
  1376. return;
  1377. }
  1378. for (n = 0; f->f_string != NULL; f++) {
  1379. if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
  1380. qemu_log("%s%s", sep, f->f_string);
  1381. flags &= ~f->f_value;
  1382. sep = "|";
  1383. n++;
  1384. }
  1385. }
  1386. if (n > 0) {
  1387. /* print rest of the flags as numeric */
  1388. if (flags != 0) {
  1389. qemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
  1390. } else {
  1391. qemu_log("%s", get_comma(last));
  1392. }
  1393. } else {
  1394. /* no string version of flags found, print them in hex then */
  1395. qemu_log("%#x%s", (unsigned int)flags, get_comma(last));
  1396. }
  1397. }
  1398. static void
  1399. print_enums(const struct enums *e, abi_long enum_arg, int last)
  1400. {
  1401. for (; e->e_string != NULL; e++) {
  1402. if (e->e_value == enum_arg) {
  1403. qemu_log("%s", e->e_string);
  1404. break;
  1405. }
  1406. }
  1407. if (e->e_string == NULL) {
  1408. qemu_log("%#x", (unsigned int)enum_arg);
  1409. }
  1410. qemu_log("%s", get_comma(last));
  1411. }
  1412. static void
  1413. print_at_dirfd(abi_long dirfd, int last)
  1414. {
  1415. #ifdef AT_FDCWD
  1416. if (dirfd == AT_FDCWD) {
  1417. qemu_log("AT_FDCWD%s", get_comma(last));
  1418. return;
  1419. }
  1420. #endif
  1421. qemu_log("%d%s", (int)dirfd, get_comma(last));
  1422. }
  1423. static void
  1424. print_file_mode(abi_long mode, int last)
  1425. {
  1426. const char *sep = "";
  1427. const struct flags *m;
  1428. if (mode == 0) {
  1429. qemu_log("000%s", get_comma(last));
  1430. return;
  1431. }
  1432. for (m = &mode_flags[0]; m->f_string != NULL; m++) {
  1433. if ((m->f_value & mode) == m->f_value) {
  1434. qemu_log("%s%s", m->f_string, sep);
  1435. sep = "|";
  1436. mode &= ~m->f_value;
  1437. break;
  1438. }
  1439. }
  1440. mode &= ~S_IFMT;
  1441. /* print rest of the mode as octal */
  1442. if (mode != 0)
  1443. qemu_log("%s%#o", sep, (unsigned int)mode);
  1444. qemu_log("%s", get_comma(last));
  1445. }
  1446. static void
  1447. print_open_flags(abi_long flags, int last)
  1448. {
  1449. print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
  1450. flags &= ~TARGET_O_ACCMODE;
  1451. if (flags == 0) {
  1452. qemu_log("%s", get_comma(last));
  1453. return;
  1454. }
  1455. qemu_log("|");
  1456. print_flags(open_flags, flags, last);
  1457. }
  1458. static void
  1459. print_syscall_prologue(const struct syscallname *sc)
  1460. {
  1461. qemu_log("%s(", sc->name);
  1462. }
  1463. /*ARGSUSED*/
  1464. static void
  1465. print_syscall_epilogue(const struct syscallname *sc)
  1466. {
  1467. (void)sc;
  1468. qemu_log(")");
  1469. }
  1470. static void
  1471. print_string(abi_long addr, int last)
  1472. {
  1473. char *s;
  1474. if ((s = lock_user_string(addr)) != NULL) {
  1475. qemu_log("\"%s\"%s", s, get_comma(last));
  1476. unlock_user(s, addr, 0);
  1477. } else {
  1478. /* can't get string out of it, so print it as pointer */
  1479. print_pointer(addr, last);
  1480. }
  1481. }
  1482. #define MAX_PRINT_BUF 40
  1483. static void
  1484. print_buf(abi_long addr, abi_long len, int last)
  1485. {
  1486. uint8_t *s;
  1487. int i;
  1488. s = lock_user(VERIFY_READ, addr, len, 1);
  1489. if (s) {
  1490. qemu_log("\"");
  1491. for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
  1492. if (isprint(s[i])) {
  1493. qemu_log("%c", s[i]);
  1494. } else {
  1495. qemu_log("\\%o", s[i]);
  1496. }
  1497. }
  1498. qemu_log("\"");
  1499. if (i != len) {
  1500. qemu_log("...");
  1501. }
  1502. if (!last) {
  1503. qemu_log(",");
  1504. }
  1505. unlock_user(s, addr, 0);
  1506. } else {
  1507. print_pointer(addr, last);
  1508. }
  1509. }
  1510. /*
  1511. * Prints out raw parameter using given format. Caller needs
  1512. * to do byte swapping if needed.
  1513. */
  1514. static void
  1515. print_raw_param(const char *fmt, abi_long param, int last)
  1516. {
  1517. char format[64];
  1518. (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
  1519. qemu_log(format, param);
  1520. }
  1521. /*
  1522. * Same as print_raw_param() but prints out raw 64-bit parameter.
  1523. */
  1524. static void
  1525. print_raw_param64(const char *fmt, long long param, int last)
  1526. {
  1527. char format[64];
  1528. (void)snprintf(format, sizeof(format), "%s%s", fmt, get_comma(last));
  1529. qemu_log(format, param);
  1530. }
  1531. static void
  1532. print_pointer(abi_long p, int last)
  1533. {
  1534. if (p == 0)
  1535. qemu_log("NULL%s", get_comma(last));
  1536. else
  1537. qemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
  1538. }
  1539. /*
  1540. * Reads 32-bit (int) number from guest address space from
  1541. * address 'addr' and prints it.
  1542. */
  1543. static void
  1544. print_number(abi_long addr, int last)
  1545. {
  1546. if (addr == 0) {
  1547. qemu_log("NULL%s", get_comma(last));
  1548. } else {
  1549. int num;
  1550. get_user_s32(num, addr);
  1551. qemu_log("[%d]%s", num, get_comma(last));
  1552. }
  1553. }
  1554. static void
  1555. print_timeval(abi_ulong tv_addr, int last)
  1556. {
  1557. if( tv_addr ) {
  1558. struct target_timeval *tv;
  1559. tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
  1560. if (!tv) {
  1561. print_pointer(tv_addr, last);
  1562. return;
  1563. }
  1564. qemu_log("{tv_sec = " TARGET_ABI_FMT_ld
  1565. ",tv_usec = " TARGET_ABI_FMT_ld "}%s",
  1566. tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
  1567. unlock_user(tv, tv_addr, 0);
  1568. } else
  1569. qemu_log("NULL%s", get_comma(last));
  1570. }
  1571. static void
  1572. print_timespec(abi_ulong ts_addr, int last)
  1573. {
  1574. if (ts_addr) {
  1575. struct target_timespec *ts;
  1576. ts = lock_user(VERIFY_READ, ts_addr, sizeof(*ts), 1);
  1577. if (!ts) {
  1578. print_pointer(ts_addr, last);
  1579. return;
  1580. }
  1581. qemu_log("{tv_sec = " TARGET_ABI_FMT_ld
  1582. ",tv_nsec = " TARGET_ABI_FMT_ld "}%s",
  1583. tswapal(ts->tv_sec), tswapal(ts->tv_nsec), get_comma(last));
  1584. unlock_user(ts, ts_addr, 0);
  1585. } else {
  1586. qemu_log("NULL%s", get_comma(last));
  1587. }
  1588. }
  1589. static void
  1590. print_timespec64(abi_ulong ts_addr, int last)
  1591. {
  1592. if (ts_addr) {
  1593. struct target__kernel_timespec *ts;
  1594. ts = lock_user(VERIFY_READ, ts_addr, sizeof(*ts), 1);
  1595. if (!ts) {
  1596. print_pointer(ts_addr, last);
  1597. return;
  1598. }
  1599. print_raw_param64("{tv_sec=%" PRId64, tswap64(ts->tv_sec), 0);
  1600. print_raw_param64("tv_nsec=%" PRId64 "}", tswap64(ts->tv_nsec), last);
  1601. unlock_user(ts, ts_addr, 0);
  1602. } else {
  1603. qemu_log("NULL%s", get_comma(last));
  1604. }
  1605. }
  1606. static void
  1607. print_timezone(abi_ulong tz_addr, int last)
  1608. {
  1609. if (tz_addr) {
  1610. struct target_timezone *tz;
  1611. tz = lock_user(VERIFY_READ, tz_addr, sizeof(*tz), 1);
  1612. if (!tz) {
  1613. print_pointer(tz_addr, last);
  1614. return;
  1615. }
  1616. qemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
  1617. tswap32(tz->tz_dsttime), get_comma(last));
  1618. unlock_user(tz, tz_addr, 0);
  1619. } else {
  1620. qemu_log("NULL%s", get_comma(last));
  1621. }
  1622. }
  1623. static void
  1624. print_itimerval(abi_ulong it_addr, int last)
  1625. {
  1626. if (it_addr) {
  1627. qemu_log("{it_interval=");
  1628. print_timeval(it_addr +
  1629. offsetof(struct target_itimerval, it_interval), 0);
  1630. qemu_log("it_value=");
  1631. print_timeval(it_addr +
  1632. offsetof(struct target_itimerval, it_value), 0);
  1633. qemu_log("}%s", get_comma(last));
  1634. } else {
  1635. qemu_log("NULL%s", get_comma(last));
  1636. }
  1637. }
  1638. void
  1639. print_termios(void *arg)
  1640. {
  1641. const struct target_termios *target = arg;
  1642. target_tcflag_t iflags = tswap32(target->c_iflag);
  1643. target_tcflag_t oflags = tswap32(target->c_oflag);
  1644. target_tcflag_t cflags = tswap32(target->c_cflag);
  1645. target_tcflag_t lflags = tswap32(target->c_lflag);
  1646. qemu_log("{");
  1647. qemu_log("c_iflag = ");
  1648. print_flags(termios_iflags, iflags, 0);
  1649. qemu_log("c_oflag = ");
  1650. target_tcflag_t oflags_clean = oflags & ~(TARGET_NLDLY | TARGET_CRDLY |
  1651. TARGET_TABDLY | TARGET_BSDLY |
  1652. TARGET_VTDLY | TARGET_FFDLY);
  1653. print_flags(termios_oflags, oflags_clean, 0);
  1654. if (oflags & TARGET_NLDLY) {
  1655. print_enums(termios_oflags_NLDLY, oflags & TARGET_NLDLY, 0);
  1656. }
  1657. if (oflags & TARGET_CRDLY) {
  1658. print_enums(termios_oflags_CRDLY, oflags & TARGET_CRDLY, 0);
  1659. }
  1660. if (oflags & TARGET_TABDLY) {
  1661. print_enums(termios_oflags_TABDLY, oflags & TARGET_TABDLY, 0);
  1662. }
  1663. if (oflags & TARGET_BSDLY) {
  1664. print_enums(termios_oflags_BSDLY, oflags & TARGET_BSDLY, 0);
  1665. }
  1666. if (oflags & TARGET_VTDLY) {
  1667. print_enums(termios_oflags_VTDLY, oflags & TARGET_VTDLY, 0);
  1668. }
  1669. if (oflags & TARGET_FFDLY) {
  1670. print_enums(termios_oflags_FFDLY, oflags & TARGET_FFDLY, 0);
  1671. }
  1672. qemu_log("c_cflag = ");
  1673. if (cflags & TARGET_CBAUD) {
  1674. print_enums(termios_cflags_CBAUD, cflags & TARGET_CBAUD, 0);
  1675. }
  1676. if (cflags & TARGET_CSIZE) {
  1677. print_enums(termios_cflags_CSIZE, cflags & TARGET_CSIZE, 0);
  1678. }
  1679. target_tcflag_t cflags_clean = cflags & ~(TARGET_CBAUD | TARGET_CSIZE);
  1680. print_flags(termios_cflags, cflags_clean, 0);
  1681. qemu_log("c_lflag = ");
  1682. print_flags(termios_lflags, lflags, 0);
  1683. qemu_log("c_cc = ");
  1684. qemu_log("\"%s\",", target->c_cc);
  1685. qemu_log("c_line = ");
  1686. print_raw_param("\'%c\'", target->c_line, 1);
  1687. qemu_log("}");
  1688. }
  1689. #undef UNUSED
  1690. #ifdef TARGET_NR_accept
  1691. static void
  1692. print_accept(CPUArchState *cpu_env, const struct syscallname *name,
  1693. abi_long arg0, abi_long arg1, abi_long arg2,
  1694. abi_long arg3, abi_long arg4, abi_long arg5)
  1695. {
  1696. print_syscall_prologue(name);
  1697. print_raw_param("%d", arg0, 0);
  1698. print_pointer(arg1, 0);
  1699. print_number(arg2, 1);
  1700. print_syscall_epilogue(name);
  1701. }
  1702. #endif
  1703. #ifdef TARGET_NR_access
  1704. static void
  1705. print_access(CPUArchState *cpu_env, const struct syscallname *name,
  1706. abi_long arg0, abi_long arg1, abi_long arg2,
  1707. abi_long arg3, abi_long arg4, abi_long arg5)
  1708. {
  1709. print_syscall_prologue(name);
  1710. print_string(arg0, 0);
  1711. print_flags(access_flags, arg1, 1);
  1712. print_syscall_epilogue(name);
  1713. }
  1714. #endif
  1715. #ifdef TARGET_NR_acct
  1716. static void
  1717. print_acct(CPUArchState *cpu_env, const struct syscallname *name,
  1718. abi_long arg0, abi_long arg1, abi_long arg2,
  1719. abi_long arg3, abi_long arg4, abi_long arg5)
  1720. {
  1721. print_syscall_prologue(name);
  1722. print_string(arg0, 1);
  1723. print_syscall_epilogue(name);
  1724. }
  1725. #endif
  1726. #ifdef TARGET_NR_brk
  1727. static void
  1728. print_brk(CPUArchState *cpu_env, const struct syscallname *name,
  1729. abi_long arg0, abi_long arg1, abi_long arg2,
  1730. abi_long arg3, abi_long arg4, abi_long arg5)
  1731. {
  1732. print_syscall_prologue(name);
  1733. print_pointer(arg0, 1);
  1734. print_syscall_epilogue(name);
  1735. }
  1736. #endif
  1737. #ifdef TARGET_NR_chdir
  1738. static void
  1739. print_chdir(CPUArchState *cpu_env, const struct syscallname *name,
  1740. abi_long arg0, abi_long arg1, abi_long arg2,
  1741. abi_long arg3, abi_long arg4, abi_long arg5)
  1742. {
  1743. print_syscall_prologue(name);
  1744. print_string(arg0, 1);
  1745. print_syscall_epilogue(name);
  1746. }
  1747. #endif
  1748. #ifdef TARGET_NR_chroot
  1749. static void
  1750. print_chroot(CPUArchState *cpu_env, const struct syscallname *name,
  1751. abi_long arg0, abi_long arg1, abi_long arg2,
  1752. abi_long arg3, abi_long arg4, abi_long arg5)
  1753. {
  1754. print_syscall_prologue(name);
  1755. print_string(arg0, 1);
  1756. print_syscall_epilogue(name);
  1757. }
  1758. #endif
  1759. #ifdef TARGET_NR_chmod
  1760. static void
  1761. print_chmod(CPUArchState *cpu_env, const struct syscallname *name,
  1762. abi_long arg0, abi_long arg1, abi_long arg2,
  1763. abi_long arg3, abi_long arg4, abi_long arg5)
  1764. {
  1765. print_syscall_prologue(name);
  1766. print_string(arg0, 0);
  1767. print_file_mode(arg1, 1);
  1768. print_syscall_epilogue(name);
  1769. }
  1770. #endif
  1771. #if defined(TARGET_NR_chown) || defined(TARGET_NR_lchown)
  1772. static void
  1773. print_chown(CPUArchState *cpu_env, const struct syscallname *name,
  1774. abi_long arg0, abi_long arg1, abi_long arg2,
  1775. abi_long arg3, abi_long arg4, abi_long arg5)
  1776. {
  1777. print_syscall_prologue(name);
  1778. print_string(arg0, 0);
  1779. print_raw_param("%d", arg1, 0);
  1780. print_raw_param("%d", arg2, 1);
  1781. print_syscall_epilogue(name);
  1782. }
  1783. #define print_lchown print_chown
  1784. #endif
  1785. #ifdef TARGET_NR_clock_adjtime
  1786. static void
  1787. print_clock_adjtime(CPUArchState *cpu_env, const struct syscallname *name,
  1788. abi_long arg0, abi_long arg1, abi_long arg2,
  1789. abi_long arg3, abi_long arg4, abi_long arg5)
  1790. {
  1791. print_syscall_prologue(name);
  1792. print_enums(clockids, arg0, 0);
  1793. print_pointer(arg1, 1);
  1794. print_syscall_epilogue(name);
  1795. }
  1796. #endif
  1797. #ifdef TARGET_NR_clone
  1798. static void do_print_clone(unsigned int flags, abi_ulong newsp,
  1799. abi_ulong parent_tidptr, target_ulong newtls,
  1800. abi_ulong child_tidptr)
  1801. {
  1802. print_flags(clone_flags, flags, 0);
  1803. print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
  1804. print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
  1805. print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
  1806. print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
  1807. }
  1808. static void
  1809. print_clone(CPUArchState *cpu_env, const struct syscallname *name,
  1810. abi_long arg1, abi_long arg2, abi_long arg3,
  1811. abi_long arg4, abi_long arg5, abi_long arg6)
  1812. {
  1813. print_syscall_prologue(name);
  1814. #if defined(TARGET_MICROBLAZE)
  1815. do_print_clone(arg1, arg2, arg4, arg6, arg5);
  1816. #elif defined(TARGET_CLONE_BACKWARDS)
  1817. do_print_clone(arg1, arg2, arg3, arg4, arg5);
  1818. #elif defined(TARGET_CLONE_BACKWARDS2)
  1819. do_print_clone(arg2, arg1, arg3, arg5, arg4);
  1820. #else
  1821. do_print_clone(arg1, arg2, arg3, arg5, arg4);
  1822. #endif
  1823. print_syscall_epilogue(name);
  1824. }
  1825. #endif
  1826. #ifdef TARGET_NR_creat
  1827. static void
  1828. print_creat(CPUArchState *cpu_env, const struct syscallname *name,
  1829. abi_long arg0, abi_long arg1, abi_long arg2,
  1830. abi_long arg3, abi_long arg4, abi_long arg5)
  1831. {
  1832. print_syscall_prologue(name);
  1833. print_string(arg0, 0);
  1834. print_file_mode(arg1, 1);
  1835. print_syscall_epilogue(name);
  1836. }
  1837. #endif
  1838. #ifdef TARGET_NR_execv
  1839. static void
  1840. print_execv(CPUArchState *cpu_env, const struct syscallname *name,
  1841. abi_long arg0, abi_long arg1, abi_long arg2,
  1842. abi_long arg3, abi_long arg4, abi_long arg5)
  1843. {
  1844. print_syscall_prologue(name);
  1845. print_string(arg0, 0);
  1846. print_raw_param("0x" TARGET_ABI_FMT_lx, arg1, 1);
  1847. print_syscall_epilogue(name);
  1848. }
  1849. #endif
  1850. static void
  1851. print_execve_argv(abi_long argv, int last)
  1852. {
  1853. abi_ulong arg_ptr_addr;
  1854. char *s;
  1855. qemu_log("{");
  1856. for (arg_ptr_addr = argv; ; arg_ptr_addr += sizeof(abi_ulong)) {
  1857. abi_ulong *arg_ptr, arg_addr;
  1858. arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1);
  1859. if (!arg_ptr) {
  1860. return;
  1861. }
  1862. arg_addr = tswapal(*arg_ptr);
  1863. unlock_user(arg_ptr, arg_ptr_addr, 0);
  1864. if (!arg_addr) {
  1865. break;
  1866. }
  1867. s = lock_user_string(arg_addr);
  1868. if (s) {
  1869. qemu_log("\"%s\",", s);
  1870. unlock_user(s, arg_addr, 0);
  1871. }
  1872. }
  1873. qemu_log("NULL}%s", get_comma(last));
  1874. }
  1875. static void
  1876. print_execve(CPUArchState *cpu_env, const struct syscallname *name,
  1877. abi_long arg1, abi_long arg2, abi_long arg3,
  1878. abi_long arg4, abi_long arg5, abi_long arg6)
  1879. {
  1880. print_syscall_prologue(name);
  1881. print_string(arg1, 0);
  1882. print_execve_argv(arg2, 1);
  1883. print_syscall_epilogue(name);
  1884. }
  1885. static void
  1886. print_execveat(CPUArchState *cpu_env, const struct syscallname *name,
  1887. abi_long arg1, abi_long arg2, abi_long arg3,
  1888. abi_long arg4, abi_long arg5, abi_long arg6)
  1889. {
  1890. print_syscall_prologue(name);
  1891. print_at_dirfd(arg1, 0);
  1892. print_string(arg2, 0);
  1893. print_execve_argv(arg3, 0);
  1894. print_flags(execveat_flags, arg5, 1);
  1895. print_syscall_epilogue(name);
  1896. }
  1897. #if defined(TARGET_NR_faccessat) || defined(TARGET_NR_faccessat2)
  1898. static void
  1899. print_faccessat(CPUArchState *cpu_env, const struct syscallname *name,
  1900. abi_long arg0, abi_long arg1, abi_long arg2,
  1901. abi_long arg3, abi_long arg4, abi_long arg5)
  1902. {
  1903. print_syscall_prologue(name);
  1904. print_at_dirfd(arg0, 0);
  1905. print_string(arg1, 0);
  1906. print_flags(access_flags, arg2, 0);
  1907. print_flags(at_file_flags, arg3, 1);
  1908. print_syscall_epilogue(name);
  1909. }
  1910. #endif
  1911. #ifdef TARGET_NR_fallocate
  1912. static void
  1913. print_fallocate(CPUArchState *cpu_env, const struct syscallname *name,
  1914. abi_long arg0, abi_long arg1, abi_long arg2,
  1915. abi_long arg3, abi_long arg4, abi_long arg5)
  1916. {
  1917. print_syscall_prologue(name);
  1918. print_raw_param("%d", arg0, 0);
  1919. print_flags(falloc_flags, arg1, 0);
  1920. #if TARGET_ABI_BITS == 32
  1921. print_raw_param("%" PRIu64, target_offset64(arg2, arg3), 0);
  1922. print_raw_param("%" PRIu64, target_offset64(arg4, arg5), 1);
  1923. #else
  1924. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  1925. print_raw_param(TARGET_ABI_FMT_ld, arg3, 1);
  1926. #endif
  1927. print_syscall_epilogue(name);
  1928. }
  1929. #endif
  1930. #ifdef TARGET_NR_fchmodat
  1931. static void
  1932. print_fchmodat(CPUArchState *cpu_env, const struct syscallname *name,
  1933. abi_long arg0, abi_long arg1, abi_long arg2,
  1934. abi_long arg3, abi_long arg4, abi_long arg5)
  1935. {
  1936. print_syscall_prologue(name);
  1937. print_at_dirfd(arg0, 0);
  1938. print_string(arg1, 0);
  1939. print_file_mode(arg2, 0);
  1940. print_flags(at_file_flags, arg3, 1);
  1941. print_syscall_epilogue(name);
  1942. }
  1943. #endif
  1944. #ifdef TARGET_NR_fchownat
  1945. static void
  1946. print_fchownat(CPUArchState *cpu_env, const struct syscallname *name,
  1947. abi_long arg0, abi_long arg1, abi_long arg2,
  1948. abi_long arg3, abi_long arg4, abi_long arg5)
  1949. {
  1950. print_syscall_prologue(name);
  1951. print_at_dirfd(arg0, 0);
  1952. print_string(arg1, 0);
  1953. print_raw_param("%d", arg2, 0);
  1954. print_raw_param("%d", arg3, 0);
  1955. print_flags(at_file_flags, arg4, 1);
  1956. print_syscall_epilogue(name);
  1957. }
  1958. #endif
  1959. #if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
  1960. static void
  1961. print_fcntl(CPUArchState *cpu_env, const struct syscallname *name,
  1962. abi_long arg0, abi_long arg1, abi_long arg2,
  1963. abi_long arg3, abi_long arg4, abi_long arg5)
  1964. {
  1965. print_syscall_prologue(name);
  1966. print_raw_param("%d", arg0, 0);
  1967. switch(arg1) {
  1968. case TARGET_F_DUPFD:
  1969. qemu_log("F_DUPFD,");
  1970. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  1971. break;
  1972. case TARGET_F_GETFD:
  1973. qemu_log("F_GETFD");
  1974. break;
  1975. case TARGET_F_SETFD:
  1976. qemu_log("F_SETFD,");
  1977. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  1978. break;
  1979. case TARGET_F_GETFL:
  1980. qemu_log("F_GETFL");
  1981. break;
  1982. case TARGET_F_SETFL:
  1983. qemu_log("F_SETFL,");
  1984. print_open_flags(arg2, 1);
  1985. break;
  1986. case TARGET_F_GETLK:
  1987. qemu_log("F_GETLK,");
  1988. print_pointer(arg2, 1);
  1989. break;
  1990. case TARGET_F_SETLK:
  1991. qemu_log("F_SETLK,");
  1992. print_pointer(arg2, 1);
  1993. break;
  1994. case TARGET_F_SETLKW:
  1995. qemu_log("F_SETLKW,");
  1996. print_pointer(arg2, 1);
  1997. break;
  1998. case TARGET_F_GETOWN:
  1999. qemu_log("F_GETOWN");
  2000. break;
  2001. case TARGET_F_SETOWN:
  2002. qemu_log("F_SETOWN,");
  2003. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  2004. break;
  2005. case TARGET_F_GETSIG:
  2006. qemu_log("F_GETSIG");
  2007. break;
  2008. case TARGET_F_SETSIG:
  2009. qemu_log("F_SETSIG,");
  2010. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  2011. break;
  2012. #if TARGET_ABI_BITS == 32
  2013. case TARGET_F_GETLK64:
  2014. qemu_log("F_GETLK64,");
  2015. print_pointer(arg2, 1);
  2016. break;
  2017. case TARGET_F_SETLK64:
  2018. qemu_log("F_SETLK64,");
  2019. print_pointer(arg2, 1);
  2020. break;
  2021. case TARGET_F_SETLKW64:
  2022. qemu_log("F_SETLKW64,");
  2023. print_pointer(arg2, 1);
  2024. break;
  2025. #endif
  2026. case TARGET_F_OFD_GETLK:
  2027. qemu_log("F_OFD_GETLK,");
  2028. print_pointer(arg2, 1);
  2029. break;
  2030. case TARGET_F_OFD_SETLK:
  2031. qemu_log("F_OFD_SETLK,");
  2032. print_pointer(arg2, 1);
  2033. break;
  2034. case TARGET_F_OFD_SETLKW:
  2035. qemu_log("F_OFD_SETLKW,");
  2036. print_pointer(arg2, 1);
  2037. break;
  2038. case TARGET_F_SETLEASE:
  2039. qemu_log("F_SETLEASE,");
  2040. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2041. break;
  2042. case TARGET_F_GETLEASE:
  2043. qemu_log("F_GETLEASE");
  2044. break;
  2045. #ifdef F_DUPFD_CLOEXEC
  2046. case TARGET_F_DUPFD_CLOEXEC:
  2047. qemu_log("F_DUPFD_CLOEXEC,");
  2048. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2049. break;
  2050. #endif
  2051. case TARGET_F_NOTIFY:
  2052. qemu_log("F_NOTIFY,");
  2053. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2054. break;
  2055. #ifdef F_GETOWN_EX
  2056. case TARGET_F_GETOWN_EX:
  2057. qemu_log("F_GETOWN_EX,");
  2058. print_pointer(arg2, 1);
  2059. break;
  2060. #endif
  2061. #ifdef F_SETOWN_EX
  2062. case TARGET_F_SETOWN_EX:
  2063. qemu_log("F_SETOWN_EX,");
  2064. print_pointer(arg2, 1);
  2065. break;
  2066. #endif
  2067. #ifdef F_SETPIPE_SZ
  2068. case TARGET_F_SETPIPE_SZ:
  2069. qemu_log("F_SETPIPE_SZ,");
  2070. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  2071. break;
  2072. case TARGET_F_GETPIPE_SZ:
  2073. qemu_log("F_GETPIPE_SZ");
  2074. break;
  2075. #endif
  2076. #ifdef F_ADD_SEALS
  2077. case TARGET_F_ADD_SEALS:
  2078. qemu_log("F_ADD_SEALS,");
  2079. print_raw_param("0x"TARGET_ABI_FMT_lx, arg2, 1);
  2080. break;
  2081. case TARGET_F_GET_SEALS:
  2082. qemu_log("F_GET_SEALS");
  2083. break;
  2084. #endif
  2085. default:
  2086. print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
  2087. print_pointer(arg2, 1);
  2088. break;
  2089. }
  2090. print_syscall_epilogue(name);
  2091. }
  2092. #define print_fcntl64 print_fcntl
  2093. #endif
  2094. #ifdef TARGET_NR_fgetxattr
  2095. static void
  2096. print_fgetxattr(CPUArchState *cpu_env, const struct syscallname *name,
  2097. abi_long arg0, abi_long arg1, abi_long arg2,
  2098. abi_long arg3, abi_long arg4, abi_long arg5)
  2099. {
  2100. print_syscall_prologue(name);
  2101. print_raw_param("%d", arg0, 0);
  2102. print_string(arg1, 0);
  2103. print_pointer(arg2, 0);
  2104. print_raw_param(TARGET_FMT_lu, arg3, 1);
  2105. print_syscall_epilogue(name);
  2106. }
  2107. #endif
  2108. #ifdef TARGET_NR_flistxattr
  2109. static void
  2110. print_flistxattr(CPUArchState *cpu_env, const struct syscallname *name,
  2111. abi_long arg0, abi_long arg1, abi_long arg2,
  2112. abi_long arg3, abi_long arg4, abi_long arg5)
  2113. {
  2114. print_syscall_prologue(name);
  2115. print_raw_param("%d", arg0, 0);
  2116. print_pointer(arg1, 0);
  2117. print_raw_param(TARGET_FMT_lu, arg2, 1);
  2118. print_syscall_epilogue(name);
  2119. }
  2120. #endif
  2121. #if defined(TARGET_NR_getxattr) || defined(TARGET_NR_lgetxattr)
  2122. static void
  2123. print_getxattr(CPUArchState *cpu_env, const struct syscallname *name,
  2124. abi_long arg0, abi_long arg1, abi_long arg2,
  2125. abi_long arg3, abi_long arg4, abi_long arg5)
  2126. {
  2127. print_syscall_prologue(name);
  2128. print_string(arg0, 0);
  2129. print_string(arg1, 0);
  2130. print_pointer(arg2, 0);
  2131. print_raw_param(TARGET_FMT_lu, arg3, 1);
  2132. print_syscall_epilogue(name);
  2133. }
  2134. #define print_lgetxattr print_getxattr
  2135. #endif
  2136. #if defined(TARGET_NR_listxattr) || defined(TARGET_NR_llistxattr)
  2137. static void
  2138. print_listxattr(CPUArchState *cpu_env, const struct syscallname *name,
  2139. abi_long arg0, abi_long arg1, abi_long arg2,
  2140. abi_long arg3, abi_long arg4, abi_long arg5)
  2141. {
  2142. print_syscall_prologue(name);
  2143. print_string(arg0, 0);
  2144. print_pointer(arg1, 0);
  2145. print_raw_param(TARGET_FMT_lu, arg2, 1);
  2146. print_syscall_epilogue(name);
  2147. }
  2148. #define print_llistxattr print_listxattr
  2149. #endif
  2150. #if defined(TARGET_NR_fremovexattr)
  2151. static void
  2152. print_fremovexattr(CPUArchState *cpu_env, const struct syscallname *name,
  2153. abi_long arg0, abi_long arg1, abi_long arg2,
  2154. abi_long arg3, abi_long arg4, abi_long arg5)
  2155. {
  2156. print_syscall_prologue(name);
  2157. print_raw_param("%d", arg0, 0);
  2158. print_string(arg1, 1);
  2159. print_syscall_epilogue(name);
  2160. }
  2161. #endif
  2162. #if defined(TARGET_NR_removexattr) || defined(TARGET_NR_lremovexattr)
  2163. static void
  2164. print_removexattr(CPUArchState *cpu_env, const struct syscallname *name,
  2165. abi_long arg0, abi_long arg1, abi_long arg2,
  2166. abi_long arg3, abi_long arg4, abi_long arg5)
  2167. {
  2168. print_syscall_prologue(name);
  2169. print_string(arg0, 0);
  2170. print_string(arg1, 1);
  2171. print_syscall_epilogue(name);
  2172. }
  2173. #define print_lremovexattr print_removexattr
  2174. #endif
  2175. #ifdef TARGET_NR_futimesat
  2176. static void
  2177. print_futimesat(CPUArchState *cpu_env, const struct syscallname *name,
  2178. abi_long arg0, abi_long arg1, abi_long arg2,
  2179. abi_long arg3, abi_long arg4, abi_long arg5)
  2180. {
  2181. print_syscall_prologue(name);
  2182. print_at_dirfd(arg0, 0);
  2183. print_string(arg1, 0);
  2184. print_timeval(arg2, 0);
  2185. print_timeval(arg2 + sizeof (struct target_timeval), 1);
  2186. print_syscall_epilogue(name);
  2187. }
  2188. #endif
  2189. #ifdef TARGET_NR_gettimeofday
  2190. static void
  2191. print_gettimeofday(CPUArchState *cpu_env, const struct syscallname *name,
  2192. abi_long arg0, abi_long arg1, abi_long arg2,
  2193. abi_long arg3, abi_long arg4, abi_long arg5)
  2194. {
  2195. print_syscall_prologue(name);
  2196. print_pointer(arg0, 0);
  2197. print_pointer(arg1, 1);
  2198. print_syscall_epilogue(name);
  2199. }
  2200. #endif
  2201. #ifdef TARGET_NR_settimeofday
  2202. static void
  2203. print_settimeofday(CPUArchState *cpu_env, const struct syscallname *name,
  2204. abi_long arg0, abi_long arg1, abi_long arg2,
  2205. abi_long arg3, abi_long arg4, abi_long arg5)
  2206. {
  2207. print_syscall_prologue(name);
  2208. print_timeval(arg0, 0);
  2209. print_timezone(arg1, 1);
  2210. print_syscall_epilogue(name);
  2211. }
  2212. #endif
  2213. #if defined(TARGET_NR_clock_gettime) || defined(TARGET_NR_clock_getres)
  2214. static void
  2215. print_clock_gettime(CPUArchState *cpu_env, const struct syscallname *name,
  2216. abi_long arg0, abi_long arg1, abi_long arg2,
  2217. abi_long arg3, abi_long arg4, abi_long arg5)
  2218. {
  2219. print_syscall_prologue(name);
  2220. print_enums(clockids, arg0, 0);
  2221. print_pointer(arg1, 1);
  2222. print_syscall_epilogue(name);
  2223. }
  2224. #define print_clock_getres print_clock_gettime
  2225. #endif
  2226. #if defined(TARGET_NR_clock_gettime64)
  2227. static void
  2228. print_clock_gettime64(CPUArchState *cpu_env, const struct syscallname *name,
  2229. abi_long arg0, abi_long arg1, abi_long arg2,
  2230. abi_long arg3, abi_long arg4, abi_long arg5)
  2231. {
  2232. print_syscall_prologue(name);
  2233. print_enums(clockids, arg0, 0);
  2234. print_pointer(arg1, 1);
  2235. print_syscall_epilogue(name);
  2236. }
  2237. #endif
  2238. #ifdef TARGET_NR_clock_settime
  2239. static void
  2240. print_clock_settime(CPUArchState *cpu_env, const struct syscallname *name,
  2241. abi_long arg0, abi_long arg1, abi_long arg2,
  2242. abi_long arg3, abi_long arg4, abi_long arg5)
  2243. {
  2244. print_syscall_prologue(name);
  2245. print_enums(clockids, arg0, 0);
  2246. print_timespec(arg1, 1);
  2247. print_syscall_epilogue(name);
  2248. }
  2249. #endif
  2250. #ifdef TARGET_NR_getitimer
  2251. static void
  2252. print_getitimer(CPUArchState *cpu_env, const struct syscallname *name,
  2253. abi_long arg0, abi_long arg1, abi_long arg2,
  2254. abi_long arg3, abi_long arg4, abi_long arg5)
  2255. {
  2256. print_syscall_prologue(name);
  2257. print_enums(itimer_types, arg0, 0);
  2258. print_pointer(arg1, 1);
  2259. print_syscall_epilogue(name);
  2260. }
  2261. #endif
  2262. #ifdef TARGET_NR_setitimer
  2263. static void
  2264. print_setitimer(CPUArchState *cpu_env, const struct syscallname *name,
  2265. abi_long arg0, abi_long arg1, abi_long arg2,
  2266. abi_long arg3, abi_long arg4, abi_long arg5)
  2267. {
  2268. print_syscall_prologue(name);
  2269. print_enums(itimer_types, arg0, 0);
  2270. print_itimerval(arg1, 0);
  2271. print_pointer(arg2, 1);
  2272. print_syscall_epilogue(name);
  2273. }
  2274. #endif
  2275. #ifdef TARGET_NR_link
  2276. static void
  2277. print_link(CPUArchState *cpu_env, const struct syscallname *name,
  2278. abi_long arg0, abi_long arg1, abi_long arg2,
  2279. abi_long arg3, abi_long arg4, abi_long arg5)
  2280. {
  2281. print_syscall_prologue(name);
  2282. print_string(arg0, 0);
  2283. print_string(arg1, 1);
  2284. print_syscall_epilogue(name);
  2285. }
  2286. #endif
  2287. #ifdef TARGET_NR_linkat
  2288. static void
  2289. print_linkat(CPUArchState *cpu_env, const struct syscallname *name,
  2290. abi_long arg0, abi_long arg1, abi_long arg2,
  2291. abi_long arg3, abi_long arg4, abi_long arg5)
  2292. {
  2293. print_syscall_prologue(name);
  2294. print_at_dirfd(arg0, 0);
  2295. print_string(arg1, 0);
  2296. print_at_dirfd(arg2, 0);
  2297. print_string(arg3, 0);
  2298. print_flags(at_file_flags, arg4, 1);
  2299. print_syscall_epilogue(name);
  2300. }
  2301. #endif
  2302. #if defined(TARGET_NR__llseek) || defined(TARGET_NR_llseek)
  2303. static void
  2304. print__llseek(CPUArchState *cpu_env, const struct syscallname *name,
  2305. abi_long arg0, abi_long arg1, abi_long arg2,
  2306. abi_long arg3, abi_long arg4, abi_long arg5)
  2307. {
  2308. const char *whence = "UNKNOWN";
  2309. print_syscall_prologue(name);
  2310. print_raw_param("%d", arg0, 0);
  2311. print_raw_param("%ld", arg1, 0);
  2312. print_raw_param("%ld", arg2, 0);
  2313. print_pointer(arg3, 0);
  2314. switch(arg4) {
  2315. case SEEK_SET: whence = "SEEK_SET"; break;
  2316. case SEEK_CUR: whence = "SEEK_CUR"; break;
  2317. case SEEK_END: whence = "SEEK_END"; break;
  2318. }
  2319. qemu_log("%s", whence);
  2320. print_syscall_epilogue(name);
  2321. }
  2322. #define print_llseek print__llseek
  2323. #endif
  2324. #ifdef TARGET_NR_lseek
  2325. static void
  2326. print_lseek(CPUArchState *cpu_env, const struct syscallname *name,
  2327. abi_long arg0, abi_long arg1, abi_long arg2,
  2328. abi_long arg3, abi_long arg4, abi_long arg5)
  2329. {
  2330. print_syscall_prologue(name);
  2331. print_raw_param("%d", arg0, 0);
  2332. print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
  2333. switch (arg2) {
  2334. case SEEK_SET:
  2335. qemu_log("SEEK_SET"); break;
  2336. case SEEK_CUR:
  2337. qemu_log("SEEK_CUR"); break;
  2338. case SEEK_END:
  2339. qemu_log("SEEK_END"); break;
  2340. #ifdef SEEK_DATA
  2341. case SEEK_DATA:
  2342. qemu_log("SEEK_DATA"); break;
  2343. #endif
  2344. #ifdef SEEK_HOLE
  2345. case SEEK_HOLE:
  2346. qemu_log("SEEK_HOLE"); break;
  2347. #endif
  2348. default:
  2349. print_raw_param("%#x", arg2, 1);
  2350. }
  2351. print_syscall_epilogue(name);
  2352. }
  2353. #endif
  2354. #ifdef TARGET_NR_truncate
  2355. static void
  2356. print_truncate(CPUArchState *cpu_env, const struct syscallname *name,
  2357. abi_long arg0, abi_long arg1, abi_long arg2,
  2358. abi_long arg3, abi_long arg4, abi_long arg5)
  2359. {
  2360. print_syscall_prologue(name);
  2361. print_string(arg0, 0);
  2362. print_raw_param(TARGET_ABI_FMT_ld, arg1, 1);
  2363. print_syscall_epilogue(name);
  2364. }
  2365. #endif
  2366. #ifdef TARGET_NR_truncate64
  2367. static void
  2368. print_truncate64(CPUArchState *cpu_env, const struct syscallname *name,
  2369. abi_long arg0, abi_long arg1, abi_long arg2,
  2370. abi_long arg3, abi_long arg4, abi_long arg5)
  2371. {
  2372. print_syscall_prologue(name);
  2373. print_string(arg0, 0);
  2374. if (regpairs_aligned(cpu_env, TARGET_NR_truncate64)) {
  2375. arg1 = arg2;
  2376. arg2 = arg3;
  2377. }
  2378. print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
  2379. print_syscall_epilogue(name);
  2380. }
  2381. #endif
  2382. #ifdef TARGET_NR_ftruncate64
  2383. static void
  2384. print_ftruncate64(CPUArchState *cpu_env, const struct syscallname *name,
  2385. abi_long arg0, abi_long arg1, abi_long arg2,
  2386. abi_long arg3, abi_long arg4, abi_long arg5)
  2387. {
  2388. print_syscall_prologue(name);
  2389. print_raw_param("%d", arg0, 0);
  2390. if (regpairs_aligned(cpu_env, TARGET_NR_ftruncate64)) {
  2391. arg1 = arg2;
  2392. arg2 = arg3;
  2393. }
  2394. print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
  2395. print_syscall_epilogue(name);
  2396. }
  2397. #endif
  2398. #ifdef TARGET_NR_mlockall
  2399. static void
  2400. print_mlockall(CPUArchState *cpu_env, const struct syscallname *name,
  2401. abi_long arg0, abi_long arg1, abi_long arg2,
  2402. abi_long arg3, abi_long arg4, abi_long arg5)
  2403. {
  2404. print_syscall_prologue(name);
  2405. print_flags(mlockall_flags, arg0, 1);
  2406. print_syscall_epilogue(name);
  2407. }
  2408. #endif
  2409. #if defined(TARGET_NR_socket)
  2410. static void
  2411. print_socket(CPUArchState *cpu_env, const struct syscallname *name,
  2412. abi_long arg0, abi_long arg1, abi_long arg2,
  2413. abi_long arg3, abi_long arg4, abi_long arg5)
  2414. {
  2415. abi_ulong domain = arg0, type = arg1, protocol = arg2;
  2416. print_syscall_prologue(name);
  2417. print_socket_domain(domain);
  2418. qemu_log(",");
  2419. print_socket_type(type);
  2420. qemu_log(",");
  2421. if (domain == AF_PACKET ||
  2422. (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
  2423. protocol = tswap16(protocol);
  2424. }
  2425. print_socket_protocol(domain, type, protocol);
  2426. print_syscall_epilogue(name);
  2427. }
  2428. #endif
  2429. #if defined(TARGET_NR_socketcall) || defined(TARGET_NR_bind)
  2430. static void print_sockfd(abi_long sockfd, int last)
  2431. {
  2432. print_raw_param(TARGET_ABI_FMT_ld, sockfd, last);
  2433. }
  2434. #endif
  2435. #if defined(TARGET_NR_socketcall)
  2436. #define get_user_ualx(x, gaddr, idx) \
  2437. get_user_ual(x, (gaddr) + (idx) * sizeof(abi_long))
  2438. static void do_print_socket(const char *name, abi_long arg1)
  2439. {
  2440. abi_ulong domain, type, protocol;
  2441. get_user_ualx(domain, arg1, 0);
  2442. get_user_ualx(type, arg1, 1);
  2443. get_user_ualx(protocol, arg1, 2);
  2444. qemu_log("%s(", name);
  2445. print_socket_domain(domain);
  2446. qemu_log(",");
  2447. print_socket_type(type);
  2448. qemu_log(",");
  2449. if (domain == AF_PACKET ||
  2450. (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
  2451. protocol = tswap16(protocol);
  2452. }
  2453. print_socket_protocol(domain, type, protocol);
  2454. qemu_log(")");
  2455. }
  2456. static void do_print_sockaddr(const char *name, abi_long arg1)
  2457. {
  2458. abi_ulong sockfd, addr, addrlen;
  2459. get_user_ualx(sockfd, arg1, 0);
  2460. get_user_ualx(addr, arg1, 1);
  2461. get_user_ualx(addrlen, arg1, 2);
  2462. qemu_log("%s(", name);
  2463. print_sockfd(sockfd, 0);
  2464. print_sockaddr(addr, addrlen, 0);
  2465. qemu_log(")");
  2466. }
  2467. static void do_print_listen(const char *name, abi_long arg1)
  2468. {
  2469. abi_ulong sockfd, backlog;
  2470. get_user_ualx(sockfd, arg1, 0);
  2471. get_user_ualx(backlog, arg1, 1);
  2472. qemu_log("%s(", name);
  2473. print_sockfd(sockfd, 0);
  2474. print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
  2475. qemu_log(")");
  2476. }
  2477. static void do_print_socketpair(const char *name, abi_long arg1)
  2478. {
  2479. abi_ulong domain, type, protocol, tab;
  2480. get_user_ualx(domain, arg1, 0);
  2481. get_user_ualx(type, arg1, 1);
  2482. get_user_ualx(protocol, arg1, 2);
  2483. get_user_ualx(tab, arg1, 3);
  2484. qemu_log("%s(", name);
  2485. print_socket_domain(domain);
  2486. qemu_log(",");
  2487. print_socket_type(type);
  2488. qemu_log(",");
  2489. print_socket_protocol(domain, type, protocol);
  2490. qemu_log(",");
  2491. print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
  2492. qemu_log(")");
  2493. }
  2494. static void do_print_sendrecv(const char *name, abi_long arg1)
  2495. {
  2496. abi_ulong sockfd, msg, len, flags;
  2497. get_user_ualx(sockfd, arg1, 0);
  2498. get_user_ualx(msg, arg1, 1);
  2499. get_user_ualx(len, arg1, 2);
  2500. get_user_ualx(flags, arg1, 3);
  2501. qemu_log("%s(", name);
  2502. print_sockfd(sockfd, 0);
  2503. print_buf(msg, len, 0);
  2504. print_raw_param(TARGET_ABI_FMT_ld, len, 0);
  2505. print_flags(msg_flags, flags, 1);
  2506. qemu_log(")");
  2507. }
  2508. static void do_print_msgaddr(const char *name, abi_long arg1)
  2509. {
  2510. abi_ulong sockfd, msg, len, flags, addr, addrlen;
  2511. get_user_ualx(sockfd, arg1, 0);
  2512. get_user_ualx(msg, arg1, 1);
  2513. get_user_ualx(len, arg1, 2);
  2514. get_user_ualx(flags, arg1, 3);
  2515. get_user_ualx(addr, arg1, 4);
  2516. get_user_ualx(addrlen, arg1, 5);
  2517. qemu_log("%s(", name);
  2518. print_sockfd(sockfd, 0);
  2519. print_buf(msg, len, 0);
  2520. print_raw_param(TARGET_ABI_FMT_ld, len, 0);
  2521. print_flags(msg_flags, flags, 0);
  2522. print_sockaddr(addr, addrlen, 0);
  2523. qemu_log(")");
  2524. }
  2525. static void do_print_shutdown(const char *name, abi_long arg1)
  2526. {
  2527. abi_ulong sockfd, how;
  2528. get_user_ualx(sockfd, arg1, 0);
  2529. get_user_ualx(how, arg1, 1);
  2530. qemu_log("shutdown(");
  2531. print_sockfd(sockfd, 0);
  2532. switch (how) {
  2533. case SHUT_RD:
  2534. qemu_log("SHUT_RD");
  2535. break;
  2536. case SHUT_WR:
  2537. qemu_log("SHUT_WR");
  2538. break;
  2539. case SHUT_RDWR:
  2540. qemu_log("SHUT_RDWR");
  2541. break;
  2542. default:
  2543. print_raw_param(TARGET_ABI_FMT_ld, how, 1);
  2544. break;
  2545. }
  2546. qemu_log(")");
  2547. }
  2548. static void do_print_msg(const char *name, abi_long arg1)
  2549. {
  2550. abi_ulong sockfd, msg, flags;
  2551. get_user_ualx(sockfd, arg1, 0);
  2552. get_user_ualx(msg, arg1, 1);
  2553. get_user_ualx(flags, arg1, 2);
  2554. qemu_log("%s(", name);
  2555. print_sockfd(sockfd, 0);
  2556. print_pointer(msg, 0);
  2557. print_flags(msg_flags, flags, 1);
  2558. qemu_log(")");
  2559. }
  2560. static void do_print_sockopt(const char *name, abi_long arg1)
  2561. {
  2562. abi_ulong sockfd, level, optname, optval, optlen;
  2563. get_user_ualx(sockfd, arg1, 0);
  2564. get_user_ualx(level, arg1, 1);
  2565. get_user_ualx(optname, arg1, 2);
  2566. get_user_ualx(optval, arg1, 3);
  2567. get_user_ualx(optlen, arg1, 4);
  2568. qemu_log("%s(", name);
  2569. print_sockfd(sockfd, 0);
  2570. switch (level) {
  2571. case SOL_TCP:
  2572. qemu_log("SOL_TCP,");
  2573. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2574. print_pointer(optval, 0);
  2575. break;
  2576. case SOL_UDP:
  2577. qemu_log("SOL_UDP,");
  2578. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2579. print_pointer(optval, 0);
  2580. break;
  2581. case SOL_IP:
  2582. qemu_log("SOL_IP,");
  2583. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2584. print_pointer(optval, 0);
  2585. break;
  2586. case SOL_RAW:
  2587. qemu_log("SOL_RAW,");
  2588. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2589. print_pointer(optval, 0);
  2590. break;
  2591. case TARGET_SOL_SOCKET:
  2592. qemu_log("SOL_SOCKET,");
  2593. switch (optname) {
  2594. case TARGET_SO_DEBUG:
  2595. qemu_log("SO_DEBUG,");
  2596. print_optint:
  2597. print_number(optval, 0);
  2598. break;
  2599. case TARGET_SO_REUSEADDR:
  2600. qemu_log("SO_REUSEADDR,");
  2601. goto print_optint;
  2602. case TARGET_SO_REUSEPORT:
  2603. qemu_log("SO_REUSEPORT,");
  2604. goto print_optint;
  2605. case TARGET_SO_TYPE:
  2606. qemu_log("SO_TYPE,");
  2607. goto print_optint;
  2608. case TARGET_SO_ERROR:
  2609. qemu_log("SO_ERROR,");
  2610. goto print_optint;
  2611. case TARGET_SO_DONTROUTE:
  2612. qemu_log("SO_DONTROUTE,");
  2613. goto print_optint;
  2614. case TARGET_SO_BROADCAST:
  2615. qemu_log("SO_BROADCAST,");
  2616. goto print_optint;
  2617. case TARGET_SO_SNDBUF:
  2618. qemu_log("SO_SNDBUF,");
  2619. goto print_optint;
  2620. case TARGET_SO_RCVBUF:
  2621. qemu_log("SO_RCVBUF,");
  2622. goto print_optint;
  2623. case TARGET_SO_KEEPALIVE:
  2624. qemu_log("SO_KEEPALIVE,");
  2625. goto print_optint;
  2626. case TARGET_SO_OOBINLINE:
  2627. qemu_log("SO_OOBINLINE,");
  2628. goto print_optint;
  2629. case TARGET_SO_NO_CHECK:
  2630. qemu_log("SO_NO_CHECK,");
  2631. goto print_optint;
  2632. case TARGET_SO_PRIORITY:
  2633. qemu_log("SO_PRIORITY,");
  2634. goto print_optint;
  2635. case TARGET_SO_BSDCOMPAT:
  2636. qemu_log("SO_BSDCOMPAT,");
  2637. goto print_optint;
  2638. case TARGET_SO_PASSCRED:
  2639. qemu_log("SO_PASSCRED,");
  2640. goto print_optint;
  2641. case TARGET_SO_TIMESTAMP:
  2642. qemu_log("SO_TIMESTAMP,");
  2643. goto print_optint;
  2644. case TARGET_SO_RCVLOWAT:
  2645. qemu_log("SO_RCVLOWAT,");
  2646. goto print_optint;
  2647. case TARGET_SO_RCVTIMEO:
  2648. qemu_log("SO_RCVTIMEO,");
  2649. print_timeval(optval, 0);
  2650. break;
  2651. case TARGET_SO_SNDTIMEO:
  2652. qemu_log("SO_SNDTIMEO,");
  2653. print_timeval(optval, 0);
  2654. break;
  2655. case TARGET_SO_ATTACH_FILTER: {
  2656. struct target_sock_fprog *fprog;
  2657. qemu_log("SO_ATTACH_FILTER,");
  2658. if (lock_user_struct(VERIFY_READ, fprog, optval, 0)) {
  2659. struct target_sock_filter *filter;
  2660. qemu_log("{");
  2661. if (lock_user_struct(VERIFY_READ, filter,
  2662. tswapal(fprog->filter), 0)) {
  2663. int i;
  2664. for (i = 0; i < tswap16(fprog->len) - 1; i++) {
  2665. qemu_log("[%d]{0x%x,%d,%d,0x%x},",
  2666. i, tswap16(filter[i].code),
  2667. filter[i].jt, filter[i].jf,
  2668. tswap32(filter[i].k));
  2669. }
  2670. qemu_log("[%d]{0x%x,%d,%d,0x%x}",
  2671. i, tswap16(filter[i].code),
  2672. filter[i].jt, filter[i].jf,
  2673. tswap32(filter[i].k));
  2674. } else {
  2675. qemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
  2676. }
  2677. qemu_log(",%d},", tswap16(fprog->len));
  2678. unlock_user(fprog, optval, 0);
  2679. } else {
  2680. print_pointer(optval, 0);
  2681. }
  2682. break;
  2683. }
  2684. default:
  2685. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2686. print_pointer(optval, 0);
  2687. break;
  2688. }
  2689. break;
  2690. case SOL_IPV6:
  2691. qemu_log("SOL_IPV6,");
  2692. switch (optname) {
  2693. case IPV6_MTU_DISCOVER:
  2694. qemu_log("IPV6_MTU_DISCOVER,");
  2695. goto print_optint;
  2696. case IPV6_MTU:
  2697. qemu_log("IPV6_MTU,");
  2698. goto print_optint;
  2699. case IPV6_V6ONLY:
  2700. qemu_log("IPV6_V6ONLY,");
  2701. goto print_optint;
  2702. case IPV6_RECVPKTINFO:
  2703. qemu_log("IPV6_RECVPKTINFO,");
  2704. goto print_optint;
  2705. case IPV6_UNICAST_HOPS:
  2706. qemu_log("IPV6_UNICAST_HOPS,");
  2707. goto print_optint;
  2708. case IPV6_MULTICAST_HOPS:
  2709. qemu_log("IPV6_MULTICAST_HOPS,");
  2710. goto print_optint;
  2711. case IPV6_MULTICAST_LOOP:
  2712. qemu_log("IPV6_MULTICAST_LOOP,");
  2713. goto print_optint;
  2714. case IPV6_RECVERR:
  2715. qemu_log("IPV6_RECVERR,");
  2716. goto print_optint;
  2717. case IPV6_RECVHOPLIMIT:
  2718. qemu_log("IPV6_RECVHOPLIMIT,");
  2719. goto print_optint;
  2720. case IPV6_2292HOPLIMIT:
  2721. qemu_log("IPV6_2292HOPLIMIT,");
  2722. goto print_optint;
  2723. case IPV6_CHECKSUM:
  2724. qemu_log("IPV6_CHECKSUM,");
  2725. goto print_optint;
  2726. case IPV6_ADDRFORM:
  2727. qemu_log("IPV6_ADDRFORM,");
  2728. goto print_optint;
  2729. case IPV6_2292PKTINFO:
  2730. qemu_log("IPV6_2292PKTINFO,");
  2731. goto print_optint;
  2732. case IPV6_RECVTCLASS:
  2733. qemu_log("IPV6_RECVTCLASS,");
  2734. goto print_optint;
  2735. case IPV6_RECVRTHDR:
  2736. qemu_log("IPV6_RECVRTHDR,");
  2737. goto print_optint;
  2738. case IPV6_2292RTHDR:
  2739. qemu_log("IPV6_2292RTHDR,");
  2740. goto print_optint;
  2741. case IPV6_RECVHOPOPTS:
  2742. qemu_log("IPV6_RECVHOPOPTS,");
  2743. goto print_optint;
  2744. case IPV6_2292HOPOPTS:
  2745. qemu_log("IPV6_2292HOPOPTS,");
  2746. goto print_optint;
  2747. case IPV6_RECVDSTOPTS:
  2748. qemu_log("IPV6_RECVDSTOPTS,");
  2749. goto print_optint;
  2750. case IPV6_2292DSTOPTS:
  2751. qemu_log("IPV6_2292DSTOPTS,");
  2752. goto print_optint;
  2753. case IPV6_TCLASS:
  2754. qemu_log("IPV6_TCLASS,");
  2755. goto print_optint;
  2756. case IPV6_ADDR_PREFERENCES:
  2757. qemu_log("IPV6_ADDR_PREFERENCES,");
  2758. goto print_optint;
  2759. #ifdef IPV6_RECVPATHMTU
  2760. case IPV6_RECVPATHMTU:
  2761. qemu_log("IPV6_RECVPATHMTU,");
  2762. goto print_optint;
  2763. #endif
  2764. #ifdef IPV6_TRANSPARENT
  2765. case IPV6_TRANSPARENT:
  2766. qemu_log("IPV6_TRANSPARENT,");
  2767. goto print_optint;
  2768. #endif
  2769. #ifdef IPV6_FREEBIND
  2770. case IPV6_FREEBIND:
  2771. qemu_log("IPV6_FREEBIND,");
  2772. goto print_optint;
  2773. #endif
  2774. #ifdef IPV6_RECVORIGDSTADDR
  2775. case IPV6_RECVORIGDSTADDR:
  2776. qemu_log("IPV6_RECVORIGDSTADDR,");
  2777. goto print_optint;
  2778. #endif
  2779. case IPV6_PKTINFO:
  2780. qemu_log("IPV6_PKTINFO,");
  2781. print_pointer(optval, 0);
  2782. break;
  2783. case IPV6_ADD_MEMBERSHIP:
  2784. qemu_log("IPV6_ADD_MEMBERSHIP,");
  2785. print_pointer(optval, 0);
  2786. break;
  2787. case IPV6_DROP_MEMBERSHIP:
  2788. qemu_log("IPV6_DROP_MEMBERSHIP,");
  2789. print_pointer(optval, 0);
  2790. break;
  2791. default:
  2792. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2793. print_pointer(optval, 0);
  2794. break;
  2795. }
  2796. break;
  2797. default:
  2798. print_raw_param(TARGET_ABI_FMT_ld, level, 0);
  2799. print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
  2800. print_pointer(optval, 0);
  2801. break;
  2802. }
  2803. print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
  2804. qemu_log(")");
  2805. }
  2806. #define PRINT_SOCKOP(name, func) \
  2807. [TARGET_SYS_##name] = { #name, func }
  2808. static struct {
  2809. const char *name;
  2810. void (*print)(const char *, abi_long);
  2811. } scall[] = {
  2812. PRINT_SOCKOP(SOCKET, do_print_socket),
  2813. PRINT_SOCKOP(BIND, do_print_sockaddr),
  2814. PRINT_SOCKOP(CONNECT, do_print_sockaddr),
  2815. PRINT_SOCKOP(LISTEN, do_print_listen),
  2816. PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
  2817. PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
  2818. PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
  2819. PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
  2820. PRINT_SOCKOP(SEND, do_print_sendrecv),
  2821. PRINT_SOCKOP(RECV, do_print_sendrecv),
  2822. PRINT_SOCKOP(SENDTO, do_print_msgaddr),
  2823. PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
  2824. PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
  2825. PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
  2826. PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
  2827. PRINT_SOCKOP(SENDMSG, do_print_msg),
  2828. PRINT_SOCKOP(RECVMSG, do_print_msg),
  2829. PRINT_SOCKOP(ACCEPT4, NULL),
  2830. PRINT_SOCKOP(RECVMMSG, NULL),
  2831. PRINT_SOCKOP(SENDMMSG, NULL),
  2832. };
  2833. static void
  2834. print_socketcall(CPUArchState *cpu_env, const struct syscallname *name,
  2835. abi_long arg0, abi_long arg1, abi_long arg2,
  2836. abi_long arg3, abi_long arg4, abi_long arg5)
  2837. {
  2838. if (arg0 >= 0 && arg0 < ARRAY_SIZE(scall) && scall[arg0].print) {
  2839. scall[arg0].print(scall[arg0].name, arg1);
  2840. return;
  2841. }
  2842. print_syscall_prologue(name);
  2843. print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
  2844. print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
  2845. print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
  2846. print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
  2847. print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
  2848. print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
  2849. print_syscall_epilogue(name);
  2850. }
  2851. #endif
  2852. #if defined(TARGET_NR_bind)
  2853. static void
  2854. print_bind(CPUArchState *cpu_env, const struct syscallname *name,
  2855. abi_long arg0, abi_long arg1, abi_long arg2,
  2856. abi_long arg3, abi_long arg4, abi_long arg5)
  2857. {
  2858. print_syscall_prologue(name);
  2859. print_sockfd(arg0, 0);
  2860. print_sockaddr(arg1, arg2, 1);
  2861. print_syscall_epilogue(name);
  2862. }
  2863. #endif
  2864. #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
  2865. defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
  2866. static void
  2867. print_stat(CPUArchState *cpu_env, const struct syscallname *name,
  2868. abi_long arg0, abi_long arg1, abi_long arg2,
  2869. abi_long arg3, abi_long arg4, abi_long arg5)
  2870. {
  2871. print_syscall_prologue(name);
  2872. print_string(arg0, 0);
  2873. print_pointer(arg1, 1);
  2874. print_syscall_epilogue(name);
  2875. }
  2876. #define print_lstat print_stat
  2877. #define print_stat64 print_stat
  2878. #define print_lstat64 print_stat
  2879. #endif
  2880. #if defined(TARGET_NR_madvise)
  2881. static struct enums madvise_advice[] = {
  2882. ENUM_TARGET(MADV_NORMAL),
  2883. ENUM_TARGET(MADV_RANDOM),
  2884. ENUM_TARGET(MADV_SEQUENTIAL),
  2885. ENUM_TARGET(MADV_WILLNEED),
  2886. ENUM_TARGET(MADV_DONTNEED),
  2887. ENUM_TARGET(MADV_FREE),
  2888. ENUM_TARGET(MADV_REMOVE),
  2889. ENUM_TARGET(MADV_DONTFORK),
  2890. ENUM_TARGET(MADV_DOFORK),
  2891. ENUM_TARGET(MADV_MERGEABLE),
  2892. ENUM_TARGET(MADV_UNMERGEABLE),
  2893. ENUM_TARGET(MADV_HUGEPAGE),
  2894. ENUM_TARGET(MADV_NOHUGEPAGE),
  2895. ENUM_TARGET(MADV_DONTDUMP),
  2896. ENUM_TARGET(MADV_DODUMP),
  2897. ENUM_TARGET(MADV_WIPEONFORK),
  2898. ENUM_TARGET(MADV_KEEPONFORK),
  2899. ENUM_TARGET(MADV_COLD),
  2900. ENUM_TARGET(MADV_PAGEOUT),
  2901. ENUM_TARGET(MADV_POPULATE_READ),
  2902. ENUM_TARGET(MADV_POPULATE_WRITE),
  2903. ENUM_TARGET(MADV_DONTNEED_LOCKED),
  2904. ENUM_END,
  2905. };
  2906. static void
  2907. print_madvise(CPUArchState *cpu_env, const struct syscallname *name,
  2908. abi_long arg0, abi_long arg1, abi_long arg2,
  2909. abi_long arg3, abi_long arg4, abi_long arg5)
  2910. {
  2911. print_syscall_prologue(name);
  2912. print_pointer(arg0, 0);
  2913. print_raw_param("%d", arg1, 0);
  2914. print_enums(madvise_advice, arg2, 1);
  2915. print_syscall_epilogue(name);
  2916. }
  2917. #endif
  2918. #if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
  2919. static void
  2920. print_fstat(CPUArchState *cpu_env, const struct syscallname *name,
  2921. abi_long arg0, abi_long arg1, abi_long arg2,
  2922. abi_long arg3, abi_long arg4, abi_long arg5)
  2923. {
  2924. print_syscall_prologue(name);
  2925. print_raw_param("%d", arg0, 0);
  2926. print_pointer(arg1, 1);
  2927. print_syscall_epilogue(name);
  2928. }
  2929. #define print_fstat64 print_fstat
  2930. #endif
  2931. #ifdef TARGET_NR_mkdir
  2932. static void
  2933. print_mkdir(CPUArchState *cpu_env, const struct syscallname *name,
  2934. abi_long arg0, abi_long arg1, abi_long arg2,
  2935. abi_long arg3, abi_long arg4, abi_long arg5)
  2936. {
  2937. print_syscall_prologue(name);
  2938. print_string(arg0, 0);
  2939. print_file_mode(arg1, 1);
  2940. print_syscall_epilogue(name);
  2941. }
  2942. #endif
  2943. #ifdef TARGET_NR_mkdirat
  2944. static void
  2945. print_mkdirat(CPUArchState *cpu_env, const struct syscallname *name,
  2946. abi_long arg0, abi_long arg1, abi_long arg2,
  2947. abi_long arg3, abi_long arg4, abi_long arg5)
  2948. {
  2949. print_syscall_prologue(name);
  2950. print_at_dirfd(arg0, 0);
  2951. print_string(arg1, 0);
  2952. print_file_mode(arg2, 1);
  2953. print_syscall_epilogue(name);
  2954. }
  2955. #endif
  2956. #ifdef TARGET_NR_rmdir
  2957. static void
  2958. print_rmdir(CPUArchState *cpu_env, const struct syscallname *name,
  2959. abi_long arg0, abi_long arg1, abi_long arg2,
  2960. abi_long arg3, abi_long arg4, abi_long arg5)
  2961. {
  2962. print_syscall_prologue(name);
  2963. print_string(arg0, 0);
  2964. print_syscall_epilogue(name);
  2965. }
  2966. #endif
  2967. #ifdef TARGET_NR_rt_sigaction
  2968. static void
  2969. print_rt_sigaction(CPUArchState *cpu_env, const struct syscallname *name,
  2970. abi_long arg0, abi_long arg1, abi_long arg2,
  2971. abi_long arg3, abi_long arg4, abi_long arg5)
  2972. {
  2973. print_syscall_prologue(name);
  2974. print_signal(arg0, 0);
  2975. print_pointer(arg1, 0);
  2976. print_pointer(arg2, 1);
  2977. print_syscall_epilogue(name);
  2978. }
  2979. #endif
  2980. #ifdef TARGET_NR_rt_sigprocmask
  2981. static void
  2982. print_rt_sigprocmask(CPUArchState *cpu_env, const struct syscallname *name,
  2983. abi_long arg0, abi_long arg1, abi_long arg2,
  2984. abi_long arg3, abi_long arg4, abi_long arg5)
  2985. {
  2986. const char *how = "UNKNOWN";
  2987. print_syscall_prologue(name);
  2988. switch(arg0) {
  2989. case TARGET_SIG_BLOCK: how = "SIG_BLOCK"; break;
  2990. case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
  2991. case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
  2992. }
  2993. qemu_log("%s,", how);
  2994. print_pointer(arg1, 0);
  2995. print_pointer(arg2, 0);
  2996. print_raw_param("%u", arg3, 1);
  2997. print_syscall_epilogue(name);
  2998. }
  2999. #endif
  3000. #ifdef TARGET_NR_rt_sigqueueinfo
  3001. static void
  3002. print_rt_sigqueueinfo(CPUArchState *cpu_env, const struct syscallname *name,
  3003. abi_long arg0, abi_long arg1, abi_long arg2,
  3004. abi_long arg3, abi_long arg4, abi_long arg5)
  3005. {
  3006. void *p;
  3007. target_siginfo_t uinfo;
  3008. print_syscall_prologue(name);
  3009. print_raw_param("%d", arg0, 0);
  3010. print_signal(arg1, 0);
  3011. p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
  3012. if (p) {
  3013. get_target_siginfo(&uinfo, p);
  3014. print_siginfo(&uinfo);
  3015. unlock_user(p, arg2, 0);
  3016. } else {
  3017. print_pointer(arg2, 1);
  3018. }
  3019. print_syscall_epilogue(name);
  3020. }
  3021. #endif
  3022. #ifdef TARGET_NR_rt_tgsigqueueinfo
  3023. static void
  3024. print_rt_tgsigqueueinfo(CPUArchState *cpu_env, const struct syscallname *name,
  3025. abi_long arg0, abi_long arg1, abi_long arg2,
  3026. abi_long arg3, abi_long arg4, abi_long arg5)
  3027. {
  3028. void *p;
  3029. target_siginfo_t uinfo;
  3030. print_syscall_prologue(name);
  3031. print_raw_param("%d", arg0, 0);
  3032. print_raw_param("%d", arg1, 0);
  3033. print_signal(arg2, 0);
  3034. p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
  3035. if (p) {
  3036. get_target_siginfo(&uinfo, p);
  3037. print_siginfo(&uinfo);
  3038. unlock_user(p, arg3, 0);
  3039. } else {
  3040. print_pointer(arg3, 1);
  3041. }
  3042. print_syscall_epilogue(name);
  3043. }
  3044. #endif
  3045. #ifdef TARGET_NR_syslog
  3046. static void
  3047. print_syslog_action(abi_ulong arg, int last)
  3048. {
  3049. const char *type;
  3050. switch (arg) {
  3051. case TARGET_SYSLOG_ACTION_CLOSE: {
  3052. type = "SYSLOG_ACTION_CLOSE";
  3053. break;
  3054. }
  3055. case TARGET_SYSLOG_ACTION_OPEN: {
  3056. type = "SYSLOG_ACTION_OPEN";
  3057. break;
  3058. }
  3059. case TARGET_SYSLOG_ACTION_READ: {
  3060. type = "SYSLOG_ACTION_READ";
  3061. break;
  3062. }
  3063. case TARGET_SYSLOG_ACTION_READ_ALL: {
  3064. type = "SYSLOG_ACTION_READ_ALL";
  3065. break;
  3066. }
  3067. case TARGET_SYSLOG_ACTION_READ_CLEAR: {
  3068. type = "SYSLOG_ACTION_READ_CLEAR";
  3069. break;
  3070. }
  3071. case TARGET_SYSLOG_ACTION_CLEAR: {
  3072. type = "SYSLOG_ACTION_CLEAR";
  3073. break;
  3074. }
  3075. case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
  3076. type = "SYSLOG_ACTION_CONSOLE_OFF";
  3077. break;
  3078. }
  3079. case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
  3080. type = "SYSLOG_ACTION_CONSOLE_ON";
  3081. break;
  3082. }
  3083. case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
  3084. type = "SYSLOG_ACTION_CONSOLE_LEVEL";
  3085. break;
  3086. }
  3087. case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
  3088. type = "SYSLOG_ACTION_SIZE_UNREAD";
  3089. break;
  3090. }
  3091. case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
  3092. type = "SYSLOG_ACTION_SIZE_BUFFER";
  3093. break;
  3094. }
  3095. default: {
  3096. print_raw_param("%ld", arg, last);
  3097. return;
  3098. }
  3099. }
  3100. qemu_log("%s%s", type, get_comma(last));
  3101. }
  3102. static void
  3103. print_syslog(CPUArchState *cpu_env, const struct syscallname *name,
  3104. abi_long arg0, abi_long arg1, abi_long arg2,
  3105. abi_long arg3, abi_long arg4, abi_long arg5)
  3106. {
  3107. print_syscall_prologue(name);
  3108. print_syslog_action(arg0, 0);
  3109. print_pointer(arg1, 0);
  3110. print_raw_param("%d", arg2, 1);
  3111. print_syscall_epilogue(name);
  3112. }
  3113. #endif
  3114. #ifdef TARGET_NR_mknod
  3115. static void
  3116. print_mknod(CPUArchState *cpu_env, const struct syscallname *name,
  3117. abi_long arg0, abi_long arg1, abi_long arg2,
  3118. abi_long arg3, abi_long arg4, abi_long arg5)
  3119. {
  3120. int hasdev = (arg1 & (S_IFCHR|S_IFBLK));
  3121. print_syscall_prologue(name);
  3122. print_string(arg0, 0);
  3123. print_file_mode(arg1, (hasdev == 0));
  3124. if (hasdev) {
  3125. print_raw_param("makedev(%d", major(arg2), 0);
  3126. print_raw_param("%d)", minor(arg2), 1);
  3127. }
  3128. print_syscall_epilogue(name);
  3129. }
  3130. #endif
  3131. #ifdef TARGET_NR_mknodat
  3132. static void
  3133. print_mknodat(CPUArchState *cpu_env, const struct syscallname *name,
  3134. abi_long arg0, abi_long arg1, abi_long arg2,
  3135. abi_long arg3, abi_long arg4, abi_long arg5)
  3136. {
  3137. int hasdev = (arg2 & (S_IFCHR|S_IFBLK));
  3138. print_syscall_prologue(name);
  3139. print_at_dirfd(arg0, 0);
  3140. print_string(arg1, 0);
  3141. print_file_mode(arg2, (hasdev == 0));
  3142. if (hasdev) {
  3143. print_raw_param("makedev(%d", major(arg3), 0);
  3144. print_raw_param("%d)", minor(arg3), 1);
  3145. }
  3146. print_syscall_epilogue(name);
  3147. }
  3148. #endif
  3149. #ifdef TARGET_NR_mq_open
  3150. static void
  3151. print_mq_open(CPUArchState *cpu_env, const struct syscallname *name,
  3152. abi_long arg0, abi_long arg1, abi_long arg2,
  3153. abi_long arg3, abi_long arg4, abi_long arg5)
  3154. {
  3155. int is_creat = (arg1 & TARGET_O_CREAT);
  3156. print_syscall_prologue(name);
  3157. print_string(arg0, 0);
  3158. print_open_flags(arg1, (is_creat == 0));
  3159. if (is_creat) {
  3160. print_file_mode(arg2, 0);
  3161. print_pointer(arg3, 1);
  3162. }
  3163. print_syscall_epilogue(name);
  3164. }
  3165. #endif
  3166. #ifdef TARGET_NR_open
  3167. static void
  3168. print_open(CPUArchState *cpu_env, const struct syscallname *name,
  3169. abi_long arg0, abi_long arg1, abi_long arg2,
  3170. abi_long arg3, abi_long arg4, abi_long arg5)
  3171. {
  3172. int is_creat = (arg1 & TARGET_O_CREAT);
  3173. print_syscall_prologue(name);
  3174. print_string(arg0, 0);
  3175. print_open_flags(arg1, (is_creat == 0));
  3176. if (is_creat)
  3177. print_file_mode(arg2, 1);
  3178. print_syscall_epilogue(name);
  3179. }
  3180. #endif
  3181. #ifdef TARGET_NR_openat
  3182. static void
  3183. print_openat(CPUArchState *cpu_env, const struct syscallname *name,
  3184. abi_long arg0, abi_long arg1, abi_long arg2,
  3185. abi_long arg3, abi_long arg4, abi_long arg5)
  3186. {
  3187. int is_creat = (arg2 & TARGET_O_CREAT);
  3188. print_syscall_prologue(name);
  3189. print_at_dirfd(arg0, 0);
  3190. print_string(arg1, 0);
  3191. print_open_flags(arg2, (is_creat == 0));
  3192. if (is_creat)
  3193. print_file_mode(arg3, 1);
  3194. print_syscall_epilogue(name);
  3195. }
  3196. #endif
  3197. #ifdef TARGET_NR_pidfd_send_signal
  3198. static void
  3199. print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name,
  3200. abi_long arg0, abi_long arg1, abi_long arg2,
  3201. abi_long arg3, abi_long arg4, abi_long arg5)
  3202. {
  3203. void *p;
  3204. target_siginfo_t uinfo;
  3205. print_syscall_prologue(name);
  3206. print_raw_param("%d", arg0, 0);
  3207. print_signal(arg1, 0);
  3208. p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
  3209. if (p) {
  3210. get_target_siginfo(&uinfo, p);
  3211. print_siginfo(&uinfo);
  3212. unlock_user(p, arg2, 0);
  3213. } else {
  3214. print_pointer(arg2, 0);
  3215. }
  3216. print_raw_param("%u", arg3, 1);
  3217. print_syscall_epilogue(name);
  3218. }
  3219. #endif
  3220. #ifdef TARGET_NR_mq_unlink
  3221. static void
  3222. print_mq_unlink(CPUArchState *cpu_env, const struct syscallname *name,
  3223. abi_long arg0, abi_long arg1, abi_long arg2,
  3224. abi_long arg3, abi_long arg4, abi_long arg5)
  3225. {
  3226. print_syscall_prologue(name);
  3227. print_string(arg0, 1);
  3228. print_syscall_epilogue(name);
  3229. }
  3230. #endif
  3231. #if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
  3232. static void
  3233. print_fstatat64(CPUArchState *cpu_env, const struct syscallname *name,
  3234. abi_long arg0, abi_long arg1, abi_long arg2,
  3235. abi_long arg3, abi_long arg4, abi_long arg5)
  3236. {
  3237. print_syscall_prologue(name);
  3238. print_at_dirfd(arg0, 0);
  3239. print_string(arg1, 0);
  3240. print_pointer(arg2, 0);
  3241. print_flags(at_file_flags, arg3, 1);
  3242. print_syscall_epilogue(name);
  3243. }
  3244. #define print_newfstatat print_fstatat64
  3245. #endif
  3246. #ifdef TARGET_NR_readlink
  3247. static void
  3248. print_readlink(CPUArchState *cpu_env, const struct syscallname *name,
  3249. abi_long arg0, abi_long arg1, abi_long arg2,
  3250. abi_long arg3, abi_long arg4, abi_long arg5)
  3251. {
  3252. print_syscall_prologue(name);
  3253. print_string(arg0, 0);
  3254. print_pointer(arg1, 0);
  3255. print_raw_param("%u", arg2, 1);
  3256. print_syscall_epilogue(name);
  3257. }
  3258. #endif
  3259. #ifdef TARGET_NR_readlinkat
  3260. static void
  3261. print_readlinkat(CPUArchState *cpu_env, const struct syscallname *name,
  3262. abi_long arg0, abi_long arg1, abi_long arg2,
  3263. abi_long arg3, abi_long arg4, abi_long arg5)
  3264. {
  3265. print_syscall_prologue(name);
  3266. print_at_dirfd(arg0, 0);
  3267. print_string(arg1, 0);
  3268. print_pointer(arg2, 0);
  3269. print_raw_param("%u", arg3, 1);
  3270. print_syscall_epilogue(name);
  3271. }
  3272. #endif
  3273. #ifdef TARGET_NR_rename
  3274. static void
  3275. print_rename(CPUArchState *cpu_env, const struct syscallname *name,
  3276. abi_long arg0, abi_long arg1, abi_long arg2,
  3277. abi_long arg3, abi_long arg4, abi_long arg5)
  3278. {
  3279. print_syscall_prologue(name);
  3280. print_string(arg0, 0);
  3281. print_string(arg1, 1);
  3282. print_syscall_epilogue(name);
  3283. }
  3284. #endif
  3285. #ifdef TARGET_NR_renameat
  3286. static void
  3287. print_renameat(CPUArchState *cpu_env, const struct syscallname *name,
  3288. abi_long arg0, abi_long arg1, abi_long arg2,
  3289. abi_long arg3, abi_long arg4, abi_long arg5)
  3290. {
  3291. print_syscall_prologue(name);
  3292. print_at_dirfd(arg0, 0);
  3293. print_string(arg1, 0);
  3294. print_at_dirfd(arg2, 0);
  3295. print_string(arg3, 1);
  3296. print_syscall_epilogue(name);
  3297. }
  3298. #endif
  3299. #ifdef TARGET_NR_statfs
  3300. static void
  3301. print_statfs(CPUArchState *cpu_env, const struct syscallname *name,
  3302. abi_long arg0, abi_long arg1, abi_long arg2,
  3303. abi_long arg3, abi_long arg4, abi_long arg5)
  3304. {
  3305. print_syscall_prologue(name);
  3306. print_string(arg0, 0);
  3307. print_pointer(arg1, 1);
  3308. print_syscall_epilogue(name);
  3309. }
  3310. #endif
  3311. #ifdef TARGET_NR_statfs64
  3312. static void
  3313. print_statfs64(CPUArchState *cpu_env, const struct syscallname *name,
  3314. abi_long arg0, abi_long arg1, abi_long arg2,
  3315. abi_long arg3, abi_long arg4, abi_long arg5)
  3316. {
  3317. print_syscall_prologue(name);
  3318. print_string(arg0, 0);
  3319. print_pointer(arg1, 1);
  3320. print_syscall_epilogue(name);
  3321. }
  3322. #endif
  3323. #ifdef TARGET_NR_symlink
  3324. static void
  3325. print_symlink(CPUArchState *cpu_env, const struct syscallname *name,
  3326. abi_long arg0, abi_long arg1, abi_long arg2,
  3327. abi_long arg3, abi_long arg4, abi_long arg5)
  3328. {
  3329. print_syscall_prologue(name);
  3330. print_string(arg0, 0);
  3331. print_string(arg1, 1);
  3332. print_syscall_epilogue(name);
  3333. }
  3334. #endif
  3335. #ifdef TARGET_NR_symlinkat
  3336. static void
  3337. print_symlinkat(CPUArchState *cpu_env, const struct syscallname *name,
  3338. abi_long arg0, abi_long arg1, abi_long arg2,
  3339. abi_long arg3, abi_long arg4, abi_long arg5)
  3340. {
  3341. print_syscall_prologue(name);
  3342. print_string(arg0, 0);
  3343. print_at_dirfd(arg1, 0);
  3344. print_string(arg2, 1);
  3345. print_syscall_epilogue(name);
  3346. }
  3347. #endif
  3348. #ifdef TARGET_NR_mount
  3349. static void
  3350. print_mount(CPUArchState *cpu_env, const struct syscallname *name,
  3351. abi_long arg0, abi_long arg1, abi_long arg2,
  3352. abi_long arg3, abi_long arg4, abi_long arg5)
  3353. {
  3354. print_syscall_prologue(name);
  3355. print_string(arg0, 0);
  3356. print_string(arg1, 0);
  3357. print_string(arg2, 0);
  3358. print_flags(mount_flags, arg3, 0);
  3359. print_pointer(arg4, 1);
  3360. print_syscall_epilogue(name);
  3361. }
  3362. #endif
  3363. #ifdef TARGET_NR_umount
  3364. static void
  3365. print_umount(CPUArchState *cpu_env, const struct syscallname *name,
  3366. abi_long arg0, abi_long arg1, abi_long arg2,
  3367. abi_long arg3, abi_long arg4, abi_long arg5)
  3368. {
  3369. print_syscall_prologue(name);
  3370. print_string(arg0, 1);
  3371. print_syscall_epilogue(name);
  3372. }
  3373. #endif
  3374. #ifdef TARGET_NR_umount2
  3375. static void
  3376. print_umount2(CPUArchState *cpu_env, const struct syscallname *name,
  3377. abi_long arg0, abi_long arg1, abi_long arg2,
  3378. abi_long arg3, abi_long arg4, abi_long arg5)
  3379. {
  3380. print_syscall_prologue(name);
  3381. print_string(arg0, 0);
  3382. print_flags(umount2_flags, arg1, 1);
  3383. print_syscall_epilogue(name);
  3384. }
  3385. #endif
  3386. #ifdef TARGET_NR_unlink
  3387. static void
  3388. print_unlink(CPUArchState *cpu_env, const struct syscallname *name,
  3389. abi_long arg0, abi_long arg1, abi_long arg2,
  3390. abi_long arg3, abi_long arg4, abi_long arg5)
  3391. {
  3392. print_syscall_prologue(name);
  3393. print_string(arg0, 1);
  3394. print_syscall_epilogue(name);
  3395. }
  3396. #endif
  3397. #ifdef TARGET_NR_unlinkat
  3398. static void
  3399. print_unlinkat(CPUArchState *cpu_env, const struct syscallname *name,
  3400. abi_long arg0, abi_long arg1, abi_long arg2,
  3401. abi_long arg3, abi_long arg4, abi_long arg5)
  3402. {
  3403. print_syscall_prologue(name);
  3404. print_at_dirfd(arg0, 0);
  3405. print_string(arg1, 0);
  3406. print_flags(unlinkat_flags, arg2, 1);
  3407. print_syscall_epilogue(name);
  3408. }
  3409. #endif
  3410. #ifdef TARGET_NR_unshare
  3411. static void
  3412. print_unshare(CPUArchState *cpu_env, const struct syscallname *name,
  3413. abi_long arg0, abi_long arg1, abi_long arg2,
  3414. abi_long arg3, abi_long arg4, abi_long arg5)
  3415. {
  3416. print_syscall_prologue(name);
  3417. print_flags(clone_flags, arg0, 1);
  3418. print_syscall_epilogue(name);
  3419. }
  3420. #endif
  3421. #ifdef TARGET_NR_clock_nanosleep
  3422. static void
  3423. print_clock_nanosleep(CPUArchState *cpu_env, const struct syscallname *name,
  3424. abi_long arg0, abi_long arg1, abi_long arg2,
  3425. abi_long arg3, abi_long arg4, abi_long arg5)
  3426. {
  3427. print_syscall_prologue(name);
  3428. print_enums(clockids, arg0, 0);
  3429. print_raw_param("%d", arg1, 0);
  3430. print_timespec(arg2, 0);
  3431. print_timespec(arg3, 1);
  3432. print_syscall_epilogue(name);
  3433. }
  3434. #endif
  3435. #ifdef TARGET_NR_utime
  3436. static void
  3437. print_utime(CPUArchState *cpu_env, const struct syscallname *name,
  3438. abi_long arg0, abi_long arg1, abi_long arg2,
  3439. abi_long arg3, abi_long arg4, abi_long arg5)
  3440. {
  3441. print_syscall_prologue(name);
  3442. print_string(arg0, 0);
  3443. print_pointer(arg1, 1);
  3444. print_syscall_epilogue(name);
  3445. }
  3446. #endif
  3447. #ifdef TARGET_NR_utimes
  3448. static void
  3449. print_utimes(CPUArchState *cpu_env, const struct syscallname *name,
  3450. abi_long arg0, abi_long arg1, abi_long arg2,
  3451. abi_long arg3, abi_long arg4, abi_long arg5)
  3452. {
  3453. print_syscall_prologue(name);
  3454. print_string(arg0, 0);
  3455. print_pointer(arg1, 1);
  3456. print_syscall_epilogue(name);
  3457. }
  3458. #endif
  3459. #ifdef TARGET_NR_utimensat
  3460. static void
  3461. print_utimensat(CPUArchState *cpu_env, const struct syscallname *name,
  3462. abi_long arg0, abi_long arg1, abi_long arg2,
  3463. abi_long arg3, abi_long arg4, abi_long arg5)
  3464. {
  3465. print_syscall_prologue(name);
  3466. print_at_dirfd(arg0, 0);
  3467. print_string(arg1, 0);
  3468. print_pointer(arg2, 0);
  3469. print_flags(at_file_flags, arg3, 1);
  3470. print_syscall_epilogue(name);
  3471. }
  3472. #endif
  3473. #if defined(TARGET_NR_mmap) || defined(TARGET_NR_mmap2)
  3474. static void
  3475. print_mmap(CPUArchState *cpu_env, const struct syscallname *name,
  3476. abi_long arg0, abi_long arg1, abi_long arg2,
  3477. abi_long arg3, abi_long arg4, abi_long arg5)
  3478. {
  3479. print_syscall_prologue(name);
  3480. print_pointer(arg0, 0);
  3481. print_raw_param("%d", arg1, 0);
  3482. print_flags(mmap_prot_flags, arg2, 0);
  3483. print_flags(mmap_flags, arg3, 0);
  3484. print_raw_param("%d", arg4, 0);
  3485. print_raw_param("%#x", arg5, 1);
  3486. print_syscall_epilogue(name);
  3487. }
  3488. #define print_mmap2 print_mmap
  3489. #endif
  3490. #ifdef TARGET_NR_mprotect
  3491. static void
  3492. print_mprotect(CPUArchState *cpu_env, const struct syscallname *name,
  3493. abi_long arg0, abi_long arg1, abi_long arg2,
  3494. abi_long arg3, abi_long arg4, abi_long arg5)
  3495. {
  3496. print_syscall_prologue(name);
  3497. print_pointer(arg0, 0);
  3498. print_raw_param("%d", arg1, 0);
  3499. print_flags(mmap_prot_flags, arg2, 1);
  3500. print_syscall_epilogue(name);
  3501. }
  3502. #endif
  3503. #ifdef TARGET_NR_munmap
  3504. static void
  3505. print_munmap(CPUArchState *cpu_env, const struct syscallname *name,
  3506. abi_long arg0, abi_long arg1, abi_long arg2,
  3507. abi_long arg3, abi_long arg4, abi_long arg5)
  3508. {
  3509. print_syscall_prologue(name);
  3510. print_pointer(arg0, 0);
  3511. print_raw_param("%d", arg1, 1);
  3512. print_syscall_epilogue(name);
  3513. }
  3514. #endif
  3515. #ifdef TARGET_NR_futex
  3516. static void print_futex_op(int cmd, int last)
  3517. {
  3518. static const char * const futex_names[] = {
  3519. #define NAME(X) [X] = #X
  3520. NAME(FUTEX_WAIT),
  3521. NAME(FUTEX_WAKE),
  3522. NAME(FUTEX_FD),
  3523. NAME(FUTEX_REQUEUE),
  3524. NAME(FUTEX_CMP_REQUEUE),
  3525. NAME(FUTEX_WAKE_OP),
  3526. NAME(FUTEX_LOCK_PI),
  3527. NAME(FUTEX_UNLOCK_PI),
  3528. NAME(FUTEX_TRYLOCK_PI),
  3529. NAME(FUTEX_WAIT_BITSET),
  3530. NAME(FUTEX_WAKE_BITSET),
  3531. NAME(FUTEX_WAIT_REQUEUE_PI),
  3532. NAME(FUTEX_CMP_REQUEUE_PI),
  3533. NAME(FUTEX_LOCK_PI2),
  3534. #undef NAME
  3535. };
  3536. unsigned base_cmd = cmd & FUTEX_CMD_MASK;
  3537. if (base_cmd < ARRAY_SIZE(futex_names)) {
  3538. qemu_log("%s%s%s",
  3539. (cmd & FUTEX_PRIVATE_FLAG ? "FUTEX_PRIVATE_FLAG|" : ""),
  3540. (cmd & FUTEX_CLOCK_REALTIME ? "FUTEX_CLOCK_REALTIME|" : ""),
  3541. futex_names[base_cmd]);
  3542. } else {
  3543. qemu_log("0x%x", cmd);
  3544. }
  3545. }
  3546. static void
  3547. print_futex(CPUArchState *cpu_env, const struct syscallname *name,
  3548. abi_long arg0, abi_long arg1, abi_long arg2,
  3549. abi_long arg3, abi_long arg4, abi_long arg5)
  3550. {
  3551. abi_long op = arg1 & FUTEX_CMD_MASK;
  3552. print_syscall_prologue(name);
  3553. print_pointer(arg0, 0);
  3554. print_futex_op(arg1, 0);
  3555. print_raw_param(",%d", arg2, 0);
  3556. switch (op) {
  3557. case FUTEX_WAIT:
  3558. case FUTEX_WAIT_BITSET:
  3559. case FUTEX_LOCK_PI:
  3560. case FUTEX_LOCK_PI2:
  3561. case FUTEX_WAIT_REQUEUE_PI:
  3562. print_timespec(arg3, 0);
  3563. break;
  3564. default:
  3565. print_pointer(arg3, 0);
  3566. break;
  3567. }
  3568. print_pointer(arg4, 0);
  3569. print_raw_param("%d", arg4, 1);
  3570. print_syscall_epilogue(name);
  3571. }
  3572. #endif
  3573. #ifdef TARGET_NR_prlimit64
  3574. static const char *target_ressource_string(abi_ulong r)
  3575. {
  3576. #define RET_RES_ENTRY(res) case TARGET_##res: return #res;
  3577. switch (r) {
  3578. RET_RES_ENTRY(RLIMIT_AS);
  3579. RET_RES_ENTRY(RLIMIT_CORE);
  3580. RET_RES_ENTRY(RLIMIT_CPU);
  3581. RET_RES_ENTRY(RLIMIT_DATA);
  3582. RET_RES_ENTRY(RLIMIT_FSIZE);
  3583. RET_RES_ENTRY(RLIMIT_LOCKS);
  3584. RET_RES_ENTRY(RLIMIT_MEMLOCK);
  3585. RET_RES_ENTRY(RLIMIT_MSGQUEUE);
  3586. RET_RES_ENTRY(RLIMIT_NICE);
  3587. RET_RES_ENTRY(RLIMIT_NOFILE);
  3588. RET_RES_ENTRY(RLIMIT_NPROC);
  3589. RET_RES_ENTRY(RLIMIT_RSS);
  3590. RET_RES_ENTRY(RLIMIT_RTPRIO);
  3591. #ifdef RLIMIT_RTTIME
  3592. RET_RES_ENTRY(RLIMIT_RTTIME);
  3593. #endif
  3594. RET_RES_ENTRY(RLIMIT_SIGPENDING);
  3595. RET_RES_ENTRY(RLIMIT_STACK);
  3596. default:
  3597. return NULL;
  3598. }
  3599. #undef RET_RES_ENTRY
  3600. }
  3601. static void
  3602. print_rlimit64(abi_ulong rlim_addr, int last)
  3603. {
  3604. if (rlim_addr) {
  3605. struct target_rlimit64 *rl;
  3606. rl = lock_user(VERIFY_READ, rlim_addr, sizeof(*rl), 1);
  3607. if (!rl) {
  3608. print_pointer(rlim_addr, last);
  3609. return;
  3610. }
  3611. print_raw_param64("{rlim_cur=%" PRId64, tswap64(rl->rlim_cur), 0);
  3612. print_raw_param64("rlim_max=%" PRId64 "}", tswap64(rl->rlim_max),
  3613. last);
  3614. unlock_user(rl, rlim_addr, 0);
  3615. } else {
  3616. qemu_log("NULL%s", get_comma(last));
  3617. }
  3618. }
  3619. static void
  3620. print_prlimit64(CPUArchState *cpu_env, const struct syscallname *name,
  3621. abi_long arg0, abi_long arg1, abi_long arg2,
  3622. abi_long arg3, abi_long arg4, abi_long arg5)
  3623. {
  3624. const char *rlim_name;
  3625. print_syscall_prologue(name);
  3626. print_raw_param("%d", arg0, 0);
  3627. rlim_name = target_ressource_string(arg1);
  3628. if (rlim_name) {
  3629. qemu_log("%s,", rlim_name);
  3630. } else {
  3631. print_raw_param("%d", arg1, 0);
  3632. }
  3633. print_rlimit64(arg2, 0);
  3634. print_pointer(arg3, 1);
  3635. print_syscall_epilogue(name);
  3636. }
  3637. static void
  3638. print_syscall_ret_prlimit64(CPUArchState *cpu_env,
  3639. const struct syscallname *name,
  3640. abi_long ret, abi_long arg0, abi_long arg1,
  3641. abi_long arg2, abi_long arg3, abi_long arg4,
  3642. abi_long arg5)
  3643. {
  3644. if (!print_syscall_err(ret)) {
  3645. qemu_log(TARGET_ABI_FMT_ld, ret);
  3646. if (arg3) {
  3647. qemu_log(" (");
  3648. print_rlimit64(arg3, 1);
  3649. qemu_log(")");
  3650. }
  3651. }
  3652. qemu_log("\n");
  3653. }
  3654. #endif
  3655. #ifdef TARGET_NR_kill
  3656. static void
  3657. print_kill(CPUArchState *cpu_env, const struct syscallname *name,
  3658. abi_long arg0, abi_long arg1, abi_long arg2,
  3659. abi_long arg3, abi_long arg4, abi_long arg5)
  3660. {
  3661. print_syscall_prologue(name);
  3662. print_raw_param("%d", arg0, 0);
  3663. print_signal(arg1, 1);
  3664. print_syscall_epilogue(name);
  3665. }
  3666. #endif
  3667. #ifdef TARGET_NR_tkill
  3668. static void
  3669. print_tkill(CPUArchState *cpu_env, const struct syscallname *name,
  3670. abi_long arg0, abi_long arg1, abi_long arg2,
  3671. abi_long arg3, abi_long arg4, abi_long arg5)
  3672. {
  3673. print_syscall_prologue(name);
  3674. print_raw_param("%d", arg0, 0);
  3675. print_signal(arg1, 1);
  3676. print_syscall_epilogue(name);
  3677. }
  3678. #endif
  3679. #ifdef TARGET_NR_tgkill
  3680. static void
  3681. print_tgkill(CPUArchState *cpu_env, const struct syscallname *name,
  3682. abi_long arg0, abi_long arg1, abi_long arg2,
  3683. abi_long arg3, abi_long arg4, abi_long arg5)
  3684. {
  3685. print_syscall_prologue(name);
  3686. print_raw_param("%d", arg0, 0);
  3687. print_raw_param("%d", arg1, 0);
  3688. print_signal(arg2, 1);
  3689. print_syscall_epilogue(name);
  3690. }
  3691. #endif
  3692. #ifdef TARGET_NR_statx
  3693. static void
  3694. print_statx(CPUArchState *cpu_env, const struct syscallname *name,
  3695. abi_long arg0, abi_long arg1, abi_long arg2,
  3696. abi_long arg3, abi_long arg4, abi_long arg5)
  3697. {
  3698. print_syscall_prologue(name);
  3699. print_at_dirfd(arg0, 0);
  3700. print_string(arg1, 0);
  3701. print_flags(statx_flags, arg2, 0);
  3702. print_flags(statx_mask, arg3, 0);
  3703. print_pointer(arg4, 1);
  3704. print_syscall_epilogue(name);
  3705. }
  3706. #endif
  3707. #ifdef TARGET_NR_ioctl
  3708. static void
  3709. print_ioctl(CPUArchState *cpu_env, const struct syscallname *name,
  3710. abi_long arg0, abi_long arg1, abi_long arg2,
  3711. abi_long arg3, abi_long arg4, abi_long arg5)
  3712. {
  3713. print_syscall_prologue(name);
  3714. print_raw_param("%d", arg0, 0);
  3715. const IOCTLEntry *ie;
  3716. const argtype *arg_type;
  3717. void *argptr;
  3718. int target_size;
  3719. for (ie = ioctl_entries; ie->target_cmd != 0; ie++) {
  3720. if (ie->target_cmd == arg1) {
  3721. break;
  3722. }
  3723. }
  3724. if (ie->target_cmd == 0) {
  3725. print_raw_param("%#x", arg1, 0);
  3726. print_raw_param("%#x", arg2, 1);
  3727. } else {
  3728. qemu_log("%s", ie->name);
  3729. arg_type = ie->arg_type;
  3730. if (arg_type[0] != TYPE_NULL) {
  3731. qemu_log(",");
  3732. switch (arg_type[0]) {
  3733. case TYPE_PTRVOID:
  3734. print_pointer(arg2, 1);
  3735. break;
  3736. case TYPE_CHAR:
  3737. case TYPE_SHORT:
  3738. case TYPE_INT:
  3739. print_raw_param("%d", arg2, 1);
  3740. break;
  3741. case TYPE_LONG:
  3742. print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
  3743. break;
  3744. case TYPE_ULONG:
  3745. print_raw_param(TARGET_ABI_FMT_lu, arg2, 1);
  3746. break;
  3747. case TYPE_PTR:
  3748. switch (ie->access) {
  3749. case IOC_R:
  3750. print_pointer(arg2, 1);
  3751. break;
  3752. case IOC_W:
  3753. case IOC_RW:
  3754. arg_type++;
  3755. target_size = thunk_type_size(arg_type, 0);
  3756. argptr = lock_user(VERIFY_READ, arg2, target_size, 1);
  3757. if (argptr) {
  3758. thunk_print(argptr, arg_type);
  3759. unlock_user(argptr, arg2, target_size);
  3760. } else {
  3761. print_pointer(arg2, 1);
  3762. }
  3763. break;
  3764. }
  3765. break;
  3766. default:
  3767. g_assert_not_reached();
  3768. }
  3769. }
  3770. }
  3771. print_syscall_epilogue(name);
  3772. }
  3773. #endif
  3774. /*
  3775. * An array of all of the syscalls we know about
  3776. */
  3777. static const struct syscallname scnames[] = {
  3778. #include "strace.list"
  3779. };
  3780. static int nsyscalls = ARRAY_SIZE(scnames);
  3781. /*
  3782. * The public interface to this module.
  3783. */
  3784. void
  3785. print_syscall(CPUArchState *cpu_env, int num,
  3786. abi_long arg1, abi_long arg2, abi_long arg3,
  3787. abi_long arg4, abi_long arg5, abi_long arg6)
  3788. {
  3789. int i;
  3790. FILE *f;
  3791. const char *format = "%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
  3792. TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
  3793. TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
  3794. f = qemu_log_trylock();
  3795. if (!f) {
  3796. return;
  3797. }
  3798. fprintf(f, "%d ", getpid());
  3799. for (i = 0; i < nsyscalls; i++) {
  3800. if (scnames[i].nr == num) {
  3801. if (scnames[i].call != NULL) {
  3802. scnames[i].call(cpu_env, &scnames[i], arg1, arg2, arg3,
  3803. arg4, arg5, arg6);
  3804. } else {
  3805. /* XXX: this format system is broken because it uses
  3806. host types and host pointers for strings */
  3807. if (scnames[i].format != NULL) {
  3808. format = scnames[i].format;
  3809. }
  3810. fprintf(f, format, scnames[i].name, arg1, arg2,
  3811. arg3, arg4, arg5, arg6);
  3812. }
  3813. qemu_log_unlock(f);
  3814. return;
  3815. }
  3816. }
  3817. fprintf(f, "Unknown syscall %d\n", num);
  3818. qemu_log_unlock(f);
  3819. }
  3820. void
  3821. print_syscall_ret(CPUArchState *cpu_env, int num, abi_long ret,
  3822. abi_long arg1, abi_long arg2, abi_long arg3,
  3823. abi_long arg4, abi_long arg5, abi_long arg6)
  3824. {
  3825. int i;
  3826. FILE *f;
  3827. f = qemu_log_trylock();
  3828. if (!f) {
  3829. return;
  3830. }
  3831. for (i = 0; i < nsyscalls; i++) {
  3832. if (scnames[i].nr == num) {
  3833. if (scnames[i].result != NULL) {
  3834. scnames[i].result(cpu_env, &scnames[i], ret,
  3835. arg1, arg2, arg3,
  3836. arg4, arg5, arg6);
  3837. } else {
  3838. if (!print_syscall_err(ret)) {
  3839. fprintf(f, TARGET_ABI_FMT_ld, ret);
  3840. }
  3841. fprintf(f, "\n");
  3842. }
  3843. break;
  3844. }
  3845. }
  3846. qemu_log_unlock(f);
  3847. }
  3848. void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
  3849. {
  3850. /* Print the strace output for a signal being taken:
  3851. * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
  3852. */
  3853. FILE *f;
  3854. f = qemu_log_trylock();
  3855. if (!f) {
  3856. return;
  3857. }
  3858. fprintf(f, "--- ");
  3859. print_signal(target_signum, 1);
  3860. fprintf(f, " ");
  3861. print_siginfo(tinfo);
  3862. fprintf(f, " ---\n");
  3863. qemu_log_unlock(f);
  3864. }