Commit | Line | Data |
---|---|---|
7f918cf1 CE |
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 "diskBack.unix.c" | |
11 | #include "mmap-protect.c" | |
12 | #include "nonwin.c" | |
13 | #include "recv.nonblock.c" | |
14 | #include "setenv.putenv.c" | |
15 | #include "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 | ||
84 | static void catcher (__attribute__ ((unused)) int signo, | |
85 | __attribute__ ((unused)) siginfo_t* info, | |
86 | void* context) { | |
87 | ucontext_t* ucp = (ucontext_t*)context; | |
88 | GC_handleSigProf ((code_pointer) (ucp->uc_link)); | |
89 | } | |
90 | ||
91 | void GC_setSigProfHandler (struct sigaction *sa) { | |
92 | sa->sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO; | |
93 | sa->sa_sigaction = (void (*)(int, siginfo_t*, void*))catcher; | |
94 | } | |
95 | ||
96 | size_t GC_pageSize (void) { | |
97 | struct pst_static buf; | |
98 | ||
99 | if (pstat_getstatic (&buf, sizeof (buf), 1, 0) < 0) | |
100 | diee ("failed to get page size"); | |
101 | return buf.page_size; | |
102 | } | |
103 | ||
104 | uintmax_t GC_physMem (void) { | |
105 | struct pst_static buf; | |
106 | uintmax_t physMem; | |
107 | ||
108 | if (pstat_getstatic (&buf, sizeof (buf), 1, 0) < 0) | |
109 | diee ("failed to get physical memory size"); | |
110 | physMem = (uintmax_t)buf.physical_memory * (uintmax_t)buf.page_size; | |
111 | return physMem; | |
112 | } | |
113 | ||
114 | #ifdef __hppa__ | |
115 | float modff (float x, float *iptr) | |
116 | { | |
117 | double d, i; | |
118 | d = modf ((double)x, &i); | |
119 | *iptr = (float)i; | |
120 | return d; | |
121 | } | |
122 | ||
123 | float rintf (float x) { | |
124 | return (float)rint ((double)x); | |
125 | } | |
126 | ||
127 | float frexpf (float x, int *e) { | |
128 | return (float)frexp ((double)x, e); | |
129 | } | |
130 | ||
131 | float ldexpf (float x, int e) { | |
132 | return (float)ldexp ((double)x, e); | |
133 | } | |
134 | #endif /* __hppa__ */ |