Revision edf8e2af exec.c

b/exec.c
2131 2131
    return 0;
2132 2132
}
2133 2133

  
2134
/* dump memory mappings */
2135
void page_dump(FILE *f)
2134
/*
2135
 * Walks guest process memory "regions" one by one
2136
 * and calls callback function 'fn' for each region.
2137
 */
2138
int walk_memory_regions(void *priv,
2139
    int (*fn)(void *, unsigned long, unsigned long, unsigned long))
2136 2140
{
2137 2141
    unsigned long start, end;
2142
    PageDesc *p = NULL;
2138 2143
    int i, j, prot, prot1;
2139
    PageDesc *p;
2144
    int rc = 0;
2140 2145

  
2141
    fprintf(f, "%-8s %-8s %-8s %s\n",
2142
            "start", "end", "size", "prot");
2143
    start = -1;
2144
    end = -1;
2146
    start = end = -1;
2145 2147
    prot = 0;
2146
    for(i = 0; i <= L1_SIZE; i++) {
2147
        if (i < L1_SIZE)
2148
            p = l1_map[i];
2149
        else
2150
            p = NULL;
2151
        for(j = 0;j < L2_SIZE; j++) {
2152
            if (!p)
2153
                prot1 = 0;
2154
            else
2155
                prot1 = p[j].flags;
2148

  
2149
    for (i = 0; i <= L1_SIZE; i++) {
2150
        p = (i < L1_SIZE) ? l1_map[i] : NULL;
2151
        for (j = 0; j < L2_SIZE; j++) {
2152
            prot1 = (p == NULL) ? 0 : p[j].flags;
2153
            /*
2154
             * "region" is one continuous chunk of memory
2155
             * that has same protection flags set.
2156
             */
2156 2157
            if (prot1 != prot) {
2157 2158
                end = (i << (32 - L1_BITS)) | (j << TARGET_PAGE_BITS);
2158 2159
                if (start != -1) {
2159
                    fprintf(f, "%08lx-%08lx %08lx %c%c%c\n",
2160
                            start, end, end - start,
2161
                            prot & PAGE_READ ? 'r' : '-',
2162
                            prot & PAGE_WRITE ? 'w' : '-',
2163
                            prot & PAGE_EXEC ? 'x' : '-');
2160
                    rc = (*fn)(priv, start, end, prot);
2161
                    /* callback can stop iteration by returning != 0 */
2162
                    if (rc != 0)
2163
                        return (rc);
2164 2164
                }
2165 2165
                if (prot1 != 0)
2166 2166
                    start = end;
......
2168 2168
                    start = -1;
2169 2169
                prot = prot1;
2170 2170
            }
2171
            if (!p)
2171
            if (p == NULL)
2172 2172
                break;
2173 2173
        }
2174 2174
    }
2175
    return (rc);
2176
}
2177

  
2178
static int dump_region(void *priv, unsigned long start,
2179
    unsigned long end, unsigned long prot)
2180
{
2181
    FILE *f = (FILE *)priv;
2182

  
2183
    (void) fprintf(f, "%08lx-%08lx %08lx %c%c%c\n",
2184
        start, end, end - start,
2185
        ((prot & PAGE_READ) ? 'r' : '-'),
2186
        ((prot & PAGE_WRITE) ? 'w' : '-'),
2187
        ((prot & PAGE_EXEC) ? 'x' : '-'));
2188

  
2189
    return (0);
2190
}
2191

  
2192
/* dump memory mappings */
2193
void page_dump(FILE *f)
2194
{
2195
    (void) fprintf(f, "%-8s %-8s %-8s %s\n",
2196
            "start", "end", "size", "prot");
2197
    walk_memory_regions(f, dump_region);
2175 2198
}
2176 2199

  
2177 2200
int page_get_flags(target_ulong address)

Also available in: Unified diff