+ kd_entropy_count = avail/sizeof(mach_timespec_t);
+ kd_entropy_bufsize = kd_entropy_count * sizeof(mach_timespec_t);
+ kd_entropy_indx = 0;
+
+ /* Enforce maximum entropy entries here if needed */
+
+ /* allocate entropy buffer */
+ if (kmem_alloc(kernel_map, &kd_entropy_buftomem,
+ (vm_size_t)kd_entropy_bufsize) == KERN_SUCCESS)
+ {
+ kd_entropy_buffer = (mach_timespec_t *)kd_entropy_buftomem;
+ }
+ else
+ {
+ kd_entropy_buffer = (mach_timespec_t *) 0;
+ kd_entropy_count = 0;
+ kd_entropy_indx = 0;
+ return (EINVAL);
+ }
+
+ if (ms_timeout < 10)
+ ms_timeout = 10;
+
+ /* Enable entropy sampling */
+ kdebug_enable |= KDEBUG_ENABLE_ENTROPY;
+
+ ret = tsleep (kdbg_getentropy, PRIBIO | PCATCH, "kd_entropy", (ms_timeout/(1000/HZ)));
+
+ /* Disable entropy sampling */
+ kdebug_enable &= ~KDEBUG_ENABLE_ENTROPY;
+
+ *number = 0;
+ ret = 0;
+
+ if (kd_entropy_indx > 0)
+ {
+ /* copyout the buffer */
+ if (copyout(kd_entropy_buffer, buffer, kd_entropy_indx * sizeof(mach_timespec_t)))
+ ret = EINVAL;
+ else
+ *number = kd_entropy_indx;
+ }
+
+ /* Always cleanup */
+ kd_entropy_count = 0;
+ kd_entropy_indx = 0;
+ kd_entropy_buftomem = 0;
+ kmem_free(kernel_map, (char *)kd_entropy_buffer, kd_entropy_bufsize);
+ kd_entropy_buffer = (mach_timespec_t *) 0;
+ return(ret);
+}
+
+
+/*
+ * This function is provided for the CHUD toolkit only.
+ * int val:
+ * zero disables kdebug_chudhook function call
+ * non-zero enables kdebug_chudhook function call
+ * char *fn:
+ * address of the enabled kdebug_chudhook function
+*/
+
+void kdbg_control_chud(int val, void *fn)
+{
+ if (val) {
+ /* enable chudhook */
+ kdebug_enable |= KDEBUG_ENABLE_CHUD;
+ kdebug_chudhook = fn;
+ }
+ else {
+ /* disable chudhook */
+ kdebug_enable &= ~KDEBUG_ENABLE_CHUD;
+ kdebug_chudhook = 0;
+ }
+}
+
+