2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2000 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <stdio.h>
2N/A#include <sys/shm.h>
2N/A#include <dlfcn.h>
2N/A#include <fcode/private.h>
2N/A
2N/Astatic void
2N/Ado_dlopen(fcode_env_t *env)
2N/A{
2N/A char *name;
2N/A int mode;
2N/A void *pl;
2N/A
2N/A mode = POP(DS);
2N/A name = pop_a_string(env, NULL);
2N/A pl = dlopen(name, mode);
2N/A PUSH(DS, (fstack_t)pl);
2N/A}
2N/A
2N/Astatic void
2N/Ado_extend(fcode_env_t *env)
2N/A{
2N/A parse_word(env);
2N/A PUSH(DS, (fstack_t)RTLD_NOW);
2N/A do_dlopen(env);
2N/A drop(env);
2N/A}
2N/A
2N/Astatic void
2N/Ado_dlclose(fcode_env_t *env)
2N/A{
2N/A void *pl = (void *)POP(DS);
2N/A dlclose(pl);
2N/A}
2N/A
2N/Astatic void
2N/Ado_dlsym(fcode_env_t *env)
2N/A{
2N/A char *name;
2N/A fstack_t d;
2N/A
2N/A name = pop_a_string(env, NULL);
2N/A d = POP(DS);
2N/A d = (fstack_t)dlsym((void *) d, name);
2N/A PUSH(DS, d);
2N/A}
2N/A
2N/Astatic void
2N/Ado_dlexec(fcode_env_t *env)
2N/A{
2N/A int args;
2N/A fstack_t a, b, c, d;
2N/A fstack_t (*fn0)(void);
2N/A fstack_t (*fn1)(fstack_t);
2N/A fstack_t (*fn2)(fstack_t, fstack_t);
2N/A fstack_t (*fn3)(fstack_t, fstack_t, fstack_t);
2N/A fstack_t (*fn4)(fstack_t, fstack_t, fstack_t, fstack_t);
2N/A
2N/A args = POP(DS);
2N/A a = POP(DS);
2N/A switch (args) {
2N/A
2N/A case 0:
2N/A fn0 = (fstack_t (*)(void)) a;
2N/A a = fn0();
2N/A PUSH(DS, a);
2N/A break;
2N/A
2N/A case 1:
2N/A fn1 = (fstack_t (*)(fstack_t)) a;
2N/A a = POP(DS);
2N/A a = fn1(a);
2N/A PUSH(DS, a);
2N/A break;
2N/A
2N/A case 2:
2N/A fn2 = (fstack_t (*)(fstack_t, fstack_t))a;
2N/A a = POP(DS);
2N/A b = POP(DS);
2N/A a = fn2(a, b);
2N/A PUSH(DS, a);
2N/A break;
2N/A
2N/A case 3:
2N/A fn3 = (fstack_t (*)(fstack_t, fstack_t, fstack_t))a;
2N/A a = POP(DS);
2N/A b = POP(DS);
2N/A c = POP(DS);
2N/A a = fn3(a, b, c);
2N/A PUSH(DS, a);
2N/A break;
2N/A
2N/A case 4:
2N/A fn4 = (fstack_t (*)(fstack_t, fstack_t, fstack_t, fstack_t))a;
2N/A a = POP(DS);
2N/A b = POP(DS);
2N/A c = POP(DS);
2N/A d = POP(DS);
2N/A a = fn4(a, b, c, d);
2N/A PUSH(DS, a);
2N/A break;
2N/A }
2N/A}
2N/A
2N/A#pragma init(_init)
2N/A
2N/Astatic void
2N/A_init(void)
2N/A{
2N/A fcode_env_t *env = initial_env;
2N/A
2N/A ASSERT(env);
2N/A NOTICE;
2N/A
2N/A FORTH(0, "dl-open", do_dlopen);
2N/A FORTH(0, "dl-close", do_dlclose);
2N/A FORTH(0, "dl-sym", do_dlsym);
2N/A FORTH(0, "dl-exec", do_dlexec);
2N/A FORTH(IMMEDIATE, "extend-from", do_extend);
2N/A}