| 751 | } |
| 752 | |
| 753 | int |
| 754 | kern_getitimer(struct thread *td, u_int which, struct itimerval *aitv) |
| 755 | { |
| 756 | struct proc *p = td->td_proc; |
| 757 | struct timeval ctv; |
| 758 | |
| 759 | if (which > ITIMER_PROF) |
| 760 | return (EINVAL); |
| 761 | |
| 762 | if (which == ITIMER_REAL) { |
| 763 | /* |
| 764 | * Convert from absolute to relative time in .it_value |
| 765 | * part of real time timer. If time for real time timer |
| 766 | * has passed return 0, else return difference between |
| 767 | * current time and time for the timer to go off. |
| 768 | */ |
| 769 | PROC_LOCK(p); |
| 770 | *aitv = p->p_realtimer; |
| 771 | PROC_UNLOCK(p); |
| 772 | if (timevalisset(&aitv->it_value)) { |
| 773 | microuptime(&ctv); |
| 774 | if (timevalcmp(&aitv->it_value, &ctv, <)) |
| 775 | timevalclear(&aitv->it_value); |
| 776 | else |
| 777 | timevalsub(&aitv->it_value, &ctv); |
| 778 | } |
| 779 | } else { |
| 780 | PROC_ITIMLOCK(p); |
| 781 | *aitv = p->p_stats->p_timer[which]; |
| 782 | PROC_ITIMUNLOCK(p); |
| 783 | } |
| 784 | #ifdef KTRACE |
| 785 | if (KTRPOINT(td, KTR_STRUCT)) |
| 786 | ktritimerval(aitv); |
| 787 | #endif |
| 788 | return (0); |
| 789 | } |
| 790 | |
| 791 | #ifndef _SYS_SYSPROTO_H_ |
| 792 | struct setitimer_args { |
no test coverage detected