星期五 八月 24, 2007

Notable magic numbers


Many computer processors, operating systems, and debuggers make use of magic numbers, especially as a magic debug value.

  • 0xABADBABE ("a bad babe") is used by Apple as the "Boot Zero Block" magic number.
  • 0xBAADF00D ("bad food") is used by Microsoft's LocalAlloc(LMEM_FIXED) to indicate uninitialised allocated heap memory.
  • 0xBADDCAFE ("bad cafe") is used by 'watchmalloc' in OpenSolaris to mark allocated but uninitialized memory.
  • 0xCAFEBABE ("cafe babe") is used by both Mach-O ("Fat binary" in both 68k and PowerPC) to identify object files and the Java programming language to identify Java bytecode class files
  • 0xDEADBEEF ("dead beef") is used by IBM RS/6000 systems and Mac OS on 32-bit PowerPC processors as a magic debug value. On Sun Microsystems' Solaris, marks freed kernel memory
  • 0xDEFEC8ED ("defecated") is the magic number for OpenSolaris core dumps.
  • 0xFEEDFACE ("feed face") is used as a header for Mach-O binaries, and as an invalid pointer value for 'watchmalloc' in OpenSolaris.
kmem_flags
The setting of kmem_flags (a kernel global variable) can be very useful in
debugging problems. Here are some of the interesting values relating to
kmem_flags (from kmem_impl.h):
/*
* kernel memory allocator: implementation-private data structures
*/
#define KMF_AUDIT 0x00000001 /* transaction auditing */
#define KMF_DEADBEEF 0x00000002 /* deadbeef checking */
#define KMF_REDZONE 0x00000004 /* redzone checking */
#define KMF_CONTENTS 0x00000008 /* freed-buffer content logging */
#define KMF_STICKY 0x00000010 /* if set, override /etc/system */
#define KMF_NOMAGAZINE 0x00000020 /* disable per-cpu magazines */
#define KMF_FIREWALL 0x00000040 /* put all bufs before unmapped
pages */
#define KMF_LITE 0x00000100 /* lightweight debugging */
#define KMF_HASH 0x00000200 /* cache has hash table */
#define KMF_RANDOMIZE 0x00000400 /* randomize other kmem_flags */
#define KMF_BUFTAG (KMF_DEADBEEF | KMF_REDZONE)
#define KMF_TOUCH (KMF_BUFTAG | KMF_LITE | KMF_CONTENTS)
#define KMF_RANDOM (KMF_TOUCH | KMF_AUDIT | KMF_NOMAGAZINE)
#define KMF_DEBUG (KMF_RANDOM | KMF_FIREWALL)
#define KMEM_STACK_DEPTH 15
#define KMEM_FREE_PATTERN 0xdeadbeefdeadbeefULL
#define KMEM_UNINITIALIZED_PATTERN 0xbaddcafebaddcafeULL
#define KMEM_REDZONE_PATTERN 0xfeedfacefeedfaceULL
#define KMEM_REDZONE_BYTE 0xbb
Setting kmem_flags to 0xf will provide the necessary information

评论:

jeff@jschroeder2:~$ grep dead git/linux-2.6/include/linux/reboot.h
#define LINUX_REBOOT_MAGIC1 0xfee1dead

发表于 Jeff Schroeder 在 2009年01月03日, 12:25 上午 CST #

发表一条评论:
  • HTML语法: 禁用