--- Gnu-Mach/kern/pc_sample.c 2020/09/02 04:36:57 1.1 +++ Gnu-Mach/kern/pc_sample.c 2020/09/02 04:52:00 1.1.1.4 @@ -24,16 +24,18 @@ * the rights to redistribute these changes. */ - - -#include +#include +#include #include /* vm_address_t */ #include /* pointer_t */ #include +#include +#include #include #include #include +#include #if MACH_PCSAMPLE @@ -41,21 +43,24 @@ typedef sampled_pc_t sampled_pcs[MAX_PC_SAMPLES]; -int pc_sampling_enabled = 0; -decl_simple_lock_data(, pc_sampling_lock) /* lock for enabling */ - void take_pc_sample( - register thread_t t, - register sample_control_t *cp, - sampled_pc_flavor_t flavor) + const thread_t t, + sample_control_t *cp, + sampled_pc_flavor_t flavor, + boolean_t usermode, + vm_offset_t kern_pc) { vm_offset_t pc; struct sampled_pc *sample; - pc = interrupted_pc(t); + if (usermode) + pc = interrupted_pc(t); + else + pc = kern_pc; + cp->seqno++; sample = &((sampled_pc_t *)cp->buffer)[cp->seqno % MAX_PC_SAMPLES]; - sample->id = (natural_t)t; + sample->id = (vm_offset_t)t; sample->pc = pc; sample->sampletype = flavor; } @@ -67,7 +72,6 @@ thread_enable_pc_sampling( sampled_pc_flavor_t flavors) { vm_offset_t buf; - extern int tick; if (thread == THREAD_NULL) { return KERN_INVALID_ARGUMENT; @@ -93,7 +97,6 @@ task_enable_pc_sampling( sampled_pc_flavor_t flavors) { vm_offset_t buf; - extern int tick; if (task == TASK_NULL) { return KERN_INVALID_ARGUMENT; @@ -178,20 +181,23 @@ get_sampled_pcs( * Simple case: no wraparound. * Copy from seqidx1 to seqidx2. */ - bcopy((sampled_pc_array_t)cp->buffer + seqidx1 + 1, - sampled_pcs_out, - nsamples * sizeof(sampled_pc_t)); + memcpy(sampled_pcs_out, + (sampled_pc_array_t)cp->buffer + seqidx1 + 1, + nsamples * sizeof(sampled_pc_t)); } else { /* seqidx1 > seqidx2 -- Handle wraparound. */ - bcopy((sampled_pc_array_t)cp->buffer + seqidx1 + 1, - sampled_pcs_out, - (MAX_PC_SAMPLES - seqidx1 - 1) * sizeof(sampled_pc_t)); - - bcopy((sampled_pc_array_t)cp->buffer, - sampled_pcs_out + (MAX_PC_SAMPLES - seqidx1 - 1), - (seqidx2 + 1) * sizeof(sampled_pc_t)); + memcpy(sampled_pcs_out, + (sampled_pc_array_t)cp->buffer + seqidx1 + 1, + (MAX_PC_SAMPLES - seqidx1 - 1) * sizeof(sampled_pc_t)); + + memcpy(sampled_pcs_out + (MAX_PC_SAMPLES - seqidx1 - 1), + (sampled_pc_array_t)cp->buffer, + (seqidx2 + 1) * sizeof(sampled_pc_t)); } + } else if (nsamples < 0) { + /* Bogus SEQNO supplied. */ + nsamples = 0; } else { /* could either be zero because of overflow, or because * we are being lied to. In either case, return nothing. @@ -244,8 +250,8 @@ task_get_sampled_pcs( kern_return_t thread_enable_pc_sampling( - thread_t thread, - int *tickp, + const thread_t thread, + const int *tickp, sampled_pc_flavor_t flavors) { return KERN_FAILURE; /* not implemented */ @@ -253,8 +259,8 @@ thread_enable_pc_sampling( kern_return_t task_enable_pc_sampling( - task_t task, - int *tickp, + const task_t task, + const int *tickp, sampled_pc_flavor_t flavors) { return KERN_FAILURE; /* not implemented */ @@ -262,36 +268,36 @@ task_enable_pc_sampling( kern_return_t thread_disable_pc_sampling( - thread_t thread, - int *samplecntp) + const thread_t thread, + const int *samplecntp) { return KERN_FAILURE; /* not implemented */ } kern_return_t task_disable_pc_sampling( - task_t task, - int *samplecntp) + const task_t task, + const int *samplecntp) { return KERN_FAILURE; /* not implemented */ } kern_return_t thread_get_sampled_pcs( - thread_t thread, - sampled_pc_seqno_t *seqnop, - sampled_pc_array_t sampled_pcs_out, - int *sampled_pcs_cntp) + const thread_t thread, + const sampled_pc_seqno_t *seqnop, + const sampled_pc_array_t sampled_pcs_out, + const int *sampled_pcs_cntp) { return KERN_FAILURE; /* not implemented */ } kern_return_t task_get_sampled_pcs( - task_t task, - sampled_pc_seqno_t *seqnop, - sampled_pc_array_t sampled_pcs_out, - int *sampled_pcs_cntp) + const task_t task, + const sampled_pc_seqno_t *seqnop, + const sampled_pc_array_t sampled_pcs_out, + const int *sampled_pcs_cntp) { return KERN_FAILURE; /* not implemented */ }