Ядро Linux в комментариях




Fs/binfmt_elf.c - часть 3


8865 notes[0].name = "CORE"; 8866 notes[0].type = NT_PRSTATUS; 8867 notes[0].datasz = sizeof(prstatus); 8868 notes[0].data = &prstatus; 8869 prstatus.pr_info.si_signo = prstatus.pr_cursig = signr; 8870 prstatus.pr_sigpend = current->signal.sig[0]; 8871 prstatus.pr_sighold = current->blocked.sig[0]; 8872 psinfo.pr_pid = prstatus.pr_pid = current->pid; 8873 psinfo.pr_ppid = prstatus.pr_ppid = 8874 current->p_pptr->pid; 8875 psinfo.pr_pgrp = prstatus.pr_pgrp = current->pgrp; 8876 psinfo.pr_sid = prstatus.pr_sid = current->session; 8877 prstatus.pr_utime.tv_sec = 8878 CT_TO_SECS(current->times.tms_utime); 8879 prstatus.pr_utime.tv_usec = 8880 CT_TO_USECS(current->times.tms_utime); 8881 prstatus.pr_stime.tv_sec = 8882 CT_TO_SECS(current->times.tms_stime); 8883 prstatus.pr_stime.tv_usec = 8884 CT_TO_USECS(current->times.tms_stime); 8885 prstatus.pr_cutime.tv_sec = 8886 CT_TO_SECS(current->times.tms_cutime); 8887 prstatus.pr_cutime.tv_usec = 8888 CT_TO_USECS(current->times.tms_cutime); 8889 prstatus.pr_cstime.tv_sec = 8890 CT_TO_SECS(current->times.tms_cstime); 8891 prstatus.pr_cstime.tv_usec = 8892 CT_TO_USECS(current->times.tms_cstime); 8893 8894 /* This transfers the registers from regs into the 8895 * standard coredump arrangement, whatever that is. */ 8896 #ifdef ELF_CORE_COPY_REGS 8897 ELF_CORE_COPY_REGS(prstatus.pr_reg, regs) 8898 #else 8899 if (sizeof(elf_gregset_t) != sizeof(struct pt_regs)) 8900 { 8901 printk("sizeof(elf_gregset_t) (%ld) != " 8902 "sizeof(struct pt_regs) (%ld)\n", 8903 (long)sizeof(elf_gregset_t), 8904 (long)sizeof(struct pt_regs)); 8905 } 8906 else 8907 *(struct pt_regs *)&prstatus.pr_reg = *regs; 8908 #endif 8909 8910 #ifdef DEBUG 8911 dump_regs("Passed in regs", (elf_greg_t *)regs); 8912 dump_regs("prstatus regs", 8913 (elf_greg_t *)&prstatus.pr_reg); 8914 #endif 8915 8916 notes[1].name = "CORE"; 8917 notes[1].type = NT_PRPSINFO; 8918 notes[1].datasz = sizeof(psinfo); 8919 notes[1].data = &psinfo; 8920 i = current->state ? ffz(~current->state) + 1 : 0; 8921 psinfo.pr_state = i; 8922 psinfo.pr_sname = (i < 0 i > 5) ? '.' : "RSDZTD"[i]; 8923 psinfo.pr_zomb = psinfo.pr_sname == 'Z'; 8924 psinfo.pr_nice = current->priority-15; 8925 psinfo.pr_flag = current->flags; 8926 psinfo.pr_uid = current->uid; 8927 psinfo.pr_gid = current->gid; 8928 { 8929 int i, len; 8930 8931 set_fs(fs); 8932 8933 len = current->mm->arg_end - current->mm->arg_start; 8934 if (len >= ELF_PRARGSZ) 8935 len = ELF_PRARGSZ-1; 8936 copy_from_user(&psinfo.pr_psargs, 8937 (const char *)current->mm->arg_start, len); 8938 for(i = 0; i < len; i++) 8939 if (psinfo.pr_psargs[i] == 0) 8940 psinfo.pr_psargs[i] = ' '; 8941 psinfo.pr_psargs[len] = 0; 8942 8943 set_fs(KERNEL_DS); 8944 } 8945 strncpy(psinfo.pr_fname, current->comm, 8946 sizeof(psinfo.pr_fname)); 8947 8948 notes[2].name = "CORE"; 8949 notes[2].type = NT_TASKSTRUCT; 8950 notes[2].datasz = sizeof(*current); 8951 notes[2].data = current; 8952 8953 /* Try to dump the FPU. */ 8954 prstatus.pr_fpvalid = dump_fpu (regs, &fpu); 8955 if (!prstatus.pr_fpvalid) 8956 { 8957 numnote--; 8958 } 8959 else 8960 { 8961 notes[3].name = "CORE"; 8962 notes[3].type = NT_PRFPREG; 8963 notes[3].datasz = sizeof(fpu); 8964 notes[3].data = &fpu; 8965 } 8966 8967 /* Write notes phdr entry */ 8968 { 8969 struct elf_phdr phdr; 8970 int sz = 0; 8971 8972 for(i = 0; i < numnote; i++) 8973 sz += notesize(&notes[i]); 8974 8975 phdr.p_type = PT_NOTE; 8976 phdr.p_offset = offset; 8977 phdr.p_vaddr = 0; 8978 phdr.p_paddr = 0; 8979 phdr.p_filesz = sz; 8980 phdr.p_memsz = 0; 8981 phdr.p_flags = 0; 8982 phdr.p_align = 0; 8983 8984 offset += phdr.p_filesz; 8985 DUMP_WRITE(&phdr, sizeof(phdr)); 8986 } 8987 8988 /* Page-align dumped data */ 8989 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE); 8990 8991 /* Write program headers for segments dump */ 8992 for(vma = current->mm->mmap, i = 0; 8993 i < segs && vma != NULL; vma = vma->vm_next) { 8994 struct elf_phdr phdr; 8995 size_t sz; 8996 8997 i++; 8998 8999 sz = vma->vm_end - vma->vm_start; 9000 9001 phdr.p_type = PT_LOAD; 9002 phdr.p_offset = offset; 9003 phdr.p_vaddr = vma->vm_start; 9004 phdr.p_paddr = 0; 9005 phdr.p_filesz = maydump(vma) ? sz : 0; 9006 phdr.p_memsz = sz; 9007 offset += phdr.p_filesz; 9008 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0; 9009 if (vma->vm_flags & VM_WRITE) phdr.p_flags |= PF_W; 9010 if (vma->vm_flags & VM_EXEC) phdr.p_flags |= PF_X; 9011 phdr.p_align = ELF_EXEC_PAGESIZE; 9012 9013 DUMP_WRITE(&phdr, sizeof(phdr)); 9014 } 9015 9016 for(i = 0; i < numnote; i++) 9017 if (!writenote(&notes[i], &file)) 9018 goto close_coredump; 9019 9020 set_fs(fs); 9021 9022 DUMP_SEEK(dataoff); 9023 9024 for(i = 0, vma = current->mm->mmap; 9025 i < segs && vma != NULL; 9026 vma = vma->vm_next) { 9027 unsigned long addr = vma->vm_start; 9028 unsigned long len = vma->vm_end - vma->vm_start; 9029 9030 i++; 9031 if (!maydump(vma)) 9032 continue; 9033 #ifdef DEBUG 9034 printk("elf_core_dump: writing %08lx %lx\n", 9035 addr, len); 9036 #endif 9037 DUMP_WRITE((void *)addr, len); 9038 } 9039 9040 if ((off_t) file.f_pos != offset) { 9041 /* Sanity check */ 9042 printk("elf_core_dump: file.f_pos (%ld) != " 9043 "offset (%ld)\n", 9044 (off_t) file.f_pos, offset); 9045 } 9046 9047 close_coredump: 9048 if (file.f_op->release) 9049 file.f_op->release(inode,&file); 9050 9051 end_coredump: 9052 set_fs(fs); 9053 dput(dentry); 9054 #ifndef CONFIG_BINFMT_ELF 9055 MOD_DEC_USE_COUNT; 9056 #endif 9057 return has_dumped; 9058 } 9059 #endif /* USE_ELF_CORE_DUMP */ 9060 9061 int __init init_elf_binfmt(void) 9062 { 9063 return register_binfmt(&elf_format); 9064 } 9065 9066 #ifdef MODULE 9067 9068 int init_module(void) 9069 { 9070 /* Install the COFF, ELF and XOUT loaders. N.B. We 9071 * *rely* on the table being the right size with the 9072 * right number of free slots... */ 9073 return init_elf_binfmt(); 9074 } 9075 9076 9077 void cleanup_module( void) 9078 { 9079 /* Remove the COFF and ELF loaders. */ 9080 unregister_binfmt(&elf_format); 9081 } 9082 #endif




Содержание  Назад  Вперед