1266989Smarkj#! /usr/bin/ksh
2266989Smarkj#
3266989Smarkj#
4266989Smarkj# This file and its contents are supplied under the terms of the
5266989Smarkj# Common Development and Distribution License ("CDDL"), version 1.0.
6266989Smarkj# You may only use this file in accordance with the terms of version
7266989Smarkj# 1.0 of the CDDL.
8266989Smarkj#
9266989Smarkj# A full copy of the text of the CDDL should have accompanied this
10266989Smarkj# source.  A copy of the CDDL is also available via the Internet at
11266989Smarkj# http://www.illumos.org/license/CDDL.
12266989Smarkj#
13266989Smarkj
14266989Smarkj#
15266989Smarkj# Copyright (c) 2013 Joyent, Inc. All rights reserved.
16266989Smarkj#
17266989Smarkj
18266989Smarkj#
19266989Smarkj# This test is purposefully using a 64-bit DTrace and thus 64-bit types
20266989Smarkj# when compared with a 32-bit process. This test uses the userland
21266989Smarkj# keyword and so the implicit copyin should access illegal memory and
22266989Smarkj# thus exit.
23266989Smarkj#
24266989Smarkj
25266989Smarkjif [ $# != 1 ]; then
26266989Smarkj        echo expected one argument: '<'dtrace-path'>'
27266989Smarkj        exit 2
28266989Smarkjfi
29266989Smarkj
30266989Smarkjdtrace=$1
31266989Smarkjt="zelda_info_t"
32266989Smarkjexe="tst.chasestrings.exe"
33266989Smarkj
34266989Smarkjelfdump "./$exe" | grep -q '.SUNW_ctf' 
35266989Smarkjif [[ $? -ne 0 ]]; then
36266989Smarkj	echo "CTF does not exist in $exe, that's a bug" >&2
37266989Smarkj	exit 1
38266989Smarkjfi
39266989Smarkj
40266989Smarkj./$exe &
41266989Smarkjpid=$!
42266989Smarkj
43266989Smarkj$dtrace -64 -qs /dev/stdin <<EOF
44266989Smarkjtypedef struct info {
45266989Smarkj        char    *zi_gamename;
46266989Smarkj        int     zi_ndungeons;
47266989Smarkj        char    *zi_villain;
48266989Smarkj        int     zi_haszelda;
49266989Smarkj} info_t;
50266989Smarkj
51266989Smarkjpid$pid::has_princess:entry
52266989Smarkj/next == 0/
53266989Smarkj{
54266989Smarkj	this->t = (userland info_t *)arg0;
55266989Smarkj	printf("game: %s, dungeon: %d, villain: %s, zelda: %d\n",
56266989Smarkj	    stringof(this->t->zi_gamename), this->t->zi_ndungeons,
57266989Smarkj	    stringof(this->t->zi_villain), this->t->zi_haszelda);
58266989Smarkj	next = 1;
59266989Smarkj}
60266989Smarkj
61266989Smarkjpid$pid::has_dungeons:entry
62266989Smarkj/next == 1/
63266989Smarkj{
64266989Smarkj	this->t = (userland info_t *)arg0;
65266989Smarkj	printf("game: %s, dungeon: %d, villain: %s, zelda: %d\n",
66266989Smarkj	    stringof(this->t->zi_gamename), this->t->zi_ndungeons,
67266989Smarkj	    stringof(this->t->zi_villain), this->t->zi_haszelda);
68266989Smarkj	next = 2;
69266989Smarkj}
70266989Smarkj
71266989Smarkjpid$pid::has_villain:entry
72266989Smarkj/next == 2/
73266989Smarkj{
74266989Smarkj	this->t = (userland info_t *)arg0;
75266989Smarkj	printf("game: %s, dungeon: %d, villain: %s, zelda: %d\n",
76266989Smarkj	    stringof(this->t->zi_gamename), this->t->zi_ndungeons,
77266989Smarkj	    stringof(this->t->zi_villain), this->t->zi_haszelda);
78266989Smarkj	exit(0);
79266989Smarkj}
80266989Smarkj
81266989SmarkjERROR
82266989Smarkj{
83266989Smarkj	exit(1);
84266989Smarkj}
85266989SmarkjEOF
86266989Smarkjrc=$?
87266989Smarkj
88266989Smarkjkill -9 $pid
89266989Smarkj
90266989Smarkjexit $rc
91