Skip to content

Instantly share code, notes, and snippets.

@pefoley2
Last active December 24, 2015 02:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pefoley2/6731533 to your computer and use it in GitHub Desktop.
Save pefoley2/6731533 to your computer and use it in GitHub Desktop.
horrible things with java.
import jnr.posix.*;
import jnr.constants.platform.*;
import java.io.*;
public class Fun {
public static void main(String[] args) throws Segfault {
throw new Segfault();
}
}
class Segfault extends Throwable {
// jnr-posix
POSIX posix = POSIXFactory.getPOSIX(new POSIXHandler(){
public PrintStream getErrorStream(){return System.err;}
public PrintStream getOutputStream(){return System.out;}
public InputStream getInputStream(){return System.in;}
public int getPID(){return 0;}
public String[] getEnv(){return new String[0];}
public File getCurrentWorkingDirectory(){return new File(".");}
public boolean isVerbose(){return true;}
public void warn(WARNING_ID warning_id, String s, Object... objects){}
public void unimplementedError(String s){}
public void error(Errno errno, String s){}
public void error(Errno errno, String s, String s2){}
},true);
Segfault() {
System.out.println("It is time!");
int s = Signal.SIGSEGV.intValue();
posix.kill(posix.getpid(),s);
}
}
It is time!
Successfully loaded native POSIX impl.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb)Exception in thread "main" at pc=0x00007fb9a84101ad, pid=12776, tid=140435372766976
#
# JRE version: OpenJDK Runtime Environment (7.0_40-b31) (build 1.7.0_40-b31)
# Java VM: OpenJDK 64-Bit Server VM (24.0-b50 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libpthread.so.0+0xa1ad] pthread_join+0xad
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/peter/segv/hs_err_pid12776.log
Segfault
at Fun.main(Fun.java:7)
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
# http://icedtea.classpath.org/bugzilla
#
./b: line 2: 12776 Aborted java Fun
export CLASSPATH=".:/usr/share/jnr-posix-3.0/lib/jnr-posix.jar:/usr/share/jnr-constants/lib/jnr-constants.jar:/usr/share/jnr-ffi-0.7/lib/jnr-ffi.jar:/usr/share/jffi-1.2/lib/jffi.jar:/usr/share/asm-4/lib/asm.jar"
javac Fun.java && java Fun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment