X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/b0d623f7f2ae71ed96e60569f61f9a9a27016e80..04b8595b18b1b41ac7a206e4b3d51a635f8413d7:/bsd/kern/kern_core.c diff --git a/bsd/kern/kern_core.c b/bsd/kern/kern_core.c index 52c0a3095..2bd9de059 100644 --- a/bsd/kern/kern_core.c +++ b/bsd/kern/kern_core.c @@ -70,24 +70,7 @@ typedef struct { mach_msg_type_number_t count; /* count of ints in this flavor */ } mythread_state_flavor_t; -#if defined (__ppc__) -/* 64 bit */ -mythread_state_flavor_t thread_flavor_array64[]={ - {PPC_THREAD_STATE64 , PPC_THREAD_STATE64_COUNT}, - {PPC_FLOAT_STATE, PPC_FLOAT_STATE_COUNT}, - {PPC_EXCEPTION_STATE64, PPC_EXCEPTION_STATE64_COUNT}, - {PPC_VECTOR_STATE, PPC_VECTOR_STATE_COUNT} - }; - -/* 32 bit */ -mythread_state_flavor_t thread_flavor_array[]={ - {PPC_THREAD_STATE , PPC_THREAD_STATE_COUNT}, - {PPC_FLOAT_STATE, PPC_FLOAT_STATE_COUNT}, - {PPC_EXCEPTION_STATE, PPC_EXCEPTION_STATE_COUNT}, - {PPC_VECTOR_STATE, PPC_VECTOR_STATE_COUNT} - }; - -#elif defined (__i386__) || defined (__x86_64__) +#if defined (__i386__) || defined (__x86_64__) mythread_state_flavor_t thread_flavor_array [] = { {x86_THREAD_STATE, x86_THREAD_STATE_COUNT}, {x86_FLOAT_STATE, x86_FLOAT_STATE_COUNT}, @@ -110,20 +93,23 @@ typedef struct { /* XXX should be static */ void collectth_state(thread_t th_act, void *tirp); +extern int freespace_mb(vnode_t vp); + /* XXX not in a Mach header anywhere */ kern_return_t thread_getstatus(register thread_t act, int flavor, thread_state_t tstate, mach_msg_type_number_t *count); void task_act_iterate_wth_args(task_t, void(*)(thread_t, void *), void *); +extern kern_return_t task_suspend_internal(task_t); static cpu_type_t process_cpu_type(proc_t proc); static cpu_type_t process_cpu_subtype(proc_t proc); #ifdef SECURE_KERNEL -__private_extern__ int do_coredump = 0; /* default: don't dump cores */ +__XNU_PRIVATE_EXTERN int do_coredump = 0; /* default: don't dump cores */ #else -__private_extern__ int do_coredump = 1; /* default: dump cores */ +__XNU_PRIVATE_EXTERN int do_coredump = 1; /* default: dump cores */ #endif -__private_extern__ int sugid_coredump = 0; /* default: but not SGUID binaries */ +__XNU_PRIVATE_EXTERN int sugid_coredump = 0; /* default: but not SGUID binaries */ /* cpu_type returns only the most generic indication of the current CPU. */ @@ -139,9 +125,6 @@ process_cpu_type(proc_t core_proc) } else { what_we_think = CPU_TYPE_I386; } -#elif defined (__ppc__) - #pragma unused(core_proc) - what_we_think = CPU_TYPE_POWERPC; #endif return what_we_think; } @@ -156,9 +139,6 @@ process_cpu_subtype(proc_t core_proc) } else { what_we_think = CPU_SUBTYPE_I386_ALL; } -#elif defined (__ppc__) - #pragma unused(core_proc) - what_we_think = CPU_SUBTYPE_POWERPC_ALL; #endif return what_we_think; } @@ -210,6 +190,9 @@ collectth_state(thread_t th_act, void *tirp) * indicated * * Parameters: core_proc Process to dump core [*] + * reserve_mb If non-zero, leave filesystem with + * at least this much free space. + * ignore_ulimit If set, ignore the process's core file ulimit. * * Returns: 0 Success * EFAULT Failed @@ -220,7 +203,7 @@ collectth_state(thread_t th_act, void *tirp) */ #define MAX_TSTATE_FLAVORS 10 int -coredump(proc_t core_proc) +coredump(proc_t core_proc, uint32_t reserve_mb, int ignore_ulimit) { /* Begin assumptions that limit us to only the current process */ vfs_context_t ctx = vfs_context_current(); @@ -234,9 +217,9 @@ coredump(proc_t core_proc) int command_size, header_size, tstate_size; int hoffset; off_t foffset; - vm_map_offset_t vmoffset; + mach_vm_offset_t vmoffset; vm_offset_t header; - vm_map_size_t vmsize; + mach_vm_size_t vmsize; vm_prot_t prot; vm_prot_t maxprot; vm_inherit_t inherit; @@ -258,11 +241,15 @@ coredump(proc_t core_proc) int is_64 = 0; size_t mach_header_sz = sizeof(struct mach_header); size_t segment_command_sz = sizeof(struct segment_command); + + if (current_proc() != core_proc) { + panic("coredump() called against proc that is not current_proc: %p", core_proc); + } if (do_coredump == 0 || /* Not dumping at all */ ( (sugid_coredump == 0) && /* Not dumping SUID/SGID binaries */ - ( (cred->cr_svuid != cred->cr_ruid) || - (cred->cr_svgid != cred->cr_rgid)))) { + ( (kauth_cred_getsvuid(cred) != kauth_cred_getruid(cred)) || + (kauth_cred_getsvgid(cred) != kauth_cred_getrgid(cred))))) { #if CONFIG_AUDIT audit_proc_coredump(core_proc, NULL, EFAULT); @@ -278,9 +265,9 @@ coredump(proc_t core_proc) mapsize = get_vmmap_size(map); - if (mapsize >= core_proc->p_rlimit[RLIMIT_CORE].rlim_cur) + if ((mapsize >= core_proc->p_rlimit[RLIMIT_CORE].rlim_cur) && (ignore_ulimit == 0)) return (EFAULT); - (void) task_suspend(task); + (void) task_suspend_internal(task); MALLOC(alloced_name, char *, MAXPATHLEN, M_TEMP, M_NOWAIT | M_ZERO); @@ -312,6 +299,12 @@ coredump(proc_t core_proc) vnode_setattr(vp, &va, ctx); core_proc->p_acflag |= ACORE; + if ((reserve_mb > 0) && + ((freespace_mb(vp) - (mapsize >> 20)) < reserve_mb)) { + error = ENOSPC; + goto out; + } + /* * If the task is modified while dumping the file * (e.g., changes in threads or VM, the resulting @@ -320,17 +313,8 @@ coredump(proc_t core_proc) thread_count = get_task_numacts(task); segment_count = get_vmmap_entries(map); /* XXX */ -#if defined (__ppc__) - if (is_64) { - tir1.flavor_count = sizeof(thread_flavor_array64)/sizeof(mythread_state_flavor_t); - bcopy(thread_flavor_array64, flavors,sizeof(thread_flavor_array64)); - } else { -#endif /* __ppc __ */ - tir1.flavor_count = sizeof(thread_flavor_array)/sizeof(mythread_state_flavor_t); - bcopy(thread_flavor_array, flavors,sizeof(thread_flavor_array)); -#if defined (__ppc__) - } -#endif /* __ppc __ */ + tir1.flavor_count = sizeof(thread_flavor_array)/sizeof(mythread_state_flavor_t); + bcopy(thread_flavor_array, flavors,sizeof(thread_flavor_array)); tstate_size = 0; for (i = 0; i < tir1.flavor_count; i++) tstate_size += sizeof(mythread_state_flavor_t) +