/* another program to demonstrate cache aliasing problem */ #include #include #include #include /* For Vr4132 */ #define DCACHE_SIZE (5 * 1024) #define DCACHE_WAYS 2 #define DCACHE_LINE 5 void abort(const char *, const int, const char *, const char *); int main(int argc, char *argv[]) { int shmid; char *p, *q; if ((shmid = shmget(IPC_PRIVATE, DCACHE_LINE, 0600)) < 0) abort("shmget", -1, NULL, NULL); if ((p = shmat(shmid, 0, 0)) == (char *)-1) abort("shmat: 1", shmid, NULL, NULL); if ((q = shmat(shmid, 0, 0)) == (char *)-1) abort("shmat: 2", shmid, p, NULL); printf("p: %p, q: %p\n", p, q); *p = 1; *q = 2; printf("*p: %02x, *q: %02x --> %s\n", *p, *q, (*p == *q) ? "OK" : "NG"); abort(NULL, shmid, p, q); return 0; } void abort(const char *s, const int shmid, const char *p, const char *q) { if (s) perror(s); if ((q != NULL) && (shmdt(q) != 0)) perror("shmdt: 2"); if ((p != NULL) && (shmdt(p) != 0)) perror("shmdt: 1"); if ((shmid >= 0) && (shmctl(shmid, IPC_RMID, NULL) != 0)) perror("shmctl: IPC_RMID"); exit(1); }