require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_SYS_MALLOC_H_)) {
    eval 'sub _SYS_MALLOC_H_ () {1;}' unless defined(&_SYS_MALLOC_H_);
    eval 'sub KERN_MALLOC_BUCKETS () {1;}' unless defined(&KERN_MALLOC_BUCKETS);
    eval 'sub KERN_MALLOC_BUCKET () {2;}' unless defined(&KERN_MALLOC_BUCKET);
    eval 'sub KERN_MALLOC_KMEMNAMES () {3;}' unless defined(&KERN_MALLOC_KMEMNAMES);
    eval 'sub KERN_MALLOC_KMEMSTATS () {4;}' unless defined(&KERN_MALLOC_KMEMSTATS);
    eval 'sub KERN_MALLOC_MAXID () {5;}' unless defined(&KERN_MALLOC_MAXID);
    eval 'sub CTL_KERN_MALLOC_NAMES () {{ { 0, 0}, { "buckets",  &CTLTYPE_STRING }, { "bucket",  &CTLTYPE_NODE }, { "kmemnames",  &CTLTYPE_STRING }, { "kmemstat",  &CTLTYPE_NODE }, };}' unless defined(&CTL_KERN_MALLOC_NAMES);
    eval 'sub M_WAITOK () {0x;}' unless defined(&M_WAITOK);
    eval 'sub M_NOWAIT () {0x1;}' unless defined(&M_NOWAIT);
    eval 'sub M_CANFAIL () {0x2;}' unless defined(&M_CANFAIL);
    eval 'sub M_FREE () {0;}' unless defined(&M_FREE);
    eval 'sub M_MBUF () {1;}' unless defined(&M_MBUF);
    eval 'sub M_DEVBUF () {2;}' unless defined(&M_DEVBUF);
    eval 'sub M_DEBUG () {3;}' unless defined(&M_DEBUG);
    eval 'sub M_PCB () {4;}' unless defined(&M_PCB);
    eval 'sub M_RTABLE () {5;}' unless defined(&M_RTABLE);
    eval 'sub M_FTABLE () {7;}' unless defined(&M_FTABLE);
    eval 'sub M_IFADDR () {9;}' unless defined(&M_IFADDR);
    eval 'sub M_SOOPTS () {10;}' unless defined(&M_SOOPTS);
    eval 'sub M_SYSCTL () {11;}' unless defined(&M_SYSCTL);
    eval 'sub M_IOCTLOPS () {14;}' unless defined(&M_IOCTLOPS);
    eval 'sub M_IOV () {19;}' unless defined(&M_IOV);
    eval 'sub M_MOUNT () {20;}' unless defined(&M_MOUNT);
    eval 'sub M_NFSREQ () {22;}' unless defined(&M_NFSREQ);
    eval 'sub M_NFSMNT () {23;}' unless defined(&M_NFSMNT);
    eval 'sub M_NFSNODE () {24;}' unless defined(&M_NFSNODE);
    eval 'sub M_VNODE () {25;}' unless defined(&M_VNODE);
    eval 'sub M_CACHE () {26;}' unless defined(&M_CACHE);
    eval 'sub M_DQUOT () {27;}' unless defined(&M_DQUOT);
    eval 'sub M_UFSMNT () {28;}' unless defined(&M_UFSMNT);
    eval 'sub M_SHM () {29;}' unless defined(&M_SHM);
    eval 'sub M_VMMAP () {30;}' unless defined(&M_VMMAP);
    eval 'sub M_SEM () {31;}' unless defined(&M_SEM);
    eval 'sub M_DIRHASH () {32;}' unless defined(&M_DIRHASH);
    eval 'sub M_VMPMAP () {34;}' unless defined(&M_VMPMAP);
    eval 'sub M_FILE () {38;}' unless defined(&M_FILE);
    eval 'sub M_FILEDESC () {39;}' unless defined(&M_FILEDESC);
    eval 'sub M_PROC () {41;}' unless defined(&M_PROC);
    eval 'sub M_SUBPROC () {42;}' unless defined(&M_SUBPROC);
    eval 'sub M_VCLUSTER () {43;}' unless defined(&M_VCLUSTER);
    eval 'sub M_MFSNODE () {46;}' unless defined(&M_MFSNODE);
    eval 'sub M_NETADDR () {49;}' unless defined(&M_NETADDR);
    eval 'sub M_NFSSVC () {50;}' unless defined(&M_NFSSVC);
    eval 'sub M_NFSUID () {51;}' unless defined(&M_NFSUID);
    eval 'sub M_NFSD () {52;}' unless defined(&M_NFSD);
    eval 'sub M_IPMOPTS () {53;}' unless defined(&M_IPMOPTS);
    eval 'sub M_IPMADDR () {54;}' unless defined(&M_IPMADDR);
    eval 'sub M_IFMADDR () {55;}' unless defined(&M_IFMADDR);
    eval 'sub M_MRTABLE () {56;}' unless defined(&M_MRTABLE);
    eval 'sub M_ISOFSMNT () {57;}' unless defined(&M_ISOFSMNT);
    eval 'sub M_ISOFSNODE () {58;}' unless defined(&M_ISOFSNODE);
    eval 'sub M_MSDOSFSMNT () {59;}' unless defined(&M_MSDOSFSMNT);
    eval 'sub M_MSDOSFSFAT () {60;}' unless defined(&M_MSDOSFSFAT);
    eval 'sub M_MSDOSFSNODE () {61;}' unless defined(&M_MSDOSFSNODE);
    eval 'sub M_TTYS () {62;}' unless defined(&M_TTYS);
    eval 'sub M_EXEC () {63;}' unless defined(&M_EXEC);
    eval 'sub M_MISCFSMNT () {64;}' unless defined(&M_MISCFSMNT);
    eval 'sub M_ADOSFSMNT () {66;}' unless defined(&M_ADOSFSMNT);
    eval 'sub M_ANODE () {68;}' unless defined(&M_ANODE);
    eval 'sub M_ADOSFSBITMAP () {71;}' unless defined(&M_ADOSFSBITMAP);
    eval 'sub M_PFKEY () {74;}' unless defined(&M_PFKEY);
    eval 'sub M_TDB () {75;}' unless defined(&M_TDB);
    eval 'sub M_XDATA () {76;}' unless defined(&M_XDATA);
    eval 'sub M_PAGEDEP () {78;}' unless defined(&M_PAGEDEP);
    eval 'sub M_INODEDEP () {79;}' unless defined(&M_INODEDEP);
    eval 'sub M_NEWBLK () {80;}' unless defined(&M_NEWBLK);
    eval 'sub M_INDIRDEP () {83;}' unless defined(&M_INDIRDEP);
    eval 'sub M_VMSWAP () {92;}' unless defined(&M_VMSWAP);
    eval 'sub M_RAIDFRAME () {97;}' unless defined(&M_RAIDFRAME);
    eval 'sub M_UVMAMAP () {98;}' unless defined(&M_UVMAMAP);
    eval 'sub M_UVMAOBJ () {99;}' unless defined(&M_UVMAOBJ);
    eval 'sub M_USB () {101;}' unless defined(&M_USB);
    eval 'sub M_USBDEV () {102;}' unless defined(&M_USBDEV);
    eval 'sub M_USBHC () {103;}' unless defined(&M_USBHC);
    eval 'sub M_MEMDESC () {105;}' unless defined(&M_MEMDESC);
    eval 'sub M_CRYPTO_DATA () {108;}' unless defined(&M_CRYPTO_DATA);
    eval 'sub M_CREDENTIALS () {110;}' unless defined(&M_CREDENTIALS);
    eval 'sub M_PACKET_TAGS () {111;}' unless defined(&M_PACKET_TAGS);
    eval 'sub M_1394CTL () {112;}' unless defined(&M_1394CTL);
    eval 'sub M_1394DATA () {113;}' unless defined(&M_1394DATA);
    eval 'sub M_EMULDATA () {114;}' unless defined(&M_EMULDATA);
    eval 'sub M_IP6OPT () {123;}' unless defined(&M_IP6OPT);
    eval 'sub M_IP6NDP () {124;}' unless defined(&M_IP6NDP);
    eval 'sub M_IP6RR () {125;}' unless defined(&M_IP6RR);
    eval 'sub M_RR_ADDR () {126;}' unless defined(&M_RR_ADDR);
    eval 'sub M_TEMP () {127;}' unless defined(&M_TEMP);
    eval 'sub M_NTFSMNT () {128;}' unless defined(&M_NTFSMNT);
    eval 'sub M_NTFSNTNODE () {129;}' unless defined(&M_NTFSNTNODE);
    eval 'sub M_NTFSFNODE () {130;}' unless defined(&M_NTFSFNODE);
    eval 'sub M_NTFSDIR () {131;}' unless defined(&M_NTFSDIR);
    eval 'sub M_NTFSNTHASH () {132;}' unless defined(&M_NTFSNTHASH);
    eval 'sub M_NTFSNTVATTR () {133;}' unless defined(&M_NTFSNTVATTR);
    eval 'sub M_NTFSRDATA () {134;}' unless defined(&M_NTFSRDATA);
    eval 'sub M_NTFSDECOMP () {135;}' unless defined(&M_NTFSDECOMP);
    eval 'sub M_NTFSRUN () {136;}' unless defined(&M_NTFSRUN);
    eval 'sub M_KEVENT () {137;}' unless defined(&M_KEVENT);
    eval 'sub M_BLUETOOTH () {138;}' unless defined(&M_BLUETOOTH);
    eval 'sub M_BWMETER () {139;}' unless defined(&M_BWMETER);
    eval 'sub M_UDFMOUNT () {140;}' unless defined(&M_UDFMOUNT);
    eval 'sub M_UDFFENTRY () {141;}' unless defined(&M_UDFFENTRY);
    eval 'sub M_UDFFID () {142;}' unless defined(&M_UDFFID);
    eval 'sub M_LAST () {143;}' unless defined(&M_LAST);
    eval 'sub INITKMEMNAMES () {{ "free", "mbuf", "devbuf", "debug", "pcb", "routetbl",  &NULL, "fragtbl",  &NULL, "ifaddr", "soopts", "sysctl",  &NULL,  &NULL, "ioctlops",  &NULL,  &NULL,  &NULL,  &NULL, "iov", "mount",  &NULL, "NFS req", "NFS mount", "NFS node", "vnodes", "namecache", "UFS quota", "UFS mount", "shm", "VM map", "sem", "dirhash",  &NULL, "VM pmap",  &NULL,  &NULL,  &NULL, "file", "file desc",  &NULL, "proc", "subproc", "VFS cluster",  &NULL,  &NULL, "MFS node",  &NULL,  &NULL, "Export Host", "NFS srvsock", "NFS uid", "NFS daemon", "ip_moptions", "in_multi", "ether_multi", "mrt", "ISOFS mount", "ISOFS node", "MSDOSFS mount", "MSDOSFS fat", "MSDOSFS node", "ttys", "exec", "miscfs mount",  &NULL, "adosfs mount",  &NULL, "adosfs anode",  &NULL,  &NULL, "adosfs bitmap",  &NULL,  &NULL, "pfkey data", "tdb", "xform_data",  &NULL, "pagedep", "inodedep", "newblk",  &NULL,  &NULL, "indirdep",  &NULL,  &NULL,  &NULL,  &NULL,  &NULL,  &NULL,  &NULL,  &NULL, "VM swap",  &NULL,  &NULL,  &NULL,  &NULL, "RAIDframe data", "UVM amap", "UVM aobj",  &NULL, "USB", "USB device", "USB HC",  &NULL, "memdesc",  &NULL,  &NULL, "crypto data",  &NULL, "IPsec creds", "packet tags", "1394ctl", "1394data", "emuldata",  &NULL,  &NULL,  &NULL,  &NULL,  &NULL,  &NULL,  &NULL,  &NULL, "ip6_options", "NDP", "ip6rr", "rp_addr", "temp", "NTFS mount", "NTFS node", "NTFS fnode", "NTFS dir", "NTFS hash tables", "NTFS file attr", "NTFS resident data ", "NTFS decomp", "NTFS vrun", "kqueue", "bluetooth", "bwmeter", "UDF mount", "UDF file entry", "UDF file id", };}' unless defined(&INITKMEMNAMES);
    eval 'sub ku_freecnt () { ($ku_un->{freecnt});}' unless defined(&ku_freecnt);
    eval 'sub ku_pagecnt () { ($ku_un->{pagecnt});}' unless defined(&ku_pagecnt);
    if(defined(&_KERNEL)) {
	eval 'sub MINALLOCSIZE () {(1<<  &MINBUCKET);}' unless defined(&MINALLOCSIZE);
	eval 'sub BUCKETINDX {
	    my($size) = @_;
    	    eval q((($size) <= ( &MINALLOCSIZE * 128) ? ($size) <= ( &MINALLOCSIZE * 8) ? ($size) <= ( &MINALLOCSIZE * 2) ? ($size) <= ( &MINALLOCSIZE * 1) ? ( &MINBUCKET + 0) : ( &MINBUCKET + 1) : ($size) <= ( &MINALLOCSIZE * 4) ? ( &MINBUCKET + 2) : ( &MINBUCKET + 3) : ($size) <= ( &MINALLOCSIZE* 32) ? ($size) <= ( &MINALLOCSIZE * 16) ? ( &MINBUCKET + 4) : ( &MINBUCKET + 5) : ($size) <= ( &MINALLOCSIZE * 64) ? ( &MINBUCKET + 6) : ( &MINBUCKET + 7) : ($size) <= ( &MINALLOCSIZE * 2048) ? ($size) <= ( &MINALLOCSIZE * 512) ? ($size) <= ( &MINALLOCSIZE * 256) ? ( &MINBUCKET + 8) : ( &MINBUCKET + 9) : ($size) <= ( &MINALLOCSIZE * 1024) ? ( &MINBUCKET + 10) : ( &MINBUCKET + 11) : ($size) <= ( &MINALLOCSIZE * 8192) ? ($size) <= ( &MINALLOCSIZE * 4096) ? ( &MINBUCKET + 12) : ( &MINBUCKET + 13) : ($size) <= ( &MINALLOCSIZE * 16384) ? ( &MINBUCKET + 14) : ( &MINBUCKET + 15)));
	}' unless defined(&BUCKETINDX);
	eval 'sub kmemxtob {
	    my($alloc) = @_;
    	    eval q(( &kmembase + ($alloc) *  &NBPG));
	}' unless defined(&kmemxtob);
	eval 'sub btokmemx {
	    my($addr) = @_;
    	    eval q(((($addr) -  &kmembase) /  &NBPG));
	}' unless defined(&btokmemx);
	eval 'sub btokup {
	    my($addr) = @_;
    	    eval q(( $kmemusage[(($addr) -  &kmembase) >>  &PAGE_SHIFT]));
	}' unless defined(&btokup);
	if(defined( &KMEMSTATS) || defined( &DIAGNOSTIC) || defined( &_LKM) || defined( &SMALL_KERNEL)) {
	    eval 'sub MALLOC {
	        my($space, $cast, $size, $type, $flags) = @_;
    		eval q(($space) = ($cast) &malloc(($size), $type, $flags));
	    }' unless defined(&MALLOC);
	    eval 'sub FREE {
	        my($addr, $type) = @_;
    		eval q( &free(($addr), $type));
	    }' unless defined(&FREE);
	} else {
	    eval 'sub MALLOC {
	        my($space, $cast, $size, $type, $flags) = @_;
    		eval q( &do { \'u_long kbp_size\' = ($size);  &register \'struct kmembuckets\' * &kbp =  $bucket[ &BUCKETINDX( &kbp_size)]; \'int\'  &__s =  &splvm();  &if ( ($kbp->{kb_next}) ==  &NULL) { ($space) = ($cast) &malloc( &kbp_size, $type, $flags); }  &else { ($space) = ($cast) ($kbp->{kb_next});  ($kbp->{kb_next}) = *($space); }  &splx( &__s); }  &while (0));
	    }' unless defined(&MALLOC);
	    eval 'sub FREE {
	        my($addr, $type) = @_;
    		eval q( &do {  &register \'struct kmembuckets\' * &kbp;  &register \'struct kmemusage\' * &kup =  &btokup; \'int\'  &__s =  &splvm();  &if (1<<  ($kup->{ku_indx}) >  &MAXALLOCSAVE) {  &free(, $type); }  &else {  &kbp =  $bucket[ ($kup->{ku_indx})];  &if ( ($kbp->{kb_next}) ==  &NULL)  ($kbp->{kb_next}) = ;  &else *( ($kbp->{kb_last})) = ; * =  &NULL;  ($kbp->{kb_last}) = ($addr); }  &splx( &__s); }  &while(0));
	    }' unless defined(&FREE);
	}
	if(defined(&MALLOC_DEBUG)) {
	    eval 'sub DEBUG_MALLOC_ASSERT_ALLOCATED {
	        my($addr) = @_;
    		eval q( &debug_malloc_assert_allocated($addr,  &__func__));
	    }' unless defined(&DEBUG_MALLOC_ASSERT_ALLOCATED);
	}
    }
}
1;
