1#!/bin/sh 2 3# Regression test for D33416 vm_fault: Fix vm_fault_populate()'s handling of VM_FAULT_WIRE 4# Bug report: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260347 5 6# Test scenario by: martin 7 8# Fixed by 88642d978a99 9 10[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 11[ -d /usr/src/sys ] || exit 0 12builddir=`sysctl kern.version | grep @ | sed 's/.*://'` 13[ -d "$builddir" ] && export KERNBUILDDIR=$builddir || exit 0 14export SYSDIR=`echo $builddir | sed 's#/sys.*#/sys#'` 15 16. ../default.cfg 17 18odir=`pwd` 19dir=$RUNDIR/skeleton 20mkdir -p $dir 21 22cd $dir 23cat > skeleton.c <<EOF 24/* 25 * KLD Skeleton 26 * Inspired by Andrew Reiter's Daemonnews article 27 */ 28 29#include <sys/param.h> 30#include <sys/module.h> 31#include <sys/systm.h> /* uprintf */ 32#include <sys/errno.h> 33#include <sys/param.h> /* defines used in kernel.h */ 34#include <sys/kernel.h> /* types used in module initialization */ 35 36#define BUFFER_SIZE 10*1000*1024 // 10 MB 37static char gBuffer[BUFFER_SIZE]; 38 39static int demo_init (void) 40{ 41 for (int i=0; i<BUFFER_SIZE; i++) 42 { 43 gBuffer[i] = 'A'; 44 } 45 return 0; 46} 47 48static void demo_exit (void) 49{ 50 for (int i=0; i<BUFFER_SIZE; i++) 51 { 52 gBuffer[i] += 1; 53 } 54} 55 56/* 57 * Load handler that deals with the loading and unloading of a KLD. 58 */ 59 60static int 61skel_loader(struct module *m, int what, void *arg) 62{ 63 int err = 0; 64 65 switch (what) { 66 case MOD_LOAD: /* kldload */ 67 uprintf("Skeleton KLD loaded.\n"); 68 demo_init(); 69 break; 70 case MOD_UNLOAD: 71 uprintf("Skeleton KLD unloaded.\n"); 72 demo_exit(); 73 break; 74 default: 75 err = EOPNOTSUPP; 76 break; 77 } 78 return(err); 79} 80 81/* Declare this module to the rest of the kernel */ 82 83static moduledata_t skel_mod = { 84 "skel", 85 skel_loader, 86 NULL 87}; 88 89DECLARE_MODULE(skeleton, skel_mod, SI_SUB_KLD, SI_ORDER_ANY); 90EOF 91 92cat > Makefile <<EOF 93KMOD= skeleton 94SRCS= skeleton.c 95 96.include <bsd.kmod.mk> 97EOF 98 99make 100old=`sysctl -n vm.stats.vm.v_wire_count` 101kldload $dir/skeleton.ko 102kldunload $dir/skeleton.ko 103leak=$((`sysctl -n vm.stats.vm.v_wire_count` - old)) 104if [ $leak -gt 25 ]; then 105 echo "Test leaked $leak pages in the skeleton.ko module" 106 s=1 107else 108 s=0 109fi 110 111cd $odir 112rm -rf $dir 113exit $s 114