From 8e765da941f4f0649aca2b28234ac31adde45f06 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Thu, 2 Feb 2012 14:09:27 -0500 Subject: runtime: add runtime.cputicks() and seed fastrand with it This patch adds a function to get the current cpu ticks. This is deemed to be 'sufficiently random' to use to seed fastrand to mitigate the algorithmic complexity attacks on the hash table implementation. On AMD64 we use the RDTSC instruction. For 386, this instruction, while valid, is not recognized by 8a so I've inserted the opcode by hand. For ARM, this routine is currently stubbed to return a constant 0 value. Future work: update 8a to recognize RDTSC. Fixes #2630. R=rsc CC=golang-dev https://golang.org/cl/5606048 --- src/pkg/runtime/runtime.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/pkg/runtime/runtime.h') diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index df2cd149f2..692992150a 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -566,6 +566,7 @@ void runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp); void runtime·resetcpuprofiler(int32); void runtime·setcpuprofilerate(void(*)(uintptr*, int32), int32); void runtime·usleep(uint32); +int64 runtime·cputicks(void); #pragma varargck argpos runtime·printf 1 #pragma varargck type "d" int32 -- cgit v1.3-5-g9baa