• 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 package android.system;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 
21 import java.io.FileDescriptor;
22 import java.io.InterruptedIOException;
23 import java.net.InetAddress;
24 import java.net.InetSocketAddress;
25 import java.net.SocketAddress;
26 import java.net.SocketException;
27 import java.nio.ByteBuffer;
28 import libcore.io.Libcore;
29 import libcore.util.NonNull;
30 import libcore.util.Nullable;
31 
32 /**
33  * Access to low-level system functionality. Most of these are system calls. Most users will want
34  * to use higher-level APIs where available, but this class provides access to the underlying
35  * primitives used to implement the higher-level APIs.
36  *
37  * <p>The corresponding constants can be found in {@link OsConstants}.
38  */
39 public final class Os {
Os()40     private Os() {}
41 
42     // Ideally we'd just have the version that accepts SocketAddress but we're stuck with
43     // this one for legacy reasons. http://b/123568439
44     /**
45      * See <a href="http://man7.org/linux/man-pages/man2/accept.2.html">accept(2)</a>.
46      */
accept(FileDescriptor fd, InetSocketAddress peerAddress)47     public static FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException, SocketException { return accept(fd, (SocketAddress) peerAddress); }
48 
49     /**
50      * See <a href="http://man7.org/linux/man-pages/man2/accept.2.html">accept(2)</a>.
51      * @hide
52      */
accept(FileDescriptor fd, SocketAddress peerAddress)53     public static FileDescriptor accept(FileDescriptor fd, SocketAddress peerAddress) throws ErrnoException, SocketException { return Libcore.os.accept(fd, peerAddress); }
54 
55     /**
56      * See <a href="http://man7.org/linux/man-pages/man2/access.2.html">access(2)</a>.
57      */
access(String path, int mode)58     public static boolean access(String path, int mode) throws ErrnoException { return Libcore.os.access(path, mode); }
59 
60     /** @hide */
android_getaddrinfo(String node, StructAddrinfo hints, int netId)61     public static InetAddress[] android_getaddrinfo(String node, StructAddrinfo hints, int netId) throws GaiException { return Libcore.os.android_getaddrinfo(node, hints, netId); }
62 
63     /**
64      * See <a href="http://man7.org/linux/man-pages/man2/bind.2.html">bind(2)</a>.
65      */
bind(FileDescriptor fd, InetAddress address, int port)66     public static void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.bind(fd, address, port); }
67 
68     /**
69      * See <a href="http://man7.org/linux/man-pages/man2/bind.2.html">bind(2)</a>.
70      */
bind(@onNull FileDescriptor fd, @NonNull SocketAddress address)71     public static void bind(@NonNull FileDescriptor fd, @NonNull SocketAddress address) throws ErrnoException, SocketException { Libcore.os.bind(fd, address); }
72 
73     /**
74      * See <a href="http://man7.org/linux/man-pages/man2/capget.2.html">capget(2)</a>.
75      *
76      * @hide
77      */
78     @libcore.api.CorePlatformApi
capget(StructCapUserHeader hdr)79     public static StructCapUserData[] capget(StructCapUserHeader hdr) throws ErrnoException {
80         return Libcore.os.capget(hdr);
81     }
82 
83     /**
84      * See <a href="http://man7.org/linux/man-pages/man2/capset.2.html">capset(2)</a>.
85      *
86      * @hide
87      */
88     @libcore.api.CorePlatformApi
capset(StructCapUserHeader hdr, StructCapUserData[] data)89     public static void capset(StructCapUserHeader hdr, StructCapUserData[] data)
90             throws ErrnoException {
91         Libcore.os.capset(hdr, data);
92     }
93 
94     /**
95      * See <a href="http://man7.org/linux/man-pages/man2/chmod.2.html">chmod(2)</a>.
96      */
chmod(String path, int mode)97     public static void chmod(String path, int mode) throws ErrnoException { Libcore.os.chmod(path, mode); }
98 
99     /**
100      * See <a href="http://man7.org/linux/man-pages/man2/chown.2.html">chown(2)</a>.
101      */
chown(String path, int uid, int gid)102     public static void chown(String path, int uid, int gid) throws ErrnoException { Libcore.os.chown(path, uid, gid); }
103 
104     /**
105      * See <a href="http://man7.org/linux/man-pages/man2/close.2.html">close(2)</a>.
106      */
close(FileDescriptor fd)107     public static void close(FileDescriptor fd) throws ErrnoException { Libcore.os.close(fd); }
108 
109     /**
110      * See <a href="http://man7.org/linux/man-pages/man2/connect.2.html">connect(2)</a>.
111      */
connect(FileDescriptor fd, InetAddress address, int port)112     public static void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.connect(fd, address, port); }
113 
114     /**
115      * See <a href="http://man7.org/linux/man-pages/man2/connect.2.html">connect(2)</a>.
116      */
connect(@onNull FileDescriptor fd, @NonNull SocketAddress address)117     public static void connect(@NonNull FileDescriptor fd, @NonNull SocketAddress address) throws ErrnoException, SocketException { Libcore.os.connect(fd, address); }
118 
119     /**
120      * See <a href="http://man7.org/linux/man-pages/man2/dup.2.html">dup(2)</a>.
121      */
dup(FileDescriptor oldFd)122     public static FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException { return Libcore.os.dup(oldFd); }
123 
124     /**
125      * See <a href="http://man7.org/linux/man-pages/man2/dup2.2.html">dup2(2)</a>.
126      */
dup2(FileDescriptor oldFd, int newFd)127     public static FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException { return Libcore.os.dup2(oldFd, newFd); }
128 
129     /**
130      * See <a href="http://man7.org/linux/man-pages/man3/environ.3.html">environ(3)</a>.
131      */
environ()132     public static String[] environ() { return Libcore.os.environ(); }
133 
134     /**
135      * See <a href="http://man7.org/linux/man-pages/man2/execv.2.html">execv(2)</a>.
136      */
execv(String filename, String[] argv)137     public static void execv(String filename, String[] argv) throws ErrnoException { Libcore.os.execv(filename, argv); }
138 
139     /**
140      * See <a href="http://man7.org/linux/man-pages/man2/execve.2.html">execve(2)</a>.
141      */
execve(String filename, String[] argv, String[] envp)142     public static void execve(String filename, String[] argv, String[] envp) throws ErrnoException { Libcore.os.execve(filename, argv, envp); }
143 
144     /**
145      * See <a href="http://man7.org/linux/man-pages/man2/fchmod.2.html">fchmod(2)</a>.
146      */
fchmod(FileDescriptor fd, int mode)147     public static void fchmod(FileDescriptor fd, int mode) throws ErrnoException { Libcore.os.fchmod(fd, mode); }
148 
149     /**
150      * See <a href="http://man7.org/linux/man-pages/man2/fchown.2.html">fchown(2)</a>.
151      */
fchown(FileDescriptor fd, int uid, int gid)152     public static void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException { Libcore.os.fchown(fd, uid, gid); }
153 
154     /**
155      * See <a href="http://man7.org/linux/man-pages/man2/fcntl.2.html">fcntl(2)</a>.
156      */
fcntlInt(@onNull FileDescriptor fd, int cmd, int arg)157     public static int fcntlInt(@NonNull FileDescriptor fd, int cmd, int arg) throws ErrnoException { return Libcore.os.fcntlInt(fd, cmd, arg); }
158 
159     /** @hide */
fcntlVoid(FileDescriptor fd, int cmd)160     public static int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException { return Libcore.os.fcntlVoid(fd, cmd); }
161 
162     /**
163      * See <a href="http://man7.org/linux/man-pages/man2/fdatasync.2.html">fdatasync(2)</a>.
164      */
fdatasync(FileDescriptor fd)165     public static void fdatasync(FileDescriptor fd) throws ErrnoException { Libcore.os.fdatasync(fd); }
166 
167     /**
168      * See <a href="http://man7.org/linux/man-pages/man2/fstat.2.html">fstat(2)</a>.
169      */
fstat(FileDescriptor fd)170     public static StructStat fstat(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstat(fd); }
171 
172     /**
173      * See <a href="http://man7.org/linux/man-pages/man2/fstatvfs.2.html">fstatvfs(2)</a>.
174      */
fstatvfs(FileDescriptor fd)175     public static StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstatvfs(fd); }
176 
177     /**
178      * See <a href="http://man7.org/linux/man-pages/man2/fsync.2.html">fsync(2)</a>.
179      */
fsync(FileDescriptor fd)180     public static void fsync(FileDescriptor fd) throws ErrnoException { Libcore.os.fsync(fd); }
181 
182     /**
183      * See <a href="http://man7.org/linux/man-pages/man2/ftruncate.2.html">ftruncate(2)</a>.
184      */
ftruncate(FileDescriptor fd, long length)185     public static void ftruncate(FileDescriptor fd, long length) throws ErrnoException { Libcore.os.ftruncate(fd, length); }
186 
187     /**
188      * See <a href="http://man7.org/linux/man-pages/man3/gai_strerror.3.html">gai_strerror(3)</a>.
189      */
gai_strerror(int error)190     public static String gai_strerror(int error) { return Libcore.os.gai_strerror(error); }
191 
192     /**
193      * See <a href="http://man7.org/linux/man-pages/man2/getegid.2.html">getegid(2)</a>.
194      */
getegid()195     public static int getegid() { return Libcore.os.getegid(); }
196 
197     /**
198      * See <a href="http://man7.org/linux/man-pages/man2/geteuid.2.html">geteuid(2)</a>.
199      */
geteuid()200     public static int geteuid() { return Libcore.os.geteuid(); }
201 
202     /**
203      * See <a href="http://man7.org/linux/man-pages/man2/getgid.2.html">getgid(2)</a>.
204      */
getgid()205     public static int getgid() { return Libcore.os.getgid(); }
206 
207     /**
208      * See <a href="http://man7.org/linux/man-pages/man3/getenv.3.html">getenv(3)</a>.
209      */
getenv(String name)210     public static String getenv(String name) { return Libcore.os.getenv(name); }
211 
212     /**
213      * See <a href="http://man7.org/linux/man-pages/man3/getifaddrs.3.html">getifaddrs(3)</a>.
214      * @hide
215      */
getifaddrs()216     public static StructIfaddrs[] getifaddrs() throws ErrnoException { return Libcore.os.getifaddrs(); }
217 
218     /** @hide */
getnameinfo(InetAddress address, int flags)219     public static String getnameinfo(InetAddress address, int flags) throws GaiException { return Libcore.os.getnameinfo(address, flags); }
220 
221     /**
222      * See <a href="http://man7.org/linux/man-pages/man2/getpeername.2.html">getpeername(2)</a>.
223      */
getpeername(FileDescriptor fd)224     public static SocketAddress getpeername(FileDescriptor fd) throws ErrnoException { return Libcore.os.getpeername(fd); }
225 
226     /**
227      * See <a href="http://man7.org/linux/man-pages/man2/getpgid.2.html">getpgid(2)</a>.
228      * @hide
229      */
230     @libcore.api.CorePlatformApi
getpgid(int pid)231     public static int getpgid(int pid) throws ErrnoException { return Libcore.os.getpgid(pid); }
232 
233     /**
234      * See <a href="http://man7.org/linux/man-pages/man2/getpid.2.html">getpid(2)</a>.
235      */
getpid()236     public static int getpid() { return Libcore.os.getpid(); }
237 
238     /**
239      * See <a href="http://man7.org/linux/man-pages/man2/getppid.2.html">getppid(2)</a>.
240      */
getppid()241     public static int getppid() { return Libcore.os.getppid(); }
242 
243     /** @hide */
getpwnam(String name)244     public static StructPasswd getpwnam(String name) throws ErrnoException { return Libcore.os.getpwnam(name); }
245 
246     /** @hide */
getpwuid(int uid)247     public static StructPasswd getpwuid(int uid) throws ErrnoException { return Libcore.os.getpwuid(uid); }
248 
249     /** @hide */
250     @libcore.api.CorePlatformApi
getrlimit(int resource)251     public static StructRlimit getrlimit(int resource) throws ErrnoException { return Libcore.os.getrlimit(resource); }
252 
253     /**
254      * See <a href="http://man7.org/linux/man-pages/man2/getsockname.2.html">getsockname(2)</a>.
255      */
getsockname(FileDescriptor fd)256     public static SocketAddress getsockname(FileDescriptor fd) throws ErrnoException { return Libcore.os.getsockname(fd); }
257 
258     /** @hide */
getsockoptByte(FileDescriptor fd, int level, int option)259     public static int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptByte(fd, level, option); }
260 
261     /** @hide */
getsockoptInAddr(FileDescriptor fd, int level, int option)262     public static InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInAddr(fd, level, option); }
263 
264     /** @hide */
265     @libcore.api.CorePlatformApi
getsockoptInt(FileDescriptor fd, int level, int option)266     public static int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInt(fd, level, option); }
267 
268     /** @hide */
269     @libcore.api.CorePlatformApi
getsockoptLinger(FileDescriptor fd, int level, int option)270     public static StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptLinger(fd, level, option); }
271 
272     /**
273      * See <a href="http://man7.org/linux/man-pages/man2/setsockopt.2.html">getsockopt(2)</a>.
274      *
275      * <p>Only for use with {@code option} values that return a {@code struct timeval} such as
276      * {@link OsConstants#SO_RCVTIMEO} and {@link OsConstants#SO_SNDTIMEO}. Use with other
277      * options may throw an {@code IllegalArgumentException} or return junk values.
278      */
getsockoptTimeval(@onNull FileDescriptor fd, int level, int option)279     public static @NonNull StructTimeval getsockoptTimeval(@NonNull FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptTimeval(fd, level, option); }
280 
281     /** @hide */
getsockoptUcred(FileDescriptor fd, int level, int option)282     public static StructUcred getsockoptUcred(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptUcred(fd, level, option); }
283 
284     /**
285      * See <a href="http://man7.org/linux/man-pages/man2/gettid.2.html">gettid(2)</a>.
286      */
gettid()287     public static int gettid() { return Libcore.os.gettid(); }
288 
289     /**
290      * See <a href="http://man7.org/linux/man-pages/man2/getuid.2.html">getuid(2)</a>.
291      */
getuid()292     public static int getuid() { return Libcore.os.getuid(); }
293 
294     /**
295      * See <a href="http://man7.org/linux/man-pages/man2/getxattr.2.html">getxattr(2)</a>
296      */
getxattr(String path, String name)297     public static byte[] getxattr(String path, String name) throws ErrnoException { return Libcore.os.getxattr(path, name); }
298 
299     /**
300      * See <a href="http://man7.org/linux/man-pages/man3/if_indextoname.3.html">if_indextoname(3)</a>.
301      */
if_indextoname(int index)302     public static String if_indextoname(int index) { return Libcore.os.if_indextoname(index); }
303 
304     /**
305      * See <a href="http://man7.org/linux/man-pages/man3/if_nametoindex.3.html">if_nametoindex(3)</a>.
306      */
if_nametoindex(String name)307     public static int if_nametoindex(String name) { return Libcore.os.if_nametoindex(name); }
308 
309     /**
310      * See <a href="http://man7.org/linux/man-pages/man3/inet_pton.3.html">inet_pton(3)</a>.
311      */
inet_pton(int family, String address)312     public static InetAddress inet_pton(int family, String address) { return Libcore.os.inet_pton(family, address); }
313 
314     /** @hide */
ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName)315     public static InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException { return Libcore.os.ioctlInetAddress(fd, cmd, interfaceName); }
316 
317 
318     /** @hide */
319     @libcore.api.CorePlatformApi
ioctlInt(FileDescriptor fd, int cmd, Int32Ref arg)320     public static int ioctlInt(FileDescriptor fd, int cmd, Int32Ref arg) throws ErrnoException {
321         return Libcore.os.ioctlInt(fd, cmd, arg);
322     }
323 
324     /**
325      * See <a href="http://man7.org/linux/man-pages/man3/isatty.3.html">isatty(3)</a>.
326      */
isatty(FileDescriptor fd)327     public static boolean isatty(FileDescriptor fd) { return Libcore.os.isatty(fd); }
328 
329     /**
330      * See <a href="http://man7.org/linux/man-pages/man2/kill.2.html">kill(2)</a>.
331      */
kill(int pid, int signal)332     public static void kill(int pid, int signal) throws ErrnoException { Libcore.os.kill(pid, signal); }
333 
334     /**
335      * See <a href="http://man7.org/linux/man-pages/man2/lchown.2.html">lchown(2)</a>.
336      */
lchown(String path, int uid, int gid)337     public static void lchown(String path, int uid, int gid) throws ErrnoException { Libcore.os.lchown(path, uid, gid); }
338 
339     /**
340      * See <a href="http://man7.org/linux/man-pages/man2/link.2.html">link(2)</a>.
341      */
link(String oldPath, String newPath)342     public static void link(String oldPath, String newPath) throws ErrnoException { Libcore.os.link(oldPath, newPath); }
343 
344     /**
345      * See <a href="http://man7.org/linux/man-pages/man2/listen.2.html">listen(2)</a>.
346      */
listen(FileDescriptor fd, int backlog)347     public static void listen(FileDescriptor fd, int backlog) throws ErrnoException { Libcore.os.listen(fd, backlog); }
348 
349     /**
350      * See <a href="http://man7.org/linux/man-pages/man2/listxattr.2.html">listxattr(2)</a>
351      */
listxattr(String path)352     public static String[] listxattr(String path) throws ErrnoException { return Libcore.os.listxattr(path); }
353 
354     /**
355      * See <a href="http://man7.org/linux/man-pages/man2/lseek.2.html">lseek(2)</a>.
356      */
lseek(FileDescriptor fd, long offset, int whence)357     public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return Libcore.os.lseek(fd, offset, whence); }
358 
359     /**
360      * See <a href="http://man7.org/linux/man-pages/man2/lstat.2.html">lstat(2)</a>.
361      */
lstat(String path)362     public static StructStat lstat(String path) throws ErrnoException { return Libcore.os.lstat(path); }
363 
364     /**
365      * See <a href="http://man7.org/linux/man-pages/man2/memfd_create.2.html">memfd_create(2)</a>.
366      */
memfd_create(@onNull String name, int flags)367     public static @NonNull FileDescriptor memfd_create(@NonNull String name, int flags) throws ErrnoException { return Libcore.os.memfd_create(name, flags); }
368 
369     /**
370      * See <a href="http://man7.org/linux/man-pages/man2/mincore.2.html">mincore(2)</a>.
371      */
mincore(long address, long byteCount, byte[] vector)372     public static void mincore(long address, long byteCount, byte[] vector) throws ErrnoException { Libcore.os.mincore(address, byteCount, vector); }
373 
374     /**
375      * See <a href="http://man7.org/linux/man-pages/man2/mkdir.2.html">mkdir(2)</a>.
376      */
mkdir(String path, int mode)377     public static void mkdir(String path, int mode) throws ErrnoException { Libcore.os.mkdir(path, mode); }
378 
379     /**
380      * See <a href="http://man7.org/linux/man-pages/man3/mkfifo.3.html">mkfifo(3)</a>.
381      */
mkfifo(String path, int mode)382     public static void mkfifo(String path, int mode) throws ErrnoException { Libcore.os.mkfifo(path, mode); }
383 
384     /**
385      * See <a href="http://man7.org/linux/man-pages/man2/mlock.2.html">mlock(2)</a>.
386      */
mlock(long address, long byteCount)387     public static void mlock(long address, long byteCount) throws ErrnoException { Libcore.os.mlock(address, byteCount); }
388 
389     /**
390      * See <a href="http://man7.org/linux/man-pages/man2/mmap.2.html">mmap(2)</a>.
391      */
mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset)392     public static long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException { return Libcore.os.mmap(address, byteCount, prot, flags, fd, offset); }
393 
394     /**
395      * See <a href="http://man7.org/linux/man-pages/man2/msync.2.html">msync(2)</a>.
396      */
msync(long address, long byteCount, int flags)397     public static void msync(long address, long byteCount, int flags) throws ErrnoException { Libcore.os.msync(address, byteCount, flags); }
398 
399     /**
400      * See <a href="http://man7.org/linux/man-pages/man2/munlock.2.html">munlock(2)</a>.
401      */
munlock(long address, long byteCount)402     public static void munlock(long address, long byteCount) throws ErrnoException { Libcore.os.munlock(address, byteCount); }
403 
404     /**
405      * See <a href="http://man7.org/linux/man-pages/man2/munmap.2.html">munmap(2)</a>.
406      */
munmap(long address, long byteCount)407     public static void munmap(long address, long byteCount) throws ErrnoException { Libcore.os.munmap(address, byteCount); }
408 
409     /**
410      * See <a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>.
411      */
open(String path, int flags, int mode)412     public static FileDescriptor open(String path, int flags, int mode) throws ErrnoException { return Libcore.os.open(path, flags, mode); }
413 
414     /**
415      * See <a href="http://man7.org/linux/man-pages/man2/pipe.2.html">pipe(2)</a>.
416      */
pipe()417     public static FileDescriptor[] pipe() throws ErrnoException { return Libcore.os.pipe2(0); }
418 
419     /** @hide */
420     @libcore.api.CorePlatformApi
pipe2(int flags)421     public static FileDescriptor[] pipe2(int flags) throws ErrnoException { return Libcore.os.pipe2(flags); }
422 
423     /**
424      * See <a href="http://man7.org/linux/man-pages/man2/poll.2.html">poll(2)</a>.
425      *
426      * <p>Note that in Lollipop this could throw an {@code ErrnoException} with {@code EINTR}.
427      * In later releases, the implementation will automatically just restart the system call with
428      * an appropriately reduced timeout.
429      */
poll(StructPollfd[] fds, int timeoutMs)430     public static int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return Libcore.os.poll(fds, timeoutMs); }
431 
432     /**
433      * See <a href="http://man7.org/linux/man-pages/man3/posix_fallocate.3.html">posix_fallocate(3)</a>.
434      */
posix_fallocate(FileDescriptor fd, long offset, long length)435     public static void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { Libcore.os.posix_fallocate(fd, offset, length); }
436 
437     /**
438      * See <a href="http://man7.org/linux/man-pages/man2/prctl.2.html">prctl(2)</a>.
439      */
prctl(int option, long arg2, long arg3, long arg4, long arg5)440     public static int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return Libcore.os.prctl(option, arg2, arg3, arg4, arg5); };
441 
442     /**
443      * See <a href="http://man7.org/linux/man-pages/man2/pread.2.html">pread(2)</a>.
444      */
pread(FileDescriptor fd, ByteBuffer buffer, long offset)445     public static int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, buffer, offset); }
446 
447     /**
448      * See <a href="http://man7.org/linux/man-pages/man2/pread.2.html">pread(2)</a>.
449      */
pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)450     public static int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, bytes, byteOffset, byteCount, offset); }
451 
452     /**
453      * See <a href="http://man7.org/linux/man-pages/man2/pwrite.2.html">pwrite(2)</a>.
454      */
pwrite(FileDescriptor fd, ByteBuffer buffer, long offset)455     public static int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, buffer, offset); }
456 
457     /**
458      * See <a href="http://man7.org/linux/man-pages/man2/pwrite.2.html">pwrite(2)</a>.
459      */
pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)460     public static int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, bytes, byteOffset, byteCount, offset); }
461 
462     /**
463      * See <a href="http://man7.org/linux/man-pages/man2/read.2.html">read(2)</a>.
464      */
read(FileDescriptor fd, ByteBuffer buffer)465     public static int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, buffer); }
466 
467     /**
468      * See <a href="http://man7.org/linux/man-pages/man2/read.2.html">read(2)</a>.
469      */
read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)470     public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, bytes, byteOffset, byteCount); }
471 
472     /**
473      * See <a href="http://man7.org/linux/man-pages/man2/readlink.2.html">readlink(2)</a>.
474      */
readlink(String path)475     public static String readlink(String path) throws ErrnoException { return Libcore.os.readlink(path); }
476 
477     /**
478      * See <a href="http://man7.org/linux/man-pages/man3/realpath.3.html">realpath(3)</a>.
479      * @hide
480      */
481     @libcore.api.CorePlatformApi
realpath(String path)482     public static String realpath(String path) throws ErrnoException { return Libcore.os.realpath(path); }
483 
484     /**
485      * See <a href="http://man7.org/linux/man-pages/man2/readv.2.html">readv(2)</a>.
486      */
readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)487     public static int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.readv(fd, buffers, offsets, byteCounts); }
488 
489     /**
490      * See <a href="http://man7.org/linux/man-pages/man2/recvfrom.2.html">recvfrom(2)</a>.
491      */
recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress)492     public static int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return Libcore.os.recvfrom(fd, buffer, flags, srcAddress); }
493 
494     /**
495      * See <a href="http://man7.org/linux/man-pages/man2/recvfrom.2.html">recvfrom(2)</a>.
496      */
recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress)497     public static int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return Libcore.os.recvfrom(fd, bytes, byteOffset, byteCount, flags, srcAddress); }
498 
499     /**
500      * See <a href="http://man7.org/linux/man-pages/man3/remove.3.html">remove(3)</a>.
501      */
remove(String path)502     public static void remove(String path) throws ErrnoException { Libcore.os.remove(path); }
503 
504     /**
505      * See <a href="http://man7.org/linux/man-pages/man2/removexattr.2.html">removexattr(2)</a>.
506      */
removexattr(String path, String name)507     public static void removexattr(String path, String name) throws ErrnoException { Libcore.os.removexattr(path, name); }
508 
509     /**
510      * See <a href="http://man7.org/linux/man-pages/man2/rename.2.html">rename(2)</a>.
511      */
rename(String oldPath, String newPath)512     public static void rename(String oldPath, String newPath) throws ErrnoException { Libcore.os.rename(oldPath, newPath); }
513 
514     /**
515      * See <a href="http://man7.org/linux/man-pages/man2/sendfile.2.html">sendfile(2)</a>.
516      */
sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount)517     public static long sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount) throws ErrnoException {
518         return Libcore.os.sendfile(outFd, inFd, offset, byteCount);
519     }
520 
521     /**
522      * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>.
523      */
sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port)524     public static int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, buffer, flags, inetAddress, port); }
525 
526     /**
527      * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>.
528      */
sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port)529     public static int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port); }
530 
531     /**
532      * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>.
533      */
sendto(@onNull FileDescriptor fd, @NonNull byte[] bytes, int byteOffset, int byteCount, int flags, @Nullable SocketAddress address)534     public static int sendto(@NonNull FileDescriptor fd, @NonNull byte[] bytes, int byteOffset, int byteCount, int flags, @Nullable SocketAddress address) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, bytes, byteOffset, byteCount, flags, address); }
535 
536     /**
537      * See <a href="http://man7.org/linux/man-pages/man2/setegid.2.html">setegid(2)</a>.
538      * @deprecated Android Applications do not have sufficient privileges to call this method.
539      */
540     @Deprecated
setegid(int egid)541     public static void setegid(int egid) throws ErrnoException { Libcore.os.setegid(egid); }
542 
543     /**
544      * See <a href="http://man7.org/linux/man-pages/man3/setenv.3.html">setenv(3)</a>.
545      */
setenv(String name, String value, boolean overwrite)546     public static void setenv(String name, String value, boolean overwrite) throws ErrnoException { Libcore.os.setenv(name, value, overwrite); }
547 
548     /**
549      * See <a href="http://man7.org/linux/man-pages/man2/seteuid.2.html">seteuid(2)</a>.
550      * @deprecated Android Applications do not have sufficient privileges to call this method.
551      */
552     @Deprecated
seteuid(int euid)553     public static void seteuid(int euid) throws ErrnoException { Libcore.os.seteuid(euid); }
554 
555     /**
556      * See <a href="http://man7.org/linux/man-pages/man2/setgid.2.html">setgid(2)</a>.
557      * @deprecated Android Applications do not have sufficient privileges to call this method.
558      */
559     @Deprecated
setgid(int gid)560     public static void setgid(int gid) throws ErrnoException { Libcore.os.setgid(gid); }
561 
562     /**
563      * See <a href="http://man7.org/linux/man-pages/man2/setpgid.2.html">setpgid(2)</a>.
564      * @hide
565      */
566     @libcore.api.CorePlatformApi
setpgid(int pid, int pgid)567     public static void setpgid(int pid, int pgid) throws ErrnoException { Libcore.os.setpgid(pid, pgid); }
568 
569     /**
570      * See <a href="http://man7.org/linux/man-pages/man2/setregid.2.html">setregid(2)</a>.
571      * @hide
572      */
573     @libcore.api.CorePlatformApi
setregid(int rgid, int egid)574     public static void setregid(int rgid, int egid) throws ErrnoException { Libcore.os.setregid(rgid, egid); }
575 
576     /**
577      * See <a href="http://man7.org/linux/man-pages/man2/setreuid.2.html">setreuid(2)</a>.
578      * @hide
579      */
580     @libcore.api.CorePlatformApi
setreuid(int ruid, int euid)581     public static void setreuid(int ruid, int euid) throws ErrnoException { Libcore.os.setreuid(ruid, euid); }
582 
583     /**
584      * See <a href="http://man7.org/linux/man-pages/man2/setsid.2.html">setsid(2)</a>.
585      */
setsid()586     public static int setsid() throws ErrnoException { return Libcore.os.setsid(); }
587 
588     /** @hide */
setsockoptByte(FileDescriptor fd, int level, int option, int value)589     public static void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptByte(fd, level, option, value); }
590 
591     /** @hide */
592     @UnsupportedAppUsage
593     @libcore.api.CorePlatformApi
setsockoptIfreq(FileDescriptor fd, int level, int option, String value)594     public static void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException { Libcore.os.setsockoptIfreq(fd, level, option, value); }
595 
596     /**
597      * See <a href="http://man7.org/linux/man-pages/man2/setsockopt.2.html">setsockopt(2)</a>.
598      */
setsockoptInt(FileDescriptor fd, int level, int option, int value)599     public static void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptInt(fd, level, option, value); }
600 
601     /** @hide */
setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value)602     public static void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptIpMreqn(fd, level, option, value); }
603 
604     /** @hide */
setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value)605     public static void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { Libcore.os.setsockoptGroupReq(fd, level, option, value); }
606 
607     /** @hide */
608     @libcore.api.CorePlatformApi
setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value)609     public static void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException { Libcore.os.setsockoptLinger(fd, level, option, value); }
610 
611     /**
612      * See <a href="http://man7.org/linux/man-pages/man2/setsockopt.2.html">setsockopt(2)</a>.
613      *
614      * <p>Only for use with {@code option} values that take a {@code struct timeval} such as
615      * {@link OsConstants#SO_RCVTIMEO} and {@link OsConstants#SO_SNDTIMEO}. Use with other
616      * options is likely to cause incorrect behavior.
617      */
setsockoptTimeval(@onNull FileDescriptor fd, int level, int option, @NonNull StructTimeval value)618     public static void setsockoptTimeval(@NonNull FileDescriptor fd, int level, int option, @NonNull StructTimeval value) throws ErrnoException { Libcore.os.setsockoptTimeval(fd, level, option, value); }
619 
620     /**
621      * See <a href="http://man7.org/linux/man-pages/man2/setuid.2.html">setuid(2)</a>.
622      * @deprecated Android Applications do not have sufficient privileges to call this method.
623      */
624     @Deprecated
setuid(int uid)625     public static void setuid(int uid) throws ErrnoException { Libcore.os.setuid(uid); }
626 
627     /**
628      * See <a href="http://man7.org/linux/man-pages/man2/setxattr.2.html">setxattr(2)</a>
629      */
setxattr(String path, String name, byte[] value, int flags)630     public static void setxattr(String path, String name, byte[] value, int flags) throws ErrnoException { Libcore.os.setxattr(path, name, value, flags); };
631 
632     /**
633      * See <a href="http://man7.org/linux/man-pages/man2/shutdown.2.html">shutdown(2)</a>.
634      */
shutdown(FileDescriptor fd, int how)635     public static void shutdown(FileDescriptor fd, int how) throws ErrnoException { Libcore.os.shutdown(fd, how); }
636 
637     /**
638      * See <a href="http://man7.org/linux/man-pages/man2/socket.2.html">socket(2)</a>.
639      */
socket(int domain, int type, int protocol)640     public static FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return Libcore.os.socket(domain, type, protocol); }
641 
642     /**
643      * See <a href="http://man7.org/linux/man-pages/man2/socketpair.2.html">socketpair(2)</a>.
644      */
socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2)645     public static void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException { Libcore.os.socketpair(domain, type, protocol, fd1, fd2); }
646 
647     /**
648      * See <a href="http://man7.org/linux/man-pages/man2/splice.2.html">splice(2)</a>.
649      * @hide
650      */
651     @libcore.api.CorePlatformApi
splice(FileDescriptor fdIn, Int64Ref offIn, FileDescriptor fdOut, Int64Ref offOut, long len, int flags)652     public static long splice(FileDescriptor fdIn, Int64Ref offIn, FileDescriptor fdOut, Int64Ref offOut, long len, int flags) throws ErrnoException { return Libcore.os.splice(fdIn, offIn, fdOut, offOut, len, flags); }
653 
654     /**
655      * See <a href="http://man7.org/linux/man-pages/man2/stat.2.html">stat(2)</a>.
656      */
stat(String path)657     public static StructStat stat(String path) throws ErrnoException { return Libcore.os.stat(path); }
658 
659     /**
660      * See <a href="http://man7.org/linux/man-pages/man2/statvfs.2.html">statvfs(2)</a>.
661      */
statvfs(String path)662     public static StructStatVfs statvfs(String path) throws ErrnoException { return Libcore.os.statvfs(path); }
663 
664     /**
665      * See <a href="http://man7.org/linux/man-pages/man3/strerror.3.html">strerror(2)</a>.
666      */
strerror(int errno)667     public static String strerror(int errno) { return Libcore.os.strerror(errno); }
668 
669     /**
670      * See <a href="http://man7.org/linux/man-pages/man3/strsignal.3.html">strsignal(3)</a>.
671      */
strsignal(int signal)672     public static String strsignal(int signal) { return Libcore.os.strsignal(signal); }
673 
674     /**
675      * See <a href="http://man7.org/linux/man-pages/man2/symlink.2.html">symlink(2)</a>.
676      */
symlink(String oldPath, String newPath)677     public static void symlink(String oldPath, String newPath) throws ErrnoException { Libcore.os.symlink(oldPath, newPath); }
678 
679     /**
680      * See <a href="http://man7.org/linux/man-pages/man3/sysconf.3.html">sysconf(3)</a>.
681      */
sysconf(int name)682     public static long sysconf(int name) { return Libcore.os.sysconf(name); }
683 
684     /**
685      * See <a href="http://man7.org/linux/man-pages/man3/tcdrain.3.html">tcdrain(3)</a>.
686      */
tcdrain(FileDescriptor fd)687     public static void tcdrain(FileDescriptor fd) throws ErrnoException { Libcore.os.tcdrain(fd); }
688 
689     /**
690      * See <a href="http://man7.org/linux/man-pages/man3/tcsendbreak.3.html">tcsendbreak(3)</a>.
691      */
tcsendbreak(FileDescriptor fd, int duration)692     public static void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException { Libcore.os.tcsendbreak(fd, duration); }
693 
694     /**
695      * See <a href="http://man7.org/linux/man-pages/man2/umask.2.html">umask(2)</a>.
696      */
umask(int mask)697     public static int umask(int mask) { return Libcore.os.umask(mask); }
698 
699     /**
700      * See <a href="http://man7.org/linux/man-pages/man2/uname.2.html">uname(2)</a>.
701      */
uname()702     public static StructUtsname uname() { return Libcore.os.uname(); }
703 
704     /**
705      * @hide See <a href="http://man7.org/linux/man-pages/man2/unlink.2.html">unlink(2)</a>.
706      */
707     @libcore.api.CorePlatformApi
unlink(String pathname)708     public static void unlink(String pathname) throws ErrnoException { Libcore.os.unlink(pathname); }
709 
710     /**
711      * See <a href="http://man7.org/linux/man-pages/man3/unsetenv.3.html">unsetenv(3)</a>.
712      */
unsetenv(String name)713     public static void unsetenv(String name) throws ErrnoException { Libcore.os.unsetenv(name); }
714 
715     /**
716      * @hide See <a href="http://man7.org/linux/man-pages/man2/waitpid.2.html">waitpid(2)</a>.
717      *
718      * @throws IllegalArgumentException if {@code status != null && status.length != 1}
719      */
waitpid(int pid, Int32Ref status, int options)720     public static int waitpid(int pid, Int32Ref status, int options) throws ErrnoException {
721         return Libcore.os.waitpid(pid, status, options);
722     }
723 
724     /**
725      * See <a href="http://man7.org/linux/man-pages/man2/write.2.html">write(2)</a>.
726      */
write(FileDescriptor fd, ByteBuffer buffer)727     public static int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, buffer); }
728 
729     /**
730      * See <a href="http://man7.org/linux/man-pages/man2/write.2.html">write(2)</a>.
731      */
write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)732     public static int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, bytes, byteOffset, byteCount); }
733 
734     /**
735      * See <a href="http://man7.org/linux/man-pages/man2/writev.2.html">writev(2)</a>.
736      */
writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)737     public static int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.writev(fd, buffers, offsets, byteCounts); }
738 }
739