machine.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. #include "callchain.h"
  2. #include "debug.h"
  3. #include "event.h"
  4. #include "evsel.h"
  5. #include "hist.h"
  6. #include "machine.h"
  7. #include "map.h"
  8. #include "sort.h"
  9. #include "strlist.h"
  10. #include "thread.h"
  11. #include <stdbool.h>
  12. #include "unwind.h"
  13. int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
  14. {
  15. map_groups__init(&machine->kmaps);
  16. RB_CLEAR_NODE(&machine->rb_node);
  17. INIT_LIST_HEAD(&machine->user_dsos);
  18. INIT_LIST_HEAD(&machine->kernel_dsos);
  19. machine->threads = RB_ROOT;
  20. INIT_LIST_HEAD(&machine->dead_threads);
  21. machine->last_match = NULL;
  22. machine->kmaps.machine = machine;
  23. machine->pid = pid;
  24. machine->symbol_filter = NULL;
  25. machine->root_dir = strdup(root_dir);
  26. if (machine->root_dir == NULL)
  27. return -ENOMEM;
  28. if (pid != HOST_KERNEL_ID) {
  29. struct thread *thread = machine__findnew_thread(machine, 0,
  30. pid);
  31. char comm[64];
  32. if (thread == NULL)
  33. return -ENOMEM;
  34. snprintf(comm, sizeof(comm), "[guest/%d]", pid);
  35. thread__set_comm(thread, comm, 0);
  36. }
  37. return 0;
  38. }
  39. struct machine *machine__new_host(void)
  40. {
  41. struct machine *machine = malloc(sizeof(*machine));
  42. if (machine != NULL) {
  43. machine__init(machine, "", HOST_KERNEL_ID);
  44. if (machine__create_kernel_maps(machine) < 0)
  45. goto out_delete;
  46. }
  47. return machine;
  48. out_delete:
  49. free(machine);
  50. return NULL;
  51. }
  52. static void dsos__delete(struct list_head *dsos)
  53. {
  54. struct dso *pos, *n;
  55. list_for_each_entry_safe(pos, n, dsos, node) {
  56. list_del(&pos->node);
  57. dso__delete(pos);
  58. }
  59. }
  60. void machine__delete_dead_threads(struct machine *machine)
  61. {
  62. struct thread *n, *t;
  63. list_for_each_entry_safe(t, n, &machine->dead_threads, node) {
  64. list_del(&t->node);
  65. thread__delete(t);
  66. }
  67. }
  68. void machine__delete_threads(struct machine *machine)
  69. {
  70. struct rb_node *nd = rb_first(&machine->threads);
  71. while (nd) {
  72. struct thread *t = rb_entry(nd, struct thread, rb_node);
  73. rb_erase(&t->rb_node, &machine->threads);
  74. nd = rb_next(nd);
  75. thread__delete(t);
  76. }
  77. }
  78. void machine__exit(struct machine *machine)
  79. {
  80. map_groups__exit(&machine->kmaps);
  81. dsos__delete(&machine->user_dsos);
  82. dsos__delete(&machine->kernel_dsos);
  83. free(machine->root_dir);
  84. machine->root_dir = NULL;
  85. }
  86. void machine__delete(struct machine *machine)
  87. {
  88. machine__exit(machine);
  89. free(machine);
  90. }
  91. void machines__init(struct machines *machines)
  92. {
  93. machine__init(&machines->host, "", HOST_KERNEL_ID);
  94. machines->guests = RB_ROOT;
  95. machines->symbol_filter = NULL;
  96. }
  97. void machines__exit(struct machines *machines)
  98. {
  99. machine__exit(&machines->host);
  100. /* XXX exit guest */
  101. }
  102. struct machine *machines__add(struct machines *machines, pid_t pid,
  103. const char *root_dir)
  104. {
  105. struct rb_node **p = &machines->guests.rb_node;
  106. struct rb_node *parent = NULL;
  107. struct machine *pos, *machine = malloc(sizeof(*machine));
  108. if (machine == NULL)
  109. return NULL;
  110. if (machine__init(machine, root_dir, pid) != 0) {
  111. free(machine);
  112. return NULL;
  113. }
  114. machine->symbol_filter = machines->symbol_filter;
  115. while (*p != NULL) {
  116. parent = *p;
  117. pos = rb_entry(parent, struct machine, rb_node);
  118. if (pid < pos->pid)
  119. p = &(*p)->rb_left;
  120. else
  121. p = &(*p)->rb_right;
  122. }
  123. rb_link_node(&machine->rb_node, parent, p);
  124. rb_insert_color(&machine->rb_node, &machines->guests);
  125. return machine;
  126. }
  127. void machines__set_symbol_filter(struct machines *machines,
  128. symbol_filter_t symbol_filter)
  129. {
  130. struct rb_node *nd;
  131. machines->symbol_filter = symbol_filter;
  132. machines->host.symbol_filter = symbol_filter;
  133. for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
  134. struct machine *machine = rb_entry(nd, struct machine, rb_node);
  135. machine->symbol_filter = symbol_filter;
  136. }
  137. }
  138. struct machine *machines__find(struct machines *machines, pid_t pid)
  139. {
  140. struct rb_node **p = &machines->guests.rb_node;
  141. struct rb_node *parent = NULL;
  142. struct machine *machine;
  143. struct machine *default_machine = NULL;
  144. if (pid == HOST_KERNEL_ID)
  145. return &machines->host;
  146. while (*p != NULL) {
  147. parent = *p;
  148. machine = rb_entry(parent, struct machine, rb_node);
  149. if (pid < machine->pid)
  150. p = &(*p)->rb_left;
  151. else if (pid > machine->pid)
  152. p = &(*p)->rb_right;
  153. else
  154. return machine;
  155. if (!machine->pid)
  156. default_machine = machine;
  157. }
  158. return default_machine;
  159. }
  160. struct machine *machines__findnew(struct machines *machines, pid_t pid)
  161. {
  162. char path[PATH_MAX];
  163. const char *root_dir = "";
  164. struct machine *machine = machines__find(machines, pid);
  165. if (machine && (machine->pid == pid))
  166. goto out;
  167. if ((pid != HOST_KERNEL_ID) &&
  168. (pid != DEFAULT_GUEST_KERNEL_ID) &&
  169. (symbol_conf.guestmount)) {
  170. sprintf(path, "%s/%d", symbol_conf.guestmount, pid);
  171. if (access(path, R_OK)) {
  172. static struct strlist *seen;
  173. if (!seen)
  174. seen = strlist__new(true, NULL);
  175. if (!strlist__has_entry(seen, path)) {
  176. pr_err("Can't access file %s\n", path);
  177. strlist__add(seen, path);
  178. }
  179. machine = NULL;
  180. goto out;
  181. }
  182. root_dir = path;
  183. }
  184. machine = machines__add(machines, pid, root_dir);
  185. out:
  186. return machine;
  187. }
  188. void machines__process_guests(struct machines *machines,
  189. machine__process_t process, void *data)
  190. {
  191. struct rb_node *nd;
  192. for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
  193. struct machine *pos = rb_entry(nd, struct machine, rb_node);
  194. process(pos, data);
  195. }
  196. }
  197. char *machine__mmap_name(struct machine *machine, char *bf, size_t size)
  198. {
  199. if (machine__is_host(machine))
  200. snprintf(bf, size, "[%s]", "kernel.kallsyms");
  201. else if (machine__is_default_guest(machine))
  202. snprintf(bf, size, "[%s]", "guest.kernel.kallsyms");
  203. else {
  204. snprintf(bf, size, "[%s.%d]", "guest.kernel.kallsyms",
  205. machine->pid);
  206. }
  207. return bf;
  208. }
  209. void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size)
  210. {
  211. struct rb_node *node;
  212. struct machine *machine;
  213. machines->host.id_hdr_size = id_hdr_size;
  214. for (node = rb_first(&machines->guests); node; node = rb_next(node)) {
  215. machine = rb_entry(node, struct machine, rb_node);
  216. machine->id_hdr_size = id_hdr_size;
  217. }
  218. return;
  219. }
  220. static struct thread *__machine__findnew_thread(struct machine *machine,
  221. pid_t pid, pid_t tid,
  222. bool create)
  223. {
  224. struct rb_node **p = &machine->threads.rb_node;
  225. struct rb_node *parent = NULL;
  226. struct thread *th;
  227. /*
  228. * Front-end cache - TID lookups come in blocks,
  229. * so most of the time we dont have to look up
  230. * the full rbtree:
  231. */
  232. if (machine->last_match && machine->last_match->tid == tid) {
  233. if (pid && pid != machine->last_match->pid_)
  234. machine->last_match->pid_ = pid;
  235. return machine->last_match;
  236. }
  237. while (*p != NULL) {
  238. parent = *p;
  239. th = rb_entry(parent, struct thread, rb_node);
  240. if (th->tid == tid) {
  241. machine->last_match = th;
  242. if (pid && pid != th->pid_)
  243. th->pid_ = pid;
  244. return th;
  245. }
  246. if (tid < th->tid)
  247. p = &(*p)->rb_left;
  248. else
  249. p = &(*p)->rb_right;
  250. }
  251. if (!create)
  252. return NULL;
  253. th = thread__new(pid, tid);
  254. if (th != NULL) {
  255. rb_link_node(&th->rb_node, parent, p);
  256. rb_insert_color(&th->rb_node, &machine->threads);
  257. machine->last_match = th;
  258. }
  259. return th;
  260. }
  261. struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,
  262. pid_t tid)
  263. {
  264. return __machine__findnew_thread(machine, pid, tid, true);
  265. }
  266. struct thread *machine__find_thread(struct machine *machine, pid_t tid)
  267. {
  268. return __machine__findnew_thread(machine, 0, tid, false);
  269. }
  270. int machine__process_comm_event(struct machine *machine, union perf_event *event,
  271. struct perf_sample *sample)
  272. {
  273. struct thread *thread = machine__findnew_thread(machine,
  274. event->comm.pid,
  275. event->comm.tid);
  276. if (dump_trace)
  277. perf_event__fprintf_comm(event, stdout);
  278. if (thread == NULL || thread__set_comm(thread, event->comm.comm, sample->time)) {
  279. dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
  280. return -1;
  281. }
  282. return 0;
  283. }
  284. int machine__process_lost_event(struct machine *machine __maybe_unused,
  285. union perf_event *event, struct perf_sample *sample __maybe_unused)
  286. {
  287. dump_printf(": id:%" PRIu64 ": lost:%" PRIu64 "\n",
  288. event->lost.id, event->lost.lost);
  289. return 0;
  290. }
  291. struct map *machine__new_module(struct machine *machine, u64 start,
  292. const char *filename)
  293. {
  294. struct map *map;
  295. struct dso *dso = __dsos__findnew(&machine->kernel_dsos, filename);
  296. if (dso == NULL)
  297. return NULL;
  298. map = map__new2(start, dso, MAP__FUNCTION);
  299. if (map == NULL)
  300. return NULL;
  301. if (machine__is_host(machine))
  302. dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
  303. else
  304. dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
  305. map_groups__insert(&machine->kmaps, map);
  306. return map;
  307. }
  308. size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
  309. {
  310. struct rb_node *nd;
  311. size_t ret = __dsos__fprintf(&machines->host.kernel_dsos, fp) +
  312. __dsos__fprintf(&machines->host.user_dsos, fp);
  313. for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
  314. struct machine *pos = rb_entry(nd, struct machine, rb_node);
  315. ret += __dsos__fprintf(&pos->kernel_dsos, fp);
  316. ret += __dsos__fprintf(&pos->user_dsos, fp);
  317. }
  318. return ret;
  319. }
  320. size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
  321. bool (skip)(struct dso *dso, int parm), int parm)
  322. {
  323. return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, skip, parm) +
  324. __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm);
  325. }
  326. size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
  327. bool (skip)(struct dso *dso, int parm), int parm)
  328. {
  329. struct rb_node *nd;
  330. size_t ret = machine__fprintf_dsos_buildid(&machines->host, fp, skip, parm);
  331. for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
  332. struct machine *pos = rb_entry(nd, struct machine, rb_node);
  333. ret += machine__fprintf_dsos_buildid(pos, fp, skip, parm);
  334. }
  335. return ret;
  336. }
  337. size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp)
  338. {
  339. int i;
  340. size_t printed = 0;
  341. struct dso *kdso = machine->vmlinux_maps[MAP__FUNCTION]->dso;
  342. if (kdso->has_build_id) {
  343. char filename[PATH_MAX];
  344. if (dso__build_id_filename(kdso, filename, sizeof(filename)))
  345. printed += fprintf(fp, "[0] %s\n", filename);
  346. }
  347. for (i = 0; i < vmlinux_path__nr_entries; ++i)
  348. printed += fprintf(fp, "[%d] %s\n",
  349. i + kdso->has_build_id, vmlinux_path[i]);
  350. return printed;
  351. }
  352. size_t machine__fprintf(struct machine *machine, FILE *fp)
  353. {
  354. size_t ret = 0;
  355. struct rb_node *nd;
  356. for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
  357. struct thread *pos = rb_entry(nd, struct thread, rb_node);
  358. ret += thread__fprintf(pos, fp);
  359. }
  360. return ret;
  361. }
  362. static struct dso *machine__get_kernel(struct machine *machine)
  363. {
  364. const char *vmlinux_name = NULL;
  365. struct dso *kernel;
  366. if (machine__is_host(machine)) {
  367. vmlinux_name = symbol_conf.vmlinux_name;
  368. if (!vmlinux_name)
  369. vmlinux_name = "[kernel.kallsyms]";
  370. kernel = dso__kernel_findnew(machine, vmlinux_name,
  371. "[kernel]",
  372. DSO_TYPE_KERNEL);
  373. } else {
  374. char bf[PATH_MAX];
  375. if (machine__is_default_guest(machine))
  376. vmlinux_name = symbol_conf.default_guest_vmlinux_name;
  377. if (!vmlinux_name)
  378. vmlinux_name = machine__mmap_name(machine, bf,
  379. sizeof(bf));
  380. kernel = dso__kernel_findnew(machine, vmlinux_name,
  381. "[guest.kernel]",
  382. DSO_TYPE_GUEST_KERNEL);
  383. }
  384. if (kernel != NULL && (!kernel->has_build_id))
  385. dso__read_running_kernel_build_id(kernel, machine);
  386. return kernel;
  387. }
  388. struct process_args {
  389. u64 start;
  390. };
  391. static int symbol__in_kernel(void *arg, const char *name,
  392. char type __maybe_unused, u64 start)
  393. {
  394. struct process_args *args = arg;
  395. if (strchr(name, '['))
  396. return 0;
  397. args->start = start;
  398. return 1;
  399. }
  400. /* Figure out the start address of kernel map from /proc/kallsyms */
  401. static u64 machine__get_kernel_start_addr(struct machine *machine)
  402. {
  403. const char *filename;
  404. char path[PATH_MAX];
  405. struct process_args args;
  406. if (machine__is_host(machine)) {
  407. filename = "/proc/kallsyms";
  408. } else {
  409. if (machine__is_default_guest(machine))
  410. filename = (char *)symbol_conf.default_guest_kallsyms;
  411. else {
  412. sprintf(path, "%s/proc/kallsyms", machine->root_dir);
  413. filename = path;
  414. }
  415. }
  416. if (symbol__restricted_filename(filename, "/proc/kallsyms"))
  417. return 0;
  418. if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
  419. return 0;
  420. return args.start;
  421. }
  422. int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
  423. {
  424. enum map_type type;
  425. u64 start = machine__get_kernel_start_addr(machine);
  426. for (type = 0; type < MAP__NR_TYPES; ++type) {
  427. struct kmap *kmap;
  428. machine->vmlinux_maps[type] = map__new2(start, kernel, type);
  429. if (machine->vmlinux_maps[type] == NULL)
  430. return -1;
  431. machine->vmlinux_maps[type]->map_ip =
  432. machine->vmlinux_maps[type]->unmap_ip =
  433. identity__map_ip;
  434. kmap = map__kmap(machine->vmlinux_maps[type]);
  435. kmap->kmaps = &machine->kmaps;
  436. map_groups__insert(&machine->kmaps,
  437. machine->vmlinux_maps[type]);
  438. }
  439. return 0;
  440. }
  441. void machine__destroy_kernel_maps(struct machine *machine)
  442. {
  443. enum map_type type;
  444. for (type = 0; type < MAP__NR_TYPES; ++type) {
  445. struct kmap *kmap;
  446. if (machine->vmlinux_maps[type] == NULL)
  447. continue;
  448. kmap = map__kmap(machine->vmlinux_maps[type]);
  449. map_groups__remove(&machine->kmaps,
  450. machine->vmlinux_maps[type]);
  451. if (kmap->ref_reloc_sym) {
  452. /*
  453. * ref_reloc_sym is shared among all maps, so free just
  454. * on one of them.
  455. */
  456. if (type == MAP__FUNCTION) {
  457. free((char *)kmap->ref_reloc_sym->name);
  458. kmap->ref_reloc_sym->name = NULL;
  459. free(kmap->ref_reloc_sym);
  460. }
  461. kmap->ref_reloc_sym = NULL;
  462. }
  463. map__delete(machine->vmlinux_maps[type]);
  464. machine->vmlinux_maps[type] = NULL;
  465. }
  466. }
  467. int machines__create_guest_kernel_maps(struct machines *machines)
  468. {
  469. int ret = 0;
  470. struct dirent **namelist = NULL;
  471. int i, items = 0;
  472. char path[PATH_MAX];
  473. pid_t pid;
  474. char *endp;
  475. if (symbol_conf.default_guest_vmlinux_name ||
  476. symbol_conf.default_guest_modules ||
  477. symbol_conf.default_guest_kallsyms) {
  478. machines__create_kernel_maps(machines, DEFAULT_GUEST_KERNEL_ID);
  479. }
  480. if (symbol_conf.guestmount) {
  481. items = scandir(symbol_conf.guestmount, &namelist, NULL, NULL);
  482. if (items <= 0)
  483. return -ENOENT;
  484. for (i = 0; i < items; i++) {
  485. if (!isdigit(namelist[i]->d_name[0])) {
  486. /* Filter out . and .. */
  487. continue;
  488. }
  489. pid = (pid_t)strtol(namelist[i]->d_name, &endp, 10);
  490. if ((*endp != '\0') ||
  491. (endp == namelist[i]->d_name) ||
  492. (errno == ERANGE)) {
  493. pr_debug("invalid directory (%s). Skipping.\n",
  494. namelist[i]->d_name);
  495. continue;
  496. }
  497. sprintf(path, "%s/%s/proc/kallsyms",
  498. symbol_conf.guestmount,
  499. namelist[i]->d_name);
  500. ret = access(path, R_OK);
  501. if (ret) {
  502. pr_debug("Can't access file %s\n", path);
  503. goto failure;
  504. }
  505. machines__create_kernel_maps(machines, pid);
  506. }
  507. failure:
  508. free(namelist);
  509. }
  510. return ret;
  511. }
  512. void machines__destroy_kernel_maps(struct machines *machines)
  513. {
  514. struct rb_node *next = rb_first(&machines->guests);
  515. machine__destroy_kernel_maps(&machines->host);
  516. while (next) {
  517. struct machine *pos = rb_entry(next, struct machine, rb_node);
  518. next = rb_next(&pos->rb_node);
  519. rb_erase(&pos->rb_node, &machines->guests);
  520. machine__delete(pos);
  521. }
  522. }
  523. int machines__create_kernel_maps(struct machines *machines, pid_t pid)
  524. {
  525. struct machine *machine = machines__findnew(machines, pid);
  526. if (machine == NULL)
  527. return -1;
  528. return machine__create_kernel_maps(machine);
  529. }
  530. int machine__load_kallsyms(struct machine *machine, const char *filename,
  531. enum map_type type, symbol_filter_t filter)
  532. {
  533. struct map *map = machine->vmlinux_maps[type];
  534. int ret = dso__load_kallsyms(map->dso, filename, map, filter);
  535. if (ret > 0) {
  536. dso__set_loaded(map->dso, type);
  537. /*
  538. * Since /proc/kallsyms will have multiple sessions for the
  539. * kernel, with modules between them, fixup the end of all
  540. * sections.
  541. */
  542. __map_groups__fixup_end(&machine->kmaps, type);
  543. }
  544. return ret;
  545. }
  546. int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
  547. symbol_filter_t filter)
  548. {
  549. struct map *map = machine->vmlinux_maps[type];
  550. int ret = dso__load_vmlinux_path(map->dso, map, filter);
  551. if (ret > 0)
  552. dso__set_loaded(map->dso, type);
  553. return ret;
  554. }
  555. static void map_groups__fixup_end(struct map_groups *mg)
  556. {
  557. int i;
  558. for (i = 0; i < MAP__NR_TYPES; ++i)
  559. __map_groups__fixup_end(mg, i);
  560. }
  561. static char *get_kernel_version(const char *root_dir)
  562. {
  563. char version[PATH_MAX];
  564. FILE *file;
  565. char *name, *tmp;
  566. const char *prefix = "Linux version ";
  567. sprintf(version, "%s/proc/version", root_dir);
  568. file = fopen(version, "r");
  569. if (!file)
  570. return NULL;
  571. version[0] = '\0';
  572. tmp = fgets(version, sizeof(version), file);
  573. fclose(file);
  574. name = strstr(version, prefix);
  575. if (!name)
  576. return NULL;
  577. name += strlen(prefix);
  578. tmp = strchr(name, ' ');
  579. if (tmp)
  580. *tmp = '\0';
  581. return strdup(name);
  582. }
  583. static int map_groups__set_modules_path_dir(struct map_groups *mg,
  584. const char *dir_name)
  585. {
  586. struct dirent *dent;
  587. DIR *dir = opendir(dir_name);
  588. int ret = 0;
  589. if (!dir) {
  590. pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
  591. return -1;
  592. }
  593. while ((dent = readdir(dir)) != NULL) {
  594. char path[PATH_MAX];
  595. struct stat st;
  596. /*sshfs might return bad dent->d_type, so we have to stat*/
  597. snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
  598. if (stat(path, &st))
  599. continue;
  600. if (S_ISDIR(st.st_mode)) {
  601. if (!strcmp(dent->d_name, ".") ||
  602. !strcmp(dent->d_name, ".."))
  603. continue;
  604. ret = map_groups__set_modules_path_dir(mg, path);
  605. if (ret < 0)
  606. goto out;
  607. } else {
  608. char *dot = strrchr(dent->d_name, '.'),
  609. dso_name[PATH_MAX];
  610. struct map *map;
  611. char *long_name;
  612. if (dot == NULL || strcmp(dot, ".ko"))
  613. continue;
  614. snprintf(dso_name, sizeof(dso_name), "[%.*s]",
  615. (int)(dot - dent->d_name), dent->d_name);
  616. strxfrchar(dso_name, '-', '_');
  617. map = map_groups__find_by_name(mg, MAP__FUNCTION,
  618. dso_name);
  619. if (map == NULL)
  620. continue;
  621. long_name = strdup(path);
  622. if (long_name == NULL) {
  623. ret = -1;
  624. goto out;
  625. }
  626. dso__set_long_name(map->dso, long_name);
  627. map->dso->lname_alloc = 1;
  628. dso__kernel_module_get_build_id(map->dso, "");
  629. }
  630. }
  631. out:
  632. closedir(dir);
  633. return ret;
  634. }
  635. static int machine__set_modules_path(struct machine *machine)
  636. {
  637. char *version;
  638. char modules_path[PATH_MAX];
  639. version = get_kernel_version(machine->root_dir);
  640. if (!version)
  641. return -1;
  642. snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel",
  643. machine->root_dir, version);
  644. free(version);
  645. return map_groups__set_modules_path_dir(&machine->kmaps, modules_path);
  646. }
  647. static int machine__create_module(void *arg, const char *name, u64 start)
  648. {
  649. struct machine *machine = arg;
  650. struct map *map;
  651. map = machine__new_module(machine, start, name);
  652. if (map == NULL)
  653. return -1;
  654. dso__kernel_module_get_build_id(map->dso, machine->root_dir);
  655. return 0;
  656. }
  657. static int machine__create_modules(struct machine *machine)
  658. {
  659. const char *modules;
  660. char path[PATH_MAX];
  661. if (machine__is_default_guest(machine)) {
  662. modules = symbol_conf.default_guest_modules;
  663. } else {
  664. snprintf(path, PATH_MAX, "%s/proc/modules", machine->root_dir);
  665. modules = path;
  666. }
  667. if (symbol__restricted_filename(modules, "/proc/modules"))
  668. return -1;
  669. if (modules__parse(modules, machine, machine__create_module))
  670. return -1;
  671. if (!machine__set_modules_path(machine))
  672. return 0;
  673. pr_debug("Problems setting modules path maps, continuing anyway...\n");
  674. return 0;
  675. }
  676. int machine__create_kernel_maps(struct machine *machine)
  677. {
  678. struct dso *kernel = machine__get_kernel(machine);
  679. if (kernel == NULL ||
  680. __machine__create_kernel_maps(machine, kernel) < 0)
  681. return -1;
  682. if (symbol_conf.use_modules && machine__create_modules(machine) < 0) {
  683. if (machine__is_host(machine))
  684. pr_debug("Problems creating module maps, "
  685. "continuing anyway...\n");
  686. else
  687. pr_debug("Problems creating module maps for guest %d, "
  688. "continuing anyway...\n", machine->pid);
  689. }
  690. /*
  691. * Now that we have all the maps created, just set the ->end of them:
  692. */
  693. map_groups__fixup_end(&machine->kmaps);
  694. return 0;
  695. }
  696. static void machine__set_kernel_mmap_len(struct machine *machine,
  697. union perf_event *event)
  698. {
  699. int i;
  700. for (i = 0; i < MAP__NR_TYPES; i++) {
  701. machine->vmlinux_maps[i]->start = event->mmap.start;
  702. machine->vmlinux_maps[i]->end = (event->mmap.start +
  703. event->mmap.len);
  704. /*
  705. * Be a bit paranoid here, some perf.data file came with
  706. * a zero sized synthesized MMAP event for the kernel.
  707. */
  708. if (machine->vmlinux_maps[i]->end == 0)
  709. machine->vmlinux_maps[i]->end = ~0ULL;
  710. }
  711. }
  712. static bool machine__uses_kcore(struct machine *machine)
  713. {
  714. struct dso *dso;
  715. list_for_each_entry(dso, &machine->kernel_dsos, node) {
  716. if (dso__is_kcore(dso))
  717. return true;
  718. }
  719. return false;
  720. }
  721. static int machine__process_kernel_mmap_event(struct machine *machine,
  722. union perf_event *event)
  723. {
  724. struct map *map;
  725. char kmmap_prefix[PATH_MAX];
  726. enum dso_kernel_type kernel_type;
  727. bool is_kernel_mmap;
  728. /* If we have maps from kcore then we do not need or want any others */
  729. if (machine__uses_kcore(machine))
  730. return 0;
  731. machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix));
  732. if (machine__is_host(machine))
  733. kernel_type = DSO_TYPE_KERNEL;
  734. else
  735. kernel_type = DSO_TYPE_GUEST_KERNEL;
  736. is_kernel_mmap = memcmp(event->mmap.filename,
  737. kmmap_prefix,
  738. strlen(kmmap_prefix) - 1) == 0;
  739. if (event->mmap.filename[0] == '/' ||
  740. (!is_kernel_mmap && event->mmap.filename[0] == '[')) {
  741. char short_module_name[1024];
  742. char *name, *dot;
  743. if (event->mmap.filename[0] == '/') {
  744. name = strrchr(event->mmap.filename, '/');
  745. if (name == NULL)
  746. goto out_problem;
  747. ++name; /* skip / */
  748. dot = strrchr(name, '.');
  749. if (dot == NULL)
  750. goto out_problem;
  751. snprintf(short_module_name, sizeof(short_module_name),
  752. "[%.*s]", (int)(dot - name), name);
  753. strxfrchar(short_module_name, '-', '_');
  754. } else
  755. strcpy(short_module_name, event->mmap.filename);
  756. map = machine__new_module(machine, event->mmap.start,
  757. event->mmap.filename);
  758. if (map == NULL)
  759. goto out_problem;
  760. name = strdup(short_module_name);
  761. if (name == NULL)
  762. goto out_problem;
  763. map->dso->short_name = name;
  764. map->dso->sname_alloc = 1;
  765. map->end = map->start + event->mmap.len;
  766. } else if (is_kernel_mmap) {
  767. const char *symbol_name = (event->mmap.filename +
  768. strlen(kmmap_prefix));
  769. /*
  770. * Should be there already, from the build-id table in
  771. * the header.
  772. */
  773. struct dso *kernel = __dsos__findnew(&machine->kernel_dsos,
  774. kmmap_prefix);
  775. if (kernel == NULL)
  776. goto out_problem;
  777. kernel->kernel = kernel_type;
  778. if (__machine__create_kernel_maps(machine, kernel) < 0)
  779. goto out_problem;
  780. machine__set_kernel_mmap_len(machine, event);
  781. /*
  782. * Avoid using a zero address (kptr_restrict) for the ref reloc
  783. * symbol. Effectively having zero here means that at record
  784. * time /proc/sys/kernel/kptr_restrict was non zero.
  785. */
  786. if (event->mmap.pgoff != 0) {
  787. maps__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps,
  788. symbol_name,
  789. event->mmap.pgoff);
  790. }
  791. if (machine__is_default_guest(machine)) {
  792. /*
  793. * preload dso of guest kernel and modules
  794. */
  795. dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION],
  796. NULL);
  797. }
  798. }
  799. return 0;
  800. out_problem:
  801. return -1;
  802. }
  803. int machine__process_mmap2_event(struct machine *machine,
  804. union perf_event *event,
  805. struct perf_sample *sample __maybe_unused)
  806. {
  807. u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  808. struct thread *thread;
  809. struct map *map;
  810. enum map_type type;
  811. int ret = 0;
  812. if (dump_trace)
  813. perf_event__fprintf_mmap2(event, stdout);
  814. if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
  815. cpumode == PERF_RECORD_MISC_KERNEL) {
  816. ret = machine__process_kernel_mmap_event(machine, event);
  817. if (ret < 0)
  818. goto out_problem;
  819. return 0;
  820. }
  821. thread = machine__findnew_thread(machine, event->mmap2.pid,
  822. event->mmap2.pid);
  823. if (thread == NULL)
  824. goto out_problem;
  825. if (event->header.misc & PERF_RECORD_MISC_MMAP_DATA)
  826. type = MAP__VARIABLE;
  827. else
  828. type = MAP__FUNCTION;
  829. map = map__new(&machine->user_dsos, event->mmap2.start,
  830. event->mmap2.len, event->mmap2.pgoff,
  831. event->mmap2.pid, event->mmap2.maj,
  832. event->mmap2.min, event->mmap2.ino,
  833. event->mmap2.ino_generation,
  834. event->mmap2.filename, type);
  835. if (map == NULL)
  836. goto out_problem;
  837. thread__insert_map(thread, map);
  838. return 0;
  839. out_problem:
  840. dump_printf("problem processing PERF_RECORD_MMAP2, skipping event.\n");
  841. return 0;
  842. }
  843. int machine__process_mmap_event(struct machine *machine, union perf_event *event,
  844. struct perf_sample *sample __maybe_unused)
  845. {
  846. u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  847. struct thread *thread;
  848. struct map *map;
  849. enum map_type type;
  850. int ret = 0;
  851. if (dump_trace)
  852. perf_event__fprintf_mmap(event, stdout);
  853. if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
  854. cpumode == PERF_RECORD_MISC_KERNEL) {
  855. ret = machine__process_kernel_mmap_event(machine, event);
  856. if (ret < 0)
  857. goto out_problem;
  858. return 0;
  859. }
  860. thread = machine__findnew_thread(machine, event->mmap.pid,
  861. event->mmap.pid);
  862. if (thread == NULL)
  863. goto out_problem;
  864. if (event->header.misc & PERF_RECORD_MISC_MMAP_DATA)
  865. type = MAP__VARIABLE;
  866. else
  867. type = MAP__FUNCTION;
  868. map = map__new(&machine->user_dsos, event->mmap.start,
  869. event->mmap.len, event->mmap.pgoff,
  870. event->mmap.pid, 0, 0, 0, 0,
  871. event->mmap.filename,
  872. type);
  873. if (map == NULL)
  874. goto out_problem;
  875. thread__insert_map(thread, map);
  876. return 0;
  877. out_problem:
  878. dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
  879. return 0;
  880. }
  881. static void machine__remove_thread(struct machine *machine, struct thread *th)
  882. {
  883. machine->last_match = NULL;
  884. rb_erase(&th->rb_node, &machine->threads);
  885. /*
  886. * We may have references to this thread, for instance in some hist_entry
  887. * instances, so just move them to a separate list.
  888. */
  889. list_add_tail(&th->node, &machine->dead_threads);
  890. }
  891. int machine__process_fork_event(struct machine *machine, union perf_event *event,
  892. struct perf_sample *sample)
  893. {
  894. struct thread *thread = machine__find_thread(machine, event->fork.tid);
  895. struct thread *parent = machine__findnew_thread(machine,
  896. event->fork.ppid,
  897. event->fork.ptid);
  898. /* if a thread currently exists for the thread id remove it */
  899. if (thread != NULL)
  900. machine__remove_thread(machine, thread);
  901. thread = machine__findnew_thread(machine, event->fork.pid,
  902. event->fork.tid);
  903. if (dump_trace)
  904. perf_event__fprintf_task(event, stdout);
  905. if (thread == NULL || parent == NULL ||
  906. thread__fork(thread, parent, sample->time) < 0) {
  907. dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
  908. return -1;
  909. }
  910. return 0;
  911. }
  912. int machine__process_exit_event(struct machine *machine, union perf_event *event,
  913. struct perf_sample *sample __maybe_unused)
  914. {
  915. struct thread *thread = machine__find_thread(machine, event->fork.tid);
  916. if (dump_trace)
  917. perf_event__fprintf_task(event, stdout);
  918. if (thread != NULL)
  919. thread__exited(thread);
  920. return 0;
  921. }
  922. int machine__process_event(struct machine *machine, union perf_event *event,
  923. struct perf_sample *sample)
  924. {
  925. int ret;
  926. switch (event->header.type) {
  927. case PERF_RECORD_COMM:
  928. ret = machine__process_comm_event(machine, event, sample); break;
  929. case PERF_RECORD_MMAP:
  930. ret = machine__process_mmap_event(machine, event, sample); break;
  931. case PERF_RECORD_MMAP2:
  932. ret = machine__process_mmap2_event(machine, event, sample); break;
  933. case PERF_RECORD_FORK:
  934. ret = machine__process_fork_event(machine, event, sample); break;
  935. case PERF_RECORD_EXIT:
  936. ret = machine__process_exit_event(machine, event, sample); break;
  937. case PERF_RECORD_LOST:
  938. ret = machine__process_lost_event(machine, event, sample); break;
  939. default:
  940. ret = -1;
  941. break;
  942. }
  943. return ret;
  944. }
  945. static bool symbol__match_regex(struct symbol *sym, regex_t *regex)
  946. {
  947. if (sym->name && !regexec(regex, sym->name, 0, NULL, 0))
  948. return 1;
  949. return 0;
  950. }
  951. static const u8 cpumodes[] = {
  952. PERF_RECORD_MISC_USER,
  953. PERF_RECORD_MISC_KERNEL,
  954. PERF_RECORD_MISC_GUEST_USER,
  955. PERF_RECORD_MISC_GUEST_KERNEL
  956. };
  957. #define NCPUMODES (sizeof(cpumodes)/sizeof(u8))
  958. static void ip__resolve_ams(struct machine *machine, struct thread *thread,
  959. struct addr_map_symbol *ams,
  960. u64 ip)
  961. {
  962. struct addr_location al;
  963. size_t i;
  964. u8 m;
  965. memset(&al, 0, sizeof(al));
  966. for (i = 0; i < NCPUMODES; i++) {
  967. m = cpumodes[i];
  968. /*
  969. * We cannot use the header.misc hint to determine whether a
  970. * branch stack address is user, kernel, guest, hypervisor.
  971. * Branches may straddle the kernel/user/hypervisor boundaries.
  972. * Thus, we have to try consecutively until we find a match
  973. * or else, the symbol is unknown
  974. */
  975. thread__find_addr_location(thread, machine, m, MAP__FUNCTION,
  976. ip, &al);
  977. if (al.sym)
  978. goto found;
  979. }
  980. found:
  981. ams->addr = ip;
  982. ams->al_addr = al.addr;
  983. ams->sym = al.sym;
  984. ams->map = al.map;
  985. }
  986. static void ip__resolve_data(struct machine *machine, struct thread *thread,
  987. u8 m, struct addr_map_symbol *ams, u64 addr)
  988. {
  989. struct addr_location al;
  990. memset(&al, 0, sizeof(al));
  991. thread__find_addr_location(thread, machine, m, MAP__VARIABLE, addr,
  992. &al);
  993. ams->addr = addr;
  994. ams->al_addr = al.addr;
  995. ams->sym = al.sym;
  996. ams->map = al.map;
  997. }
  998. struct mem_info *machine__resolve_mem(struct machine *machine,
  999. struct thread *thr,
  1000. struct perf_sample *sample,
  1001. u8 cpumode)
  1002. {
  1003. struct mem_info *mi = zalloc(sizeof(*mi));
  1004. if (!mi)
  1005. return NULL;
  1006. ip__resolve_ams(machine, thr, &mi->iaddr, sample->ip);
  1007. ip__resolve_data(machine, thr, cpumode, &mi->daddr, sample->addr);
  1008. mi->data_src.val = sample->data_src;
  1009. return mi;
  1010. }
  1011. struct branch_info *machine__resolve_bstack(struct machine *machine,
  1012. struct thread *thr,
  1013. struct branch_stack *bs)
  1014. {
  1015. struct branch_info *bi;
  1016. unsigned int i;
  1017. bi = calloc(bs->nr, sizeof(struct branch_info));
  1018. if (!bi)
  1019. return NULL;
  1020. for (i = 0; i < bs->nr; i++) {
  1021. ip__resolve_ams(machine, thr, &bi[i].to, bs->entries[i].to);
  1022. ip__resolve_ams(machine, thr, &bi[i].from, bs->entries[i].from);
  1023. bi[i].flags = bs->entries[i].flags;
  1024. }
  1025. return bi;
  1026. }
  1027. static int machine__resolve_callchain_sample(struct machine *machine,
  1028. struct thread *thread,
  1029. struct ip_callchain *chain,
  1030. struct symbol **parent,
  1031. struct addr_location *root_al,
  1032. int max_stack)
  1033. {
  1034. u8 cpumode = PERF_RECORD_MISC_USER;
  1035. int chain_nr = min(max_stack, (int)chain->nr);
  1036. int i;
  1037. int err;
  1038. callchain_cursor_reset(&callchain_cursor);
  1039. if (chain->nr > PERF_MAX_STACK_DEPTH) {
  1040. pr_warning("corrupted callchain. skipping...\n");
  1041. return 0;
  1042. }
  1043. for (i = 0; i < chain_nr; i++) {
  1044. u64 ip;
  1045. struct addr_location al;
  1046. if (callchain_param.order == ORDER_CALLEE)
  1047. ip = chain->ips[i];
  1048. else
  1049. ip = chain->ips[chain->nr - i - 1];
  1050. if (ip >= PERF_CONTEXT_MAX) {
  1051. switch (ip) {
  1052. case PERF_CONTEXT_HV:
  1053. cpumode = PERF_RECORD_MISC_HYPERVISOR;
  1054. break;
  1055. case PERF_CONTEXT_KERNEL:
  1056. cpumode = PERF_RECORD_MISC_KERNEL;
  1057. break;
  1058. case PERF_CONTEXT_USER:
  1059. cpumode = PERF_RECORD_MISC_USER;
  1060. break;
  1061. default:
  1062. pr_debug("invalid callchain context: "
  1063. "%"PRId64"\n", (s64) ip);
  1064. /*
  1065. * It seems the callchain is corrupted.
  1066. * Discard all.
  1067. */
  1068. callchain_cursor_reset(&callchain_cursor);
  1069. return 0;
  1070. }
  1071. continue;
  1072. }
  1073. al.filtered = false;
  1074. thread__find_addr_location(thread, machine, cpumode,
  1075. MAP__FUNCTION, ip, &al);
  1076. if (al.sym != NULL) {
  1077. if (sort__has_parent && !*parent &&
  1078. symbol__match_regex(al.sym, &parent_regex))
  1079. *parent = al.sym;
  1080. else if (have_ignore_callees && root_al &&
  1081. symbol__match_regex(al.sym, &ignore_callees_regex)) {
  1082. /* Treat this symbol as the root,
  1083. forgetting its callees. */
  1084. *root_al = al;
  1085. callchain_cursor_reset(&callchain_cursor);
  1086. }
  1087. if (!symbol_conf.use_callchain)
  1088. break;
  1089. }
  1090. err = callchain_cursor_append(&callchain_cursor,
  1091. ip, al.map, al.sym);
  1092. if (err)
  1093. return err;
  1094. }
  1095. return 0;
  1096. }
  1097. static int unwind_entry(struct unwind_entry *entry, void *arg)
  1098. {
  1099. struct callchain_cursor *cursor = arg;
  1100. return callchain_cursor_append(cursor, entry->ip,
  1101. entry->map, entry->sym);
  1102. }
  1103. int machine__resolve_callchain(struct machine *machine,
  1104. struct perf_evsel *evsel,
  1105. struct thread *thread,
  1106. struct perf_sample *sample,
  1107. struct symbol **parent,
  1108. struct addr_location *root_al,
  1109. int max_stack)
  1110. {
  1111. int ret;
  1112. ret = machine__resolve_callchain_sample(machine, thread,
  1113. sample->callchain, parent,
  1114. root_al, max_stack);
  1115. if (ret)
  1116. return ret;
  1117. /* Can we do dwarf post unwind? */
  1118. if (!((evsel->attr.sample_type & PERF_SAMPLE_REGS_USER) &&
  1119. (evsel->attr.sample_type & PERF_SAMPLE_STACK_USER)))
  1120. return 0;
  1121. /* Bail out if nothing was captured. */
  1122. if ((!sample->user_regs.regs) ||
  1123. (!sample->user_stack.size))
  1124. return 0;
  1125. return unwind__get_entries(unwind_entry, &callchain_cursor, machine,
  1126. thread, evsel->attr.sample_regs_user,
  1127. sample, max_stack);
  1128. }
  1129. int machine__for_each_thread(struct machine *machine,
  1130. int (*fn)(struct thread *thread, void *p),
  1131. void *priv)
  1132. {
  1133. struct rb_node *nd;
  1134. struct thread *thread;
  1135. int rc = 0;
  1136. for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
  1137. thread = rb_entry(nd, struct thread, rb_node);
  1138. rc = fn(thread, priv);
  1139. if (rc != 0)
  1140. return rc;
  1141. }
  1142. list_for_each_entry(thread, &machine->dead_threads, node) {
  1143. rc = fn(thread, priv);
  1144. if (rc != 0)
  1145. return rc;
  1146. }
  1147. return rc;
  1148. }
  1149. int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
  1150. struct target *target, struct thread_map *threads,
  1151. perf_event__handler_t process, bool data_mmap)
  1152. {
  1153. if (target__has_task(target))
  1154. return perf_event__synthesize_thread_map(tool, threads, process, machine, data_mmap);
  1155. else if (target__has_cpu(target))
  1156. return perf_event__synthesize_threads(tool, process, machine, data_mmap);
  1157. /* command specified */
  1158. return 0;
  1159. }