static int memguard_sysctl_desc(SYSCTL_HANDLER_ARGS) { char desc[sizeof(vm_memguard_desc)]; int error; strlcpy(desc, vm_memguard_desc, sizeof(desc)); error = sysctl_handle_string(oidp, desc, sizeof(desc), req); if (error != 0 || req->newptr == NULL) return (error); mtx_lock(&malloc_mtx); /* If mtp is NULL, it will be initialized in memguard_cmp() */ vm_memguard_mtype = malloc_desc2type(desc); strlcpy(vm_memguard_desc, desc, sizeof(vm_memguard_desc)); mtx_unlock(&malloc_mtx); return (error); }
static int memguard_sysctl_desc(SYSCTL_HANDLER_ARGS) { struct malloc_type_internal *mtip; struct malloc_type_stats *mtsp; struct malloc_type *mtp; char desc[128]; long bytes; int error, i; strlcpy(desc, vm_memguard_desc, sizeof(desc)); error = sysctl_handle_string(oidp, desc, sizeof(desc), req); if (error != 0 || req->newptr == NULL) return (error); /* * We can change memory type when no memory has been allocated for it * or when there is no such memory type yet (ie. it will be loaded with * kernel module). */ bytes = 0; mtx_lock(&malloc_mtx); mtp = malloc_desc2type(desc); if (mtp != NULL) { mtip = mtp->ks_handle; for (i = 0; i < MAXCPU; i++) { mtsp = &mtip->mti_stats[i]; bytes += mtsp->mts_memalloced; bytes -= mtsp->mts_memfreed; } } if (bytes > 0) error = EBUSY; else { /* * If mtp is NULL, it will be initialized in memguard_cmp(). */ vm_memguard_mtype = mtp; strlcpy(vm_memguard_desc, desc, sizeof(vm_memguard_desc)); } mtx_unlock(&malloc_mtx); return (error); }