require '_h2ph_pre.ph';

no warnings qw(redefine misc);

require 'sys/ptrace.ph';
if(defined(&_KERNEL)) {
    require 'sys/proc.ph';
    eval("sub PFSauxv () { 0; }") unless defined(&PFSauxv);
    eval("sub PFSchroot () { 1; }") unless defined(&PFSchroot);
    eval("sub PFScmdline () { 2; }") unless defined(&PFScmdline);
    eval("sub PFScpuinfo () { 3; }") unless defined(&PFScpuinfo);
    eval("sub PFScpustat () { 4; }") unless defined(&PFScpustat);
    eval("sub PFScurproc () { 5; }") unless defined(&PFScurproc);
    eval("sub PFScwd () { 6; }") unless defined(&PFScwd);
    eval("sub PFSdevices () { 7; }") unless defined(&PFSdevices);
    eval("sub PFSemul () { 8; }") unless defined(&PFSemul);
    eval("sub PFSenviron () { 9; }") unless defined(&PFSenviron);
    eval("sub PFSexe () { 10; }") unless defined(&PFSexe);
    eval("sub PFSfd () { 11; }") unless defined(&PFSfd);
    eval("sub PFSfile () { 12; }") unless defined(&PFSfile);
    eval("sub PFSfpregs () { 13; }") unless defined(&PFSfpregs);
    eval("sub PFSloadavg () { 14; }") unless defined(&PFSloadavg);
    eval("sub PFSlimit () { 15; }") unless defined(&PFSlimit);
    eval("sub PFSmap () { 16; }") unless defined(&PFSmap);
    eval("sub PFSmaps () { 17; }") unless defined(&PFSmaps);
    eval("sub PFSmem () { 18; }") unless defined(&PFSmem);
    eval("sub PFSmeminfo () { 19; }") unless defined(&PFSmeminfo);
    eval("sub PFSmounts () { 20; }") unless defined(&PFSmounts);
    eval("sub PFSnote () { 21; }") unless defined(&PFSnote);
    eval("sub PFSnotepg () { 22; }") unless defined(&PFSnotepg);
    eval("sub PFSproc () { 23; }") unless defined(&PFSproc);
    eval("sub PFSregs () { 24; }") unless defined(&PFSregs);
    eval("sub PFSroot () { 25; }") unless defined(&PFSroot);
    eval("sub PFSself () { 26; }") unless defined(&PFSself);
    eval("sub PFSstat () { 27; }") unless defined(&PFSstat);
    eval("sub PFSstatm () { 28; }") unless defined(&PFSstatm);
    eval("sub PFSstatus () { 29; }") unless defined(&PFSstatus);
    eval("sub PFStask () { 30; }") unless defined(&PFStask);
    eval("sub PFSuptime () { 31; }") unless defined(&PFSuptime);
    eval("sub PFSversion () { 32; }") unless defined(&PFSversion);
    eval("sub PFSlast () { 33; }") unless defined(&PFSlast);
    eval 'sub pfs_type () { ($pfs_key->{pk_type});}' unless defined(&pfs_type);
    eval 'sub pfs_pid () { ($pfs_key->{pk_pid});}' unless defined(&pfs_pid);
    eval 'sub pfs_fd () { ($pfs_key->{pk_fd});}' unless defined(&pfs_fd);
    eval 'sub PROCFS_NOTELEN () {64;}' unless defined(&PROCFS_NOTELEN);
    eval 'sub PROCFS_MAXNAMLEN () {255;}' unless defined(&PROCFS_MAXNAMLEN);
}
eval 'sub PROCFS_ARGSVERSION () {1;}' unless defined(&PROCFS_ARGSVERSION);
eval 'sub PROCFSMNT_LINUXCOMPAT () {0x1;}' unless defined(&PROCFSMNT_LINUXCOMPAT);
eval 'sub PROCFSMNT_BITS () {"\\177\\20" "b\\00linuxcompat\\0";}' unless defined(&PROCFSMNT_BITS);
if(defined(&_KERNEL)) {
    eval 'sub CNEQ {
        my($cnp, $s, $len) = @_;
	    eval q((($cnp)-> &cn_namelen == ($len)  && ( &memcmp(($s), ($cnp)-> &cn_nameptr, ($len)) == 0)));
    }' unless defined(&CNEQ);
    eval 'sub UIO_MX () {32;}' unless defined(&UIO_MX);
    eval 'sub procfs_fileno {
        my($_pid,$_type,$_fd) = @_;
	    eval q({  &ino_t  &_ino;  &switch ($_type) {  &case  &PFSroot: 2;  &case  &PFScurproc: 3;  &case  &PFSself: 4;  &default:  &_ino = $_pid + 1;  &if ($_fd != -1)  &_ino =  &_ino << 32| $_fd;  &_ino *  &PFSlast + $_type; } });
    }' unless defined(&procfs_fileno);
    eval 'sub PROCFS_FILENO {
        my($pid, $type, $fd) = @_;
	    eval q( &procfs_fileno($pid, $type, $fd));
    }' unless defined(&PROCFS_FILENO);
    eval 'sub PROCFS_TYPE {
        my($type) = @_;
	    eval q((($type) %  &PFSlast));
    }' unless defined(&PROCFS_TYPE);
    eval 'sub VFSTOPROC {
        my($mp) = @_;
	    eval q((($mp)-> &mnt_data));
    }' unless defined(&VFSTOPROC);
    eval 'sub VTOPFS {
        my($vp) = @_;
	    eval q((($vp)-> &v_data));
    }' unless defined(&VTOPFS);
    eval 'sub PFSTOV {
        my($pfs) = @_;
	    eval q((($pfs)-> &pfs_vnode));
    }' unless defined(&PFSTOV);
    eval 'sub procfs_proc_is_linux_compat {
        my($void) = @_;
	    eval q({  &const \'char\' * &emulname =  ($curlwp->{l_proc}->{p_emul}->{e_name}); ( &strncmp( &emulname, \\"linux\\", 5) == 0); });
    }' unless defined(&procfs_proc_is_linux_compat);
    eval 'sub PROCFS_LOCKED () {0x1;}' unless defined(&PROCFS_LOCKED);
    eval 'sub PROCFS_WANT () {0x2;}' unless defined(&PROCFS_WANT);
    if(defined(&__HAVE_PROCFS_MACHDEP)) {
    }
}
1;
