thread.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. #include <asm/fcntl.h>
  2. #include <asm/mman.h>
  3. #include <asm/prctl.h>
  4. #include <asm/unistd.h>
  5. #include <errno.h>
  6. #include <linux/fcntl.h>
  7. #include <pal.h>
  8. #include <pal_error.h>
  9. #include <shim_fs.h>
  10. #include <shim_handle.h>
  11. #include <shim_internal.h>
  12. #include <shim_table.h>
  13. #include <shim_thread.h>
  14. #include <shim_utils.h>
  15. // TODO: For some reason S_IF* macros are missing if this file is included before our headers. We
  16. // should investigate and fix this behavior.
  17. #include <linux/stat.h>
  18. static int parse_thread_name(const char* name, IDTYPE* pidptr, const char** next, size_t* next_len,
  19. const char** nextnext) {
  20. const char* p = name;
  21. IDTYPE pid = 0;
  22. if (*p == '/')
  23. p++;
  24. if (strpartcmp_static(p, "self")) {
  25. p += static_strlen("self");
  26. if (*p && *p != '/')
  27. return -ENOENT;
  28. pid = get_cur_tid();
  29. } else {
  30. for (; *p && *p != '/'; p++) {
  31. if (*p < '0' || *p > '9')
  32. return -ENOENT;
  33. pid = pid * 10 + *p - '0';
  34. }
  35. }
  36. if (next) {
  37. if (*(p++) == '/' && *p) {
  38. *next = p;
  39. if (next_len || nextnext)
  40. for (; *p && *p != '/'; p++)
  41. ;
  42. if (next_len)
  43. *next_len = p - *next;
  44. if (nextnext)
  45. *nextnext = (*(p++) == '/' && *p) ? p : NULL;
  46. } else {
  47. *next = NULL;
  48. }
  49. }
  50. if (pidptr)
  51. *pidptr = pid;
  52. return 0;
  53. }
  54. static int find_thread_link(const char* name, struct shim_qstr* link, struct shim_dentry** dentptr,
  55. struct shim_thread** threadptr) {
  56. const char* next;
  57. const char* nextnext;
  58. size_t next_len;
  59. IDTYPE pid;
  60. int ret = parse_thread_name(name, &pid, &next, &next_len, &nextnext);
  61. if (ret < 0)
  62. return ret;
  63. struct shim_thread* thread = lookup_thread(pid);
  64. struct shim_dentry* dent = NULL;
  65. if (!thread)
  66. return -ENOENT;
  67. if (!thread->in_vm) {
  68. ret = -ENOENT;
  69. goto out;
  70. }
  71. lock(&thread->lock);
  72. if (next_len == static_strlen("root") && !memcmp(next, "root", next_len)) {
  73. dent = thread->root;
  74. get_dentry(dent);
  75. }
  76. if (next_len == static_strlen("cwd") && !memcmp(next, "cwd", next_len)) {
  77. dent = thread->cwd;
  78. get_dentry(dent);
  79. }
  80. if (next_len == static_strlen("exe") && !memcmp(next, "exe", next_len)) {
  81. struct shim_handle* exec = thread->exec;
  82. if (!exec->dentry) {
  83. unlock(&thread->lock);
  84. ret = -EINVAL;
  85. goto out;
  86. }
  87. dent = exec->dentry;
  88. get_dentry(dent);
  89. }
  90. unlock(&thread->lock);
  91. if (nextnext) {
  92. struct shim_dentry* next_dent = NULL;
  93. ret = path_lookupat(dent, nextnext, 0, &next_dent, dent->fs);
  94. if (ret < 0)
  95. goto out;
  96. put_dentry(dent);
  97. dent = next_dent;
  98. }
  99. if (link) {
  100. size_t size;
  101. char* path = dentry_get_path(dent, true, &size);
  102. qstrsetstr(link, path, size);
  103. }
  104. if (dentptr) {
  105. get_dentry(dent);
  106. *dentptr = dent;
  107. }
  108. if (threadptr) {
  109. get_thread(thread);
  110. *threadptr = thread;
  111. }
  112. ret = 0;
  113. out:
  114. if (dent)
  115. put_dentry(dent);
  116. if (thread)
  117. put_thread(thread);
  118. return ret;
  119. }
  120. static int proc_thread_link_open(struct shim_handle* hdl, const char* name, int flags) {
  121. struct shim_dentry* dent;
  122. int ret = find_thread_link(name, NULL, &dent, NULL);
  123. if (ret < 0)
  124. return ret;
  125. if (!dent->fs || !dent->fs->d_ops || !dent->fs->d_ops->open) {
  126. ret = -EACCES;
  127. goto out;
  128. }
  129. ret = dent->fs->d_ops->open(hdl, dent, flags);
  130. out:
  131. put_dentry(dent);
  132. return 0;
  133. }
  134. static int proc_thread_link_mode(const char* name, mode_t* mode) {
  135. struct shim_dentry* dent;
  136. int ret = find_thread_link(name, NULL, &dent, NULL);
  137. if (ret < 0)
  138. return ret;
  139. if (!dent->fs || !dent->fs->d_ops || !dent->fs->d_ops->mode) {
  140. ret = -EACCES;
  141. goto out;
  142. }
  143. ret = dent->fs->d_ops->mode(dent, mode);
  144. out:
  145. put_dentry(dent);
  146. return ret;
  147. }
  148. static int proc_thread_link_stat(const char* name, struct stat* buf) {
  149. struct shim_dentry* dent;
  150. int ret = find_thread_link(name, NULL, &dent, NULL);
  151. if (ret < 0)
  152. return ret;
  153. if (!dent->fs || !dent->fs->d_ops || !dent->fs->d_ops->stat) {
  154. ret = -EACCES;
  155. goto out;
  156. }
  157. ret = dent->fs->d_ops->stat(dent, buf);
  158. out:
  159. put_dentry(dent);
  160. return ret;
  161. }
  162. static int proc_thread_link_follow_link(const char* name, struct shim_qstr* link) {
  163. return find_thread_link(name, link, NULL, NULL);
  164. }
  165. static const struct proc_fs_ops fs_thread_link = {
  166. .open = &proc_thread_link_open,
  167. .mode = &proc_thread_link_mode,
  168. .stat = &proc_thread_link_stat,
  169. .follow_link = &proc_thread_link_follow_link,
  170. };
  171. /* If *phdl is returned on success, the ref count is incremented */
  172. static int parse_thread_fd(const char* name, const char** rest, struct shim_handle** phdl) {
  173. const char* next;
  174. const char* nextnext;
  175. size_t next_len;
  176. IDTYPE pid;
  177. int ret = parse_thread_name(name, &pid, &next, &next_len, &nextnext);
  178. if (ret < 0)
  179. return ret;
  180. if (!next || !nextnext || memcmp(next, "fd", next_len))
  181. return -EINVAL;
  182. const char* p = nextnext;
  183. FDTYPE fd = 0;
  184. for (; *p && *p != '/'; p++) {
  185. if (*p < '0' || *p > '9')
  186. return -ENOENT;
  187. fd = fd * 10 + *p - '0';
  188. if ((uint64_t)fd >= get_rlimit_cur(RLIMIT_NOFILE))
  189. return -ENOENT;
  190. }
  191. struct shim_thread* thread = lookup_thread(pid);
  192. if (!thread)
  193. return -ENOENT;
  194. struct shim_handle_map* handle_map = get_cur_handle_map(thread);
  195. lock(&handle_map->lock);
  196. if (fd >= handle_map->fd_top || handle_map->map[fd] == NULL ||
  197. handle_map->map[fd]->handle == NULL) {
  198. unlock(&handle_map->lock);
  199. return -ENOENT;
  200. }
  201. if (phdl) {
  202. *phdl = handle_map->map[fd]->handle;
  203. get_handle(*phdl);
  204. }
  205. unlock(&handle_map->lock);
  206. if (rest)
  207. *rest = *p ? p + 1 : NULL;
  208. return 0;
  209. }
  210. static int proc_match_thread_each_fd(const char* name) {
  211. return parse_thread_fd(name, NULL, NULL) == 0 ? 1 : 0;
  212. }
  213. static int proc_list_thread_each_fd(const char* name, struct shim_dirent** buf, int count) {
  214. const char* next;
  215. size_t next_len;
  216. IDTYPE pid;
  217. int ret = parse_thread_name(name, &pid, &next, &next_len, NULL);
  218. if (ret < 0)
  219. return ret;
  220. if (!next || memcmp(next, "fd", next_len))
  221. return -EINVAL;
  222. struct shim_thread* thread = lookup_thread(pid);
  223. if (!thread)
  224. return -ENOENT;
  225. struct shim_handle_map* handle_map = get_cur_handle_map(thread);
  226. int err = 0, bytes = 0;
  227. struct shim_dirent* dirent = *buf;
  228. struct shim_dirent** last = NULL;
  229. lock(&handle_map->lock);
  230. for (int i = 0; i < handle_map->fd_size; i++)
  231. if (handle_map->map[i] && handle_map->map[i]->handle) {
  232. int d = i, l = 0;
  233. for (; d; d /= 10, l++)
  234. ;
  235. l = l ?: 1;
  236. bytes += sizeof(struct shim_dirent) + l + 1;
  237. if (bytes > count) {
  238. err = -ENOMEM;
  239. break;
  240. }
  241. dirent->next = (void*)(dirent + 1) + l + 1;
  242. dirent->ino = 1;
  243. dirent->type = LINUX_DT_LNK;
  244. dirent->name[0] = '0';
  245. dirent->name[l--] = 0;
  246. for (d = i; d; d /= 10) {
  247. dirent->name[l--] = '0' + d % 10;
  248. }
  249. last = &dirent->next;
  250. dirent = dirent->next;
  251. }
  252. unlock(&handle_map->lock);
  253. put_thread(thread);
  254. if (last)
  255. *last = NULL;
  256. *buf = dirent;
  257. return err;
  258. }
  259. static const struct proc_nm_ops nm_thread_each_fd = {
  260. .match_name = &proc_match_thread_each_fd,
  261. .list_name = &proc_list_thread_each_fd,
  262. };
  263. static int find_thread_each_fd(const char* name, struct shim_qstr* link,
  264. struct shim_dentry** dentptr) {
  265. const char* rest;
  266. struct shim_handle* handle;
  267. struct shim_dentry* dent = NULL;
  268. int ret;
  269. if ((ret = parse_thread_fd(name, &rest, &handle)) < 0)
  270. return ret;
  271. lock(&handle->lock);
  272. if (handle->dentry) {
  273. dent = handle->dentry;
  274. get_dentry(dent);
  275. }
  276. unlock(&handle->lock);
  277. if (!dent) {
  278. ret = -ENOENT;
  279. goto out;
  280. }
  281. if (rest) {
  282. struct shim_dentry* next_dent = NULL;
  283. ret = path_lookupat(dent, rest, 0, &next_dent, dent->fs);
  284. if (ret < 0)
  285. goto out;
  286. put_dentry(dent);
  287. dent = next_dent;
  288. }
  289. if (link) {
  290. size_t size;
  291. char* path = dentry_get_path(dent, true, &size);
  292. qstrsetstr(link, path, size);
  293. }
  294. if (dentptr) {
  295. get_dentry(dent);
  296. *dentptr = dent;
  297. }
  298. out:
  299. if (dent)
  300. put_dentry(dent);
  301. put_handle(handle);
  302. return ret;
  303. }
  304. static int proc_thread_each_fd_open(struct shim_handle* hdl, const char* name, int flags) {
  305. struct shim_dentry* dent;
  306. int ret = find_thread_each_fd(name, NULL, &dent);
  307. if (ret < 0)
  308. return ret;
  309. if (!dent->fs || !dent->fs->d_ops || !dent->fs->d_ops->open) {
  310. ret = -EACCES;
  311. goto out;
  312. }
  313. ret = dent->fs->d_ops->open(hdl, dent, flags);
  314. out:
  315. put_dentry(dent);
  316. return 0;
  317. }
  318. static int proc_thread_each_fd_mode(const char* name, mode_t* mode) {
  319. struct shim_dentry* dent;
  320. int ret = find_thread_each_fd(name, NULL, &dent);
  321. if (ret < 0)
  322. return ret;
  323. if (!dent->fs || !dent->fs->d_ops || !dent->fs->d_ops->mode) {
  324. ret = -EACCES;
  325. goto out;
  326. }
  327. ret = dent->fs->d_ops->mode(dent, mode);
  328. out:
  329. put_dentry(dent);
  330. return 0;
  331. }
  332. static int proc_thread_each_fd_stat(const char* name, struct stat* buf) {
  333. struct shim_dentry* dent;
  334. int ret = find_thread_each_fd(name, NULL, &dent);
  335. if (ret < 0)
  336. return ret;
  337. if (!dent->fs || !dent->fs->d_ops || !dent->fs->d_ops->stat) {
  338. ret = -EACCES;
  339. goto out;
  340. }
  341. ret = dent->fs->d_ops->stat(dent, buf);
  342. out:
  343. put_dentry(dent);
  344. return 0;
  345. }
  346. static int proc_thread_each_fd_follow_link(const char* name, struct shim_qstr* link) {
  347. return find_thread_each_fd(name, link, NULL);
  348. }
  349. static const struct proc_fs_ops fs_thread_each_fd = {
  350. .open = &proc_thread_each_fd_open,
  351. .mode = &proc_thread_each_fd_mode,
  352. .stat = &proc_thread_each_fd_stat,
  353. .follow_link = &proc_thread_each_fd_follow_link,
  354. };
  355. static const struct proc_dir dir_fd = {
  356. .size = 1,
  357. .ent =
  358. {
  359. {
  360. .nm_ops = &nm_thread_each_fd,
  361. .fs_ops = &fs_thread_each_fd,
  362. },
  363. },
  364. };
  365. static int proc_thread_maps_open(struct shim_handle* hdl, const char* name, int flags) {
  366. if (flags & (O_WRONLY | O_RDWR))
  367. return -EACCES;
  368. const char* next;
  369. size_t next_len;
  370. IDTYPE pid;
  371. int ret = parse_thread_name(name, &pid, &next, &next_len, NULL);
  372. if (ret < 0)
  373. return ret;
  374. struct shim_thread* thread = lookup_thread(pid);
  375. if (!thread)
  376. return -ENOENT;
  377. size_t count = DEFAULT_VMA_COUNT;
  378. struct shim_vma_val* vmas = malloc(sizeof(struct shim_vma_val) * count);
  379. if (!vmas) {
  380. ret = -ENOMEM;
  381. goto out;
  382. }
  383. retry_dump_vmas:
  384. ret = dump_all_vmas(vmas, count);
  385. if (ret == -EOVERFLOW) {
  386. struct shim_vma_val* new_vmas = malloc(sizeof(struct shim_vma_val) * count * 2);
  387. if (!new_vmas) {
  388. ret = -ENOMEM;
  389. goto err;
  390. }
  391. free(vmas);
  392. vmas = new_vmas;
  393. count *= 2;
  394. goto retry_dump_vmas;
  395. }
  396. if (ret < 0)
  397. goto err;
  398. #define DEFAULT_VMA_BUFFER_SIZE 256
  399. count = ret;
  400. size_t buffer_size = DEFAULT_VMA_BUFFER_SIZE, offset = 0;
  401. char* buffer = malloc(buffer_size);
  402. if (!buffer) {
  403. ret = -ENOMEM;
  404. goto err;
  405. }
  406. for (struct shim_vma_val* vma = vmas; vma < vmas + count; vma++) {
  407. size_t old_offset = offset;
  408. uintptr_t start = (uintptr_t)vma->addr;
  409. uintptr_t end = (uintptr_t)vma->addr + vma->length;
  410. char pt[3] = {
  411. (vma->prot & PROT_READ) ? 'r' : '-',
  412. (vma->prot & PROT_WRITE) ? 'w' : '-',
  413. (vma->prot & PROT_EXEC) ? 'x' : '-',
  414. };
  415. char pr = (vma->flags & MAP_PRIVATE) ? 'p' : 's';
  416. #define ADDR_FMT(addr) ((addr) > 0xffffffff ? "%lx" : "%08lx")
  417. #define EMIT(fmt...) \
  418. do { \
  419. offset += snprintf(buffer + offset, buffer_size - offset, fmt); \
  420. } while (0)
  421. retry_emit_vma:
  422. if (vma->file) {
  423. int dev_major = 0, dev_minor = 0;
  424. unsigned long ino = vma->file->dentry ? vma->file->dentry->ino : 0;
  425. const char* name = "[unknown]";
  426. if (!qstrempty(&vma->file->path))
  427. name = qstrgetstr(&vma->file->path);
  428. EMIT(ADDR_FMT(start), start);
  429. EMIT("-");
  430. EMIT(ADDR_FMT(end), end);
  431. EMIT(" %c%c%c%c %08lx %02d:%02d %lu %s\n", pt[0], pt[1], pt[2], pr, vma->offset,
  432. dev_major, dev_minor, ino, name);
  433. } else {
  434. EMIT(ADDR_FMT(start), start);
  435. EMIT("-");
  436. EMIT(ADDR_FMT(end), end);
  437. if (vma->comment[0])
  438. EMIT(" %c%c%c%c 00000000 00:00 0 %s\n", pt[0], pt[1], pt[2], pr, vma->comment);
  439. else
  440. EMIT(" %c%c%c%c 00000000 00:00 0\n", pt[0], pt[1], pt[2], pr);
  441. }
  442. if (offset >= buffer_size) {
  443. char* new_buffer = malloc(buffer_size * 2);
  444. if (!new_buffer) {
  445. ret = -ENOMEM;
  446. goto err;
  447. }
  448. offset = old_offset;
  449. memcpy(new_buffer, buffer, old_offset);
  450. free(buffer);
  451. buffer = new_buffer;
  452. buffer_size *= 2;
  453. goto retry_emit_vma;
  454. }
  455. }
  456. struct shim_str_data* data = calloc(1, sizeof(struct shim_str_data));
  457. if (!data) {
  458. ret = -ENOMEM;
  459. goto err;
  460. }
  461. data->str = buffer;
  462. data->len = offset;
  463. hdl->type = TYPE_STR;
  464. hdl->flags = flags & ~O_RDONLY;
  465. hdl->acc_mode = MAY_READ;
  466. hdl->info.str.data = data;
  467. ret = 0;
  468. out:
  469. put_thread(thread);
  470. if (vmas)
  471. free_vma_val_array(vmas, count);
  472. return ret;
  473. err:
  474. if (buffer)
  475. free(buffer);
  476. goto out;
  477. }
  478. static int proc_thread_maps_mode(const char* name, mode_t* mode) {
  479. // Only used by one file
  480. __UNUSED(name);
  481. *mode = 0400;
  482. return 0;
  483. }
  484. static int proc_thread_maps_stat(const char* name, struct stat* buf) {
  485. // Only used by one file
  486. __UNUSED(name);
  487. memset(buf, 0, sizeof(struct stat));
  488. buf->st_dev = buf->st_ino = 1;
  489. buf->st_mode = 0400 | S_IFREG;
  490. buf->st_uid = 0;
  491. buf->st_gid = 0;
  492. buf->st_size = 0;
  493. return 0;
  494. }
  495. static const struct proc_fs_ops fs_thread_maps = {
  496. .open = &proc_thread_maps_open,
  497. .mode = &proc_thread_maps_mode,
  498. .stat = &proc_thread_maps_stat,
  499. };
  500. static int proc_thread_dir_open(struct shim_handle* hdl, const char* name, int flags) {
  501. __UNUSED(hdl);
  502. __UNUSED(name);
  503. if (flags & (O_WRONLY | O_RDWR))
  504. return -EISDIR;
  505. // Don't really need to do any work here, but keeping as a placeholder,
  506. // just in case.
  507. return 0;
  508. }
  509. static int proc_thread_dir_mode(const char* name, mode_t* mode) {
  510. const char* next;
  511. size_t next_len;
  512. IDTYPE pid;
  513. int ret = parse_thread_name(name, &pid, &next, &next_len, NULL);
  514. if (ret < 0)
  515. return ret;
  516. *mode = 0500;
  517. return 0;
  518. }
  519. static int proc_thread_dir_stat(const char* name, struct stat* buf) {
  520. const char* next;
  521. size_t next_len;
  522. IDTYPE pid;
  523. int ret = parse_thread_name(name, &pid, &next, &next_len, NULL);
  524. if (ret < 0)
  525. return ret;
  526. struct shim_thread* thread = lookup_thread(pid);
  527. if (!thread)
  528. return -ENOENT;
  529. memset(buf, 0, sizeof(struct stat));
  530. buf->st_dev = buf->st_ino = 1;
  531. buf->st_mode = 0500 | S_IFDIR;
  532. lock(&thread->lock);
  533. buf->st_uid = thread->uid;
  534. buf->st_gid = thread->gid;
  535. unlock(&thread->lock);
  536. buf->st_size = 4096;
  537. return 0;
  538. }
  539. static const struct proc_fs_ops fs_thread_fd = {
  540. .mode = &proc_thread_dir_mode,
  541. .stat = &proc_thread_dir_stat,
  542. };
  543. static int proc_match_thread(const char* name) {
  544. IDTYPE pid;
  545. if (parse_thread_name(name, &pid, NULL, NULL, NULL) < 0)
  546. return 0;
  547. struct shim_thread* thread = lookup_thread(pid);
  548. return thread ? 1 : 0;
  549. }
  550. struct walk_thread_arg {
  551. struct shim_dirent *buf, *buf_end;
  552. };
  553. static int walk_cb(struct shim_thread* thread, void* arg, bool* unlocked) {
  554. // unlocked needed for kill
  555. __UNUSED(unlocked);
  556. struct walk_thread_arg* args = (struct walk_thread_arg*)arg;
  557. IDTYPE pid = thread->tid;
  558. int p = pid, l = 0;
  559. for (; p; p /= 10, l++)
  560. ;
  561. if ((void*)(args->buf + 1) + l + 1 > (void*)args->buf_end)
  562. return -ENOBUFS;
  563. struct shim_dirent* buf = args->buf;
  564. buf->next = (void*)(buf + 1) + l + 1;
  565. buf->ino = 1;
  566. buf->type = LINUX_DT_DIR;
  567. buf->name[l--] = 0;
  568. for (p = pid; p; p /= 10) {
  569. buf->name[l--] = p % 10 + '0';
  570. }
  571. args->buf = buf->next;
  572. return 1;
  573. }
  574. static int proc_list_thread(const char* name, struct shim_dirent** buf, int len) {
  575. __UNUSED(name); // We know this is for "/proc/self"
  576. struct walk_thread_arg args = {
  577. .buf = *buf,
  578. .buf_end = (void*)*buf + len,
  579. };
  580. int ret = walk_thread_list(&walk_cb, &args);
  581. if (ret < 0)
  582. return ret;
  583. *buf = args.buf;
  584. return 0;
  585. }
  586. const struct proc_nm_ops nm_thread = {
  587. .match_name = &proc_match_thread,
  588. .list_name = &proc_list_thread,
  589. };
  590. const struct proc_fs_ops fs_thread = {
  591. .open = &proc_thread_dir_open,
  592. .mode = &proc_thread_dir_mode,
  593. .stat = &proc_thread_dir_stat,
  594. };
  595. const struct proc_dir dir_thread = {
  596. .size = 5,
  597. .ent =
  598. {
  599. {
  600. .name = "cwd",
  601. .fs_ops = &fs_thread_link,
  602. },
  603. {
  604. .name = "exe",
  605. .fs_ops = &fs_thread_link,
  606. },
  607. {
  608. .name = "root",
  609. .fs_ops = &fs_thread_link,
  610. },
  611. {
  612. .name = "fd",
  613. .dir = &dir_fd,
  614. .fs_ops = &fs_thread_fd,
  615. },
  616. {
  617. .name = "maps",
  618. .fs_ops = &fs_thread_maps,
  619. },
  620. },
  621. };