Skip to content

Commit

Permalink
Copyright header, add test of util mmap
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Jun 8, 2020
1 parent 32c84e1 commit 813b4a7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
23 changes: 23 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/linux/ErrNo.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/* Copyright (c) 2020 Daniel Widdis, All Rights Reserved
*
* The contents of this file is dual-licensed under 2
* alternative Open Source/Free licenses: LGPL 2.1 or later and
* Apache License 2.0. (starting with JNA version 4.0.0).
*
* You can freely decide which license you want to apply to
* the project.
*
* You may obtain a copy of the LGPL License at:
*
* http://www.gnu.org/licenses/licenses.html
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "LGPL2.1".
*
* You may obtain a copy of the Apache License at:
*
* http://www.apache.org/licenses/
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "AL2.0".
*/
package com.sun.jna.platform.linux;

import com.sun.jna.Native;
Expand Down
10 changes: 6 additions & 4 deletions contrib/platform/test/com/sun/jna/platform/linux/LibRTTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.sun.jna.Pointer;
import com.sun.jna.platform.unix.LibCAPI.off_t;
import com.sun.jna.platform.unix.LibCAPI.size_t;
import com.sun.jna.platform.unix.LibCUtil;

import junit.framework.TestCase;

Expand All @@ -63,8 +64,9 @@ public void testMmapToShm() throws IOException {
assertNotEquals("Failed to shm_open " + share + ". Error: " + Native.getLastError(), -1, fd);
try {
// Multiply by 4 to handle all possible encodings
size_t length = new size_t(4 * (share.length() + 1));
off_t truncLen = new off_t(4 * (share.length() + 1));
int bufLen = 4 * (share.length() + 1);
size_t length = new size_t(bufLen);
off_t truncLen = new off_t(bufLen);
// Allocate memory to the share (fills with null bytes)
int ret = LIBC.ftruncate(fd, truncLen);
assertNotEquals("Failed to ftruncate. Error: " + Native.getLastError(), -1, ret);
Expand Down Expand Up @@ -93,8 +95,8 @@ public void testMmapToShm() throws IOException {
// So let's not recreate it, instead get a file descriptor to the existing share
fd = LIBRT.shm_open(share, O_RDWR, S_IRWXU);
assertNotEquals("Failed to re-open " + share + ". Error: " + Native.getLastError(), -1, fd);
// Map another pointer to the share.
Pointer q = LIBC.mmap(null, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, off_t.ZERO);
// Map another pointer to the share. Use the util version to test it
Pointer q = LibCUtil.mmap(null, bufLen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
assertNotEquals("Failed mmap to existing share. Error: " + Native.getLastError(), MAP_FAILED, q);
// Close the file descriptor
ret = LIBC.close(fd);
Expand Down

0 comments on commit 813b4a7

Please sign in to comment.