summaryrefslogtreecommitdiffstats
path: root/dalvik
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-06-25 12:57:09 -0700
committerJeff Sharkey <jsharkey@android.com>2011-06-28 17:04:30 -0700
commit2b60e181ccfa98611f1e6fd3709be50f32a84540 (patch)
tree28b63e397e98473fafd76fabd6b42cdd83cc19bf /dalvik
parent028654aaf71592bb60abffb9fc8aaa3707308609 (diff)
downloadlibcore-2b60e181ccfa98611f1e6fd3709be50f32a84540.zip
libcore-2b60e181ccfa98611f1e6fd3709be50f32a84540.tar.gz
libcore-2b60e181ccfa98611f1e6fd3709be50f32a84540.tar.bz2
Migrate setThreadStatsTag() from String to int.
Also write out tag as unsigned int. Bug: 4948913 Change-Id: I314655d0698df26e545107b4dea37ce4629be01a
Diffstat (limited to 'dalvik')
-rw-r--r--dalvik/src/main/java/dalvik/system/BlockGuard.java58
1 files changed, 34 insertions, 24 deletions
diff --git a/dalvik/src/main/java/dalvik/system/BlockGuard.java b/dalvik/src/main/java/dalvik/system/BlockGuard.java
index 57bdeb1..f7441b7 100644
--- a/dalvik/src/main/java/dalvik/system/BlockGuard.java
+++ b/dalvik/src/main/java/dalvik/system/BlockGuard.java
@@ -16,22 +16,14 @@
package dalvik.system;
-import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.FileWriter;
import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.InetAddress;
+import java.math.BigInteger;
import java.net.SocketException;
-import java.net.SocketImpl;
import java.nio.charset.Charsets;
-import libcore.io.ErrnoException;
-import libcore.io.Libcore;
-import libcore.io.StructLinger;
-import libcore.util.EmptyArray;
-import static libcore.io.OsConstants.*;
+
/**
* Mechanism to let threads set restrictions on what code is allowed
* to do in their thread.
@@ -86,7 +78,7 @@ public final class BlockGuard {
}
public static class SocketTags {
- public String statsTag = null;
+ public int statsTag = -1;
public int statsUid = -1;
}
@@ -162,7 +154,7 @@ public final class BlockGuard {
return threadPolicy.get();
}
- public static void setThreadSocketStatsTag(String tag) {
+ public static void setThreadSocketStatsTag(int tag) {
threadSocketTags.get().statsTag = tag;
}
@@ -208,19 +200,18 @@ public final class BlockGuard {
}
}
- private static void internalTagSocketFd(FileDescriptor fd, String tag, int uid)
+ private static void internalTagSocketFd(FileDescriptor fd, int tag, int uid)
throws IOException {
- int fdNum = fd.getInt$();
- if (fdNum == -1 || (tag == null && uid == -1)) return;
+ final int fdNum = fd.getInt$();
+ if (fdNum == -1 || (tag == -1 && uid == -1)) return;
String cmd = "t " + fdNum;
- if (tag == null) {
+ if (tag == -1) {
// Case where just the uid needs adjusting. But probaly the caller
// will want to track his own name here, just in case.
cmd += " 0";
} else {
- // TODO: See about supporting strings, or assume always acct_tag (1..2^32-1)
- cmd += " " + ((long)tag.hashCode() << 32);
+ cmd += " " + tagToKernel(tag);
}
if (uid != -1) {
cmd += " " + uid;
@@ -228,12 +219,11 @@ public final class BlockGuard {
internalModuleCtrl(cmd);
}
- private static void internalUnTagSocketFd(FileDescriptor fd)
- throws IOException {
- int fdNum = fd.getInt$();
- if (fdNum == -1) return;
- String cmd = "u " + fdNum;
- internalModuleCtrl(cmd);
+ private static void internalUnTagSocketFd(FileDescriptor fd) throws IOException {
+ final int fdNum = fd.getInt$();
+ if (fdNum == -1) return;
+ String cmd = "u " + fdNum;
+ internalModuleCtrl(cmd);
}
/**
@@ -275,5 +265,25 @@ public final class BlockGuard {
}
}
+ /**
+ * Convert {@link Integer} tag to {@code /proc/} format. Assumes unsigned
+ * base-10 format like {@code 2147483647}. Currently strips signed bit to
+ * avoid using {@link BigInteger}.
+ */
+ public static String tagToKernel(int tag) {
+ // TODO: eventually write in hex, since thats what proc exports
+ // TODO: migrate to direct integer instead of odd shifting
+ return Long.toString((((long) tag) << 32) & 0x7FFFFFFF00000000L);
+ }
+
+ /**
+ * Convert {@code /proc/} tag format to {@link Integer}. Assumes incoming
+ * format like {@code 0x7fffffff00000000}.
+ */
+ public static int kernelToTag(String string) {
+ // TODO: migrate to direct integer instead of odd shifting
+ return (int) (Long.decode(string) >> 32);
+ }
+
private BlockGuard() {}
}