This is the mail archive of the
frysk@sources.redhat.com
mailing list for the frysk project.
Patch: various Syscall changes
- From: Tom Tromey <tromey at redhat dot com>
- To: Frysk Hackers <frysk at sourceware dot org>
- Date: 06 Sep 2006 19:23:39 -0600
- Subject: Patch: various Syscall changes
- Reply-to: tromey at redhat dot com
This patch makes a few changes to Syscall:
* Updates javadoc of syscallByNum
* Fixed typo in syscallByNum
* Changes syscallByNum to cache requested unknown syscalls, so that
each Syscall object is unique
* Adds equals() method. We don't really need this but it is a
convenient place to add a comment
* Adds syscallByName. This is needed for 'ftrace -e' (or "--trace" as
I spell it in my impl...)
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* Syscall.java (syscallByNum): Updated javadoc. Fixed typo.
Cache unknown syscalls.
(unknownSyscalls): New field.
(equals): New method.
(syscallByName): Likewise.
Index: Syscall.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/Syscall.java,v
retrieving revision 1.11
diff -u -r1.11 Syscall.java
--- Syscall.java 24 Aug 2006 03:13:05 -0000 1.11
+++ Syscall.java 7 Sep 2006 01:29:16 -0000
@@ -38,6 +38,7 @@
// exception.
package frysk.proc;
+import java.util.HashMap;
import inua.util.PrintWriter;
/**
@@ -53,6 +54,10 @@
String argList;
boolean noreturn;
+ // This is used to keep track of syscalls whose number we do not
+ // know.
+ static HashMap unknownSyscalls;
+
Syscall (String name, int number, int numArgs,
String argList, boolean noreturn)
{
@@ -62,6 +67,7 @@
this.argList = argList;
this.noreturn = noreturn;
}
+
Syscall (String name, int number, int numArgs, String argList)
{
this.name = name;
@@ -97,6 +103,13 @@
return number;
}
+ /** Return true if this object equals the argument. */
+ public boolean equals(Object other)
+ {
+ // Syscall objects are unique.
+ return this == other;
+ }
+
private void printStringArg (PrintWriter writer,
frysk.proc.Task task,
long addr)
@@ -215,17 +228,48 @@
/**
* Given a system call's number, this will return the corresponding
* Syscall object. Note that system call numbers are platform
- * dependent.
+ * dependent. This will return a Syscall object in all cases; if
+ * there is no predefined system call with the given number, a unique
+ * "unknown" system call with the indicated number will be
+ * returned.
* XXX: Eventually this will be moved down to Linux, or even
* further.
* @param num the number of the system call
+ * @return the Syscall object
*/
public static Syscall syscallByNum (int num)
{
- if(num >= syscallList.length || num < 0){
- return new Syscall("UKNOWN SYSCALL", num);
- }
- return syscallList[num];
+ if (num >= 0 && num < syscallList.length)
+ return syscallList[num];
+ synchronized (Syscall.class)
+ {
+ Integer key = new Integer(num);
+ if (unknownSyscalls == null)
+ unknownSyscalls = new HashMap();
+ else if (unknownSyscalls.containsKey(key))
+ return (Syscall) unknownSyscalls.get(key);
+ Syscall result = new Syscall("UNKNOWN SYSCALL", num);
+ unknownSyscalls.put(key, result);
+ return result;
+ }
+ }
+
+ /**
+ * Given a system call's name, this will return the corresponding
+ * Syscall object. If no predefined system call with that name
+ * is available, this will return null.
+ * XXX: Eventually this will be moved down to Linux, or even
+ * further.
+ * @param name the name of the system call
+ * @return the Syscall object, or null
+ * @throws NullPointerException if name is null
+ */
+ public static Syscall syscallByName (String name)
+ {
+ for (int i = 0; i < syscallList.length; ++i)
+ if (name.equals(syscallList[i].name))
+ return syscallList[i];
+ return null;
}
private static Syscall[] syscallList = {