| 1 |
#include "platform.h" |
| 2 |
|
| 3 |
#include <sys/mman.h> |
| 4 |
#include <sys/newsig.h> |
| 5 |
#include <sys/param.h> |
| 6 |
#include <sys/pstat.h> |
| 7 |
|
| 8 |
#define MAP_ANON MAP_ANONYMOUS |
| 9 |
|
| 10 |
#include "platform/diskBack.unix.c" |
| 11 |
#include "platform/mmap-protect.c" |
| 12 |
#include "platform/nonwin.c" |
| 13 |
#include "platform/recv.nonblock.c" |
| 14 |
#include "platform/setenv.putenv.c" |
| 15 |
#include "platform/use-mmap.c" |
| 16 |
|
| 17 |
struct pstnames { |
| 18 |
int type; |
| 19 |
const char *name; |
| 20 |
}; |
| 21 |
|
| 22 |
static struct pstnames pst_type_names[] = |
| 23 |
{{ PS_NOTUSED, "unused" }, |
| 24 |
{ PS_USER_AREA, "user" }, |
| 25 |
{ PS_TEXT, "text" }, |
| 26 |
{ PS_DATA, "data" }, |
| 27 |
{ PS_STACK, "stack" }, |
| 28 |
{ PS_SHARED, "shared" }, |
| 29 |
{ PS_NULLDEREF, "null" }, |
| 30 |
{ PS_IO, "io" }, |
| 31 |
{ PS_MMF, "mmap" }, |
| 32 |
{ PS_GRAPHICS, "gfx" }, |
| 33 |
{ PS_GRAPHICS_DMA, "gfxdma" }, |
| 34 |
#ifdef PS_RSESTACK |
| 35 |
{ PS_RSESTACK, "rsestack" }, |
| 36 |
#endif |
| 37 |
{ 0, NULL }}; |
| 38 |
|
| 39 |
static const char * |
| 40 |
pst_type_name(int type) |
| 41 |
{ |
| 42 |
int i; |
| 43 |
|
| 44 |
for (i = 0; pst_type_names[i].name; i++) |
| 45 |
if (pst_type_names[i].type == type) |
| 46 |
return pst_type_names[i].name; |
| 47 |
return "unknown"; |
| 48 |
} |
| 49 |
|
| 50 |
static const char* |
| 51 |
pst_filename(struct pst_vm_status vm) |
| 52 |
{ |
| 53 |
static char fname[256]; |
| 54 |
#ifdef PSTAT_FILEDETAILS |
| 55 |
if (pstat_getpathname (fname, sizeof (fname), &vm.pst_fid) < 0) |
| 56 |
#endif |
| 57 |
strcpy (fname, "unknown"); |
| 58 |
return fname; |
| 59 |
} |
| 60 |
|
| 61 |
void GC_displayMem (void) { |
| 62 |
int i; |
| 63 |
struct pst_vm_status buf; |
| 64 |
size_t page_size = sysconf (_SC_PAGE_SIZE); |
| 65 |
|
| 66 |
printf("va_start va_end perms type phys filename\n"); |
| 67 |
printf("--------+--------+-----+-------+------+-----------\n"); |
| 68 |
for (i = 0;; i++) { |
| 69 |
if (pstat_getprocvm (&buf, sizeof (buf), 0, i) < 0) |
| 70 |
break; |
| 71 |
printf("%p %p %s%s%s %-8s %4d %s\n", |
| 72 |
(void*)buf.pst_vaddr, |
| 73 |
(void*)(buf.pst_vaddr + buf.pst_length * page_size - 1), |
| 74 |
(buf.pst_flags & PS_PROT_READ) ? "-" : "r", |
| 75 |
(buf.pst_flags & PS_PROT_WRITE) ? "-" : "w", |
| 76 |
(buf.pst_flags & PS_PROT_EXECUTE) ? "-" : "x", |
| 77 |
pst_type_name (buf.pst_type), |
| 78 |
buf.pst_phys_pages, |
| 79 |
pst_filename (buf)); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
size_t GC_pageSize (void) { |
| 84 |
struct pst_static buf; |
| 85 |
|
| 86 |
if (pstat_getstatic (&buf, sizeof (buf), 1, 0) < 0) |
| 87 |
diee ("failed to get page size"); |
| 88 |
return buf.page_size; |
| 89 |
} |
| 90 |
|
| 91 |
uintmax_t GC_physMem (void) { |
| 92 |
struct pst_static buf; |
| 93 |
uintmax_t physMem; |
| 94 |
|
| 95 |
if (pstat_getstatic (&buf, sizeof (buf), 1, 0) < 0) |
| 96 |
diee ("failed to get physical memory size"); |
| 97 |
physMem = (uintmax_t)buf.physical_memory * (uintmax_t)buf.page_size; |
| 98 |
return physMem; |
| 99 |
} |
| 100 |
|
| 101 |
#ifdef __hppa__ |
| 102 |
float modff (float x, float *iptr) |
| 103 |
{ |
| 104 |
double d, i; |
| 105 |
d = modf ((double)x, &i); |
| 106 |
*iptr = (float)i; |
| 107 |
return d; |
| 108 |
} |
| 109 |
|
| 110 |
float rintf (float x) { |
| 111 |
return (float)rint ((double)x); |
| 112 |
} |
| 113 |
|
| 114 |
float frexpf (float x, int *e) { |
| 115 |
return (float)frexp ((double)x, e); |
| 116 |
} |
| 117 |
|
| 118 |
float ldexpf (float x, int e) { |
| 119 |
return (float)ldexp ((double)x, e); |
| 120 |
} |
| 121 |
#endif |