1*8b184c19SRobert Mustacchi#!/usr/bin/ksh 2*8b184c19SRobert Mustacchi# 3*8b184c19SRobert Mustacchi# This file and its contents are supplied under the terms of the 4*8b184c19SRobert Mustacchi# Common Development and Distribution License ("CDDL"), version 1.0. 5*8b184c19SRobert Mustacchi# You may only use this file in accordance with the terms of version 6*8b184c19SRobert Mustacchi# 1.0 of the CDDL. 7*8b184c19SRobert Mustacchi# 8*8b184c19SRobert Mustacchi# A full copy of the text of the CDDL should have accompanied this 9*8b184c19SRobert Mustacchi# source. A copy of the CDDL is also available via the Internet at 10*8b184c19SRobert Mustacchi# http://www.illumos.org/license/CDDL. 11*8b184c19SRobert Mustacchi# 12*8b184c19SRobert Mustacchi 13*8b184c19SRobert Mustacchi# 14*8b184c19SRobert Mustacchi# Copyright 2025 Oxide Computer Company 15*8b184c19SRobert Mustacchi# 16*8b184c19SRobert Mustacchi 17*8b184c19SRobert Mustacchi# 18*8b184c19SRobert Mustacchi# Test that we can correctly determine the offsets in various anonymous 19*8b184c19SRobert Mustacchi# structures and unions. 20*8b184c19SRobert Mustacchi# 21*8b184c19SRobert Mustacchi 22*8b184c19SRobert Mustacchiif (( $# != 1 )); then 23*8b184c19SRobert Mustacchi printf "%s\n" "expected one argument: <dtrace-path>" >&2 24*8b184c19SRobert Mustacchi exit 2 25*8b184c19SRobert Mustacchifi 26*8b184c19SRobert Mustacchi 27*8b184c19SRobert Mustacchidtrace=$1 28*8b184c19SRobert Mustacchi$dtrace -c ./tst.anon.exe -qs /dev/stdin <<EOF 29*8b184c19SRobert MustacchiBEGIN 30*8b184c19SRobert Mustacchi{ 31*8b184c19SRobert Mustacchi printf("a: %d, exp 0\n", offsetof(struct pid\`foo, a)); 32*8b184c19SRobert Mustacchi printf("b: %d, exp 4\n", offsetof(struct pid\`foo, b)); 33*8b184c19SRobert Mustacchi printf("c: %d, exp 4\n", offsetof(struct pid\`foo, c)); 34*8b184c19SRobert Mustacchi printf("d: %d, exp 4\n", offsetof(struct pid\`foo, d)); 35*8b184c19SRobert Mustacchi printf("e: %d, exp 8\n", offsetof(struct pid\`foo, e)); 36*8b184c19SRobert Mustacchi printf("f: %d, exp 12\n", offsetof(struct pid\`foo, f)); 37*8b184c19SRobert Mustacchi printf("g: %d, exp 4\n", offsetof(struct pid\`foo, g)); 38*8b184c19SRobert Mustacchi printf("h: %d, exp 16\n", offsetof(struct pid\`foo, h)); 39*8b184c19SRobert Mustacchi printf("i: %d, exp 20\n", offsetof(struct pid\`foo, i)); 40*8b184c19SRobert Mustacchi printf("j: %d, exp 20\n", offsetof(struct pid\`foo, j)); 41*8b184c19SRobert Mustacchi printf("k: %d, exp 24\n", offsetof(struct pid\`foo, k)); 42*8b184c19SRobert Mustacchi printf("l: %d, exp 24\n", offsetof(struct pid\`foo, l)); 43*8b184c19SRobert Mustacchi printf("m: %d, exp 28\n", offsetof(struct pid\`foo, m)); 44*8b184c19SRobert Mustacchi printf("n: %d, exp 32\n", offsetof(struct pid\`foo, n)); 45*8b184c19SRobert Mustacchi printf("o: %d, exp 32\n", offsetof(struct pid\`foo, o)); 46*8b184c19SRobert Mustacchi printf("p: %d, exp 36\n", offsetof(struct pid\`foo, p)); 47*8b184c19SRobert Mustacchi printf("q: %d, exp 24\n", offsetof(struct pid\`foo, q)); 48*8b184c19SRobert Mustacchi printf("r: %d, exp 40\n", offsetof(struct pid\`foo, r)); 49*8b184c19SRobert Mustacchi printf("s: %d, exp 20\n", offsetof(struct pid\`foo, s)); 50*8b184c19SRobert Mustacchi printf("t: %d, exp 44\n", offsetof(struct pid\`foo, t)); 51*8b184c19SRobert Mustacchi 52*8b184c19SRobert Mustacchi exit(0); 53*8b184c19SRobert Mustacchi} 54*8b184c19SRobert MustacchiEOF 55