• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "OsConstants"
18 
19 #include "JNIHelp.h"
20 #include "JniConstants.h"
21 #include "Portability.h"
22 
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <netdb.h>
26 #include <netinet/in.h>
27 #include <netinet/tcp.h>
28 #include <poll.h>
29 #include <signal.h>
30 #include <stdlib.h>
31 #include <sys/ioctl.h>
32 #include <sys/mman.h>
33 #include <sys/prctl.h>
34 #include <sys/socket.h>
35 #include <sys/stat.h>
36 #include <sys/un.h>
37 #include <sys/wait.h>
38 #include <sys/xattr.h>
39 #include <unistd.h>
40 
41 #include <net/if_arp.h>
42 #include <linux/if_ether.h>
43 
44 // After the others because these are not necessarily self-contained in glibc.
45 #include <linux/if_addr.h>
46 #include <linux/rtnetlink.h>
47 
48 #include <net/if.h> // After <sys/socket.h> to work around a Mac header file bug.
49 
50 #if defined(__BIONIC__)
51 #include <linux/capability.h>
52 #endif
53 
initConstant(JNIEnv * env,jclass c,const char * fieldName,int value)54 static void initConstant(JNIEnv* env, jclass c, const char* fieldName, int value) {
55     jfieldID field = env->GetStaticFieldID(c, fieldName, "I");
56     env->SetStaticIntField(c, field, value);
57 }
58 
OsConstants_initConstants(JNIEnv * env,jclass c)59 static void OsConstants_initConstants(JNIEnv* env, jclass c) {
60     initConstant(env, c, "AF_INET", AF_INET);
61     initConstant(env, c, "AF_INET6", AF_INET6);
62     initConstant(env, c, "AF_PACKET", AF_PACKET);
63     initConstant(env, c, "AF_NETLINK", AF_NETLINK);
64     initConstant(env, c, "AF_UNIX", AF_UNIX);
65     initConstant(env, c, "AF_UNSPEC", AF_UNSPEC);
66     initConstant(env, c, "AI_ADDRCONFIG", AI_ADDRCONFIG);
67     initConstant(env, c, "AI_ALL", AI_ALL);
68     initConstant(env, c, "AI_CANONNAME", AI_CANONNAME);
69     initConstant(env, c, "AI_NUMERICHOST", AI_NUMERICHOST);
70 #if defined(AI_NUMERICSERV)
71     initConstant(env, c, "AI_NUMERICSERV", AI_NUMERICSERV);
72 #endif
73     initConstant(env, c, "AI_PASSIVE", AI_PASSIVE);
74     initConstant(env, c, "AI_V4MAPPED", AI_V4MAPPED);
75     initConstant(env, c, "ARPHRD_ETHER", ARPHRD_ETHER);
76     initConstant(env, c, "ARPHRD_LOOPBACK", ARPHRD_LOOPBACK);
77 #if defined(CAP_LAST_CAP)
78     initConstant(env, c, "CAP_AUDIT_CONTROL", CAP_AUDIT_CONTROL);
79     initConstant(env, c, "CAP_AUDIT_WRITE", CAP_AUDIT_WRITE);
80     initConstant(env, c, "CAP_BLOCK_SUSPEND", CAP_BLOCK_SUSPEND);
81     initConstant(env, c, "CAP_CHOWN", CAP_CHOWN);
82     initConstant(env, c, "CAP_DAC_OVERRIDE", CAP_DAC_OVERRIDE);
83     initConstant(env, c, "CAP_DAC_READ_SEARCH", CAP_DAC_READ_SEARCH);
84     initConstant(env, c, "CAP_FOWNER", CAP_FOWNER);
85     initConstant(env, c, "CAP_FSETID", CAP_FSETID);
86     initConstant(env, c, "CAP_IPC_LOCK", CAP_IPC_LOCK);
87     initConstant(env, c, "CAP_IPC_OWNER", CAP_IPC_OWNER);
88     initConstant(env, c, "CAP_KILL", CAP_KILL);
89     initConstant(env, c, "CAP_LAST_CAP", CAP_LAST_CAP);
90     initConstant(env, c, "CAP_LEASE", CAP_LEASE);
91     initConstant(env, c, "CAP_LINUX_IMMUTABLE", CAP_LINUX_IMMUTABLE);
92     initConstant(env, c, "CAP_MAC_ADMIN", CAP_MAC_ADMIN);
93     initConstant(env, c, "CAP_MAC_OVERRIDE", CAP_MAC_OVERRIDE);
94     initConstant(env, c, "CAP_MKNOD", CAP_MKNOD);
95     initConstant(env, c, "CAP_NET_ADMIN", CAP_NET_ADMIN);
96     initConstant(env, c, "CAP_NET_BIND_SERVICE", CAP_NET_BIND_SERVICE);
97     initConstant(env, c, "CAP_NET_BROADCAST", CAP_NET_BROADCAST);
98     initConstant(env, c, "CAP_NET_RAW", CAP_NET_RAW);
99     initConstant(env, c, "CAP_SETFCAP", CAP_SETFCAP);
100     initConstant(env, c, "CAP_SETGID", CAP_SETGID);
101     initConstant(env, c, "CAP_SETPCAP", CAP_SETPCAP);
102     initConstant(env, c, "CAP_SETUID", CAP_SETUID);
103     initConstant(env, c, "CAP_SYS_ADMIN", CAP_SYS_ADMIN);
104     initConstant(env, c, "CAP_SYS_BOOT", CAP_SYS_BOOT);
105     initConstant(env, c, "CAP_SYS_CHROOT", CAP_SYS_CHROOT);
106     initConstant(env, c, "CAP_SYSLOG", CAP_SYSLOG);
107     initConstant(env, c, "CAP_SYS_MODULE", CAP_SYS_MODULE);
108     initConstant(env, c, "CAP_SYS_NICE", CAP_SYS_NICE);
109     initConstant(env, c, "CAP_SYS_PACCT", CAP_SYS_PACCT);
110     initConstant(env, c, "CAP_SYS_PTRACE", CAP_SYS_PTRACE);
111     initConstant(env, c, "CAP_SYS_RAWIO", CAP_SYS_RAWIO);
112     initConstant(env, c, "CAP_SYS_RESOURCE", CAP_SYS_RESOURCE);
113     initConstant(env, c, "CAP_SYS_TIME", CAP_SYS_TIME);
114     initConstant(env, c, "CAP_SYS_TTY_CONFIG", CAP_SYS_TTY_CONFIG);
115     initConstant(env, c, "CAP_WAKE_ALARM", CAP_WAKE_ALARM);
116 #endif
117     initConstant(env, c, "E2BIG", E2BIG);
118     initConstant(env, c, "EACCES", EACCES);
119     initConstant(env, c, "EADDRINUSE", EADDRINUSE);
120     initConstant(env, c, "EADDRNOTAVAIL", EADDRNOTAVAIL);
121     initConstant(env, c, "EAFNOSUPPORT", EAFNOSUPPORT);
122     initConstant(env, c, "EAGAIN", EAGAIN);
123     initConstant(env, c, "EAI_AGAIN", EAI_AGAIN);
124     initConstant(env, c, "EAI_BADFLAGS", EAI_BADFLAGS);
125     initConstant(env, c, "EAI_FAIL", EAI_FAIL);
126     initConstant(env, c, "EAI_FAMILY", EAI_FAMILY);
127     initConstant(env, c, "EAI_MEMORY", EAI_MEMORY);
128     initConstant(env, c, "EAI_NODATA", EAI_NODATA);
129     initConstant(env, c, "EAI_NONAME", EAI_NONAME);
130 #if defined(EAI_OVERFLOW)
131     initConstant(env, c, "EAI_OVERFLOW", EAI_OVERFLOW);
132 #endif
133     initConstant(env, c, "EAI_SERVICE", EAI_SERVICE);
134     initConstant(env, c, "EAI_SOCKTYPE", EAI_SOCKTYPE);
135     initConstant(env, c, "EAI_SYSTEM", EAI_SYSTEM);
136     initConstant(env, c, "EALREADY", EALREADY);
137     initConstant(env, c, "EBADF", EBADF);
138     initConstant(env, c, "EBADMSG", EBADMSG);
139     initConstant(env, c, "EBUSY", EBUSY);
140     initConstant(env, c, "ECANCELED", ECANCELED);
141     initConstant(env, c, "ECHILD", ECHILD);
142     initConstant(env, c, "ECONNABORTED", ECONNABORTED);
143     initConstant(env, c, "ECONNREFUSED", ECONNREFUSED);
144     initConstant(env, c, "ECONNRESET", ECONNRESET);
145     initConstant(env, c, "EDEADLK", EDEADLK);
146     initConstant(env, c, "EDESTADDRREQ", EDESTADDRREQ);
147     initConstant(env, c, "EDOM", EDOM);
148     initConstant(env, c, "EDQUOT", EDQUOT);
149     initConstant(env, c, "EEXIST", EEXIST);
150     initConstant(env, c, "EFAULT", EFAULT);
151     initConstant(env, c, "EFBIG", EFBIG);
152     initConstant(env, c, "EHOSTUNREACH", EHOSTUNREACH);
153     initConstant(env, c, "EIDRM", EIDRM);
154     initConstant(env, c, "EILSEQ", EILSEQ);
155     initConstant(env, c, "EINPROGRESS", EINPROGRESS);
156     initConstant(env, c, "EINTR", EINTR);
157     initConstant(env, c, "EINVAL", EINVAL);
158     initConstant(env, c, "EIO", EIO);
159     initConstant(env, c, "EISCONN", EISCONN);
160     initConstant(env, c, "EISDIR", EISDIR);
161     initConstant(env, c, "ELOOP", ELOOP);
162     initConstant(env, c, "EMFILE", EMFILE);
163     initConstant(env, c, "EMLINK", EMLINK);
164     initConstant(env, c, "EMSGSIZE", EMSGSIZE);
165     initConstant(env, c, "EMULTIHOP", EMULTIHOP);
166     initConstant(env, c, "ENAMETOOLONG", ENAMETOOLONG);
167     initConstant(env, c, "ENETDOWN", ENETDOWN);
168     initConstant(env, c, "ENETRESET", ENETRESET);
169     initConstant(env, c, "ENETUNREACH", ENETUNREACH);
170     initConstant(env, c, "ENFILE", ENFILE);
171     initConstant(env, c, "ENOBUFS", ENOBUFS);
172     initConstant(env, c, "ENODATA", ENODATA);
173     initConstant(env, c, "ENODEV", ENODEV);
174     initConstant(env, c, "ENOENT", ENOENT);
175     initConstant(env, c, "ENOEXEC", ENOEXEC);
176     initConstant(env, c, "ENOLCK", ENOLCK);
177     initConstant(env, c, "ENOLINK", ENOLINK);
178     initConstant(env, c, "ENOMEM", ENOMEM);
179     initConstant(env, c, "ENOMSG", ENOMSG);
180     initConstant(env, c, "ENONET", ENONET);
181     initConstant(env, c, "ENOPROTOOPT", ENOPROTOOPT);
182     initConstant(env, c, "ENOSPC", ENOSPC);
183     initConstant(env, c, "ENOSR", ENOSR);
184     initConstant(env, c, "ENOSTR", ENOSTR);
185     initConstant(env, c, "ENOSYS", ENOSYS);
186     initConstant(env, c, "ENOTCONN", ENOTCONN);
187     initConstant(env, c, "ENOTDIR", ENOTDIR);
188     initConstant(env, c, "ENOTEMPTY", ENOTEMPTY);
189     initConstant(env, c, "ENOTSOCK", ENOTSOCK);
190     initConstant(env, c, "ENOTSUP", ENOTSUP);
191     initConstant(env, c, "ENOTTY", ENOTTY);
192     initConstant(env, c, "ENXIO", ENXIO);
193     initConstant(env, c, "EOPNOTSUPP", EOPNOTSUPP);
194     initConstant(env, c, "EOVERFLOW", EOVERFLOW);
195     initConstant(env, c, "EPERM", EPERM);
196     initConstant(env, c, "EPIPE", EPIPE);
197     initConstant(env, c, "EPROTO", EPROTO);
198     initConstant(env, c, "EPROTONOSUPPORT", EPROTONOSUPPORT);
199     initConstant(env, c, "EPROTOTYPE", EPROTOTYPE);
200     initConstant(env, c, "ERANGE", ERANGE);
201     initConstant(env, c, "EROFS", EROFS);
202     initConstant(env, c, "ESPIPE", ESPIPE);
203     initConstant(env, c, "ESRCH", ESRCH);
204     initConstant(env, c, "ESTALE", ESTALE);
205     initConstant(env, c, "ETH_P_ALL", ETH_P_ALL);
206     initConstant(env, c, "ETH_P_ARP", ETH_P_ARP);
207     initConstant(env, c, "ETH_P_IP", ETH_P_IP);
208     initConstant(env, c, "ETH_P_IPV6", ETH_P_IPV6);
209     initConstant(env, c, "ETIME", ETIME);
210     initConstant(env, c, "ETIMEDOUT", ETIMEDOUT);
211     initConstant(env, c, "ETXTBSY", ETXTBSY);
212     initConstant(env, c, "EUSERS", EUSERS);
213 #if EWOULDBLOCK != EAGAIN
214 #error EWOULDBLOCK != EAGAIN
215 #endif
216     initConstant(env, c, "EXDEV", EXDEV);
217     initConstant(env, c, "EXIT_FAILURE", EXIT_FAILURE);
218     initConstant(env, c, "EXIT_SUCCESS", EXIT_SUCCESS);
219     initConstant(env, c, "FD_CLOEXEC", FD_CLOEXEC);
220     initConstant(env, c, "FIONREAD", FIONREAD);
221     initConstant(env, c, "F_DUPFD", F_DUPFD);
222     initConstant(env, c, "F_DUPFD_CLOEXEC", F_DUPFD_CLOEXEC);
223     initConstant(env, c, "F_GETFD", F_GETFD);
224     initConstant(env, c, "F_GETFL", F_GETFL);
225     initConstant(env, c, "F_GETLK", F_GETLK);
226 #if defined(F_GETLK64)
227     initConstant(env, c, "F_GETLK64", F_GETLK64);
228 #endif
229     initConstant(env, c, "F_GETOWN", F_GETOWN);
230     initConstant(env, c, "F_OK", F_OK);
231     initConstant(env, c, "F_RDLCK", F_RDLCK);
232     initConstant(env, c, "F_SETFD", F_SETFD);
233     initConstant(env, c, "F_SETFL", F_SETFL);
234     initConstant(env, c, "F_SETLK", F_SETLK);
235 #if defined(F_SETLK64)
236     initConstant(env, c, "F_SETLK64", F_SETLK64);
237 #endif
238     initConstant(env, c, "F_SETLKW", F_SETLKW);
239 #if defined(F_SETLKW64)
240     initConstant(env, c, "F_SETLKW64", F_SETLKW64);
241 #endif
242     initConstant(env, c, "F_SETOWN", F_SETOWN);
243     initConstant(env, c, "F_UNLCK", F_UNLCK);
244     initConstant(env, c, "F_WRLCK", F_WRLCK);
245 #if defined(IFA_F_DADFAILED)
246     initConstant(env, c, "IFA_F_DADFAILED", IFA_F_DADFAILED);
247 #endif
248 #if defined(IFA_F_DEPRECATED)
249     initConstant(env, c, "IFA_F_DEPRECATED", IFA_F_DEPRECATED);
250 #endif
251 #if defined(IFA_F_HOMEADDRESS)
252     initConstant(env, c, "IFA_F_HOMEADDRESS", IFA_F_HOMEADDRESS);
253 #endif
254 #if defined(IFA_F_NODAD)
255     initConstant(env, c, "IFA_F_NODAD", IFA_F_NODAD);
256 #endif
257 #if defined(IFA_F_OPTIMISTIC)
258     initConstant(env, c, "IFA_F_OPTIMISTIC", IFA_F_OPTIMISTIC);
259 #endif
260 #if defined(IFA_F_PERMANENT)
261     initConstant(env, c, "IFA_F_PERMANENT", IFA_F_PERMANENT);
262 #endif
263 #if defined(IFA_F_SECONDARY)
264     initConstant(env, c, "IFA_F_SECONDARY", IFA_F_SECONDARY);
265 #endif
266 #if defined(IFA_F_TEMPORARY)
267     initConstant(env, c, "IFA_F_TEMPORARY", IFA_F_TEMPORARY);
268 #endif
269 #if defined(IFA_F_TENTATIVE)
270     initConstant(env, c, "IFA_F_TENTATIVE", IFA_F_TENTATIVE);
271 #endif
272     initConstant(env, c, "IFF_ALLMULTI", IFF_ALLMULTI);
273 #if defined(IFF_AUTOMEDIA)
274     initConstant(env, c, "IFF_AUTOMEDIA", IFF_AUTOMEDIA);
275 #endif
276     initConstant(env, c, "IFF_BROADCAST", IFF_BROADCAST);
277     initConstant(env, c, "IFF_DEBUG", IFF_DEBUG);
278 #if defined(IFF_DYNAMIC)
279     initConstant(env, c, "IFF_DYNAMIC", IFF_DYNAMIC);
280 #endif
281     initConstant(env, c, "IFF_LOOPBACK", IFF_LOOPBACK);
282 #if defined(IFF_MASTER)
283     initConstant(env, c, "IFF_MASTER", IFF_MASTER);
284 #endif
285     initConstant(env, c, "IFF_MULTICAST", IFF_MULTICAST);
286     initConstant(env, c, "IFF_NOARP", IFF_NOARP);
287     initConstant(env, c, "IFF_NOTRAILERS", IFF_NOTRAILERS);
288     initConstant(env, c, "IFF_POINTOPOINT", IFF_POINTOPOINT);
289 #if defined(IFF_PORTSEL)
290     initConstant(env, c, "IFF_PORTSEL", IFF_PORTSEL);
291 #endif
292     initConstant(env, c, "IFF_PROMISC", IFF_PROMISC);
293     initConstant(env, c, "IFF_RUNNING", IFF_RUNNING);
294 #if defined(IFF_SLAVE)
295     initConstant(env, c, "IFF_SLAVE", IFF_SLAVE);
296 #endif
297     initConstant(env, c, "IFF_UP", IFF_UP);
298     initConstant(env, c, "IPPROTO_ICMP", IPPROTO_ICMP);
299     initConstant(env, c, "IPPROTO_ICMPV6", IPPROTO_ICMPV6);
300     initConstant(env, c, "IPPROTO_IP", IPPROTO_IP);
301     initConstant(env, c, "IPPROTO_IPV6", IPPROTO_IPV6);
302     initConstant(env, c, "IPPROTO_RAW", IPPROTO_RAW);
303     initConstant(env, c, "IPPROTO_TCP", IPPROTO_TCP);
304     initConstant(env, c, "IPPROTO_UDP", IPPROTO_UDP);
305     initConstant(env, c, "IPV6_CHECKSUM", IPV6_CHECKSUM);
306     initConstant(env, c, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS);
307     initConstant(env, c, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF);
308     initConstant(env, c, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP);
309 #if defined(IPV6_RECVDSTOPTS)
310     initConstant(env, c, "IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS);
311 #endif
312 #if defined(IPV6_RECVHOPLIMIT)
313     initConstant(env, c, "IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT);
314 #endif
315 #if defined(IPV6_RECVHOPOPTS)
316     initConstant(env, c, "IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS);
317 #endif
318 #if defined(IPV6_RECVPKTINFO)
319     initConstant(env, c, "IPV6_RECVPKTINFO", IPV6_RECVPKTINFO);
320 #endif
321 #if defined(IPV6_RECVRTHDR)
322     initConstant(env, c, "IPV6_RECVRTHDR", IPV6_RECVRTHDR);
323 #endif
324 #if defined(IPV6_RECVTCLASS)
325     initConstant(env, c, "IPV6_RECVTCLASS", IPV6_RECVTCLASS);
326 #endif
327 #if defined(IPV6_TCLASS)
328     initConstant(env, c, "IPV6_TCLASS", IPV6_TCLASS);
329 #endif
330     initConstant(env, c, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS);
331     initConstant(env, c, "IPV6_V6ONLY", IPV6_V6ONLY);
332     initConstant(env, c, "IP_MULTICAST_IF", IP_MULTICAST_IF);
333     initConstant(env, c, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP);
334     initConstant(env, c, "IP_MULTICAST_TTL", IP_MULTICAST_TTL);
335     initConstant(env, c, "IP_RECVTOS", IP_RECVTOS);
336     initConstant(env, c, "IP_TOS", IP_TOS);
337     initConstant(env, c, "IP_TTL", IP_TTL);
338     initConstant(env, c, "MAP_FIXED", MAP_FIXED);
339     initConstant(env, c, "MAP_POPULATE", MAP_POPULATE);
340     initConstant(env, c, "MAP_PRIVATE", MAP_PRIVATE);
341     initConstant(env, c, "MAP_SHARED", MAP_SHARED);
342 #if defined(MCAST_JOIN_GROUP)
343     initConstant(env, c, "MCAST_JOIN_GROUP", MCAST_JOIN_GROUP);
344 #endif
345 #if defined(MCAST_LEAVE_GROUP)
346     initConstant(env, c, "MCAST_LEAVE_GROUP", MCAST_LEAVE_GROUP);
347 #endif
348 #if defined(MCAST_JOIN_SOURCE_GROUP)
349     initConstant(env, c, "MCAST_JOIN_SOURCE_GROUP", MCAST_JOIN_SOURCE_GROUP);
350 #endif
351 #if defined(MCAST_LEAVE_SOURCE_GROUP)
352     initConstant(env, c, "MCAST_LEAVE_SOURCE_GROUP", MCAST_LEAVE_SOURCE_GROUP);
353 #endif
354 #if defined(MCAST_BLOCK_SOURCE)
355     initConstant(env, c, "MCAST_BLOCK_SOURCE", MCAST_BLOCK_SOURCE);
356 #endif
357 #if defined(MCAST_UNBLOCK_SOURCE)
358     initConstant(env, c, "MCAST_UNBLOCK_SOURCE", MCAST_UNBLOCK_SOURCE);
359 #endif
360     initConstant(env, c, "MCL_CURRENT", MCL_CURRENT);
361     initConstant(env, c, "MCL_FUTURE", MCL_FUTURE);
362     initConstant(env, c, "MSG_CTRUNC", MSG_CTRUNC);
363     initConstant(env, c, "MSG_DONTROUTE", MSG_DONTROUTE);
364     initConstant(env, c, "MSG_EOR", MSG_EOR);
365     initConstant(env, c, "MSG_OOB", MSG_OOB);
366     initConstant(env, c, "MSG_PEEK", MSG_PEEK);
367     initConstant(env, c, "MSG_TRUNC", MSG_TRUNC);
368     initConstant(env, c, "MSG_WAITALL", MSG_WAITALL);
369     initConstant(env, c, "MS_ASYNC", MS_ASYNC);
370     initConstant(env, c, "MS_INVALIDATE", MS_INVALIDATE);
371     initConstant(env, c, "MS_SYNC", MS_SYNC);
372     initConstant(env, c, "NETLINK_ROUTE", NETLINK_ROUTE);
373     initConstant(env, c, "NI_DGRAM", NI_DGRAM);
374     initConstant(env, c, "NI_NAMEREQD", NI_NAMEREQD);
375     initConstant(env, c, "NI_NOFQDN", NI_NOFQDN);
376     initConstant(env, c, "NI_NUMERICHOST", NI_NUMERICHOST);
377     initConstant(env, c, "NI_NUMERICSERV", NI_NUMERICSERV);
378     initConstant(env, c, "O_ACCMODE", O_ACCMODE);
379     initConstant(env, c, "O_APPEND", O_APPEND);
380     initConstant(env, c, "O_CLOEXEC", O_CLOEXEC);
381     initConstant(env, c, "O_CREAT", O_CREAT);
382     initConstant(env, c, "O_EXCL", O_EXCL);
383     initConstant(env, c, "O_NOCTTY", O_NOCTTY);
384     initConstant(env, c, "O_NOFOLLOW", O_NOFOLLOW);
385     initConstant(env, c, "O_NONBLOCK", O_NONBLOCK);
386     initConstant(env, c, "O_RDONLY", O_RDONLY);
387     initConstant(env, c, "O_RDWR", O_RDWR);
388     initConstant(env, c, "O_SYNC", O_SYNC);
389     initConstant(env, c, "O_DSYNC", O_DSYNC);
390     initConstant(env, c, "O_TRUNC", O_TRUNC);
391     initConstant(env, c, "O_WRONLY", O_WRONLY);
392     initConstant(env, c, "POLLERR", POLLERR);
393     initConstant(env, c, "POLLHUP", POLLHUP);
394     initConstant(env, c, "POLLIN", POLLIN);
395     initConstant(env, c, "POLLNVAL", POLLNVAL);
396     initConstant(env, c, "POLLOUT", POLLOUT);
397     initConstant(env, c, "POLLPRI", POLLPRI);
398     initConstant(env, c, "POLLRDBAND", POLLRDBAND);
399     initConstant(env, c, "POLLRDNORM", POLLRDNORM);
400     initConstant(env, c, "POLLWRBAND", POLLWRBAND);
401     initConstant(env, c, "POLLWRNORM", POLLWRNORM);
402 #if defined(PR_GET_DUMPABLE)
403     initConstant(env, c, "PR_GET_DUMPABLE", PR_GET_DUMPABLE);
404 #endif
405 #if defined(PR_SET_DUMPABLE)
406     initConstant(env, c, "PR_SET_DUMPABLE", PR_SET_DUMPABLE);
407 #endif
408 #if defined(PR_SET_NO_NEW_PRIVS)
409     initConstant(env, c, "PR_SET_NO_NEW_PRIVS", PR_SET_NO_NEW_PRIVS);
410 #endif
411     initConstant(env, c, "PROT_EXEC", PROT_EXEC);
412     initConstant(env, c, "PROT_NONE", PROT_NONE);
413     initConstant(env, c, "PROT_READ", PROT_READ);
414     initConstant(env, c, "PROT_WRITE", PROT_WRITE);
415     initConstant(env, c, "R_OK", R_OK);
416 // NOTE: The RT_* constants are not preprocessor defines, they're enum
417 // members. The best we can do (barring UAPI / kernel version checks) is
418 // to hope they exist on all host linuxes we're building on. These
419 // constants have been around since 2.6.35 at least, so we should be ok.
420     initConstant(env, c, "RT_SCOPE_HOST", RT_SCOPE_HOST);
421     initConstant(env, c, "RT_SCOPE_LINK", RT_SCOPE_LINK);
422     initConstant(env, c, "RT_SCOPE_NOWHERE", RT_SCOPE_NOWHERE);
423     initConstant(env, c, "RT_SCOPE_SITE", RT_SCOPE_SITE);
424     initConstant(env, c, "RT_SCOPE_UNIVERSE", RT_SCOPE_UNIVERSE);
425     initConstant(env, c, "RTMGRP_IPV4_IFADDR", RTMGRP_IPV4_IFADDR);
426     initConstant(env, c, "RTMGRP_IPV4_MROUTE", RTMGRP_IPV4_MROUTE);
427     initConstant(env, c, "RTMGRP_IPV4_ROUTE", RTMGRP_IPV4_ROUTE);
428     initConstant(env, c, "RTMGRP_IPV4_RULE", RTMGRP_IPV4_RULE);
429     initConstant(env, c, "RTMGRP_IPV6_IFADDR", RTMGRP_IPV6_IFADDR);
430     initConstant(env, c, "RTMGRP_IPV6_IFINFO", RTMGRP_IPV6_IFINFO);
431     initConstant(env, c, "RTMGRP_IPV6_MROUTE", RTMGRP_IPV6_MROUTE);
432     initConstant(env, c, "RTMGRP_IPV6_PREFIX", RTMGRP_IPV6_PREFIX);
433     initConstant(env, c, "RTMGRP_IPV6_ROUTE", RTMGRP_IPV6_ROUTE);
434     initConstant(env, c, "RTMGRP_LINK", RTMGRP_LINK);
435     initConstant(env, c, "RTMGRP_NEIGH", RTMGRP_NEIGH);
436     initConstant(env, c, "RTMGRP_NOTIFY", RTMGRP_NOTIFY);
437     initConstant(env, c, "RTMGRP_TC", RTMGRP_TC);
438     initConstant(env, c, "SEEK_CUR", SEEK_CUR);
439     initConstant(env, c, "SEEK_END", SEEK_END);
440     initConstant(env, c, "SEEK_SET", SEEK_SET);
441     initConstant(env, c, "SHUT_RD", SHUT_RD);
442     initConstant(env, c, "SHUT_RDWR", SHUT_RDWR);
443     initConstant(env, c, "SHUT_WR", SHUT_WR);
444     initConstant(env, c, "SIGABRT", SIGABRT);
445     initConstant(env, c, "SIGALRM", SIGALRM);
446     initConstant(env, c, "SIGBUS", SIGBUS);
447     initConstant(env, c, "SIGCHLD", SIGCHLD);
448     initConstant(env, c, "SIGCONT", SIGCONT);
449     initConstant(env, c, "SIGFPE", SIGFPE);
450     initConstant(env, c, "SIGHUP", SIGHUP);
451     initConstant(env, c, "SIGILL", SIGILL);
452     initConstant(env, c, "SIGINT", SIGINT);
453     initConstant(env, c, "SIGIO", SIGIO);
454     initConstant(env, c, "SIGKILL", SIGKILL);
455     initConstant(env, c, "SIGPIPE", SIGPIPE);
456     initConstant(env, c, "SIGPROF", SIGPROF);
457 #if defined(SIGPWR)
458     initConstant(env, c, "SIGPWR", SIGPWR);
459 #endif
460     initConstant(env, c, "SIGQUIT", SIGQUIT);
461 #if defined(SIGRTMAX)
462     initConstant(env, c, "SIGRTMAX", SIGRTMAX);
463 #endif
464 #if defined(SIGRTMIN)
465     initConstant(env, c, "SIGRTMIN", SIGRTMIN);
466 #endif
467     initConstant(env, c, "SIGSEGV", SIGSEGV);
468 #if defined(SIGSTKFLT)
469     initConstant(env, c, "SIGSTKFLT", SIGSTKFLT);
470 #endif
471     initConstant(env, c, "SIGSTOP", SIGSTOP);
472     initConstant(env, c, "SIGSYS", SIGSYS);
473     initConstant(env, c, "SIGTERM", SIGTERM);
474     initConstant(env, c, "SIGTRAP", SIGTRAP);
475     initConstant(env, c, "SIGTSTP", SIGTSTP);
476     initConstant(env, c, "SIGTTIN", SIGTTIN);
477     initConstant(env, c, "SIGTTOU", SIGTTOU);
478     initConstant(env, c, "SIGURG", SIGURG);
479     initConstant(env, c, "SIGUSR1", SIGUSR1);
480     initConstant(env, c, "SIGUSR2", SIGUSR2);
481     initConstant(env, c, "SIGVTALRM", SIGVTALRM);
482     initConstant(env, c, "SIGWINCH", SIGWINCH);
483     initConstant(env, c, "SIGXCPU", SIGXCPU);
484     initConstant(env, c, "SIGXFSZ", SIGXFSZ);
485     initConstant(env, c, "SIOCGIFADDR", SIOCGIFADDR);
486     initConstant(env, c, "SIOCGIFBRDADDR", SIOCGIFBRDADDR);
487     initConstant(env, c, "SIOCGIFDSTADDR", SIOCGIFDSTADDR);
488     initConstant(env, c, "SIOCGIFNETMASK", SIOCGIFNETMASK);
489     initConstant(env, c, "SOCK_DGRAM", SOCK_DGRAM);
490     initConstant(env, c, "SOCK_RAW", SOCK_RAW);
491     initConstant(env, c, "SOCK_SEQPACKET", SOCK_SEQPACKET);
492     initConstant(env, c, "SOCK_STREAM", SOCK_STREAM);
493     initConstant(env, c, "SOL_SOCKET", SOL_SOCKET);
494 #if defined(SO_BINDTODEVICE)
495     initConstant(env, c, "SO_BINDTODEVICE", SO_BINDTODEVICE);
496 #endif
497     initConstant(env, c, "SO_BROADCAST", SO_BROADCAST);
498     initConstant(env, c, "SO_DEBUG", SO_DEBUG);
499     initConstant(env, c, "SO_DONTROUTE", SO_DONTROUTE);
500     initConstant(env, c, "SO_ERROR", SO_ERROR);
501     initConstant(env, c, "SO_KEEPALIVE", SO_KEEPALIVE);
502     initConstant(env, c, "SO_LINGER", SO_LINGER);
503     initConstant(env, c, "SO_OOBINLINE", SO_OOBINLINE);
504 #if defined(SO_PASSCRED)
505     initConstant(env, c, "SO_PASSCRED", SO_PASSCRED);
506 #endif
507 #if defined(SO_PEERCRED)
508     initConstant(env, c, "SO_PEERCRED", SO_PEERCRED);
509 #endif
510     initConstant(env, c, "SO_RCVBUF", SO_RCVBUF);
511     initConstant(env, c, "SO_RCVLOWAT", SO_RCVLOWAT);
512     initConstant(env, c, "SO_RCVTIMEO", SO_RCVTIMEO);
513     initConstant(env, c, "SO_REUSEADDR", SO_REUSEADDR);
514     initConstant(env, c, "SO_SNDBUF", SO_SNDBUF);
515     initConstant(env, c, "SO_SNDLOWAT", SO_SNDLOWAT);
516     initConstant(env, c, "SO_SNDTIMEO", SO_SNDTIMEO);
517     initConstant(env, c, "SO_TYPE", SO_TYPE);
518     initConstant(env, c, "STDERR_FILENO", STDERR_FILENO);
519     initConstant(env, c, "STDIN_FILENO", STDIN_FILENO);
520     initConstant(env, c, "STDOUT_FILENO", STDOUT_FILENO);
521     initConstant(env, c, "ST_MANDLOCK", ST_MANDLOCK);
522     initConstant(env, c, "ST_NOATIME", ST_NOATIME);
523     initConstant(env, c, "ST_NODEV", ST_NODEV);
524     initConstant(env, c, "ST_NODIRATIME", ST_NODIRATIME);
525     initConstant(env, c, "ST_NOEXEC", ST_NOEXEC);
526     initConstant(env, c, "ST_NOSUID", ST_NOSUID);
527     initConstant(env, c, "ST_RDONLY", ST_RDONLY);
528     initConstant(env, c, "ST_RELATIME", ST_RELATIME);
529     initConstant(env, c, "ST_SYNCHRONOUS", ST_SYNCHRONOUS);
530     initConstant(env, c, "S_IFBLK", S_IFBLK);
531     initConstant(env, c, "S_IFCHR", S_IFCHR);
532     initConstant(env, c, "S_IFDIR", S_IFDIR);
533     initConstant(env, c, "S_IFIFO", S_IFIFO);
534     initConstant(env, c, "S_IFLNK", S_IFLNK);
535     initConstant(env, c, "S_IFMT", S_IFMT);
536     initConstant(env, c, "S_IFREG", S_IFREG);
537     initConstant(env, c, "S_IFSOCK", S_IFSOCK);
538     initConstant(env, c, "S_IRGRP", S_IRGRP);
539     initConstant(env, c, "S_IROTH", S_IROTH);
540     initConstant(env, c, "S_IRUSR", S_IRUSR);
541     initConstant(env, c, "S_IRWXG", S_IRWXG);
542     initConstant(env, c, "S_IRWXO", S_IRWXO);
543     initConstant(env, c, "S_IRWXU", S_IRWXU);
544     initConstant(env, c, "S_ISGID", S_ISGID);
545     initConstant(env, c, "S_ISUID", S_ISUID);
546     initConstant(env, c, "S_ISVTX", S_ISVTX);
547     initConstant(env, c, "S_IWGRP", S_IWGRP);
548     initConstant(env, c, "S_IWOTH", S_IWOTH);
549     initConstant(env, c, "S_IWUSR", S_IWUSR);
550     initConstant(env, c, "S_IXGRP", S_IXGRP);
551     initConstant(env, c, "S_IXOTH", S_IXOTH);
552     initConstant(env, c, "S_IXUSR", S_IXUSR);
553     initConstant(env, c, "TCP_NODELAY", TCP_NODELAY);
554     initConstant(env, c, "TIOCOUTQ", TIOCOUTQ);
555     // UNIX_PATH_MAX is mentioned in some versions of unix(7), but not actually declared.
556     initConstant(env, c, "UNIX_PATH_MAX", sizeof(sockaddr_un::sun_path));
557     initConstant(env, c, "WCONTINUED", WCONTINUED);
558     initConstant(env, c, "WEXITED", WEXITED);
559     initConstant(env, c, "WNOHANG", WNOHANG);
560     initConstant(env, c, "WNOWAIT", WNOWAIT);
561     initConstant(env, c, "WSTOPPED", WSTOPPED);
562     initConstant(env, c, "WUNTRACED", WUNTRACED);
563     initConstant(env, c, "W_OK", W_OK);
564     initConstant(env, c, "XATTR_CREATE", XATTR_CREATE);
565     initConstant(env, c, "XATTR_REPLACE", XATTR_REPLACE);
566     initConstant(env, c, "X_OK", X_OK);
567     initConstant(env, c, "_SC_2_CHAR_TERM", _SC_2_CHAR_TERM);
568     initConstant(env, c, "_SC_2_C_BIND", _SC_2_C_BIND);
569     initConstant(env, c, "_SC_2_C_DEV", _SC_2_C_DEV);
570 #if defined(_SC_2_C_VERSION)
571     initConstant(env, c, "_SC_2_C_VERSION", _SC_2_C_VERSION);
572 #endif
573     initConstant(env, c, "_SC_2_FORT_DEV", _SC_2_FORT_DEV);
574     initConstant(env, c, "_SC_2_FORT_RUN", _SC_2_FORT_RUN);
575     initConstant(env, c, "_SC_2_LOCALEDEF", _SC_2_LOCALEDEF);
576     initConstant(env, c, "_SC_2_SW_DEV", _SC_2_SW_DEV);
577     initConstant(env, c, "_SC_2_UPE", _SC_2_UPE);
578     initConstant(env, c, "_SC_2_VERSION", _SC_2_VERSION);
579     initConstant(env, c, "_SC_AIO_LISTIO_MAX", _SC_AIO_LISTIO_MAX);
580     initConstant(env, c, "_SC_AIO_MAX", _SC_AIO_MAX);
581     initConstant(env, c, "_SC_AIO_PRIO_DELTA_MAX", _SC_AIO_PRIO_DELTA_MAX);
582     initConstant(env, c, "_SC_ARG_MAX", _SC_ARG_MAX);
583     initConstant(env, c, "_SC_ASYNCHRONOUS_IO", _SC_ASYNCHRONOUS_IO);
584     initConstant(env, c, "_SC_ATEXIT_MAX", _SC_ATEXIT_MAX);
585 #if defined(_SC_AVPHYS_PAGES)
586     initConstant(env, c, "_SC_AVPHYS_PAGES", _SC_AVPHYS_PAGES);
587 #endif
588     initConstant(env, c, "_SC_BC_BASE_MAX", _SC_BC_BASE_MAX);
589     initConstant(env, c, "_SC_BC_DIM_MAX", _SC_BC_DIM_MAX);
590     initConstant(env, c, "_SC_BC_SCALE_MAX", _SC_BC_SCALE_MAX);
591     initConstant(env, c, "_SC_BC_STRING_MAX", _SC_BC_STRING_MAX);
592     initConstant(env, c, "_SC_CHILD_MAX", _SC_CHILD_MAX);
593     initConstant(env, c, "_SC_CLK_TCK", _SC_CLK_TCK);
594     initConstant(env, c, "_SC_COLL_WEIGHTS_MAX", _SC_COLL_WEIGHTS_MAX);
595     initConstant(env, c, "_SC_DELAYTIMER_MAX", _SC_DELAYTIMER_MAX);
596     initConstant(env, c, "_SC_EXPR_NEST_MAX", _SC_EXPR_NEST_MAX);
597     initConstant(env, c, "_SC_FSYNC", _SC_FSYNC);
598     initConstant(env, c, "_SC_GETGR_R_SIZE_MAX", _SC_GETGR_R_SIZE_MAX);
599     initConstant(env, c, "_SC_GETPW_R_SIZE_MAX", _SC_GETPW_R_SIZE_MAX);
600     initConstant(env, c, "_SC_IOV_MAX", _SC_IOV_MAX);
601     initConstant(env, c, "_SC_JOB_CONTROL", _SC_JOB_CONTROL);
602     initConstant(env, c, "_SC_LINE_MAX", _SC_LINE_MAX);
603     initConstant(env, c, "_SC_LOGIN_NAME_MAX", _SC_LOGIN_NAME_MAX);
604     initConstant(env, c, "_SC_MAPPED_FILES", _SC_MAPPED_FILES);
605     initConstant(env, c, "_SC_MEMLOCK", _SC_MEMLOCK);
606     initConstant(env, c, "_SC_MEMLOCK_RANGE", _SC_MEMLOCK_RANGE);
607     initConstant(env, c, "_SC_MEMORY_PROTECTION", _SC_MEMORY_PROTECTION);
608     initConstant(env, c, "_SC_MESSAGE_PASSING", _SC_MESSAGE_PASSING);
609     initConstant(env, c, "_SC_MQ_OPEN_MAX", _SC_MQ_OPEN_MAX);
610     initConstant(env, c, "_SC_MQ_PRIO_MAX", _SC_MQ_PRIO_MAX);
611     initConstant(env, c, "_SC_NGROUPS_MAX", _SC_NGROUPS_MAX);
612     initConstant(env, c, "_SC_NPROCESSORS_CONF", _SC_NPROCESSORS_CONF);
613     initConstant(env, c, "_SC_NPROCESSORS_ONLN", _SC_NPROCESSORS_ONLN);
614     initConstant(env, c, "_SC_OPEN_MAX", _SC_OPEN_MAX);
615     initConstant(env, c, "_SC_PAGESIZE", _SC_PAGESIZE);
616     initConstant(env, c, "_SC_PAGE_SIZE", _SC_PAGE_SIZE);
617     initConstant(env, c, "_SC_PASS_MAX", _SC_PASS_MAX);
618 #if defined(_SC_PHYS_PAGES)
619     initConstant(env, c, "_SC_PHYS_PAGES", _SC_PHYS_PAGES);
620 #endif
621     initConstant(env, c, "_SC_PRIORITIZED_IO", _SC_PRIORITIZED_IO);
622     initConstant(env, c, "_SC_PRIORITY_SCHEDULING", _SC_PRIORITY_SCHEDULING);
623     initConstant(env, c, "_SC_REALTIME_SIGNALS", _SC_REALTIME_SIGNALS);
624     initConstant(env, c, "_SC_RE_DUP_MAX", _SC_RE_DUP_MAX);
625     initConstant(env, c, "_SC_RTSIG_MAX", _SC_RTSIG_MAX);
626     initConstant(env, c, "_SC_SAVED_IDS", _SC_SAVED_IDS);
627     initConstant(env, c, "_SC_SEMAPHORES", _SC_SEMAPHORES);
628     initConstant(env, c, "_SC_SEM_NSEMS_MAX", _SC_SEM_NSEMS_MAX);
629     initConstant(env, c, "_SC_SEM_VALUE_MAX", _SC_SEM_VALUE_MAX);
630     initConstant(env, c, "_SC_SHARED_MEMORY_OBJECTS", _SC_SHARED_MEMORY_OBJECTS);
631     initConstant(env, c, "_SC_SIGQUEUE_MAX", _SC_SIGQUEUE_MAX);
632     initConstant(env, c, "_SC_STREAM_MAX", _SC_STREAM_MAX);
633     initConstant(env, c, "_SC_SYNCHRONIZED_IO", _SC_SYNCHRONIZED_IO);
634     initConstant(env, c, "_SC_THREADS", _SC_THREADS);
635     initConstant(env, c, "_SC_THREAD_ATTR_STACKADDR", _SC_THREAD_ATTR_STACKADDR);
636     initConstant(env, c, "_SC_THREAD_ATTR_STACKSIZE", _SC_THREAD_ATTR_STACKSIZE);
637     initConstant(env, c, "_SC_THREAD_DESTRUCTOR_ITERATIONS", _SC_THREAD_DESTRUCTOR_ITERATIONS);
638     initConstant(env, c, "_SC_THREAD_KEYS_MAX", _SC_THREAD_KEYS_MAX);
639     initConstant(env, c, "_SC_THREAD_PRIORITY_SCHEDULING", _SC_THREAD_PRIORITY_SCHEDULING);
640     initConstant(env, c, "_SC_THREAD_PRIO_INHERIT", _SC_THREAD_PRIO_INHERIT);
641     initConstant(env, c, "_SC_THREAD_PRIO_PROTECT", _SC_THREAD_PRIO_PROTECT);
642     initConstant(env, c, "_SC_THREAD_SAFE_FUNCTIONS", _SC_THREAD_SAFE_FUNCTIONS);
643     initConstant(env, c, "_SC_THREAD_STACK_MIN", _SC_THREAD_STACK_MIN);
644     initConstant(env, c, "_SC_THREAD_THREADS_MAX", _SC_THREAD_THREADS_MAX);
645     initConstant(env, c, "_SC_TIMERS", _SC_TIMERS);
646     initConstant(env, c, "_SC_TIMER_MAX", _SC_TIMER_MAX);
647     initConstant(env, c, "_SC_TTY_NAME_MAX", _SC_TTY_NAME_MAX);
648     initConstant(env, c, "_SC_TZNAME_MAX", _SC_TZNAME_MAX);
649     initConstant(env, c, "_SC_VERSION", _SC_VERSION);
650     initConstant(env, c, "_SC_XBS5_ILP32_OFF32", _SC_XBS5_ILP32_OFF32);
651     initConstant(env, c, "_SC_XBS5_ILP32_OFFBIG", _SC_XBS5_ILP32_OFFBIG);
652     initConstant(env, c, "_SC_XBS5_LP64_OFF64", _SC_XBS5_LP64_OFF64);
653     initConstant(env, c, "_SC_XBS5_LPBIG_OFFBIG", _SC_XBS5_LPBIG_OFFBIG);
654     initConstant(env, c, "_SC_XOPEN_CRYPT", _SC_XOPEN_CRYPT);
655     initConstant(env, c, "_SC_XOPEN_ENH_I18N", _SC_XOPEN_ENH_I18N);
656     initConstant(env, c, "_SC_XOPEN_LEGACY", _SC_XOPEN_LEGACY);
657     initConstant(env, c, "_SC_XOPEN_REALTIME", _SC_XOPEN_REALTIME);
658     initConstant(env, c, "_SC_XOPEN_REALTIME_THREADS", _SC_XOPEN_REALTIME_THREADS);
659     initConstant(env, c, "_SC_XOPEN_SHM", _SC_XOPEN_SHM);
660     initConstant(env, c, "_SC_XOPEN_UNIX", _SC_XOPEN_UNIX);
661     initConstant(env, c, "_SC_XOPEN_VERSION", _SC_XOPEN_VERSION);
662     initConstant(env, c, "_SC_XOPEN_XCU_VERSION", _SC_XOPEN_XCU_VERSION);
663 }
664 
665 static JNINativeMethod gMethods[] = {
666     NATIVE_METHOD(OsConstants, initConstants, "()V"),
667 };
register_android_system_OsConstants(JNIEnv * env)668 void register_android_system_OsConstants(JNIEnv* env) {
669     jniRegisterNativeMethods(env, "android/system/OsConstants", gMethods, NELEM(gMethods));
670 }
671