From b69f8b201ba3767020d33a7ebe066466f00d4223 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Tue, 3 Jan 2006 02:36:17 +0000 Subject: Added checks on number of remaining elements and bytes for Buffers and arrays passed to certain APIs. Default is to not emit such range checks. The checks are currently most fully implemented for image- and texture-related APIs. Verified with debugging code and with demos that all textures used in demos are properly checked. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@509 232f8b59-042b-4e1e-8c03-345bb8c30851 --- src/classes/com/sun/gluegen/JavaConfiguration.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/classes/com/sun/gluegen/JavaConfiguration.java') diff --git a/src/classes/com/sun/gluegen/JavaConfiguration.java b/src/classes/com/sun/gluegen/JavaConfiguration.java index 152d9cf80..ae8c46eaa 100644 --- a/src/classes/com/sun/gluegen/JavaConfiguration.java +++ b/src/classes/com/sun/gluegen/JavaConfiguration.java @@ -116,6 +116,8 @@ public class JavaConfiguration { private Map/**/ javaMethodRenames = new HashMap(); private Map/*>*/ javaPrologues = new HashMap(); private Map/*>*/ javaEpilogues = new HashMap(); + private Map/*>*/ rangeChecks = new HashMap(); + private Map/*>*/ byteRangeChecks = new HashMap(); /** Reads the configuration file. @param filename path to file that should be read @@ -569,6 +571,22 @@ public class JavaConfiguration { return res; } + /** Returns a map of Integer argument numbers to expressions to be + used to range check the given arguments to the given function. + Returns null if there were no range check expressions supplied + for this function. */ + public Map/**/ rangeCheckExpressions(String functionName) { + return (Map/**/) rangeChecks.get(functionName); + } + + /** Returns a map of Integer argument numbers to expressions to be + used to range check (in size of bytes) the given arguments to + the given function. Returns null if there were no range check + expressions supplied for this function. */ + public Map/**/ byteRangeCheckExpressions(String functionName) { + return (Map/**/) byteRangeChecks.get(functionName); + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -686,6 +704,14 @@ public class JavaConfiguration { readJavaPrologueOrEpilogue(tok, filename, lineNo, false); // Warning: make sure delimiters are reset at the top of this loop // because readJavaPrologueOrEpilogue changes them. + } else if (cmd.equalsIgnoreCase("RangeCheck")) { + readRangeCheck(tok, filename, lineNo, false); + // Warning: make sure delimiters are reset at the top of this loop + // because RangeCheck changes them. + } else if (cmd.equalsIgnoreCase("RangeCheckBytes")) { + readRangeCheck(tok, filename, lineNo, true); + // Warning: make sure delimiters are reset at the top of this loop + // because RangeCheckBytes changes them. } else { throw new RuntimeException("Unknown command \"" + cmd + "\" in command file " + filename + @@ -1131,6 +1157,33 @@ public class JavaConfiguration { } } + protected void readRangeCheck(StringTokenizer tok, String filename, int lineNo, boolean inBytes) { + try { + String functionName = tok.nextToken(); + int argNum = Integer.parseInt(tok.nextToken()); + String restOfLine = tok.nextToken("\n\r\f"); + restOfLine = restOfLine.trim(); + Map/**/ checksForFunction = null; + if (inBytes) { + checksForFunction = (Map/**/) byteRangeChecks.get(functionName); + } else { + checksForFunction = (Map/**/) rangeChecks.get(functionName); + } + if (checksForFunction == null) { + checksForFunction = new HashMap/**/(); + if (inBytes) { + byteRangeChecks.put(functionName, checksForFunction); + } else { + rangeChecks.put(functionName, checksForFunction); + } + } + checksForFunction.put(new Integer(argNum), restOfLine); + } catch (Exception e) { + throw new RuntimeException("Error parsing \"RangeCheck" + (inBytes ? "Bytes" : "") + "\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + protected static TypeInfo parseTypeInfo(String cType, JavaType javaType) { String typeName = null; int pointerDepth = 0; -- cgit v1.2.3