//------------------------------------------------------------------- // ShowEflags.cpp // // This example shows how to write a shared library function in // C++ so that it can be called from a program written in Java. // It is adapted from the demo-program by Horstmann and Cornell // in "Core Java 2, Volume II (2nd Ed.)," Prentice-Hall (2005), // although our example uses some inline x86 assembly language. // // compile using: // $ g++ -fPIC -shared -o libShowEflags.so ShowEflags.cpp // $ javac ShowEflags.java // // execute using: // $ export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH // $ java ShowEflags // // // NOTE: Developed using the Fedora Core 3 Linux distribution: // kernel version 2.6.9-1.667 (as installed in November 2004). // // programmer: ALLAN CRUSE // written on: 01 JUN 2005 //------------------------------------------------------------------- #include extern "C" { JNIEXPORT void JNICALL Java_ShowEflags_output( JNIEnv *env, jclass c ) { unsigned int eflags; asm(" pushfl \n popl %0 " : "=m" (eflags) ); printf( "\n\tEFLAGS=%08X \n\n", eflags ); } }