kmem.c revision ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4
/*
* Copyright (C) 1993-2001 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*/
/*
* kmemcpy() - copies n bytes from kernel memory into user buffer.
* returns 0 on success, -1 on error.
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <kvm.h>
#endif
#include <fcntl.h>
#include <netinet/in_systm.h>
#if __FreeBSD_version >= 300000
#endif
# include <stdlib.h>
#endif
#include "kmem.h"
#ifndef __STDC__
# define const
#endif
#if !defined(lint)
#endif
/*
* For all platforms where there is a libkvm and a kvm_t, we use that...
*/
#else
/*
*...and for the others (HP-UX, IRIX, Tru64), we have to provide our own.
*/
typedef int * kvm_t;
static char *kvm_errstr = NULL;
int mode;
char *errstr;
{
kvm_t k;
int fd;
kvm_errstr = errstr;
if (fd == -1)
return NULL;
k = malloc(sizeof(*k));
if (k == NULL) {
return NULL;
}
*k = fd;
return k;
}
char *buffer;
{
int r = 0, left;
char *bufp;
if (kvm_errstr != NULL) {
perror("lseek");
}
return -1;
}
#ifdef __osf__
/*
* Tru64 returns "0" for successful operation, not the number
* of bytes read.
*/
if (r == 0)
r = left;
#endif
if (r <= 0)
return -1;
}
return r;
}
#endif /* !defined(__sgi) && !defined(__hpux) && !defined(__osf__) */
{
{
perror("openkmem:open");
return -1;
}
}
register char *buf;
long pos;
register int n;
{
register int r;
if (!n)
return 0;
return -1;
if (r <= 0)
{
perror("kmemcpy:read");
return -1;
}
else
{
buf += r;
pos += r;
n -= r;
}
return 0;
}
register char *buf;
long pos;
register int n;
{
register int r;
if (!n)
return 0;
return -1;
while (n > 0)
{
if (r <= 0)
{
perror("kmemcpy:read");
return -1;
}
else
{
if (*buf == '\0')
break;
buf++;
pos++;
n--;
}
}
return 0;
}