19512fe85Sahl /*
29512fe85Sahl  * CDDL HEADER START
39512fe85Sahl  *
49512fe85Sahl  * The contents of this file are subject to the terms of the
59512fe85Sahl  * Common Development and Distribution License (the "License").
69512fe85Sahl  * You may not use this file except in compliance with the License.
79512fe85Sahl  *
89512fe85Sahl  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99512fe85Sahl  * or http://www.opensolaris.org/os/licensing.
109512fe85Sahl  * See the License for the specific language governing permissions
119512fe85Sahl  * and limitations under the License.
129512fe85Sahl  *
139512fe85Sahl  * When distributing Covered Code, include this CDDL HEADER in each
149512fe85Sahl  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159512fe85Sahl  * If applicable, add the following below this CDDL HEADER, with the
169512fe85Sahl  * fields enclosed by brackets "[]" replaced with your own identifying
179512fe85Sahl  * information: Portions Copyright [yyyy] [name of copyright owner]
189512fe85Sahl  *
199512fe85Sahl  * CDDL HEADER END
209512fe85Sahl  */
219512fe85Sahl 
229512fe85Sahl /*
239512fe85Sahl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
249512fe85Sahl  * Use is subject to license terms.
259512fe85Sahl  */
269512fe85Sahl 
27*c93cc65aSSebastien Roy /*
28*c93cc65aSSebastien Roy  * Copyright (c) 2012 by Delphix. All rights reserved.
29*c93cc65aSSebastien Roy  */
309512fe85Sahl 
319512fe85Sahl /*
329512fe85Sahl  * ASSERTION:
339512fe85Sahl  * Using integer arithmetic providing a non-aligned memory address will throw
349512fe85Sahl  * a runtime error.
359512fe85Sahl  *
369512fe85Sahl  * SECTION: Pointers and Arrays/Generic Pointers
379512fe85Sahl  */
389512fe85Sahl 
399512fe85Sahl #pragma D option quiet
409512fe85Sahl 
41*c93cc65aSSebastien Roy #if defined(__i386) || defined(__amd64)
42*c93cc65aSSebastien Roy #define __x86 1
43*c93cc65aSSebastien Roy #endif
44*c93cc65aSSebastien Roy 
45*c93cc65aSSebastien Roy int array[2];
46*c93cc65aSSebastien Roy char *ptr;
479512fe85Sahl int *p;
489512fe85Sahl int *q;
499512fe85Sahl int *r;
509512fe85Sahl 
519512fe85Sahl BEGIN
529512fe85Sahl {
53*c93cc65aSSebastien Roy 	array[0] = 0x12345678;
54*c93cc65aSSebastien Roy 	array[1] = 0xabcdefff;
559512fe85Sahl 
56*c93cc65aSSebastien Roy 	ptr = (char *) &array[0];
579512fe85Sahl 
58*c93cc65aSSebastien Roy 	p = (int *) (ptr);
59*c93cc65aSSebastien Roy 	q = (int *) (ptr + 2);
60*c93cc65aSSebastien Roy 	r = (int *) (ptr + 3);
619512fe85Sahl 
62*c93cc65aSSebastien Roy 	printf("*p: 0x%x\n", *p);
63*c93cc65aSSebastien Roy 	printf("*q: 0x%x\n", *q);
64*c93cc65aSSebastien Roy 	printf("*r: 0x%x\n", *r);
659512fe85Sahl 
66*c93cc65aSSebastien Roy 	/*
67*c93cc65aSSebastien Roy 	 * On x86, the above unaligned memory accesses are allowed and should
68*c93cc65aSSebastien Roy 	 * not result in the ERROR probe firing.
69*c93cc65aSSebastien Roy 	 */
70*c93cc65aSSebastien Roy #ifdef __x86
71*c93cc65aSSebastien Roy 	exit(1);
72*c93cc65aSSebastien Roy #else
739512fe85Sahl 	exit(0);
749512fe85Sahl #endif
759512fe85Sahl }
769512fe85Sahl 
779512fe85Sahl ERROR
789512fe85Sahl {
79*c93cc65aSSebastien Roy #ifdef __x86
80*c93cc65aSSebastien Roy 	exit(0);
81*c93cc65aSSebastien Roy #else
829512fe85Sahl 	exit(1);
83*c93cc65aSSebastien Roy #endif
849512fe85Sahl }
85