xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/arithmetic/tst.nonarrow.ksh (revision 8c69cc8fbe729fa7b091e901c4b50508ccc6bb33)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright (c) 2012, Joyent, Inc. All rights reserved.
24#
25
26#
27# Somewhat surprisingly, DTrace very much relies on the fact that when 32-bit
28# is forced, pointers are not, in fact, narrowed to 32-bits.  In particular, if
29# this is not so (that is, if pointers are narrowed to their seemingly correct
30# 32-bit width), helpers attached to 32-bit programs will fail to operate:
31# they will erroneously zero the high 32-bits of the return values of 64-bit
32# kernel pointers as returned by copyin(), alloca(), etc.  This test asserts
33# this implicit behavior -- and this comment regrettably serves as this
34# behavior's only documentation.
35#
36doit()
37{
38	/usr/sbin/dtrace $1 -n BEGIN'{trace(sizeof (long))}' \
39	    -n 'BEGIN{*(int *)alloca(4) = 21506; exit(0)}' \
40	    -n 'ERROR{exit(1)}'
41
42	if [ "$?" -ne 0 ]; then
43		exit $?
44	fi
45}
46
47doit
48doit -32
49