Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LastErrorException broken on AIX #237

Closed
skissane opened this issue May 30, 2013 · 2 comments
Closed

LastErrorException broken on AIX #237

skissane opened this issue May 30, 2013 · 2 comments

Comments

@skissane
Copy link

The following test program works fine on, e.g. Linux, but fails on AIX. LastErrorException is not thrown even though call sets errno.

Using GIT master JNA, commit: 2b8773a
oslevel: 7.1.0.0
java version "1.6.0"
Java(TM) SE Runtime Environment (build pap6460sr9fp2-20110627_03(SR9 FP2))
IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 AIX ppc64-64 jvmap6460sr9-20110624_85526 (JIT enabled, AOT enabled)
J9VM - 20110624_085526
JIT - r9_20101028_17488ifx17
GC - 20101027_AA)
JCL - 20110530_01

import com.sun.jna.*;
import java.util.*;

public class JNATest {
   public static void main(String[] args) {
      try {
         int rc = LibC.INSTANCE.open("/nonexistentfile-" + UUID.randomUUID(), 2, 0);
         System.err.println("TEST FAILED: Expected exception, instead got rc=" + rc);
      } catch (LastErrorException ex) {
         System.err.println("TEST PASSED");
      }
   }

   public interface LibC extends Library {
      public static final LibC INSTANCE = (LibC)Native.loadLibrary("c", LibC.class);
      int open(String pathname, int flags, int mode) throws LastErrorException;
   }
}
@skissane
Copy link
Author

Cause: On AIX, errno is not thread safe unless _THREAD_SAFE_ERRNO is defined. (Read /usr/include/errno.h for details)

Solution: Add the line "#define _THREAD_SAFE_ERRNO" before every occurrence of "#include <errno.h>".
Doing so in ./native/dispatch.c is enough to get this test to pass.

For perfect correctness, might be necessary to do so in the other places where errno.h is included:
./native/testlib.c
./native/libffi/src/dlmalloc.c
./native/libffi/src/closures.c

Another option would be to change the build scripts to add -D_THREAD_SAFE_ERRNO when calling the C compiler on AIX. (I believe that defining this on all platforms, not just AIX, should be harmless.)

@twall
Copy link
Contributor

twall commented May 30, 2013

It's probably best to add it to CDEFINES in the Makfile AIX section, e.g.

CDEFINES += -D_THREAD_SAFE_ERRNO

which will ensure it's defined everywhere.

Thanks for checking; contribution of the AIX natives would be welcome when you're done.

@twall twall closed this as completed in 8579311 May 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants