9512fe850e98fdd448c638ca63fdd92a8a510255ahl/*
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * CDDL HEADER START
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * The contents of this file are subject to the terms of the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Common Development and Distribution License (the "License").
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * You may not use this file except in compliance with the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * or http://www.opensolaris.org/os/licensing.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * See the License for the specific language governing permissions
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * and limitations under the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * When distributing Covered Code, include this CDDL HEADER in each
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * If applicable, add the following below this CDDL HEADER, with the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * fields enclosed by brackets "[]" replaced with your own identifying
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * information: Portions Copyright [yyyy] [name of copyright owner]
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * CDDL HEADER END
9512fe850e98fdd448c638ca63fdd92a8a510255ahl */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl/*
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Use is subject to license terms.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#pragma ident "%Z%%M% %I% %E% SMI"
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#include <stdint.h>
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl#include <stdlib.h>
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl#include <strings.h>
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlint
9512fe850e98fdd448c638ca63fdd92a8a510255ahlbaz(void)
9512fe850e98fdd448c638ca63fdd92a8a510255ahl{
9512fe850e98fdd448c638ca63fdd92a8a510255ahl return (8);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl}
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlstatic int
9512fe850e98fdd448c638ca63fdd92a8a510255ahlfoo(void)
9512fe850e98fdd448c638ca63fdd92a8a510255ahl{
9512fe850e98fdd448c638ca63fdd92a8a510255ahl /*
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * In order to assure that our helper is properly employed to identify
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * the frame, we're going to trampoline through data.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl uint32_t instr[] = {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl 0x9de3bfa0, /* save %sp, -0x60, %sp */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl 0x40000000, /* call baz */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl 0x01000000, /* nop */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl 0x81c7e008, /* ret */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl 0x81e80000 /* restore */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl };
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl uint32_t *fp = malloc(sizeof (instr));
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl /*
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl * Do our little relocation dance.
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl */
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl instr[1] |= ((uintptr_t)baz - (uintptr_t)&fp[1]) >> 2;
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl /*
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl * Copy the code to the heap (it's a pain to build in ON with an
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl * executable stack).
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl */
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl bcopy(instr, fp, sizeof (instr));
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl (*(int (*)(void))fp)();
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl free(fp);
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl return (0);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl}
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlint
9512fe850e98fdd448c638ca63fdd92a8a510255ahlmain(int argc, char **argv)
9512fe850e98fdd448c638ca63fdd92a8a510255ahl{
9512fe850e98fdd448c638ca63fdd92a8a510255ahl for (;;) {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl foo();
9512fe850e98fdd448c638ca63fdd92a8a510255ahl }
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl return (0);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl}