Skip to content

Commit d471b15

Browse files
dbwiddismatthiasblaesing
authored andcommitted
Add mappings for size_t, ssize_t, shared memory and libc file functions
1 parent 43c4e67 commit d471b15

9 files changed

Lines changed: 796 additions & 22 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Features
1717
* [#1194](https://github.com/java-native-access/jna/pull/1194): Add `GetConsoleScreenBufferInfo`, `ReadConsoleInput` and `WriteConsole` with associated structures to `c.s.j.p.win32.Wincon` - [@rednoah](https://github.com/rednoah).
1818
* [#1198](https://github.com/java-native-access/jna/pull/1198): Add `NetSessionEnum` to `c.s.j.p.win32.Netapi32` and `WTSEnumerateSessions`, `WTSQuerySessionInformation`, and `WTSFreeMemory` to `c.s.j.p.win32.Wtsapi32` - [@dbwiddis](https://github.com/dbwiddis).
1919
* [#1200](https://github.com/java-native-access/jna/pull/1200): Add mappings for `libudev` to `c.s.j.p.linux.Udev` - [@dbwiddis](https://github.com/dbwiddis).
20+
* [#1202](https://github.com/java-native-access/jna/pull/1202): Add mappings supporting shared memory including `c.s.j.p.unix.LibCAPI` types `size_t` and `ssize_t`, `c.s.j.p.linux.LibC` methods `munmap()`, `msync()`, and `close()`, `c.s.j.p.unix.LibCUtil` mapping `mmap()` and `ftruncate()`, and `c.s.j.p.linux.LibRT` methods `shm_open()` and `shm_unlink()` - [@dbwiddis](https://github.com/dbwiddis).
2021
* [#1209](https://github.com/java-native-access/jna/pull/1209): Add mappings for `Thread32First` and `Thread32Next` to `c.s.j.p.win32.Kernel32` - [@dbwiddis](https://github.com/dbwiddis).
2122

2223
Bug Fixes
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* Copyright (c) 2020 Daniel Widdis, All Rights Reserved
2+
*
3+
* The contents of this file is dual-licensed under 2
4+
* alternative Open Source/Free licenses: LGPL 2.1 or later and
5+
* Apache License 2.0. (starting with JNA version 4.0.0).
6+
*
7+
* You can freely decide which license you want to apply to
8+
* the project.
9+
*
10+
* You may obtain a copy of the LGPL License at:
11+
*
12+
* http://www.gnu.org/licenses/licenses.html
13+
*
14+
* A copy is also included in the downloadable source code package
15+
* containing JNA, in file "LGPL2.1".
16+
*
17+
* You may obtain a copy of the Apache License at:
18+
*
19+
* http://www.apache.org/licenses/
20+
*
21+
* A copy is also included in the downloadable source code package
22+
* containing JNA, in file "AL2.0".
23+
*/
24+
package com.sun.jna.platform.linux;
25+
26+
import com.sun.jna.Native;
27+
28+
/**
29+
* System error codes set in {@code errno} and retrieved by
30+
* {@link Native#getLastError()}
31+
*/
32+
public interface ErrNo {
33+
int EPERM = 1; // Operation not permitted
34+
int ENOENT = 2; // No such file or directory
35+
int ESRCH = 3; // No such process
36+
int EINTR = 4; // Interrupted system call
37+
int EIO = 5; // I/O error
38+
int ENXIO = 6; // No such device or address
39+
int E2BIG = 7; // Argument list too long
40+
int ENOEXEC = 8; // Exec format error
41+
int EBADF = 9; // Bad file number
42+
int ECHILD = 10; // No child processes
43+
int EAGAIN = 11; // Try again
44+
int ENOMEM = 12; // Out of memory
45+
int EACCES = 13; // Permission denied
46+
int EFAULT = 14; // Bad address
47+
int ENOTBLK = 15; // Block device required
48+
int EBUSY = 16; // Device or resource busy
49+
int EEXIST = 17; // File exists
50+
int EXDEV = 18; // Cross-device link
51+
int ENODEV = 19; // No such device
52+
int ENOTDIR = 20; // Not a directory
53+
int EISDIR = 21; // Is a directory
54+
int EINVAL = 22; // Invalid argument
55+
int ENFILE = 23; // File table overflow
56+
int EMFILE = 24; // Too many open files
57+
int ENOTTY = 25; // Not a typewriter
58+
int ETXTBSY = 26; // Text file busy
59+
int EFBIG = 27; // File too large
60+
int ENOSPC = 28; // No space left on device
61+
int ESPIPE = 29; // Illegal seek
62+
int EROFS = 30; // Read-only file system
63+
int EMLINK = 31; // Too many links
64+
int EPIPE = 32; // Broken pipe
65+
int EDOM = 33; // Math argument out of domain of func
66+
int ERANGE = 34; // Math result not representable
67+
int EDEADLK = 35; // Resource deadlock would occur
68+
int ENAMETOOLONG = 36; // File name too long
69+
int ENOLCK = 37; // No record locks available
70+
int ENOSYS = 38; // Function not implemented
71+
int ENOTEMPTY = 39; // Directory not empty
72+
int ELOOP = 40; // Too many symbolic links encountered
73+
int ENOMSG = 42; // No message of desired type
74+
int EIDRM = 43; // Identifier removed
75+
int ECHRNG = 44; // Channel number out of range
76+
int EL2NSYNC = 45; // Level 2 not synchronized
77+
int EL3HLT = 46; // Level 3 halted
78+
int EL3RST = 47; // Level 3 reset
79+
int ELNRNG = 48; // Link number out of range
80+
int EUNATCH = 49; // Protocol driver not attached
81+
int ENOCSI = 50; // No CSI structure available
82+
int EL2HLT = 51; // Level 2 halted
83+
int EBADE = 52; // Invalid exchange
84+
int EBADR = 53; // Invalid request descriptor
85+
int EXFULL = 54; // Exchange full
86+
int ENOANO = 55; // No anode
87+
int EBADRQC = 56; // Invalid request code
88+
int EBADSLT = 57; // Invalid slot
89+
int EBFONT = 59; // Bad font file format
90+
int ENOSTR = 60; // Device not a stream
91+
int ENODATA = 61; // No data available
92+
int ETIME = 62; // Timer expired
93+
int ENOSR = 63; // Out of streams resources
94+
int ENONET = 64; // Machine is not on the network
95+
int ENOPKG = 65; // Package not installed
96+
int EREMOTE = 66; // Object is remote
97+
int ENOLINK = 67; // Link has been severed
98+
int EADV = 68; // Advertise error
99+
int ESRMNT = 69; // Srmount error
100+
int ECOMM = 70; // Communication error on send
101+
int EPROTO = 71; // Protocol error
102+
int EMULTIHOP = 72; // Multihop attempted
103+
int EDOTDOT = 73; // RFS specific error
104+
int EBADMSG = 74; // Not a data message
105+
int EOVERFLOW = 75; // Value too large for defined data type
106+
int ENOTUNIQ = 76; // Name not unique on network
107+
int EBADFD = 77; // File descriptor in bad state
108+
int EREMCHG = 78; // Remote address changed
109+
int ELIBACC = 79; // Can not access a needed shared library
110+
int ELIBBAD = 80; // Accessing a corrupted shared library
111+
int ELIBSCN = 81; // .lib section in a.out corrupted
112+
int ELIBMAX = 82; // Attempting to link in too many shared libraries
113+
int ELIBEXEC = 83; // Cannot exec a shared library directly
114+
int EILSEQ = 84; // Illegal byte sequence
115+
int ERESTART = 85; // Interrupted system call should be restarted
116+
int ESTRPIPE = 86; // Streams pipe error
117+
int EUSERS = 87; // Too many users
118+
int ENOTSOCK = 88; // Socket operation on non-socket
119+
int EDESTADDRREQ = 89; // Destination address required
120+
int EMSGSIZE = 90; // Message too long
121+
int EPROTOTYPE = 91; // Protocol wrong type for socket
122+
int ENOPROTOOPT = 92; // Protocol not available
123+
int EPROTONOSUPPORT = 93; // Protocol not supported
124+
int ESOCKTNOSUPPORT = 94; // Socket type not supported
125+
int EOPNOTSUPP = 95; // Operation not supported on transport endpoint
126+
int EPFNOSUPPORT = 96; // Protocol family not supported
127+
int EAFNOSUPPORT = 97; // Address family not supported by protocol
128+
int EADDRINUSE = 98; // Address already in use
129+
int EADDRNOTAVAIL = 99; // Cannot assign requested address
130+
int ENETDOWN = 100; // Network is down
131+
int ENETUNREACH = 101; // Network is unreachable
132+
int ENETRESET = 102; // Network dropped connection because of reset
133+
int ECONNABORTED = 103; // Software caused connection abort
134+
int ECONNRESET = 104; // Connection reset by peer
135+
int ENOBUFS = 105; // No buffer space available
136+
int EISCONN = 106; // Transport endpoint is already connected
137+
int ENOTCONN = 107; // Transport endpoint is not connected
138+
int ESHUTDOWN = 108; // Cannot send after transport endpoint shutdown
139+
int ETOOMANYREFS = 109; // Too many references: cannot splice
140+
int ETIMEDOUT = 110; // Connection timed out
141+
int ECONNREFUSED = 111; // Connection refused
142+
int EHOSTDOWN = 112; // Host is down
143+
int EHOSTUNREACH = 113; // No route to host
144+
int EALREADY = 114; // Operation already in progress
145+
int EINPROGRESS = 115; // Operation now in progress
146+
int ESTALE = 116; // Stale NFS file handle
147+
int EUCLEAN = 117; // Structure needs cleaning
148+
int ENOTNAM = 118; // Not a XENIX named type file
149+
int ENAVAIL = 119; // No XENIX semaphores available
150+
int EISNAM = 120; // Is a named type file
151+
int EREMOTEIO = 121; // Remote I/O error
152+
int EDQUOT = 122; // Quota exceeded
153+
int ENOMEDIUM = 123; // No medium found
154+
int EMEDIUMTYPE = 124; // Wrong medium type
155+
int ECANCELED = 125; // Operation Canceled
156+
int ENOKEY = 126; // Required key not available
157+
int EKEYEXPIRED = 127; // Key has expired
158+
int EKEYREVOKED = 128; // Key has been revoked
159+
int EKEYREJECTED = 129; // Key was rejected by service
160+
int EOWNERDEAD = 130; // Owner died
161+
int ENOTRECOVERABLE = 131; // State not recoverable
162+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* Copyright (c) 2020 Daniel Widdis, All Rights Reserved
2+
*
3+
* The contents of this file is dual-licensed under 2
4+
* alternative Open Source/Free licenses: LGPL 2.1 or later and
5+
* Apache License 2.0. (starting with JNA version 4.0.0).
6+
*
7+
* You can freely decide which license you want to apply to
8+
* the project.
9+
*
10+
* You may obtain a copy of the LGPL License at:
11+
*
12+
* http://www.gnu.org/licenses/licenses.html
13+
*
14+
* A copy is also included in the downloadable source code package
15+
* containing JNA, in file "LGPL2.1".
16+
*
17+
* You may obtain a copy of the Apache License at:
18+
*
19+
* http://www.apache.org/licenses/
20+
*
21+
* A copy is also included in the downloadable source code package
22+
* containing JNA, in file "AL2.0".
23+
*/
24+
package com.sun.jna.platform.linux;
25+
26+
/**
27+
* POSIX Standard: 6.5 File Control Operations from {@code fcntl.h}
28+
*/
29+
public interface Fcntl {
30+
/*
31+
* File access modes for `open' and `fcntl'
32+
*/
33+
int O_RDONLY = 00; // Open read-only.
34+
int O_WRONLY = 01; // Open write-only.
35+
int O_RDWR = 02; // Open read/write.
36+
37+
/*
38+
* Bits OR'd into the second argument to open. Note these are defined
39+
* differently on linux than unix fcntl header
40+
*/
41+
int O_CREAT = 0100; // Create file if it doesn't exist.
42+
int O_EXCL = 0200; // Fail if file already exists.
43+
int O_TRUNC = 01000; // Truncate file to zero length.
44+
45+
/* Protection bits. */
46+
int S_IRUSR = 00400; // Read by owner.
47+
int S_IWUSR = 00200; // Write by owner.
48+
int S_IXUSR = 00100; // Execute by owner.
49+
int S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR;
50+
51+
int S_IRGRP = 00040; // Read by group.
52+
int S_IWGRP = 00020; // Write by group.
53+
int S_IXGRP = 00010; // Execute by group.
54+
int S_IRWXG = S_IRGRP | S_IWGRP | S_IXGRP;
55+
56+
int S_IROTH = 00004; // Read by others.
57+
int S_IWOTH = 00002; // Write by others.
58+
int S_IXOTH = 00001; // Execute by others.
59+
int S_IRWXO = S_IROTH | S_IWOTH | S_IXOTH;
60+
61+
int S_ISUID = 04000; // set-user-ID bit
62+
int S_ISGID = 02000; // set-group-ID bit (see inode(7)).
63+
int S_ISVTX = 01000; // sticky bit (see inode(7)).
64+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* Copyright (c) 2020 Daniel Widdis, All Rights Reserved
2+
*
3+
* The contents of this file is dual-licensed under 2
4+
* alternative Open Source/Free licenses: LGPL 2.1 or later and
5+
* Apache License 2.0. (starting with JNA version 4.0.0).
6+
*
7+
* You can freely decide which license you want to apply to
8+
* the project.
9+
*
10+
* You may obtain a copy of the LGPL License at:
11+
*
12+
* http://www.gnu.org/licenses/licenses.html
13+
*
14+
* A copy is also included in the downloadable source code package
15+
* containing JNA, in file "LGPL2.1".
16+
*
17+
* You may obtain a copy of the Apache License at:
18+
*
19+
* http://www.apache.org/licenses/
20+
*
21+
* A copy is also included in the downloadable source code package
22+
* containing JNA, in file "AL2.0".
23+
*/
24+
package com.sun.jna.platform.linux;
25+
26+
import com.sun.jna.Library;
27+
import com.sun.jna.Native;
28+
29+
/**
30+
* POSIX.1b Realtime Extensions library (librt). Functions in this library
31+
* provide most of the interfaces specified by the POSIX.1b Realtime Extension.
32+
*/
33+
public interface LibRT extends Library {
34+
35+
LibRT INSTANCE = Native.load("rt", LibRT.class);
36+
37+
/**
38+
* Creates and opens a new, or opens an existing, POSIX shared memory object. A
39+
* POSIX shared memory object is in effect a handle which can be used by
40+
* unrelated processes to {@code mmap()} the same region of shared memory.
41+
*
42+
* @param name
43+
* The shared memory object to be created or opened. For portable
44+
* use, a shared memory object should be identified by a name of the
45+
* form {@code /somename} that is, a null-terminated string of up to
46+
* {@code NAME_MAX} (i.e., 255) characters consisting of an initial
47+
* slash, followed by one or more characters, none of which are
48+
* slashes.
49+
* @param oflag
50+
* A bit mask created by ORing together exactly one of
51+
* {@code O_RDONLY} or {@code O_RDWR} and any of the other flags
52+
* {@code O_CREAT}, {@code O_EXCL}, or {@code O_TRUNC}.
53+
* @param mode
54+
* When {@code oflag} includes {@code O_CREAT}, the object's
55+
* permission bits are set according to the low-order 9 bits of mode,
56+
* except that those bits set in the process file mode creation mask
57+
* (see {@code umask(2)}) are cleared for the new object.
58+
* @return On success, returns a file descriptor (a nonnegative integer). On
59+
* failure, returns -1. On failure, {@code errno} is set to indicate the
60+
* cause of the error.
61+
*/
62+
int shm_open(String name, int oflag, int mode);
63+
64+
/**
65+
* Removes an object previously created by {@link #shm_open}.
66+
*
67+
* @param name
68+
* The shared memory object to be unlinked.
69+
* @return returns 0 on success, or -1 on error. On failure, {@code errno} is
70+
* set to indicate the cause of the error.
71+
*/
72+
int shm_unlink(String name);
73+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* Copyright (c) 2020 Daniel Widdis, All Rights Reserved
2+
*
3+
* The contents of this file is dual-licensed under 2
4+
* alternative Open Source/Free licenses: LGPL 2.1 or later and
5+
* Apache License 2.0. (starting with JNA version 4.0.0).
6+
*
7+
* You can freely decide which license you want to apply to
8+
* the project.
9+
*
10+
* You may obtain a copy of the LGPL License at:
11+
*
12+
* http://www.gnu.org/licenses/licenses.html
13+
*
14+
* A copy is also included in the downloadable source code package
15+
* containing JNA, in file "LGPL2.1".
16+
*
17+
* You may obtain a copy of the Apache License at:
18+
*
19+
* http://www.apache.org/licenses/
20+
*
21+
* A copy is also included in the downloadable source code package
22+
* containing JNA, in file "AL2.0".
23+
*/
24+
package com.sun.jna.platform.linux;
25+
26+
import com.sun.jna.Pointer;
27+
28+
/**
29+
* Definitions for POSIX memory map interface from {@code mman.h}
30+
*/
31+
public interface Mman {
32+
/*
33+
* Protections are chosen from these bits, OR'd together. The implementation
34+
* does not necessarily support PROT_EXEC or PROT_WRITE without PROT_READ. The
35+
* only guarantees are that no writing will be allowed without PROT_WRITE and no
36+
* access will be allowed for PROT_NONE.
37+
*/
38+
int PROT_READ = 0x1; // Page can be read.
39+
int PROT_WRITE = 0x2; // Page can be written.
40+
int PROT_EXEC = 0x4; // Page can be executed.
41+
int PROT_NONE = 0x0; // Page can not be accessed.
42+
int PROT_GROWSDOWN = 0x01000000; // Extend change to start of growsdown vma (mprotect only).
43+
int PROT_GROWSUP = 0x02000000; // Extend change to start of growsup vma (mprotect only).
44+
45+
/* Sharing types (must choose one and only one of these). */
46+
int MAP_SHARED = 0x01; // Share changes.
47+
int MAP_PRIVATE = 0x02; // Changes are private.
48+
int MAP_SHARED_VALIDATE = 0x03; // share + validate extension flags
49+
int MAP_TYPE = 0x0f; // Mask for type of mapping
50+
51+
/* Other flags. */
52+
int MAP_FILE = 0; // Compatibility flag. Ignored.
53+
int MAP_FIXED = 0x10; // Interpret addr exactly.
54+
int MAP_ANONYMOUS = 0x20; // Don't use a file.
55+
int MAP_ANON = MAP_ANONYMOUS;
56+
int MAP_32BIT = 0x40; // Only give out 32-bit addresses.
57+
58+
/* These are Linux-specific. */
59+
int MAP_GROWSDOWN = 0x00100; // Stack-like segment.
60+
int MAP_DENYWRITE = 0x00800; // ETXTBSY
61+
int MAP_EXECUTABLE = 0x01000; // Mark it as an executable.
62+
int MAP_LOCKED = 0x02000; // Lock the mapping.
63+
int MAP_NORESERVE = 0x04000; // Don't check for reservations.
64+
int MAP_POPULATE = 0x08000; // Populate (prefault) pagetables.
65+
int MAP_NONBLOCK = 0x10000; // Do not block on IO.
66+
int MAP_STACK = 0x20000; // Allocation is for a stack.
67+
int MAP_HUGETLB = 0x40000; // create a huge page mapping
68+
int MAP_SYNC = 0x80000; // perform synchronous page faults for the mapping
69+
int MAP_FIXED_NOREPLACE = 0x100000; // MAP_FIXED which doesn't unmap underlying mapping
70+
71+
Pointer MAP_FAILED = new Pointer(-1); // ((void *)-1)
72+
73+
/* Flags for msync. */
74+
int MS_ASYNC = 1;
75+
int MS_SYNC = 2;
76+
int MS_INVALIDATE = 4;
77+
}

0 commit comments

Comments
 (0)