ProcFS.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. #include "ProcFS.h"
  2. #include "Console.h"
  3. #include "KSyms.h"
  4. #include "Process.h"
  5. #include "Scheduler.h"
  6. #include "StdLib.h"
  7. #include <AK/JsonArray.h>
  8. #include <AK/JsonObject.h>
  9. #include <AK/JsonValue.h>
  10. #include <AK/StringBuilder.h>
  11. #include <Kernel/Arch/i386/CPU.h>
  12. #include <Kernel/FileSystem/Custody.h>
  13. #include <Kernel/FileSystem/FileDescription.h>
  14. #include <Kernel/FileSystem/VirtualFileSystem.h>
  15. #include <Kernel/KParams.h>
  16. #include <Kernel/Net/NetworkAdapter.h>
  17. #include <Kernel/PCI.h>
  18. #include <Kernel/VM/MemoryManager.h>
  19. #include <Kernel/kmalloc.h>
  20. #include <LibC/errno_numbers.h>
  21. enum ProcParentDirectory {
  22. PDI_AbstractRoot = 0,
  23. PDI_Root,
  24. PDI_Root_sys,
  25. PDI_PID,
  26. PDI_PID_fd,
  27. };
  28. enum ProcFileType {
  29. FI_Invalid = 0,
  30. FI_Root = 1, // directory
  31. __FI_Root_Start,
  32. FI_Root_mm,
  33. FI_Root_mounts,
  34. FI_Root_df,
  35. FI_Root_kmalloc,
  36. FI_Root_all,
  37. FI_Root_memstat,
  38. FI_Root_summary,
  39. FI_Root_cpuinfo,
  40. FI_Root_inodes,
  41. FI_Root_dmesg,
  42. FI_Root_pci,
  43. FI_Root_uptime,
  44. FI_Root_cmdline,
  45. FI_Root_netadapters,
  46. FI_Root_self, // symlink
  47. FI_Root_sys, // directory
  48. __FI_Root_End,
  49. FI_PID,
  50. __FI_PID_Start,
  51. FI_PID_vm,
  52. FI_PID_vmo,
  53. FI_PID_stack,
  54. FI_PID_regs,
  55. FI_PID_fds,
  56. FI_PID_exe, // symlink
  57. FI_PID_cwd, // symlink
  58. FI_PID_fd, // directory
  59. __FI_PID_End,
  60. FI_MaxStaticFileIndex,
  61. };
  62. static inline pid_t to_pid(const InodeIdentifier& identifier)
  63. {
  64. #ifdef PROCFS_DEBUG
  65. dbgprintf("to_pid, index=%08x -> %u\n", identifier.index(), identifier.index() >> 16);
  66. #endif
  67. return identifier.index() >> 16u;
  68. }
  69. static inline ProcParentDirectory to_proc_parent_directory(const InodeIdentifier& identifier)
  70. {
  71. return (ProcParentDirectory)((identifier.index() >> 12) & 0xf);
  72. }
  73. static inline int to_fd(const InodeIdentifier& identifier)
  74. {
  75. ASSERT(to_proc_parent_directory(identifier) == PDI_PID_fd);
  76. return (identifier.index() & 0xff) - FI_MaxStaticFileIndex;
  77. }
  78. static inline int to_sys_index(const InodeIdentifier& identifier)
  79. {
  80. ASSERT(to_proc_parent_directory(identifier) == PDI_Root_sys);
  81. return identifier.index() & 0xff;
  82. }
  83. static inline InodeIdentifier to_identifier(unsigned fsid, ProcParentDirectory parent, pid_t pid, ProcFileType proc_file_type)
  84. {
  85. return { fsid, ((unsigned)parent << 12u) | ((unsigned)pid << 16u) | (unsigned)proc_file_type };
  86. }
  87. static inline InodeIdentifier to_identifier_with_fd(unsigned fsid, pid_t pid, int fd)
  88. {
  89. return { fsid, (PDI_PID_fd << 12u) | ((unsigned)pid << 16u) | (FI_MaxStaticFileIndex + fd) };
  90. }
  91. static inline InodeIdentifier sys_var_to_identifier(unsigned fsid, unsigned index)
  92. {
  93. ASSERT(index < 256);
  94. return { fsid, (PDI_Root_sys << 12u) | index };
  95. }
  96. static inline InodeIdentifier to_parent_id(const InodeIdentifier& identifier)
  97. {
  98. switch (to_proc_parent_directory(identifier)) {
  99. case PDI_AbstractRoot:
  100. case PDI_Root:
  101. return { identifier.fsid(), FI_Root };
  102. case PDI_Root_sys:
  103. return { identifier.fsid(), FI_Root_sys };
  104. case PDI_PID:
  105. return to_identifier(identifier.fsid(), PDI_Root, to_pid(identifier), FI_PID);
  106. case PDI_PID_fd:
  107. return to_identifier(identifier.fsid(), PDI_PID, to_pid(identifier), FI_PID_fd);
  108. }
  109. ASSERT_NOT_REACHED();
  110. }
  111. #if 0
  112. static inline byte to_unused_metadata(const InodeIdentifier& identifier)
  113. {
  114. return (identifier.index() >> 8) & 0xf;
  115. }
  116. #endif
  117. static inline ProcFileType to_proc_file_type(const InodeIdentifier& identifier)
  118. {
  119. return (ProcFileType)(identifier.index() & 0xff);
  120. }
  121. static inline bool is_process_related_file(const InodeIdentifier& identifier)
  122. {
  123. if (to_proc_file_type(identifier) == FI_PID)
  124. return true;
  125. auto proc_parent_directory = to_proc_parent_directory(identifier);
  126. switch (proc_parent_directory) {
  127. case PDI_PID:
  128. case PDI_PID_fd:
  129. return true;
  130. default:
  131. return false;
  132. }
  133. }
  134. static inline bool is_directory(const InodeIdentifier& identifier)
  135. {
  136. auto proc_file_type = to_proc_file_type(identifier);
  137. switch (proc_file_type) {
  138. case FI_Root:
  139. case FI_Root_sys:
  140. case FI_PID:
  141. case FI_PID_fd:
  142. return true;
  143. default:
  144. return false;
  145. }
  146. }
  147. static inline bool is_persistent_inode(const InodeIdentifier& identifier)
  148. {
  149. return to_proc_parent_directory(identifier) == PDI_Root_sys;
  150. }
  151. static ProcFS* s_the;
  152. ProcFS& ProcFS::the()
  153. {
  154. ASSERT(s_the);
  155. return *s_the;
  156. }
  157. NonnullRefPtr<ProcFS> ProcFS::create()
  158. {
  159. return adopt(*new ProcFS);
  160. }
  161. ProcFS::~ProcFS()
  162. {
  163. }
  164. ByteBuffer procfs$pid_fds(InodeIdentifier identifier)
  165. {
  166. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  167. if (!handle)
  168. return {};
  169. auto& process = handle->process();
  170. if (process.number_of_open_file_descriptors() == 0)
  171. return {};
  172. StringBuilder builder;
  173. for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
  174. auto* description = process.file_description(i);
  175. if (!description)
  176. continue;
  177. builder.appendf("%-3u %s\n", i, description->absolute_path().characters());
  178. }
  179. return builder.to_byte_buffer();
  180. }
  181. ByteBuffer procfs$pid_fd_entry(InodeIdentifier identifier)
  182. {
  183. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  184. if (!handle)
  185. return {};
  186. auto& process = handle->process();
  187. int fd = to_fd(identifier);
  188. auto* description = process.file_description(fd);
  189. if (!description)
  190. return {};
  191. return description->absolute_path().to_byte_buffer();
  192. }
  193. ByteBuffer procfs$pid_vm(InodeIdentifier identifier)
  194. {
  195. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  196. if (!handle)
  197. return {};
  198. auto& process = handle->process();
  199. StringBuilder builder;
  200. builder.appendf("BEGIN END SIZE COMMIT FLAGS NAME\n");
  201. for (auto& region : process.regions()) {
  202. StringBuilder flags_builder;
  203. if (region.is_readable())
  204. flags_builder.append('R');
  205. if (region.is_writable())
  206. flags_builder.append('W');
  207. builder.appendf("%x -- %x %x %x %-4s %s\n",
  208. region.vaddr().get(),
  209. region.vaddr().offset(region.size() - 1).get(),
  210. region.size(),
  211. region.amount_resident(),
  212. flags_builder.to_string().characters(),
  213. region.name().characters());
  214. }
  215. return builder.to_byte_buffer();
  216. }
  217. ByteBuffer procfs$pci(InodeIdentifier)
  218. {
  219. StringBuilder builder;
  220. PCI::enumerate_all([&builder](PCI::Address address, PCI::ID id) {
  221. builder.appendf("%b:%b.%b %w:%w\n", address.bus(), address.slot(), address.function(), id.vendor_id, id.device_id);
  222. });
  223. return builder.to_byte_buffer();
  224. }
  225. ByteBuffer procfs$uptime(InodeIdentifier)
  226. {
  227. StringBuilder builder;
  228. builder.appendf("%u\n", (dword)(g_uptime / 1000));
  229. return builder.to_byte_buffer();
  230. }
  231. ByteBuffer procfs$cmdline(InodeIdentifier)
  232. {
  233. StringBuilder builder;
  234. builder.appendf("%s\n", KParams::the().cmdline().characters());
  235. return builder.to_byte_buffer();
  236. }
  237. ByteBuffer procfs$netadapters(InodeIdentifier)
  238. {
  239. StringBuilder builder;
  240. NetworkAdapter::for_each([&builder](auto& adapter) {
  241. builder.appendf("%s,%s,%s,%s\n",
  242. adapter.name().characters(),
  243. adapter.class_name(),
  244. adapter.mac_address().to_string().characters(),
  245. adapter.ipv4_address().to_string().characters());
  246. });
  247. return builder.to_byte_buffer();
  248. }
  249. ByteBuffer procfs$pid_vmo(InodeIdentifier identifier)
  250. {
  251. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  252. if (!handle)
  253. return {};
  254. auto& process = handle->process();
  255. StringBuilder builder;
  256. builder.appendf("BEGIN END SIZE NAME\n");
  257. for (auto& region : process.regions()) {
  258. builder.appendf("%x -- %x %x %s\n",
  259. region.vaddr().get(),
  260. region.vaddr().offset(region.size() - 1).get(),
  261. region.size(),
  262. region.name().characters());
  263. builder.appendf("VMO: %s \"%s\" @ %x(%u)\n",
  264. region.vmo().is_anonymous() ? "anonymous" : "file-backed",
  265. region.vmo().name().characters(),
  266. &region.vmo(),
  267. region.vmo().ref_count());
  268. for (int i = 0; i < region.vmo().page_count(); ++i) {
  269. auto& physical_page = region.vmo().physical_pages()[i];
  270. builder.appendf("P%x%s(%u) ",
  271. physical_page ? physical_page->paddr().get() : 0,
  272. region.should_cow(i) ? "!" : "",
  273. physical_page ? physical_page->ref_count() : 0);
  274. }
  275. builder.appendf("\n");
  276. }
  277. return builder.to_byte_buffer();
  278. }
  279. ByteBuffer procfs$pid_stack(InodeIdentifier identifier)
  280. {
  281. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  282. if (!handle)
  283. return {};
  284. auto& process = handle->process();
  285. ProcessPagingScope paging_scope(process);
  286. struct RecognizedSymbol {
  287. dword address;
  288. const KSym* ksym;
  289. };
  290. StringBuilder builder;
  291. process.for_each_thread([&](Thread& thread) {
  292. builder.appendf("Thread %d:\n", thread.tid());
  293. Vector<RecognizedSymbol, 64> recognized_symbols;
  294. recognized_symbols.append({ thread.tss().eip, ksymbolicate(thread.tss().eip) });
  295. for (dword* stack_ptr = (dword*)thread.frame_ptr(); process.validate_read_from_kernel(VirtualAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) {
  296. dword retaddr = stack_ptr[1];
  297. recognized_symbols.append({ retaddr, ksymbolicate(retaddr) });
  298. }
  299. for (auto& symbol : recognized_symbols) {
  300. if (!symbol.address)
  301. break;
  302. if (!symbol.ksym) {
  303. builder.appendf("%p\n", symbol.address);
  304. continue;
  305. }
  306. unsigned offset = symbol.address - symbol.ksym->address;
  307. if (symbol.ksym->address == ksym_highest_address && offset > 4096)
  308. builder.appendf("%p\n", symbol.address);
  309. else
  310. builder.appendf("%p %s +%u\n", symbol.address, symbol.ksym->name, offset);
  311. }
  312. return IterationDecision::Continue;
  313. });
  314. return builder.to_byte_buffer();
  315. }
  316. ByteBuffer procfs$pid_regs(InodeIdentifier identifier)
  317. {
  318. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  319. if (!handle)
  320. return {};
  321. auto& process = handle->process();
  322. StringBuilder builder;
  323. process.for_each_thread([&](Thread& thread) {
  324. builder.appendf("Thread %d:\n", thread.tid());
  325. auto& tss = thread.tss();
  326. builder.appendf("eax: %x\n", tss.eax);
  327. builder.appendf("ebx: %x\n", tss.ebx);
  328. builder.appendf("ecx: %x\n", tss.ecx);
  329. builder.appendf("edx: %x\n", tss.edx);
  330. builder.appendf("esi: %x\n", tss.esi);
  331. builder.appendf("edi: %x\n", tss.edi);
  332. builder.appendf("ebp: %x\n", tss.ebp);
  333. builder.appendf("cr3: %x\n", tss.cr3);
  334. builder.appendf("flg: %x\n", tss.eflags);
  335. builder.appendf("sp: %w:%x\n", tss.ss, tss.esp);
  336. builder.appendf("pc: %w:%x\n", tss.cs, tss.eip);
  337. return IterationDecision::Continue;
  338. });
  339. return builder.to_byte_buffer();
  340. }
  341. ByteBuffer procfs$pid_exe(InodeIdentifier identifier)
  342. {
  343. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  344. if (!handle)
  345. return {};
  346. auto& process = handle->process();
  347. auto* custody = process.executable();
  348. ASSERT(custody);
  349. return custody->absolute_path().to_byte_buffer();
  350. }
  351. ByteBuffer procfs$pid_cwd(InodeIdentifier identifier)
  352. {
  353. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier));
  354. if (!handle)
  355. return {};
  356. return handle->process().current_directory().absolute_path().to_byte_buffer();
  357. }
  358. ByteBuffer procfs$self(InodeIdentifier)
  359. {
  360. char buffer[16];
  361. ksprintf(buffer, "%u", current->pid());
  362. return ByteBuffer::copy((const byte*)buffer, strlen(buffer));
  363. }
  364. ByteBuffer procfs$mm(InodeIdentifier)
  365. {
  366. // FIXME: Implement
  367. InterruptDisabler disabler;
  368. StringBuilder builder;
  369. for (auto* vmo : MM.m_vmos) {
  370. builder.appendf("VMO: %p %s(%u): p:%4u %s\n",
  371. vmo,
  372. vmo->is_anonymous() ? "anon" : "file",
  373. vmo->ref_count(),
  374. vmo->page_count(),
  375. vmo->name().characters());
  376. }
  377. builder.appendf("VMO count: %u\n", MM.m_vmos.size());
  378. builder.appendf("Free physical pages: %u\n", MM.user_physical_pages() - MM.user_physical_pages_used());
  379. builder.appendf("Free supervisor physical pages: %u\n", MM.super_physical_pages() - MM.super_physical_pages_used());
  380. return builder.to_byte_buffer();
  381. }
  382. ByteBuffer procfs$dmesg(InodeIdentifier)
  383. {
  384. InterruptDisabler disabler;
  385. StringBuilder builder;
  386. for (char ch : Console::the().logbuffer())
  387. builder.append(ch);
  388. return builder.to_byte_buffer();
  389. }
  390. ByteBuffer procfs$mounts(InodeIdentifier)
  391. {
  392. // FIXME: This is obviously racy against the VFS mounts changing.
  393. StringBuilder builder;
  394. VFS::the().for_each_mount([&builder](auto& mount) {
  395. auto& fs = mount.guest_fs();
  396. builder.appendf("%s @ ", fs.class_name());
  397. if (!mount.host().is_valid())
  398. builder.appendf("/");
  399. else {
  400. builder.appendf("%u:%u", mount.host().fsid(), mount.host().index());
  401. builder.append(' ');
  402. builder.append(mount.absolute_path());
  403. }
  404. builder.append('\n');
  405. });
  406. return builder.to_byte_buffer();
  407. }
  408. ByteBuffer procfs$df(InodeIdentifier)
  409. {
  410. // FIXME: This is obviously racy against the VFS mounts changing.
  411. JsonArray json;
  412. VFS::the().for_each_mount([&json](auto& mount) {
  413. auto& fs = mount.guest_fs();
  414. JsonObject fs_object;
  415. fs_object.set("class_name", fs.class_name());
  416. fs_object.set("total_block_count", fs.total_block_count());
  417. fs_object.set("free_block_count", fs.free_block_count());
  418. fs_object.set("total_inode_count", fs.total_inode_count());
  419. fs_object.set("free_inode_count", fs.free_inode_count());
  420. fs_object.set("mount_point", mount.absolute_path());
  421. json.append(fs_object);
  422. });
  423. return json.serialized().to_byte_buffer();
  424. }
  425. ByteBuffer procfs$cpuinfo(InodeIdentifier)
  426. {
  427. StringBuilder builder;
  428. {
  429. CPUID cpuid(0);
  430. builder.appendf("cpuid: ");
  431. auto emit_dword = [&](dword value) {
  432. builder.appendf("%c%c%c%c",
  433. value & 0xff,
  434. (value >> 8) & 0xff,
  435. (value >> 16) & 0xff,
  436. (value >> 24) & 0xff);
  437. };
  438. emit_dword(cpuid.ebx());
  439. emit_dword(cpuid.edx());
  440. emit_dword(cpuid.ecx());
  441. builder.appendf("\n");
  442. }
  443. {
  444. CPUID cpuid(1);
  445. dword stepping = cpuid.eax() & 0xf;
  446. dword model = (cpuid.eax() >> 4) & 0xf;
  447. dword family = (cpuid.eax() >> 8) & 0xf;
  448. dword type = (cpuid.eax() >> 12) & 0x3;
  449. dword extended_model = (cpuid.eax() >> 16) & 0xf;
  450. dword extended_family = (cpuid.eax() >> 20) & 0xff;
  451. dword display_model;
  452. dword display_family;
  453. if (family == 15) {
  454. display_family = family + extended_family;
  455. display_model = model + (extended_model << 4);
  456. } else if (family == 6) {
  457. display_family = family;
  458. display_model = model + (extended_model << 4);
  459. } else {
  460. display_family = family;
  461. display_model = model;
  462. }
  463. builder.appendf("family: %u\n", display_family);
  464. builder.appendf("model: %u\n", display_model);
  465. builder.appendf("stepping: %u\n", stepping);
  466. builder.appendf("type: %u\n", type);
  467. }
  468. {
  469. // FIXME: Check first that this is supported by calling CPUID with eax=0x80000000
  470. // and verifying that the returned eax>=0x80000004.
  471. char buffer[48];
  472. dword* bufptr = reinterpret_cast<dword*>(buffer);
  473. auto copy_brand_string_part_to_buffer = [&](dword i) {
  474. CPUID cpuid(0x80000002 + i);
  475. *bufptr++ = cpuid.eax();
  476. *bufptr++ = cpuid.ebx();
  477. *bufptr++ = cpuid.ecx();
  478. *bufptr++ = cpuid.edx();
  479. };
  480. copy_brand_string_part_to_buffer(0);
  481. copy_brand_string_part_to_buffer(1);
  482. copy_brand_string_part_to_buffer(2);
  483. builder.appendf("brandstr: \"%s\"\n", buffer);
  484. }
  485. return builder.to_byte_buffer();
  486. }
  487. ByteBuffer procfs$kmalloc(InodeIdentifier)
  488. {
  489. StringBuilder builder;
  490. builder.appendf(
  491. "eternal: %u\n"
  492. "allocated: %u\n"
  493. "free: %u\n",
  494. kmalloc_sum_eternal,
  495. sum_alloc,
  496. sum_free);
  497. return builder.to_byte_buffer();
  498. }
  499. ByteBuffer procfs$summary(InodeIdentifier)
  500. {
  501. InterruptDisabler disabler;
  502. auto processes = Process::all_processes();
  503. StringBuilder builder;
  504. builder.appendf("PID TPG PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n");
  505. for (auto* process : processes) {
  506. builder.appendf("%-3u %-3u %-3u %-3u %-4u %-8s %-3u %-9u %-3u %-4s %s\n",
  507. process->pid(),
  508. process->tty() ? process->tty()->pgid() : 0,
  509. process->pgid(),
  510. process->sid(),
  511. process->uid(),
  512. to_string(process->state()),
  513. process->ppid(),
  514. process->main_thread().times_scheduled(), // FIXME(Thread): Bill all scheds to the process
  515. process->number_of_open_file_descriptors(),
  516. process->tty() ? strrchr(process->tty()->tty_name().characters(), '/') + 1 : "n/a",
  517. process->name().characters());
  518. }
  519. return builder.to_byte_buffer();
  520. }
  521. ByteBuffer procfs$memstat(InodeIdentifier)
  522. {
  523. InterruptDisabler disabler;
  524. JsonObject json;
  525. json.set("kmalloc_allocated", sum_alloc);
  526. json.set("kmalloc_available", sum_free);
  527. json.set("kmalloc_eternal_allocated", kmalloc_sum_eternal);
  528. json.set("user_physical_allocated", MM.user_physical_pages_used());
  529. json.set("user_physical_available", MM.user_physical_pages());
  530. json.set("super_physical_allocated", MM.super_physical_pages_used());
  531. json.set("super_physical_available", MM.super_physical_pages());
  532. json.set("kmalloc_call_count", g_kmalloc_call_count);
  533. json.set("kfree_call_count", g_kfree_call_count);
  534. return json.serialized().to_byte_buffer();
  535. }
  536. ByteBuffer procfs$all(InodeIdentifier)
  537. {
  538. InterruptDisabler disabler;
  539. auto processes = Process::all_processes();
  540. JsonArray array;
  541. auto build_process = [&](const Process& process) {
  542. JsonObject process_object;
  543. process_object.set("pid", process.pid());
  544. process_object.set("times_scheduled", process.main_thread().times_scheduled());
  545. process_object.set("pgid", process.tty() ? process.tty()->pgid() : 0);
  546. process_object.set("sid", process.sid());
  547. process_object.set("uid", process.uid());
  548. process_object.set("gid", process.gid());
  549. process_object.set("state", to_string(process.state()));
  550. process_object.set("ppid", process.ppid());
  551. process_object.set("nfds", process.number_of_open_file_descriptors());
  552. process_object.set("name", process.name());
  553. process_object.set("tty", process.tty() ? process.tty()->tty_name() : "notty");
  554. process_object.set("amount_virtual", process.amount_virtual());
  555. process_object.set("amount_resident", process.amount_resident());
  556. process_object.set("amount_shared", process.amount_shared());
  557. process_object.set("ticks", process.main_thread().ticks());
  558. process_object.set("priority", to_string(process.priority()));
  559. process_object.set("syscall_count", process.syscall_count());
  560. array.append(process_object);
  561. };
  562. build_process(*Scheduler::colonel());
  563. for (auto* process : processes)
  564. build_process(*process);
  565. return array.serialized().to_byte_buffer();
  566. }
  567. ByteBuffer procfs$inodes(InodeIdentifier)
  568. {
  569. extern HashTable<Inode*>& all_inodes();
  570. StringBuilder builder;
  571. for (auto it : all_inodes()) {
  572. RefPtr<Inode> inode = *it;
  573. builder.appendf("Inode{K%x} %02u:%08u (%u)\n", inode.ptr(), inode->fsid(), inode->index(), inode->ref_count());
  574. }
  575. return builder.to_byte_buffer();
  576. }
  577. struct SysVariableData final : public ProcFSInodeCustomData {
  578. virtual ~SysVariableData() override {}
  579. enum Type {
  580. Invalid,
  581. Boolean,
  582. String,
  583. };
  584. Type type { Invalid };
  585. Function<void()> notify_callback;
  586. void* address;
  587. };
  588. static ByteBuffer read_sys_bool(InodeIdentifier inode_id)
  589. {
  590. auto inode_ptr = ProcFS::the().get_inode(inode_id);
  591. if (!inode_ptr)
  592. return {};
  593. auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
  594. ASSERT(inode.custom_data());
  595. auto buffer = ByteBuffer::create_uninitialized(2);
  596. auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
  597. ASSERT(custom_data.type == SysVariableData::Boolean);
  598. ASSERT(custom_data.address);
  599. auto* lockable_bool = reinterpret_cast<Lockable<bool>*>(custom_data.address);
  600. {
  601. LOCKER(lockable_bool->lock());
  602. buffer[0] = lockable_bool->resource() ? '1' : '0';
  603. }
  604. buffer[1] = '\n';
  605. return buffer;
  606. }
  607. static ssize_t write_sys_bool(InodeIdentifier inode_id, const ByteBuffer& data)
  608. {
  609. auto inode_ptr = ProcFS::the().get_inode(inode_id);
  610. if (!inode_ptr)
  611. return {};
  612. auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
  613. ASSERT(inode.custom_data());
  614. if (data.is_empty() || !(data[0] == '0' || data[0] == '1'))
  615. return data.size();
  616. auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
  617. auto* lockable_bool = reinterpret_cast<Lockable<bool>*>(custom_data.address);
  618. {
  619. LOCKER(lockable_bool->lock());
  620. lockable_bool->resource() = data[0] == '1';
  621. }
  622. if (custom_data.notify_callback)
  623. custom_data.notify_callback();
  624. return data.size();
  625. }
  626. static ByteBuffer read_sys_string(InodeIdentifier inode_id)
  627. {
  628. auto inode_ptr = ProcFS::the().get_inode(inode_id);
  629. if (!inode_ptr)
  630. return {};
  631. auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
  632. ASSERT(inode.custom_data());
  633. auto buffer = ByteBuffer::create_uninitialized(2);
  634. auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
  635. ASSERT(custom_data.type == SysVariableData::String);
  636. ASSERT(custom_data.address);
  637. auto* lockable_string = reinterpret_cast<Lockable<String>*>(custom_data.address);
  638. LOCKER(lockable_string->lock());
  639. return lockable_string->resource().to_byte_buffer();
  640. }
  641. static ssize_t write_sys_string(InodeIdentifier inode_id, const ByteBuffer& data)
  642. {
  643. auto inode_ptr = ProcFS::the().get_inode(inode_id);
  644. if (!inode_ptr)
  645. return {};
  646. auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
  647. ASSERT(inode.custom_data());
  648. auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
  649. ASSERT(custom_data.address);
  650. {
  651. auto* lockable_string = reinterpret_cast<Lockable<String>*>(custom_data.address);
  652. LOCKER(lockable_string->lock());
  653. lockable_string->resource() = String((const char*)data.pointer(), data.size());
  654. }
  655. if (custom_data.notify_callback)
  656. custom_data.notify_callback();
  657. return data.size();
  658. }
  659. void ProcFS::add_sys_bool(String&& name, Lockable<bool>& var, Function<void()>&& notify_callback)
  660. {
  661. InterruptDisabler disabler;
  662. int index = m_sys_entries.size();
  663. auto inode = adopt(*new ProcFSInode(*this, sys_var_to_identifier(fsid(), index).index()));
  664. auto data = make<SysVariableData>();
  665. data->type = SysVariableData::Boolean;
  666. data->notify_callback = move(notify_callback);
  667. data->address = &var;
  668. inode->set_custom_data(move(data));
  669. m_sys_entries.append({ strdup(name.characters()), 0, read_sys_bool, write_sys_bool, move(inode) });
  670. }
  671. void ProcFS::add_sys_string(String&& name, Lockable<String>& var, Function<void()>&& notify_callback)
  672. {
  673. InterruptDisabler disabler;
  674. int index = m_sys_entries.size();
  675. auto inode = adopt(*new ProcFSInode(*this, sys_var_to_identifier(fsid(), index).index()));
  676. auto data = make<SysVariableData>();
  677. data->type = SysVariableData::String;
  678. data->notify_callback = move(notify_callback);
  679. data->address = &var;
  680. inode->set_custom_data(move(data));
  681. m_sys_entries.append({ strdup(name.characters()), 0, read_sys_string, write_sys_string, move(inode) });
  682. }
  683. bool ProcFS::initialize()
  684. {
  685. return true;
  686. }
  687. const char* ProcFS::class_name() const
  688. {
  689. return "ProcFS";
  690. }
  691. RefPtr<Inode> ProcFS::create_inode(InodeIdentifier, const String&, mode_t, off_t, dev_t, int&)
  692. {
  693. kprintf("FIXME: Implement ProcFS::create_inode()?\n");
  694. return {};
  695. }
  696. RefPtr<Inode> ProcFS::create_directory(InodeIdentifier, const String&, mode_t, int& error)
  697. {
  698. error = -EROFS;
  699. return nullptr;
  700. }
  701. InodeIdentifier ProcFS::root_inode() const
  702. {
  703. return { fsid(), FI_Root };
  704. }
  705. RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
  706. {
  707. #ifdef PROCFS_DEBUG
  708. dbgprintf("ProcFS::get_inode(%u)\n", inode_id.index());
  709. #endif
  710. if (inode_id == root_inode())
  711. return m_root_inode;
  712. if (to_proc_parent_directory(inode_id) == ProcParentDirectory::PDI_Root_sys) {
  713. auto sys_index = to_sys_index(inode_id);
  714. if (sys_index < m_sys_entries.size())
  715. return m_sys_entries[sys_index].inode;
  716. }
  717. LOCKER(m_inodes_lock);
  718. auto it = m_inodes.find(inode_id.index());
  719. if (it == m_inodes.end()) {
  720. auto inode = adopt(*new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
  721. m_inodes.set(inode_id.index(), inode.ptr());
  722. return inode;
  723. }
  724. return (*it).value;
  725. }
  726. ProcFSInode::ProcFSInode(ProcFS& fs, unsigned index)
  727. : Inode(fs, index)
  728. {
  729. }
  730. ProcFSInode::~ProcFSInode()
  731. {
  732. LOCKER(fs().m_inodes_lock);
  733. fs().m_inodes.remove(index());
  734. }
  735. InodeMetadata ProcFSInode::metadata() const
  736. {
  737. #ifdef PROCFS_DEBUG
  738. dbgprintf("ProcFSInode::metadata(%u)\n", index());
  739. #endif
  740. InodeMetadata metadata;
  741. metadata.inode = identifier();
  742. metadata.ctime = mepoch;
  743. metadata.atime = mepoch;
  744. metadata.mtime = mepoch;
  745. auto proc_parent_directory = to_proc_parent_directory(identifier());
  746. auto pid = to_pid(identifier());
  747. auto proc_file_type = to_proc_file_type(identifier());
  748. #ifdef PROCFS_DEBUG
  749. dbgprintf(" -> pid: %d, fi: %u, pdi: %u\n", pid, proc_file_type, proc_parent_directory);
  750. #endif
  751. if (is_process_related_file(identifier())) {
  752. auto handle = ProcessInspectionHandle::from_pid(pid);
  753. metadata.uid = handle->process().sys$getuid();
  754. metadata.gid = handle->process().sys$getgid();
  755. }
  756. if (proc_parent_directory == PDI_PID_fd) {
  757. metadata.mode = 00120777;
  758. return metadata;
  759. }
  760. if (proc_parent_directory == PDI_Root_sys) {
  761. metadata.mode = 00100644;
  762. return metadata;
  763. }
  764. switch (proc_file_type) {
  765. case FI_Root_self:
  766. case FI_PID_cwd:
  767. case FI_PID_exe:
  768. metadata.mode = 0120777;
  769. break;
  770. case FI_Root:
  771. case FI_Root_sys:
  772. case FI_PID:
  773. case FI_PID_fd:
  774. metadata.mode = 040777;
  775. break;
  776. default:
  777. metadata.mode = 0100644;
  778. break;
  779. }
  780. #ifdef PROCFS_DEBUG
  781. dbgprintf("Returning mode %o\n", metadata.mode);
  782. #endif
  783. return metadata;
  784. }
  785. ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* description) const
  786. {
  787. #ifdef PROCFS_DEBUG
  788. dbgprintf("ProcFS: read_bytes %u\n", index());
  789. #endif
  790. ASSERT(offset >= 0);
  791. ASSERT(buffer);
  792. auto* directory_entry = fs().get_directory_entry(identifier());
  793. Function<ByteBuffer(InodeIdentifier)> callback_tmp;
  794. Function<ByteBuffer(InodeIdentifier)>* read_callback { nullptr };
  795. if (directory_entry) {
  796. read_callback = &directory_entry->read_callback;
  797. } else {
  798. if (to_proc_parent_directory(identifier()) == PDI_PID_fd) {
  799. callback_tmp = procfs$pid_fd_entry;
  800. read_callback = &callback_tmp;
  801. }
  802. }
  803. ASSERT(read_callback);
  804. ByteBuffer generated_data;
  805. if (!description) {
  806. generated_data = (*read_callback)(identifier());
  807. } else {
  808. if (!description->generator_cache())
  809. description->generator_cache() = (*read_callback)(identifier());
  810. generated_data = description->generator_cache();
  811. }
  812. auto& data = generated_data;
  813. ssize_t nread = min(static_cast<off_t>(data.size() - offset), static_cast<off_t>(count));
  814. memcpy(buffer, data.pointer() + offset, nread);
  815. if (nread == 0 && description && description->generator_cache())
  816. description->generator_cache().clear();
  817. return nread;
  818. }
  819. InodeIdentifier ProcFS::ProcFSDirectoryEntry::identifier(unsigned fsid) const
  820. {
  821. return to_identifier(fsid, PDI_Root, 0, (ProcFileType)proc_file_type);
  822. }
  823. bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback) const
  824. {
  825. #ifdef PROCFS_DEBUG
  826. dbgprintf("ProcFS: traverse_as_directory %u\n", index());
  827. #endif
  828. if (!::is_directory(identifier()))
  829. return false;
  830. auto pid = to_pid(identifier());
  831. auto proc_file_type = to_proc_file_type(identifier());
  832. auto parent_id = to_parent_id(identifier());
  833. callback({ ".", 1, identifier(), 2 });
  834. callback({ "..", 2, parent_id, 2 });
  835. switch (proc_file_type) {
  836. case FI_Root:
  837. for (auto& entry : fs().m_entries) {
  838. // FIXME: strlen() here is sad.
  839. if (!entry.name)
  840. continue;
  841. if (entry.proc_file_type > __FI_Root_Start && entry.proc_file_type < __FI_Root_End)
  842. callback({ entry.name, (int)strlen(entry.name), to_identifier(fsid(), PDI_Root, 0, (ProcFileType)entry.proc_file_type), 0 });
  843. }
  844. for (auto pid_child : Process::all_pids()) {
  845. char name[16];
  846. int name_length = ksprintf(name, "%u", pid_child);
  847. callback({ name, name_length, to_identifier(fsid(), PDI_Root, pid_child, FI_PID), 0 });
  848. }
  849. break;
  850. case FI_Root_sys:
  851. for (int i = 0; i < fs().m_sys_entries.size(); ++i) {
  852. auto& entry = fs().m_sys_entries[i];
  853. callback({ entry.name, (int)strlen(entry.name), sys_var_to_identifier(fsid(), i), 0 });
  854. }
  855. break;
  856. case FI_PID: {
  857. auto handle = ProcessInspectionHandle::from_pid(pid);
  858. if (!handle)
  859. return false;
  860. auto& process = handle->process();
  861. for (auto& entry : fs().m_entries) {
  862. if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) {
  863. if (entry.proc_file_type == FI_PID_exe && !process.executable())
  864. continue;
  865. // FIXME: strlen() here is sad.
  866. callback({ entry.name, (int)strlen(entry.name), to_identifier(fsid(), PDI_PID, pid, (ProcFileType)entry.proc_file_type), 0 });
  867. }
  868. }
  869. } break;
  870. case FI_PID_fd: {
  871. auto handle = ProcessInspectionHandle::from_pid(pid);
  872. if (!handle)
  873. return false;
  874. auto& process = handle->process();
  875. for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
  876. auto* description = process.file_description(i);
  877. if (!description)
  878. continue;
  879. char name[16];
  880. int name_length = ksprintf(name, "%u", i);
  881. callback({ name, name_length, to_identifier_with_fd(fsid(), pid, i), 0 });
  882. }
  883. } break;
  884. default:
  885. return true;
  886. }
  887. return true;
  888. }
  889. InodeIdentifier ProcFSInode::lookup(StringView name)
  890. {
  891. ASSERT(is_directory());
  892. if (name == ".")
  893. return identifier();
  894. if (name == "..")
  895. return to_parent_id(identifier());
  896. auto proc_file_type = to_proc_file_type(identifier());
  897. if (proc_file_type == FI_Root) {
  898. for (auto& entry : fs().m_entries) {
  899. if (entry.name == nullptr)
  900. continue;
  901. if (entry.proc_file_type > __FI_Root_Start && entry.proc_file_type < __FI_Root_End) {
  902. if (name == entry.name) {
  903. return to_identifier(fsid(), PDI_Root, 0, (ProcFileType)entry.proc_file_type);
  904. }
  905. }
  906. }
  907. bool ok;
  908. unsigned name_as_number = name.to_uint(ok);
  909. if (ok) {
  910. bool process_exists = false;
  911. {
  912. InterruptDisabler disabler;
  913. process_exists = Process::from_pid(name_as_number);
  914. }
  915. if (process_exists)
  916. return to_identifier(fsid(), PDI_Root, name_as_number, FI_PID);
  917. }
  918. return {};
  919. }
  920. if (proc_file_type == FI_Root_sys) {
  921. for (int i = 0; i < fs().m_sys_entries.size(); ++i) {
  922. auto& entry = fs().m_sys_entries[i];
  923. if (name == entry.name)
  924. return sys_var_to_identifier(fsid(), i);
  925. }
  926. return {};
  927. }
  928. if (proc_file_type == FI_PID) {
  929. auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier()));
  930. if (!handle)
  931. return {};
  932. auto& process = handle->process();
  933. for (auto& entry : fs().m_entries) {
  934. if (entry.proc_file_type > __FI_PID_Start && entry.proc_file_type < __FI_PID_End) {
  935. if (entry.proc_file_type == FI_PID_exe && !process.executable())
  936. continue;
  937. if (entry.name == nullptr)
  938. continue;
  939. if (name == entry.name) {
  940. return to_identifier(fsid(), PDI_PID, to_pid(identifier()), (ProcFileType)entry.proc_file_type);
  941. }
  942. }
  943. }
  944. return {};
  945. }
  946. if (proc_file_type == FI_PID_fd) {
  947. bool ok;
  948. unsigned name_as_number = name.to_uint(ok);
  949. if (ok) {
  950. bool fd_exists = false;
  951. {
  952. InterruptDisabler disabler;
  953. if (auto* process = Process::from_pid(to_pid(identifier())))
  954. fd_exists = process->file_description(name_as_number);
  955. }
  956. if (fd_exists)
  957. return to_identifier_with_fd(fsid(), to_pid(identifier()), name_as_number);
  958. }
  959. }
  960. return {};
  961. }
  962. void ProcFSInode::flush_metadata()
  963. {
  964. }
  965. ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescription*)
  966. {
  967. auto* directory_entry = fs().get_directory_entry(identifier());
  968. if (!directory_entry || !directory_entry->write_callback)
  969. return -EPERM;
  970. ASSERT(is_persistent_inode(identifier()));
  971. // FIXME: Being able to write into ProcFS at a non-zero offset seems like something we should maybe support..
  972. ASSERT(offset == 0);
  973. bool success = directory_entry->write_callback(identifier(), ByteBuffer::wrap(buffer, size));
  974. ASSERT(success);
  975. return 0;
  976. }
  977. KResult ProcFSInode::add_child(InodeIdentifier child_id, const StringView& name, mode_t)
  978. {
  979. (void)child_id;
  980. (void)name;
  981. return KResult(-EPERM);
  982. }
  983. KResult ProcFSInode::remove_child(const StringView& name)
  984. {
  985. (void)name;
  986. return KResult(-EPERM);
  987. }
  988. ProcFSInodeCustomData::~ProcFSInodeCustomData()
  989. {
  990. }
  991. size_t ProcFSInode::directory_entry_count() const
  992. {
  993. ASSERT(is_directory());
  994. size_t count = 0;
  995. traverse_as_directory([&count](const FS::DirectoryEntry&) {
  996. ++count;
  997. return true;
  998. });
  999. return count;
  1000. }
  1001. KResult ProcFSInode::chmod(mode_t)
  1002. {
  1003. return KResult(-EPERM);
  1004. }
  1005. ProcFS::ProcFS()
  1006. {
  1007. s_the = this;
  1008. m_root_inode = adopt(*new ProcFSInode(*this, 1));
  1009. m_entries.resize(FI_MaxStaticFileIndex);
  1010. m_entries[FI_Root_mm] = { "mm", FI_Root_mm, procfs$mm };
  1011. m_entries[FI_Root_mounts] = { "mounts", FI_Root_mounts, procfs$mounts };
  1012. m_entries[FI_Root_df] = { "df", FI_Root_df, procfs$df };
  1013. m_entries[FI_Root_kmalloc] = { "kmalloc", FI_Root_kmalloc, procfs$kmalloc };
  1014. m_entries[FI_Root_all] = { "all", FI_Root_all, procfs$all };
  1015. m_entries[FI_Root_memstat] = { "memstat", FI_Root_memstat, procfs$memstat };
  1016. m_entries[FI_Root_summary] = { "summary", FI_Root_summary, procfs$summary };
  1017. m_entries[FI_Root_cpuinfo] = { "cpuinfo", FI_Root_cpuinfo, procfs$cpuinfo };
  1018. m_entries[FI_Root_inodes] = { "inodes", FI_Root_inodes, procfs$inodes };
  1019. m_entries[FI_Root_dmesg] = { "dmesg", FI_Root_dmesg, procfs$dmesg };
  1020. m_entries[FI_Root_self] = { "self", FI_Root_self, procfs$self };
  1021. m_entries[FI_Root_pci] = { "pci", FI_Root_pci, procfs$pci };
  1022. m_entries[FI_Root_uptime] = { "uptime", FI_Root_uptime, procfs$uptime };
  1023. m_entries[FI_Root_cmdline] = { "cmdline", FI_Root_cmdline, procfs$cmdline };
  1024. m_entries[FI_Root_netadapters] = { "netadapters", FI_Root_netadapters, procfs$netadapters };
  1025. m_entries[FI_Root_sys] = { "sys", FI_Root_sys };
  1026. m_entries[FI_PID_vm] = { "vm", FI_PID_vm, procfs$pid_vm };
  1027. m_entries[FI_PID_vmo] = { "vmo", FI_PID_vmo, procfs$pid_vmo };
  1028. m_entries[FI_PID_stack] = { "stack", FI_PID_stack, procfs$pid_stack };
  1029. m_entries[FI_PID_regs] = { "regs", FI_PID_regs, procfs$pid_regs };
  1030. m_entries[FI_PID_fds] = { "fds", FI_PID_fds, procfs$pid_fds };
  1031. m_entries[FI_PID_exe] = { "exe", FI_PID_exe, procfs$pid_exe };
  1032. m_entries[FI_PID_cwd] = { "cwd", FI_PID_cwd, procfs$pid_cwd };
  1033. m_entries[FI_PID_fd] = { "fd", FI_PID_fd };
  1034. m_kmalloc_stack_helper.resource() = g_dump_kmalloc_stacks;
  1035. add_sys_bool("kmalloc_stacks", m_kmalloc_stack_helper, [this] {
  1036. g_dump_kmalloc_stacks = m_kmalloc_stack_helper.resource();
  1037. });
  1038. }
  1039. ProcFS::ProcFSDirectoryEntry* ProcFS::get_directory_entry(InodeIdentifier identifier) const
  1040. {
  1041. if (to_proc_parent_directory(identifier) == PDI_Root_sys) {
  1042. auto sys_index = to_sys_index(identifier);
  1043. if (sys_index < m_sys_entries.size())
  1044. return const_cast<ProcFSDirectoryEntry*>(&m_sys_entries[sys_index]);
  1045. return nullptr;
  1046. }
  1047. auto proc_file_type = to_proc_file_type(identifier);
  1048. if (proc_file_type != FI_Invalid && proc_file_type < FI_MaxStaticFileIndex)
  1049. return const_cast<ProcFSDirectoryEntry*>(&m_entries[proc_file_type]);
  1050. return nullptr;
  1051. }
  1052. KResult ProcFSInode::chown(uid_t, gid_t)
  1053. {
  1054. return KResult(-EPERM);
  1055. }