1*edba5eecSFederico Vaga.. _magicnumbers: 2*edba5eecSFederico Vaga 3186128f7SMauro Carvalho ChehabLinux magic numbers 4186128f7SMauro Carvalho Chehab=================== 5186128f7SMauro Carvalho Chehab 6186128f7SMauro Carvalho ChehabThis file is a registry of magic numbers which are in use. When you 7186128f7SMauro Carvalho Chehabadd a magic number to a structure, you should also add it to this 8186128f7SMauro Carvalho Chehabfile, since it is best if the magic numbers used by various structures 9186128f7SMauro Carvalho Chehabare unique. 10186128f7SMauro Carvalho Chehab 11186128f7SMauro Carvalho ChehabIt is a **very** good idea to protect kernel data structures with magic 12186128f7SMauro Carvalho Chehabnumbers. This allows you to check at run time whether (a) a structure 13186128f7SMauro Carvalho Chehabhas been clobbered, or (b) you've passed the wrong structure to a 14186128f7SMauro Carvalho Chehabroutine. This last is especially useful --- particularly when you are 15186128f7SMauro Carvalho Chehabpassing pointers to structures via a void * pointer. The tty code, 16186128f7SMauro Carvalho Chehabfor example, does this frequently to pass driver-specific and line 17186128f7SMauro Carvalho Chehabdiscipline-specific structures back and forth. 18186128f7SMauro Carvalho Chehab 19738947f0SMartin KepplingerThe way to use magic numbers is to declare them at the beginning of 20186128f7SMauro Carvalho Chehabthe structure, like so:: 21186128f7SMauro Carvalho Chehab 22186128f7SMauro Carvalho Chehab struct tty_ldisc { 23186128f7SMauro Carvalho Chehab int magic; 24186128f7SMauro Carvalho Chehab ... 25186128f7SMauro Carvalho Chehab }; 26186128f7SMauro Carvalho Chehab 27186128f7SMauro Carvalho ChehabPlease follow this discipline when you are adding future enhancements 28186128f7SMauro Carvalho Chehabto the kernel! It has saved me countless hours of debugging, 29186128f7SMauro Carvalho Chehabespecially in the screwy cases where an array has been overrun and 30186128f7SMauro Carvalho Chehabstructures following the array have been overwritten. Using this 31186128f7SMauro Carvalho Chehabdiscipline, these cases get detected quickly and safely. 32186128f7SMauro Carvalho Chehab 33186128f7SMauro Carvalho ChehabChangelog:: 34186128f7SMauro Carvalho Chehab 35186128f7SMauro Carvalho Chehab Theodore Ts'o 36186128f7SMauro Carvalho Chehab 31 Mar 94 37186128f7SMauro Carvalho Chehab 38186128f7SMauro Carvalho Chehab The magic table is current to Linux 2.1.55. 39186128f7SMauro Carvalho Chehab 40186128f7SMauro Carvalho Chehab Michael Chastain 41186128f7SMauro Carvalho Chehab <mailto:mec@shout.net> 42186128f7SMauro Carvalho Chehab 22 Sep 1997 43186128f7SMauro Carvalho Chehab 44186128f7SMauro Carvalho Chehab Now it should be up to date with Linux 2.1.112. Because 45186128f7SMauro Carvalho Chehab we are in feature freeze time it is very unlikely that 46186128f7SMauro Carvalho Chehab something will change before 2.2.x. The entries are 47186128f7SMauro Carvalho Chehab sorted by number field. 48186128f7SMauro Carvalho Chehab 49186128f7SMauro Carvalho Chehab Krzysztof G. Baranowski 50186128f7SMauro Carvalho Chehab <mailto: kgb@knm.org.pl> 51186128f7SMauro Carvalho Chehab 29 Jul 1998 52186128f7SMauro Carvalho Chehab 53186128f7SMauro Carvalho Chehab Updated the magic table to Linux 2.5.45. Right over the feature freeze, 54186128f7SMauro Carvalho Chehab but it is possible that some new magic numbers will sneak into the 55186128f7SMauro Carvalho Chehab kernel before 2.6.x yet. 56186128f7SMauro Carvalho Chehab 57186128f7SMauro Carvalho Chehab Petr Baudis 58186128f7SMauro Carvalho Chehab <pasky@ucw.cz> 59186128f7SMauro Carvalho Chehab 03 Nov 2002 60186128f7SMauro Carvalho Chehab 61186128f7SMauro Carvalho Chehab Updated the magic table to Linux 2.5.74. 62186128f7SMauro Carvalho Chehab 63186128f7SMauro Carvalho Chehab Fabian Frederick 64186128f7SMauro Carvalho Chehab <ffrederick@users.sourceforge.net> 65186128f7SMauro Carvalho Chehab 09 Jul 2003 66186128f7SMauro Carvalho Chehab 67186128f7SMauro Carvalho Chehab 68186128f7SMauro Carvalho Chehab===================== ================ ======================== ========================================== 69186128f7SMauro Carvalho ChehabMagic Name Number Structure File 70186128f7SMauro Carvalho Chehab===================== ================ ======================== ========================================== 71186128f7SMauro Carvalho ChehabPG_MAGIC 'P' pg_{read,write}_hdr ``include/linux/pg.h`` 72186128f7SMauro Carvalho ChehabAPM_BIOS_MAGIC 0x4101 apm_user ``arch/x86/kernel/apm_32.c`` 73186128f7SMauro Carvalho ChehabFASYNC_MAGIC 0x4601 fasync_struct ``include/linux/fs.h`` 74186128f7SMauro Carvalho ChehabSLIP_MAGIC 0x5302 slip ``drivers/net/slip.h`` 75186128f7SMauro Carvalho ChehabBAYCOM_MAGIC 0x19730510 baycom_state ``drivers/net/baycom_epp.c`` 76186128f7SMauro Carvalho ChehabHDLCDRV_MAGIC 0x5ac6e778 hdlcdrv_state ``include/linux/hdlcdrv.h`` 77186128f7SMauro Carvalho ChehabKV_MAGIC 0x5f4b565f kernel_vars_s ``arch/mips/include/asm/sn/klkernvars.h`` 78186128f7SMauro Carvalho ChehabCODA_MAGIC 0xC0DAC0DA coda_file_info ``fs/coda/coda_fs_i.h`` 79186128f7SMauro Carvalho ChehabYAM_MAGIC 0xF10A7654 yam_port ``drivers/net/hamradio/yam.c`` 80186128f7SMauro Carvalho ChehabCCB_MAGIC 0xf2691ad2 ccb ``drivers/scsi/ncr53c8xx.c`` 81186128f7SMauro Carvalho ChehabQUEUE_MAGIC_FREE 0xf7e1c9a3 queue_entry ``drivers/scsi/arm/queue.c`` 82186128f7SMauro Carvalho ChehabQUEUE_MAGIC_USED 0xf7e1cc33 queue_entry ``drivers/scsi/arm/queue.c`` 83186128f7SMauro Carvalho ChehabNMI_MAGIC 0x48414d4d455201 nmi_s ``arch/mips/include/asm/sn/nmi.h`` 84186128f7SMauro Carvalho Chehab===================== ================ ======================== ========================================== 85