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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 /* 30 * This preload library must be applied to forth after libthread is 31 * folded into libc because forth/tokenize.exe is not ABI compliant; it 32 * uses all of the %g registers, including %g7, for its internal purposes. 33 * This preload library interposes on all of the external calls made 34 * from forth/tokenize.exe and, assuming that forth is single-threaded, 35 * sets %g7 properly for use inside libc and restores it to forth's 36 * use on return from the interposed-upon function. 37 */ 38 39 enum ix { 40 ix___filbuf = 0, 41 ix___flsbuf, 42 ix__dgettext, 43 ix__exit, 44 ix_access, 45 ix_atexit, 46 ix_atoi, 47 ix_cfgetospeed, 48 ix_chdir, 49 ix_close, 50 ix_dlclose, 51 ix_dlerror, 52 ix_dlopen, 53 ix_dlsym, 54 ix_exit, 55 ix_exit_handler, 56 ix_fclose, 57 ix_fflush, 58 ix_fgetc, 59 ix_fileno, 60 ix_fopen, 61 ix_fprintf, 62 ix_fputc, 63 ix_fputs, 64 ix_fread, 65 ix_free, 66 ix_fseek, 67 ix_fstat, 68 ix_ftell, 69 ix_fwrite, 70 ix_getcwd, 71 ix_getenv, 72 ix_getopt, 73 ix_getwd, 74 ix_ioctl, 75 ix_isatty, 76 ix_kill, 77 ix_localtime, 78 ix_lseek, 79 ix_malloc, 80 ix_memcpy, 81 ix_memset, 82 ix_open, 83 ix_perror, 84 ix_printf, 85 ix_psignal, 86 ix_putchar, 87 ix_read, 88 ix_sbrk, 89 ix_signal, 90 ix_sigset, 91 ix_snprintf, 92 ix_sprintf, 93 ix_stat, 94 ix_strcat, 95 ix_strchr, 96 ix_strcmp, 97 ix_strcpy, 98 ix_strdup, 99 ix_strlen, 100 ix_strncmp, 101 ix_strncpy, 102 ix_strrchr, 103 ix_system, 104 ix_tcgetattr, 105 ix_tcsetattr, 106 ix_tgetent, 107 ix_tgetflag, 108 ix_tgetnum, 109 ix_tgetstr, 110 ix_tgoto, 111 ix_time, 112 ix_tputs, 113 ix_tzset, 114 ix_ungetc, 115 ix_unlink, 116 ix_write 117 }; 118 119 typedef long (*realfunc_t)(long, long, long, long, long, long); 120 121 struct intpose { 122 char fname[12]; 123 realfunc_t realfunc; 124 } intpose[] = { 125 { "__filbuf", 0 }, 126 { "__flsbuf", 0 }, 127 { "_dgettext", 0 }, 128 { "_exit", 0 }, 129 { "access", 0 }, 130 { "atexit", 0 }, 131 { "atoi", 0 }, 132 { "cfgetospeed", 0 }, 133 { "chdir", 0 }, 134 { "close", 0 }, 135 { "dlclose", 0 }, 136 { "dlerror", 0 }, 137 { "dlopen", 0 }, 138 { "dlsym", 0 }, 139 { "exit", 0 }, 140 { "exit_handler", 0 }, 141 { "fclose", 0 }, 142 { "fflush", 0 }, 143 { "fgetc", 0 }, 144 { "fileno", 0 }, 145 { "fopen", 0 }, 146 { "fprintf", 0 }, 147 { "fputc", 0 }, 148 { "fputs", 0 }, 149 { "fread", 0 }, 150 { "free", 0 }, 151 { "fseek", 0 }, 152 { "fstat", 0 }, 153 { "ftell", 0 }, 154 { "fwrite", 0 }, 155 { "getcwd", 0 }, 156 { "getenv", 0 }, 157 { "getopt", 0 }, 158 { "getwd", 0 }, 159 { "ioctl", 0 }, 160 { "isatty", 0 }, 161 { "kill", 0 }, 162 { "localtime", 0 }, 163 { "lseek", 0 }, 164 { "malloc", 0 }, 165 { "memcpy", 0 }, 166 { "memset", 0 }, 167 { "open", 0 }, 168 { "perror", 0 }, 169 { "printf", 0 }, 170 { "psignal", 0 }, 171 { "putchar", 0 }, 172 { "read", 0 }, 173 { "sbrk", 0 }, 174 { "signal", 0 }, 175 { "sigset", 0 }, 176 { "snprintf", 0 }, 177 { "sprintf", 0 }, 178 { "stat", 0 }, 179 { "strcat", 0 }, 180 { "strchr", 0 }, 181 { "strcmp", 0 }, 182 { "strcpy", 0 }, 183 { "strdup", 0 }, 184 { "strlen", 0 }, 185 { "strncmp", 0 }, 186 { "strncpy", 0 }, 187 { "strrchr", 0 }, 188 { "system", 0 }, 189 { "tcgetattr", 0 }, 190 { "tcsetattr", 0 }, 191 { "tgetent", 0 }, 192 { "tgetflag", 0 }, 193 { "tgetnum", 0 }, 194 { "tgetstr", 0 }, 195 { "tgoto", 0 }, 196 { "time", 0 }, 197 { "tputs", 0 }, 198 { "tzset", 0 }, 199 { "ungetc", 0 }, 200 { "unlink", 0 }, 201 { "write", 0 }, 202 }; 203 204 #define RTLD_NEXT (void *)-1 205 extern void *_dlsym(void *handle, const char *name); 206 207 static long global_g7 = -1; 208 209 long get_g7(void); 210 void set_g7(long); 211 212 static long 213 callfunc(struct intpose *ip, 214 long a0, long a1, long a2, long a3, long a4, long a5) 215 { 216 realfunc_t realfunc; 217 long my_g7; 218 long rv; 219 220 my_g7 = get_g7(); 221 if (global_g7 == -1) 222 global_g7 = my_g7; 223 set_g7(global_g7); 224 if ((realfunc = ip->realfunc) == 0) 225 ip->realfunc = realfunc = 226 (realfunc_t)_dlsym(RTLD_NEXT, ip->fname); 227 rv = realfunc(a0, a1, a2, a3, a4, a5); 228 set_g7(my_g7); 229 return (rv); 230 } 231 232 #define ipose(func) \ 233 long \ 234 func(long a0, long a1, long a2, long a3, long a4, long a5) \ 235 { \ 236 return (callfunc(&intpose[ix_##func], a0, a1, a2, a3, a4, a5)); \ 237 } 238 239 ipose(__filbuf) 240 ipose(__flsbuf) 241 ipose(_dgettext) 242 ipose(_exit) 243 ipose(access) 244 ipose(atexit) 245 ipose(atoi) 246 ipose(cfgetospeed) 247 ipose(chdir) 248 ipose(close) 249 ipose(dlclose) 250 ipose(dlerror) 251 ipose(dlopen) 252 ipose(dlsym) 253 ipose(exit) 254 ipose(exit_handler) 255 ipose(fclose) 256 ipose(fflush) 257 ipose(fgetc) 258 ipose(fileno) 259 ipose(fopen) 260 ipose(fprintf) 261 ipose(fputc) 262 ipose(fputs) 263 ipose(fread) 264 ipose(free) 265 ipose(fseek) 266 ipose(fstat) 267 ipose(ftell) 268 ipose(fwrite) 269 ipose(getcwd) 270 ipose(getenv) 271 ipose(getopt) 272 ipose(getwd) 273 ipose(ioctl) 274 ipose(isatty) 275 ipose(kill) 276 ipose(localtime) 277 ipose(lseek) 278 ipose(malloc) 279 ipose(memcpy) 280 ipose(memset) 281 ipose(open) 282 ipose(perror) 283 ipose(printf) 284 ipose(psignal) 285 ipose(putchar) 286 ipose(read) 287 ipose(sbrk) 288 ipose(signal) 289 ipose(sigset) 290 ipose(snprintf) 291 ipose(sprintf) 292 ipose(stat) 293 ipose(strcat) 294 ipose(strchr) 295 ipose(strcmp) 296 ipose(strcpy) 297 ipose(strdup) 298 ipose(strlen) 299 ipose(strncmp) 300 ipose(strncpy) 301 ipose(strrchr) 302 ipose(system) 303 ipose(tcgetattr) 304 ipose(tcsetattr) 305 ipose(tgetent) 306 ipose(tgetflag) 307 ipose(tgetnum) 308 ipose(tgetstr) 309 ipose(tgoto) 310 ipose(time) 311 ipose(tputs) 312 ipose(tzset) 313 ipose(ungetc) 314 ipose(unlink) 315 ipose(write) 316