Skip to content

Commit

Permalink
Fixed bug with typesetting of the native args by wrapping it into a
Browse files Browse the repository at this point in the history
native wrapper
  • Loading branch information
abh1nay committed Nov 29, 2012
1 parent 220c5f1 commit 2f5e776
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/java/voldemort/store/readonly/io/MemLock.java
Expand Up @@ -42,7 +42,7 @@ public MemLock(File file, FileDescriptor descriptor, long offset, long length)

int fd = voldemort.store.readonly.io.Native.getFd(descriptor);

pa = mman.mmap(length, mman.PROT_READ, mman.MAP_SHARED, fd, offset);
pa = mman.mmap(length, mman.PROT_READ, mman.MAP_SHARED | mman.MAP_ALIGN, fd, offset);

// even though technically we have specified MAP_LOCKED this isn't
// supported on OpenSolaris or older Linux kernels (or OS X).
Expand Down
24 changes: 15 additions & 9 deletions src/java/voldemort/store/readonly/io/jna/mman.java
Expand Up @@ -7,6 +7,7 @@
import org.apache.log4j.Logger;

import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;

public class mman {
Expand Down Expand Up @@ -37,7 +38,12 @@ public static Pointer mmap(long len, int prot, int flags, int fildes, long off)
// we don't really have a need to change the recommended pointer.
Pointer addr = new Pointer(0);

Pointer result = Delegate.mmap(addr, len, prot, flags, fildes, off);
Pointer result = Delegate.mmap(addr,
new NativeLong(len),
prot,
flags,
fildes,
new NativeLong(off));

if(Pointer.nativeValue(result) == -1) {

Expand All @@ -50,7 +56,7 @@ public static Pointer mmap(long len, int prot, int flags, int fildes, long off)

public static int munmap(Pointer addr, long len) throws IOException {

int result = Delegate.munmap(addr, len);
int result = Delegate.munmap(addr, new NativeLong(len));

if(result != 0) {
logger.warn(errno.strerror());
Expand All @@ -62,7 +68,7 @@ public static int munmap(Pointer addr, long len) throws IOException {

public static void mlock(Pointer addr, long len) throws IOException {

int res = Delegate.mlock(addr, len);
int res = Delegate.mlock(addr, new NativeLong(len));
if(res != 0) {
String error = errno.strerror();
logger.warn("Mlock failed probably because of insufficient privileges");
Expand All @@ -80,7 +86,7 @@ public static void mlock(Pointer addr, long len) throws IOException {
*/
public static void munlock(Pointer addr, long len) throws IOException {

if(Delegate.munlock(addr, len) != 0) {
if(Delegate.munlock(addr, new NativeLong(len)) != 0) {
logger.warn(errno.strerror());
} else {
logger.info("munlocking region");
Expand All @@ -91,17 +97,17 @@ public static void munlock(Pointer addr, long len) throws IOException {
static class Delegate {

public static native Pointer mmap(Pointer addr,
long len,
NativeLong len,
int prot,
int flags,
int fildes,
long off);
NativeLong off);

public static native int munmap(Pointer addr, long len);
public static native int munmap(Pointer addr, NativeLong len);

public static native int mlock(Pointer addr, long len);
public static native int mlock(Pointer addr, NativeLong len);

public static native int munlock(Pointer addr, long len);
public static native int munlock(Pointer addr, NativeLong len);

static {
Native.register("c");
Expand Down

0 comments on commit 2f5e776

Please sign in to comment.