tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: Eyal Rif <EYALRI () amdocs ! com>
To: tru64-unix-managers
Subject: summery: getting parameters from /dev/kmem using lseek
Date: Tue, 07 Dec 1999 08:02:06 +0000	[thread overview]
Message-ID: <96079091516187.tru64-unix-managers.marc@archive.invalid> (raw)

First of all,
thank you alan,

the thing i forgot is
knlist(nl)

using this function you can get the parameter address in
the kernel memory

here is an example how to get page_size from kernel memory
(I know there is a lot of other ways to get it but this is ment to
 keep the example simple)
you can use the same syntax or idea to get any parameters
that "nm /vmunix" will display.

#include <stdio.h>
#include <stdlib.h>
#include <nlist.h>
#include <paths.h>
#include <sys/fcntl.h>


struct nlist nl[] = {
    { "page_size" },
#define N_PAGE_SIZE 0
    { NULL },
};


static int kmem;

int pagesize;

main()
{
    int a,new,new1,retval;
    retval=knlist(nl);
    if (retval == -1)
         printf ("No kernel symbol addresses returned");
    else
    if (retval >= 0 )
        if (nl[0].n_type == 0)
          printf ("Unable to return address of symbol %s0i",
                  nl[8].n_name);

    if ((kmem = open(_PATH_KMEM, O_RDONLY)) < 0) {
                perror(_PATH_KMEM);
                exit(1);
        }
    if (lseek(kmem, (long) nl[N_PAGE_SIZE].n_value, SEEK_SET) !=
            (long) nl[N_PAGE_SIZE].n_value) {
                perror("pagesize; lseek");
        } else
          if (read(kmem, &pagesize, sizeof(pagesize)) !=
                    sizeof(pagesize)) {
                        perror("pagesize; read");
                }

     new = pagesize;
     printf("page size is: %d\n",new);

}

                 reply	other threads:[~1999-12-07  8:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox