Annotation of coherent/b/bin/ps/ps_b4_krnl68/pt.c, revision 1.1

1.1     ! root        1: /* Attempt to find page tables in /dev/mem.  */
        !             2: #include <stdio.h>
        !             3: #define ONE_CLICK 0x400        /* Number of longs in a click.  */
        !             4: #define MEM_SIZE 0x460000L /* Size of memory on qiqineb.  */
        !             5: #define PRESENT 0x00000001L    /* Present bit for Page Table Entries.  */
        !             6: #define TRUE (1==1)
        !             7: #define FALSE (1==2)
        !             8: 
        !             9: main()
        !            10: {
        !            11:        static unsigned long page_buffer[ONE_CLICK]; /* Load pages here.  */
        !            12: 
        !            13:        int fd; /* Handle for /dev/mem.  */
        !            14: 
        !            15:        unsigned long *base;    /* Loop through all possible clicks.  */
        !            16:        unsigned long *walker;  /* Loop through each long in a click.  */
        !            17: 
        !            18:        int nonzero_seen;       /* Seen a nonzero element in this click?  */
        !            19: 
        !            20:        if (-1 == (fd = open("/dev/mem", 0))) {
        !            21:                perror("Can't open /dev/mem");
        !            22:                exit (1);
        !            23:        }
        !            24:        for (base = 0; base < (unsigned long *) MEM_SIZE; base += ONE_CLICK) {
        !            25: 
        !            26:                if (-1 == read(fd, page_buffer, ONE_CLICK*sizeof(long)) ) {
        !            27:                        perror("Read error");
        !            28:                        exit (1);
        !            29:                }
        !            30: 
        !            31:                nonzero_seen = FALSE;
        !            32: 
        !            33:                for (walker = page_buffer;
        !            34:                     walker < page_buffer + ONE_CLICK;
        !            35:                     ++walker) {
        !            36: 
        !            37:                        /* There must be at least one nonzero entry.  */
        !            38:                        if (0 != *walker) {
        !            39:                                nonzero_seen = TRUE;
        !            40: 
        !            41:                                /* All nonzero PTE's must be present.  */
        !            42:                                if (0L == (*walker & PRESENT)) {
        !            43:                                        break;
        !            44:                                }
        !            45:                        }
        !            46: 
        !            47:                        /* All PTE's must point at existant memory.  */
        !            48:                        if (*walker > MEM_SIZE) {
        !            49:                                break;
        !            50:                        }
        !            51:                }
        !            52: 
        !            53:                if (nonzero_seen && (page_buffer + ONE_CLICK == walker)) {
        !            54:                        printf("Possible page table: %x\n", base);
        !            55:                }
        !            56:        }
        !            57: } /* main() */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.