Fix GNU coding style for G_.
[official-gcc.git] / libgo / sysinfo.c
blobfb11826420054eafef9e459777c82e4d2c9d6973
1 /* sysinfo.c -- input for mksysinfo.sh
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 /* This file is passed to GCC with the -fdump-go-spec option to
8 generate a Go version of the system information. */
10 #include "config.h"
12 #include <stddef.h>
13 #include <sys/types.h>
14 #include <dirent.h>
15 #include <errno.h>
16 #include <fcntl.h>
17 #include <ucontext.h>
18 #include <netinet/in.h>
19 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
20 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
21 && !_XOPEN_SOURCE.
22 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
23 <sys/ttold.h> does so unconditionally. */
24 #ifdef __sgi__
25 #include <sys/bsd_types.h>
26 #include <sys/ttold.h>
27 #endif
28 #include <netinet/tcp.h>
29 #if defined(HAVE_NETINET_IN_SYSTM_H)
30 #include <netinet/in_systm.h>
31 #endif
32 #if defined(HAVE_NETINET_IP_H)
33 #include <netinet/ip.h>
34 #endif
35 #if defined(HAVE_NETINET_IP_MROUTE_H)
36 #include <netinet/ip_mroute.h>
37 #endif
38 #if defined(HAVE_NETINET_IF_ETHER_H)
39 #include <netinet/if_ether.h>
40 #endif
41 #include <signal.h>
42 #include <sys/ioctl.h>
43 #include <termios.h>
44 #if defined(HAVE_SYSCALL_H)
45 #include <syscall.h>
46 #endif
47 #if defined(HAVE_SYS_SYSCALL_H)
48 #include <sys/syscall.h>
49 #endif
50 #if defined(HAVE_SYS_EPOLL_H)
51 #include <sys/epoll.h>
52 #endif
53 #if defined(HAVE_SYS_EVENT_H)
54 #include <sys/event.h>
55 #endif
56 #if defined(HAVE_SYS_FILE_H)
57 #include <sys/file.h>
58 #endif
59 #if defined(HAVE_SYS_MMAN_H)
60 #include <sys/mman.h>
61 #endif
62 #if defined(HAVE_SYS_PRCTL_H)
63 #include <sys/prctl.h>
64 #endif
65 #if defined(HAVE_SYS_PTRACE_H)
66 #include <sys/ptrace.h>
67 #endif
68 #include <sys/resource.h>
69 #include <sys/uio.h>
70 #include <sys/socket.h>
71 #include <sys/stat.h>
72 #include <sys/time.h>
73 #include <sys/times.h>
74 #include <sys/wait.h>
75 #include <sys/un.h>
76 #if defined(HAVE_SYS_USER_H)
77 #include <sys/user.h>
78 #endif
79 #if defined(HAVE_SYS_UTSNAME_H)
80 #include <sys/utsname.h>
81 #endif
82 #if defined(HAVE_SYS_SELECT_H)
83 #include <sys/select.h>
84 #endif
85 #include <time.h>
86 #include <unistd.h>
87 #include <netdb.h>
88 #include <pwd.h>
89 #include <grp.h>
90 #if defined(HAVE_LINUX_FILTER_H)
91 #include <linux/filter.h>
92 #endif
93 #if defined(HAVE_LINUX_IF_ADDR_H)
94 #include <linux/if_addr.h>
95 #endif
96 #if defined(HAVE_LINUX_IF_ETHER_H)
97 #include <linux/if_ether.h>
98 #endif
99 #if defined(HAVE_LINUX_IF_TUN_H)
100 #include <linux/if_tun.h>
101 #endif
102 #if defined(HAVE_LINUX_NETLINK_H)
103 #include <linux/netlink.h>
104 #endif
105 #if defined(HAVE_LINUX_PTRACE_H)
106 /* Avoid https://sourceware.org/bugzilla/show_bug.cgi?id=762 . */
107 #define ia64_fpreg pt_ia64_fpreg
108 #define pt_all_user_regs pt_ia64_all_user_regs
109 /* Avoid redefinition of ptrace_peeksiginfo from <sys/ptrace.h>.
110 https://gcc.gnu.org/PR81324 . */
111 #define ptrace_peeksiginfo_args ignore_ptrace_peeksiginfo_args
112 #include <linux/ptrace.h>
113 #undef ia64_fpreg
114 #undef pt_all_user_regs
115 #undef ptrace_peeksiginfo_args
116 #endif
117 #if defined(HAVE_LINUX_RTNETLINK_H)
118 #include <linux/rtnetlink.h>
119 #endif
120 #if defined(HAVE_NET_IF_H)
121 #include <net/if.h>
122 #endif
123 #if defined(HAVE_NET_IF_ARP_H)
124 #include <net/if_arp.h>
125 #endif
126 #if defined(HAVE_NET_ROUTE_H)
127 #include <net/route.h>
128 #endif
129 #if defined (HAVE_NETPACKET_PACKET_H)
130 #include <netpacket/packet.h>
131 #endif
132 #if defined(HAVE_SYS_MOUNT_H)
133 #include <sys/mount.h>
134 #endif
135 #if defined(HAVE_SYS_VFS_H)
136 #include <sys/vfs.h>
137 #endif
138 #if defined(HAVE_STATFS_H)
139 #include <sys/statfs.h>
140 #endif
141 #if defined(HAVE_SYS_TIMEX_H)
142 #include <sys/timex.h>
143 #endif
144 #if defined(HAVE_SYS_SYSINFO_H)
145 #include <sys/sysinfo.h>
146 #endif
147 #if defined(HAVE_USTAT_H)
148 #include <ustat.h>
149 #endif
150 #if defined(HAVE_UTIME_H)
151 #include <utime.h>
152 #endif
153 #if defined(HAVE_LINUX_ETHER_H)
154 #include <linux/ether.h>
155 #endif
156 #if defined(HAVE_LINUX_FS_H)
157 #include <linux/fs.h>
158 #endif
159 #if defined(HAVE_LINUX_REBOOT_H)
160 #include <linux/reboot.h>
161 #endif
162 #if defined(HAVE_SYS_INOTIFY_H)
163 #include <sys/inotify.h>
164 #endif
165 #if defined(HAVE_NETINET_ICMP6_H)
166 #include <netinet/icmp6.h>
167 #endif
168 #if defined(HAVE_SCHED_H)
169 #include <sched.h>
170 #endif
171 #if defined(HAVE_SEMAPHORE_H)
172 #include <semaphore.h>
173 #endif
174 #if defined(HAVE_PORT_H)
175 #include <port.h>
176 #endif
178 #ifdef USE_LIBFFI
179 #include "ffi.h"
180 #endif
182 /* Constants that may only be defined as expressions on some systems,
183 expressions too complex for -fdump-go-spec to handle. These are
184 handled specially below. */
185 enum {
186 #ifdef TIOCGWINSZ
187 TIOCGWINSZ_val = TIOCGWINSZ,
188 #endif
189 #ifdef TIOCSWINSZ
190 TIOCSWINSZ_val = TIOCSWINSZ,
191 #endif
192 #ifdef TIOCNOTTY
193 TIOCNOTTY_val = TIOCNOTTY,
194 #endif
195 #ifdef TIOCSCTTY
196 TIOCSCTTY_val = TIOCSCTTY,
197 #endif
198 #ifdef TIOCGPGRP
199 TIOCGPGRP_val = TIOCGPGRP,
200 #endif
201 #ifdef TIOCSPGRP
202 TIOCSPGRP_val = TIOCSPGRP,
203 #endif
204 #ifdef TIOCGPTN
205 TIOCGPTN_val = TIOCGPTN,
206 #endif
207 #ifdef TIOCSPTLCK
208 TIOCSPTLCK_val = TIOCSPTLCK,
209 #endif
210 #ifdef TIOCGDEV
211 TIOCGDEV_val = TIOCGDEV,
212 #endif
213 #ifdef TIOCSIG
214 TIOCSIG_val = TIOCSIG,
215 #endif
216 #ifdef TCGETS
217 TCGETS_val = TCGETS,
218 #endif
219 #ifdef TCSETS
220 TCSETS_val = TCSETS,
221 #endif
222 #ifdef TUNSETIFF
223 TUNSETIFF_val = TUNSETIFF,
224 #endif
225 #ifdef TUNSETNOCSUM
226 TUNSETNOCSUM_val = TUNSETNOCSUM,
227 #endif
228 #ifdef TUNSETDEBUG
229 TUNSETDEBUG_val = TUNSETDEBUG,
230 #endif
231 #ifdef TUNSETPERSIST
232 TUNSETPERSIST_val = TUNSETPERSIST,
233 #endif
234 #ifdef TUNSETOWNER
235 TUNSETOWNER_val = TUNSETOWNER,
236 #endif
237 #ifdef TUNSETLINK
238 TUNSETLINK_val = TUNSETLINK,
239 #endif
240 #ifdef TUNSETGROUP
241 TUNSETGROUP_val = TUNSETGROUP,
242 #endif
243 #ifdef TUNGETFEATURES
244 TUNGETFEATURES_val = TUNGETFEATURES,
245 #endif
246 #ifdef TUNSETOFFLOAD
247 TUNSETOFFLOAD_val = TUNSETOFFLOAD,
248 #endif
249 #ifdef TUNSETTXFILTER
250 TUNSETTXFILTER_val = TUNSETTXFILTER,
251 #endif
252 #ifdef TUNGETIFF
253 TUNGETIFF_val = TUNGETIFF,
254 #endif
255 #ifdef TUNGETSNDBUF
256 TUNGETSNDBUF_val = TUNGETSNDBUF,
257 #endif
258 #ifdef TUNSETSNDBUF
259 TUNSETSNDBUF_val = TUNSETSNDBUF,
260 #endif
261 #ifdef TUNATTACHFILTER
262 TUNATTACHFILTER_val = TUNATTACHFILTER,
263 #endif
264 #ifdef TUNDETACHFILTER
265 TUNDETACHFILTER_val = TUNDETACHFILTER,
266 #endif
267 #ifdef TUNGETVNETHDRSZ
268 TUNGETVNETHDRSZ_val = TUNGETVNETHDRSZ,
269 #endif
270 #ifdef TUNSETVNETHDRSZ
271 TUNSETVNETHDRSZ_val = TUNSETVNETHDRSZ,
272 #endif
273 #ifdef TUNSETQUEUE
274 TUNSETQUEUE_val = TUNSETQUEUE,
275 #endif
276 #ifdef TUNSETIFINDEX
277 TUNSETIFINDEX_val = TUNSETIFINDEX,
278 #endif
279 #ifdef TUNGETFILTER
280 TUNGETFILTER_val = TUNGETFILTER,
281 #endif
282 #ifdef NLA_HDRLEN
283 NLA_HDRLEN_val = NLA_HDRLEN,
284 #endif
287 #if defined(HAVE_SYS_EPOLL_H)
288 enum {
289 epoll_data_offset = offsetof(struct epoll_event, data)
291 #endif
293 // The following section introduces explicit references to types and
294 // constants of interest to support bootstrapping libgo using a
295 // compiler that doesn't support -fdump-go-spec (e.g., clang), via
296 // DWARF-based tools. This process is made more difficult due to the
297 // fact that clang tries hard to omit types/constants from DWARF if it
298 // can't find explicit references to them, so here we make sure that
299 // key items are mentioned in ways that will force them into the
300 // generated DWARF.
302 #if defined(__clang__)
304 // Make a reference to a type
305 #define TREF(typ) typ typ ## ref
307 // Make a reference to an opaque type
308 #define OTREF(typ) typ *typ ## ref
310 // Make a reference to a struct tag
311 #define SREF(stag) struct stag stag ## ref
313 // Make a reference to an enum literal
314 #define EREF(elit) unsigned elit ## fn(unsigned x) { return x == elit ? 1 : 0; }
316 //......................................................................
318 // From dirent.h
319 SREF(dirent);
320 SREF(dirent64);
321 OTREF(DIR);
323 // From fcntl.h
324 SREF(flock);
325 SREF(flock64);
327 // From ffi headers
328 SREF(_ffi_type);
329 TREF(ffi_cif);
330 TREF(ffi_abi);
331 TREF(ffi_status);
332 EREF(FFI_OK);
334 // From grp.h
335 SREF(group);
337 #if defined(HAVE_LINUX_FILTER_H)
338 // From linux/filter.h
339 SREF(sock_filter);
340 SREF(sock_fprog);
341 #endif
343 // From linux/if.h
344 EREF(IFF_UP);
346 #if defined(HAVE_LINUX_IF_ADDR_H)
347 // From linux/if_addr.h
348 SREF(ifaddrmsg);
349 EREF(IFA_ADDRESS);
350 #endif
352 #if defined(HAVE_LINUX_RTNETLINK_H)
353 // From linux/if_link.h
354 EREF(IFLA_ADDRESS);
355 #endif
357 // From in.h, in6.h, icmp6.h
358 SREF(ip_mreq);
359 SREF(ip_mreqn);
360 SREF(ipv6_mreq);
361 SREF(ip6_mtuinfo);
362 SREF(icmp6_filter);
363 SREF(in_pktinfo);
364 EREF(IPPROTO_TCP);
366 #if defined(HAVE_LINUX_RTNETLINK_H)
367 // From linux/rtnetlink.h
368 SREF(rtgenmsg);
369 SREF(rtmsg);
370 SREF(ifinfomsg);
371 SREF(rtattr);
372 SREF(rtnexthop);
373 EREF(RTM_BASE);
374 EREF(RTN_UNSPEC);
375 #endif
377 // From netdb.h
378 SREF(addrinfo);
380 // From netlink.h
381 SREF(nlattr);
382 SREF(nlmsgerr);
384 // From pthread.h and related
385 TREF(pthread_attr_t);
386 TREF(pthread_t);
387 TREF(pthread_mutex_t);
388 TREF(pthread_mutexattr_t);
390 // From pwd.h
391 SREF(passwd);
393 // From signal.h and related
394 TREF(sigset_t);
395 TREF(siginfo_t);
396 TREF(stack_t);
397 SREF(sigaction);
398 SREF(sigstack);
399 EREF(SI_USER);
400 EREF(FPE_INTOVF);
401 EREF(BUS_ADRALN);
402 EREF(SS_ONSTACK);
403 EREF(SEGV_MAPERR);
405 // From stat.h
406 SREF(stat64);
408 // From statfs.h
409 SREF(statfs);
410 SREF(statfs64);
412 // From sysinfo.h
413 SREF(sysinfo);
415 // From <sys/epoll.h>
416 #if defined(HAVE_SYS_EPOLL_H)
417 SREF(epoll_event);
418 EREF(EPOLLIN);
419 EREF(epoll_data_offset);
420 #endif
422 #if defined(HAVE_SYS_MOUNT_H)
423 // From sys/mount.h
424 EREF(MS_PRIVATE);
425 EREF(MNT_FORCE);
426 #endif
428 #if defined(HAVE_SYS_PTRACE_H)
429 // From <sys/ptrace.h>
430 SREF(pt_regs);
431 EREF(PTRACE_PEEKTEXT);
432 #endif
434 // From sys/resource.h
435 SREF(rusage);
436 SREF(rlimit64);
437 EREF(RLIMIT_NOFILE);
438 EREF(PRIO_USER);
440 // From sys/select.h
441 TREF(fd_set);
443 // From sys/socket.h
444 SREF(msghdr);
445 SREF(cmsghdr);
446 SREF(ucred);
447 EREF(MSG_OOB);
448 EREF(SCM_RIGHTS);
449 EREF(SOCK_RAW);
450 EREF(SHUT_RD);
452 // From sys/time.h and sys/times.h
453 SREF(timespec);
454 SREF(timeval);
455 SREF(itimerval);
456 SREF(tms);
457 EREF(ITIMER_PROF);
459 #if defined(HAVE_SYS_TIMEX_H)
460 // From sys/timex.h
461 SREF(timex);
462 #endif
464 // From sys/types.h
465 TREF(pid_t);
466 TREF(off_t);
467 TREF(loff_t);
468 TREF(size_t);
469 TREF(ssize_t);
470 TREF(mode_t);
471 TREF(dev_t);
472 TREF(time_t);
474 // From sys/ucontext.h
475 TREF(ucontext_t);
477 #if defined(HAVE_SYS_USER_H)
478 // From sys/user.h
479 SREF(user_regs_struct);
480 #endif
482 #if defined(HAVE_SYS_UTSNAME_H)
483 // From sys/utsname.h
484 SREF(utsname);
485 #endif
487 // From termios.h
488 SREF(termios);
490 // From uio.h
491 SREF(iovec);
493 // From utime.h
494 SREF(utimbuf);
496 // From unistd.h
497 EREF(_PC_NAME_MAX);
498 EREF(_SC_GETPW_R_SIZE_MAX);
500 #endif // clang