バスエラー

出典: フリー百科事典『ウィキペディア(Wikipedia)』

 (: bus error) 



使



CPUCPUCPUCPUCPUCPU

 (misaligned memory access / unaligned memory access)

CPU18bitCPU16bit32bit64bit16bit20, 2, 4, ...1, 3, 5, ...32bit40, 4, 8, 12, ...

CPUCPU22CPUCPUCPU64bit CPU[]

POSIXSIGBUS

[]


C

Note: 
#include <stdlib.h>
int main(void) {
  /* iptr is a pointer to an integer, usually 32 or 64 bits in size. It is currently undefined. */
  /* iptrはintへのポインタ。普通32bitまたは64bitのサイズがある。この時点では内容は未定義 */
  int x, *iptr;

  /* cptr is a pointer to a character (the "smallest addressable unit" of the CPU, normally a byte) */
  /* cptrはcharへのポインタ。CPUがアドレッシングできる最小単位(バイト)で、普通はオクテットすなわち8bit */
  char *cptr;

  /* malloc() gives us a valid, aligned memory address. put this in cptr */
  /* malloc()が成功した場合、返ってきたメモリアドレスはアライメントされている。このアドレスをcptrに入れる */
  cptr = (char *) malloc(33);
  if (!cptr) return 1;

  /* cptrを1増やす。これで不整列なアドレスになった */
  cptr++;

  /* 不整列アドレスで個々のバイトにアクセスするのは問題ない */
  x = *cptr;

  /* iptrに不整列アドレスを代入 */
  iptr = (int *) &cptr[1];
  /* ここでバスエラーが発生するはず。不整列アドレスで1バイト以上のデータにアクセスしている */
  x = *iptr;

  free(cptr);

  return 0;
}

x86[1]EFLAGSAlignment Check (AC) CR0AM[2]

[]


DEC使CPU

CPUCPUWindowsUNIX

WindowsUNIX

脚注[編集]

関連項目[編集]