kcore.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * fs/proc/kcore.c kernel ELF core dumper
  4. *
  5. * Modelled on fs/exec.c:aout_core_dump()
  6. * Jeremy Fitzhardinge <jeremy@sw.oz.au>
  7. * ELF version written by David Howells <David.Howells@nexor.co.uk>
  8. * Modified and incorporated into 2.3.x by Tigran Aivazian <tigran@veritas.com>
  9. * Support to dump vmalloc'd areas (ELF only), Tigran Aivazian <tigran@veritas.com>
  10. * Safe accesses to vmalloc/direct-mapped discontiguous areas, Kanoj Sarcar <kanoj@sgi.com>
  11. */
  12. #include <linux/mm.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/kcore.h>
  15. #include <linux/user.h>
  16. #include <linux/capability.h>
  17. #include <linux/elf.h>
  18. #include <linux/elfcore.h>
  19. #include <linux/notifier.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/highmem.h>
  22. #include <linux/printk.h>
  23. #include <linux/bootmem.h>
  24. #include <linux/init.h>
  25. #include <linux/slab.h>
  26. #include <linux/uaccess.h>
  27. #include <asm/io.h>
  28. #include <linux/list.h>
  29. #include <linux/ioport.h>
  30. #include <linux/memory.h>
  31. #include <linux/sched/task.h>
  32. #include <asm/sections.h>
  33. #include "internal.h"
  34. #define CORE_STR "CORE"
  35. #ifndef ELF_CORE_EFLAGS
  36. #define ELF_CORE_EFLAGS 0
  37. #endif
  38. static struct proc_dir_entry *proc_root_kcore;
  39. #ifndef kc_vaddr_to_offset
  40. #define kc_vaddr_to_offset(v) ((v) - PAGE_OFFSET)
  41. #endif
  42. #ifndef kc_offset_to_vaddr
  43. #define kc_offset_to_vaddr(o) ((o) + PAGE_OFFSET)
  44. #endif
  45. /* An ELF note in memory */
  46. struct memelfnote
  47. {
  48. const char *name;
  49. int type;
  50. unsigned int datasz;
  51. void *data;
  52. };
  53. static LIST_HEAD(kclist_head);
  54. static DEFINE_RWLOCK(kclist_lock);
  55. static int kcore_need_update = 1;
  56. void
  57. kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
  58. {
  59. new->addr = (unsigned long)addr;
  60. new->size = size;
  61. new->type = type;
  62. write_lock(&kclist_lock);
  63. list_add_tail(&new->list, &kclist_head);
  64. write_unlock(&kclist_lock);
  65. }
  66. static size_t get_kcore_size(int *nphdr, size_t *elf_buflen)
  67. {
  68. size_t try, size;
  69. struct kcore_list *m;
  70. *nphdr = 1; /* PT_NOTE */
  71. size = 0;
  72. list_for_each_entry(m, &kclist_head, list) {
  73. try = kc_vaddr_to_offset((size_t)m->addr + m->size);
  74. if (try > size)
  75. size = try;
  76. *nphdr = *nphdr + 1;
  77. }
  78. *elf_buflen = sizeof(struct elfhdr) +
  79. (*nphdr + 2)*sizeof(struct elf_phdr) +
  80. 3 * ((sizeof(struct elf_note)) +
  81. roundup(sizeof(CORE_STR), 4)) +
  82. roundup(sizeof(struct elf_prstatus), 4) +
  83. roundup(sizeof(struct elf_prpsinfo), 4) +
  84. roundup(arch_task_struct_size, 4);
  85. *elf_buflen = PAGE_ALIGN(*elf_buflen);
  86. return size + *elf_buflen;
  87. }
  88. static void free_kclist_ents(struct list_head *head)
  89. {
  90. struct kcore_list *tmp, *pos;
  91. list_for_each_entry_safe(pos, tmp, head, list) {
  92. list_del(&pos->list);
  93. kfree(pos);
  94. }
  95. }
  96. /*
  97. * Replace all KCORE_RAM/KCORE_VMEMMAP information with passed list.
  98. */
  99. static void __kcore_update_ram(struct list_head *list)
  100. {
  101. int nphdr;
  102. size_t size;
  103. struct kcore_list *tmp, *pos;
  104. LIST_HEAD(garbage);
  105. write_lock(&kclist_lock);
  106. if (kcore_need_update) {
  107. list_for_each_entry_safe(pos, tmp, &kclist_head, list) {
  108. if (pos->type == KCORE_RAM
  109. || pos->type == KCORE_VMEMMAP)
  110. list_move(&pos->list, &garbage);
  111. }
  112. list_splice_tail(list, &kclist_head);
  113. } else
  114. list_splice(list, &garbage);
  115. kcore_need_update = 0;
  116. proc_root_kcore->size = get_kcore_size(&nphdr, &size);
  117. write_unlock(&kclist_lock);
  118. free_kclist_ents(&garbage);
  119. }
  120. #ifdef CONFIG_HIGHMEM
  121. /*
  122. * If no highmem, we can assume [0...max_low_pfn) continuous range of memory
  123. * because memory hole is not as big as !HIGHMEM case.
  124. * (HIGHMEM is special because part of memory is _invisible_ from the kernel.)
  125. */
  126. static int kcore_update_ram(void)
  127. {
  128. LIST_HEAD(head);
  129. struct kcore_list *ent;
  130. int ret = 0;
  131. ent = kmalloc(sizeof(*ent), GFP_KERNEL);
  132. if (!ent)
  133. return -ENOMEM;
  134. ent->addr = (unsigned long)__va(0);
  135. ent->size = max_low_pfn << PAGE_SHIFT;
  136. ent->type = KCORE_RAM;
  137. list_add(&ent->list, &head);
  138. __kcore_update_ram(&head);
  139. return ret;
  140. }
  141. #else /* !CONFIG_HIGHMEM */
  142. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  143. /* calculate vmemmap's address from given system ram pfn and register it */
  144. static int
  145. get_sparsemem_vmemmap_info(struct kcore_list *ent, struct list_head *head)
  146. {
  147. unsigned long pfn = __pa(ent->addr) >> PAGE_SHIFT;
  148. unsigned long nr_pages = ent->size >> PAGE_SHIFT;
  149. unsigned long start, end;
  150. struct kcore_list *vmm, *tmp;
  151. start = ((unsigned long)pfn_to_page(pfn)) & PAGE_MASK;
  152. end = ((unsigned long)pfn_to_page(pfn + nr_pages)) - 1;
  153. end = PAGE_ALIGN(end);
  154. /* overlap check (because we have to align page */
  155. list_for_each_entry(tmp, head, list) {
  156. if (tmp->type != KCORE_VMEMMAP)
  157. continue;
  158. if (start < tmp->addr + tmp->size)
  159. if (end > tmp->addr)
  160. end = tmp->addr;
  161. }
  162. if (start < end) {
  163. vmm = kmalloc(sizeof(*vmm), GFP_KERNEL);
  164. if (!vmm)
  165. return 0;
  166. vmm->addr = start;
  167. vmm->size = end - start;
  168. vmm->type = KCORE_VMEMMAP;
  169. list_add_tail(&vmm->list, head);
  170. }
  171. return 1;
  172. }
  173. #else
  174. static int
  175. get_sparsemem_vmemmap_info(struct kcore_list *ent, struct list_head *head)
  176. {
  177. return 1;
  178. }
  179. #endif
  180. static int
  181. kclist_add_private(unsigned long pfn, unsigned long nr_pages, void *arg)
  182. {
  183. struct list_head *head = (struct list_head *)arg;
  184. struct kcore_list *ent;
  185. struct page *p;
  186. if (!pfn_valid(pfn))
  187. return 1;
  188. p = pfn_to_page(pfn);
  189. if (!memmap_valid_within(pfn, p, page_zone(p)))
  190. return 1;
  191. ent = kmalloc(sizeof(*ent), GFP_KERNEL);
  192. if (!ent)
  193. return -ENOMEM;
  194. ent->addr = (unsigned long)page_to_virt(p);
  195. ent->size = nr_pages << PAGE_SHIFT;
  196. if (!virt_addr_valid(ent->addr))
  197. goto free_out;
  198. /* cut not-mapped area. ....from ppc-32 code. */
  199. if (ULONG_MAX - ent->addr < ent->size)
  200. ent->size = ULONG_MAX - ent->addr;
  201. /*
  202. * We've already checked virt_addr_valid so we know this address
  203. * is a valid pointer, therefore we can check against it to determine
  204. * if we need to trim
  205. */
  206. if (VMALLOC_START > ent->addr) {
  207. if (VMALLOC_START - ent->addr < ent->size)
  208. ent->size = VMALLOC_START - ent->addr;
  209. }
  210. ent->type = KCORE_RAM;
  211. list_add_tail(&ent->list, head);
  212. if (!get_sparsemem_vmemmap_info(ent, head)) {
  213. list_del(&ent->list);
  214. goto free_out;
  215. }
  216. return 0;
  217. free_out:
  218. kfree(ent);
  219. return 1;
  220. }
  221. static int kcore_update_ram(void)
  222. {
  223. int nid, ret;
  224. unsigned long end_pfn;
  225. LIST_HEAD(head);
  226. /* Not inialized....update now */
  227. /* find out "max pfn" */
  228. end_pfn = 0;
  229. for_each_node_state(nid, N_MEMORY) {
  230. unsigned long node_end;
  231. node_end = node_end_pfn(nid);
  232. if (end_pfn < node_end)
  233. end_pfn = node_end;
  234. }
  235. /* scan 0 to max_pfn */
  236. ret = walk_system_ram_range(0, end_pfn, &head, kclist_add_private);
  237. if (ret) {
  238. free_kclist_ents(&head);
  239. return -ENOMEM;
  240. }
  241. __kcore_update_ram(&head);
  242. return ret;
  243. }
  244. #endif /* CONFIG_HIGHMEM */
  245. /*****************************************************************************/
  246. /*
  247. * determine size of ELF note
  248. */
  249. static int notesize(struct memelfnote *en)
  250. {
  251. int sz;
  252. sz = sizeof(struct elf_note);
  253. sz += roundup((strlen(en->name) + 1), 4);
  254. sz += roundup(en->datasz, 4);
  255. return sz;
  256. } /* end notesize() */
  257. /*****************************************************************************/
  258. /*
  259. * store a note in the header buffer
  260. */
  261. static char *storenote(struct memelfnote *men, char *bufp)
  262. {
  263. struct elf_note en;
  264. #define DUMP_WRITE(addr,nr) do { memcpy(bufp,addr,nr); bufp += nr; } while(0)
  265. en.n_namesz = strlen(men->name) + 1;
  266. en.n_descsz = men->datasz;
  267. en.n_type = men->type;
  268. DUMP_WRITE(&en, sizeof(en));
  269. DUMP_WRITE(men->name, en.n_namesz);
  270. /* XXX - cast from long long to long to avoid need for libgcc.a */
  271. bufp = (char*) roundup((unsigned long)bufp,4);
  272. DUMP_WRITE(men->data, men->datasz);
  273. bufp = (char*) roundup((unsigned long)bufp,4);
  274. #undef DUMP_WRITE
  275. return bufp;
  276. } /* end storenote() */
  277. /*
  278. * store an ELF coredump header in the supplied buffer
  279. * nphdr is the number of elf_phdr to insert
  280. */
  281. static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
  282. {
  283. struct elf_prstatus prstatus; /* NT_PRSTATUS */
  284. struct elf_prpsinfo prpsinfo; /* NT_PRPSINFO */
  285. struct elf_phdr *nhdr, *phdr;
  286. struct elfhdr *elf;
  287. struct memelfnote notes[3];
  288. off_t offset = 0;
  289. struct kcore_list *m;
  290. /* setup ELF header */
  291. elf = (struct elfhdr *) bufp;
  292. bufp += sizeof(struct elfhdr);
  293. offset += sizeof(struct elfhdr);
  294. memcpy(elf->e_ident, ELFMAG, SELFMAG);
  295. elf->e_ident[EI_CLASS] = ELF_CLASS;
  296. elf->e_ident[EI_DATA] = ELF_DATA;
  297. elf->e_ident[EI_VERSION]= EV_CURRENT;
  298. elf->e_ident[EI_OSABI] = ELF_OSABI;
  299. memset(elf->e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
  300. elf->e_type = ET_CORE;
  301. elf->e_machine = ELF_ARCH;
  302. elf->e_version = EV_CURRENT;
  303. elf->e_entry = 0;
  304. elf->e_phoff = sizeof(struct elfhdr);
  305. elf->e_shoff = 0;
  306. elf->e_flags = ELF_CORE_EFLAGS;
  307. elf->e_ehsize = sizeof(struct elfhdr);
  308. elf->e_phentsize= sizeof(struct elf_phdr);
  309. elf->e_phnum = nphdr;
  310. elf->e_shentsize= 0;
  311. elf->e_shnum = 0;
  312. elf->e_shstrndx = 0;
  313. /* setup ELF PT_NOTE program header */
  314. nhdr = (struct elf_phdr *) bufp;
  315. bufp += sizeof(struct elf_phdr);
  316. offset += sizeof(struct elf_phdr);
  317. nhdr->p_type = PT_NOTE;
  318. nhdr->p_offset = 0;
  319. nhdr->p_vaddr = 0;
  320. nhdr->p_paddr = 0;
  321. nhdr->p_filesz = 0;
  322. nhdr->p_memsz = 0;
  323. nhdr->p_flags = 0;
  324. nhdr->p_align = 0;
  325. /* setup ELF PT_LOAD program header for every area */
  326. list_for_each_entry(m, &kclist_head, list) {
  327. phdr = (struct elf_phdr *) bufp;
  328. bufp += sizeof(struct elf_phdr);
  329. offset += sizeof(struct elf_phdr);
  330. phdr->p_type = PT_LOAD;
  331. phdr->p_flags = PF_R|PF_W|PF_X;
  332. phdr->p_offset = kc_vaddr_to_offset(m->addr) + dataoff;
  333. phdr->p_vaddr = (size_t)m->addr;
  334. if (m->type == KCORE_RAM || m->type == KCORE_TEXT)
  335. phdr->p_paddr = __pa(m->addr);
  336. else
  337. phdr->p_paddr = (elf_addr_t)-1;
  338. phdr->p_filesz = phdr->p_memsz = m->size;
  339. phdr->p_align = PAGE_SIZE;
  340. }
  341. /*
  342. * Set up the notes in similar form to SVR4 core dumps made
  343. * with info from their /proc.
  344. */
  345. nhdr->p_offset = offset;
  346. /* set up the process status */
  347. notes[0].name = CORE_STR;
  348. notes[0].type = NT_PRSTATUS;
  349. notes[0].datasz = sizeof(struct elf_prstatus);
  350. notes[0].data = &prstatus;
  351. memset(&prstatus, 0, sizeof(struct elf_prstatus));
  352. nhdr->p_filesz = notesize(&notes[0]);
  353. bufp = storenote(&notes[0], bufp);
  354. /* set up the process info */
  355. notes[1].name = CORE_STR;
  356. notes[1].type = NT_PRPSINFO;
  357. notes[1].datasz = sizeof(struct elf_prpsinfo);
  358. notes[1].data = &prpsinfo;
  359. memset(&prpsinfo, 0, sizeof(struct elf_prpsinfo));
  360. prpsinfo.pr_state = 0;
  361. prpsinfo.pr_sname = 'R';
  362. prpsinfo.pr_zomb = 0;
  363. strcpy(prpsinfo.pr_fname, "vmlinux");
  364. strlcpy(prpsinfo.pr_psargs, saved_command_line, sizeof(prpsinfo.pr_psargs));
  365. nhdr->p_filesz += notesize(&notes[1]);
  366. bufp = storenote(&notes[1], bufp);
  367. /* set up the task structure */
  368. notes[2].name = CORE_STR;
  369. notes[2].type = NT_TASKSTRUCT;
  370. notes[2].datasz = arch_task_struct_size;
  371. notes[2].data = current;
  372. nhdr->p_filesz += notesize(&notes[2]);
  373. bufp = storenote(&notes[2], bufp);
  374. } /* end elf_kcore_store_hdr() */
  375. /*****************************************************************************/
  376. /*
  377. * read from the ELF header and then kernel memory
  378. */
  379. static ssize_t
  380. read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
  381. {
  382. char *buf = file->private_data;
  383. ssize_t acc = 0;
  384. size_t size, tsz;
  385. size_t elf_buflen;
  386. int nphdr;
  387. unsigned long start;
  388. read_lock(&kclist_lock);
  389. size = get_kcore_size(&nphdr, &elf_buflen);
  390. if (buflen == 0 || *fpos >= size) {
  391. read_unlock(&kclist_lock);
  392. return 0;
  393. }
  394. /* trim buflen to not go beyond EOF */
  395. if (buflen > size - *fpos)
  396. buflen = size - *fpos;
  397. /* construct an ELF core header if we'll need some of it */
  398. if (*fpos < elf_buflen) {
  399. char * elf_buf;
  400. tsz = elf_buflen - *fpos;
  401. if (buflen < tsz)
  402. tsz = buflen;
  403. elf_buf = kzalloc(elf_buflen, GFP_ATOMIC);
  404. if (!elf_buf) {
  405. read_unlock(&kclist_lock);
  406. return -ENOMEM;
  407. }
  408. elf_kcore_store_hdr(elf_buf, nphdr, elf_buflen);
  409. read_unlock(&kclist_lock);
  410. if (copy_to_user(buffer, elf_buf + *fpos, tsz)) {
  411. kfree(elf_buf);
  412. return -EFAULT;
  413. }
  414. kfree(elf_buf);
  415. buflen -= tsz;
  416. *fpos += tsz;
  417. buffer += tsz;
  418. acc += tsz;
  419. /* leave now if filled buffer already */
  420. if (buflen == 0)
  421. return acc;
  422. } else
  423. read_unlock(&kclist_lock);
  424. /*
  425. * Check to see if our file offset matches with any of
  426. * the addresses in the elf_phdr on our list.
  427. */
  428. start = kc_offset_to_vaddr(*fpos - elf_buflen);
  429. if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
  430. tsz = buflen;
  431. while (buflen) {
  432. struct kcore_list *m;
  433. read_lock(&kclist_lock);
  434. list_for_each_entry(m, &kclist_head, list) {
  435. if (start >= m->addr && start < (m->addr+m->size))
  436. break;
  437. }
  438. read_unlock(&kclist_lock);
  439. if (&m->list == &kclist_head) {
  440. if (clear_user(buffer, tsz))
  441. return -EFAULT;
  442. } else if (m->type == KCORE_VMALLOC) {
  443. vread(buf, (char *)start, tsz);
  444. /* we have to zero-fill user buffer even if no read */
  445. if (copy_to_user(buffer, buf, tsz))
  446. return -EFAULT;
  447. } else if (m->type == KCORE_USER) {
  448. /* User page is handled prior to normal kernel page: */
  449. if (copy_to_user(buffer, (char *)start, tsz))
  450. return -EFAULT;
  451. } else {
  452. if (kern_addr_valid(start)) {
  453. /*
  454. * Using bounce buffer to bypass the
  455. * hardened user copy kernel text checks.
  456. */
  457. if (probe_kernel_read(buf, (void *) start, tsz)) {
  458. if (clear_user(buffer, tsz))
  459. return -EFAULT;
  460. } else {
  461. if (copy_to_user(buffer, buf, tsz))
  462. return -EFAULT;
  463. }
  464. } else {
  465. if (clear_user(buffer, tsz))
  466. return -EFAULT;
  467. }
  468. }
  469. buflen -= tsz;
  470. *fpos += tsz;
  471. buffer += tsz;
  472. acc += tsz;
  473. start += tsz;
  474. tsz = (buflen > PAGE_SIZE ? PAGE_SIZE : buflen);
  475. }
  476. return acc;
  477. }
  478. static int open_kcore(struct inode *inode, struct file *filp)
  479. {
  480. if (!capable(CAP_SYS_RAWIO))
  481. return -EPERM;
  482. filp->private_data = kmalloc(PAGE_SIZE, GFP_KERNEL);
  483. if (!filp->private_data)
  484. return -ENOMEM;
  485. if (kcore_need_update)
  486. kcore_update_ram();
  487. if (i_size_read(inode) != proc_root_kcore->size) {
  488. inode_lock(inode);
  489. i_size_write(inode, proc_root_kcore->size);
  490. inode_unlock(inode);
  491. }
  492. return 0;
  493. }
  494. static int release_kcore(struct inode *inode, struct file *file)
  495. {
  496. kfree(file->private_data);
  497. return 0;
  498. }
  499. static const struct file_operations proc_kcore_operations = {
  500. .read = read_kcore,
  501. .open = open_kcore,
  502. .release = release_kcore,
  503. .llseek = default_llseek,
  504. };
  505. /* just remember that we have to update kcore */
  506. static int __meminit kcore_callback(struct notifier_block *self,
  507. unsigned long action, void *arg)
  508. {
  509. switch (action) {
  510. case MEM_ONLINE:
  511. case MEM_OFFLINE:
  512. write_lock(&kclist_lock);
  513. kcore_need_update = 1;
  514. write_unlock(&kclist_lock);
  515. }
  516. return NOTIFY_OK;
  517. }
  518. static struct notifier_block kcore_callback_nb __meminitdata = {
  519. .notifier_call = kcore_callback,
  520. .priority = 0,
  521. };
  522. static struct kcore_list kcore_vmalloc;
  523. #ifdef CONFIG_ARCH_PROC_KCORE_TEXT
  524. static struct kcore_list kcore_text;
  525. /*
  526. * If defined, special segment is used for mapping kernel text instead of
  527. * direct-map area. We need to create special TEXT section.
  528. */
  529. static void __init proc_kcore_text_init(void)
  530. {
  531. kclist_add(&kcore_text, _text, _end - _text, KCORE_TEXT);
  532. }
  533. #else
  534. static void __init proc_kcore_text_init(void)
  535. {
  536. }
  537. #endif
  538. #if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
  539. /*
  540. * MODULES_VADDR has no intersection with VMALLOC_ADDR.
  541. */
  542. struct kcore_list kcore_modules;
  543. static void __init add_modules_range(void)
  544. {
  545. if (MODULES_VADDR != VMALLOC_START && MODULES_END != VMALLOC_END) {
  546. kclist_add(&kcore_modules, (void *)MODULES_VADDR,
  547. MODULES_END - MODULES_VADDR, KCORE_VMALLOC);
  548. }
  549. }
  550. #else
  551. static void __init add_modules_range(void)
  552. {
  553. }
  554. #endif
  555. static int __init proc_kcore_init(void)
  556. {
  557. proc_root_kcore = proc_create("kcore", S_IRUSR, NULL,
  558. &proc_kcore_operations);
  559. if (!proc_root_kcore) {
  560. pr_err("couldn't create /proc/kcore\n");
  561. return 0; /* Always returns 0. */
  562. }
  563. /* Store text area if it's special */
  564. proc_kcore_text_init();
  565. /* Store vmalloc area */
  566. kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
  567. VMALLOC_END - VMALLOC_START, KCORE_VMALLOC);
  568. add_modules_range();
  569. /* Store direct-map area from physical memory map */
  570. kcore_update_ram();
  571. register_hotmemory_notifier(&kcore_callback_nb);
  572. return 0;
  573. }
  574. fs_initcall(proc_kcore_init);