|
From: Brenda L. <asp...@us...> - 2003-05-12 07:26:32
|
Update of /cvsroot/squeak/squeak/platforms/unix/vm In directory sc8-pr-cvs1:/tmp/cvs-serv30143/vm Added Files: Makefile.in aio.c aio.h dlfcn-dyld.c Log Message: Ian Piumarta's release 3.4.1 --- NEW FILE: Makefile.in --- # Makefile for core VM -*- makefile -*- # # Copyright (C) 1996-2002 Ian Piumarta and other authors/contributors # as listed elsewhere in this file. # All rights reserved. # # This file is part of Unix Squeak. # # This file is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. # # You may use and/or distribute this file ONLY as part of Squeak, under # the terms of the Squeak License as described in `LICENSE' in the base of # this distribution, subject to the following restrictions: # # 1. The origin of this software must not be misrepresented; you must not # claim that you wrote the original software. If you use this software # in a product, an acknowledgment to the original author(s) (and any # other contributors mentioned herein) in the product documentation # would be appreciated but is not required. # # 2. This notice must not be removed or altered in any source distribution. # # Using (or modifying this file for use) in any context other than Squeak # changes these copyright conditions. Read the file `COPYING' in the # directory `platforms/unix/doc' before proceeding with any such use. # # You are not allowed to distribute a modified version of this file # under its original name without explicit permission to do so. If # you change it, rename it. # # Author: ian...@in... # # Last edited: 2002-12-01 10:20:57 by piumarta on calvin.inria.fr [make_cfg] [make_plg] TARGET = vm$a OBJS = $(INTERP)$o sqNamedPrims$o sqVirtualMachine$o \ aio$o osExports$o sqUnixExternalPrims$o sqUnixMozilla$o sqXWindow$o XINCLUDES = [includes] -I$(topdir)/platforms/Cross/plugins/FilePlugin $(TARGET) : $(OBJS) Makefile $(LINK) $(TARGET) $(OBJS) $(RANLIB) $(TARGET) # rebuild sqNamedPrims.o if sqNamedPrims.h changes sqNamedPrims$o : $(srcdir)/vm/sqNamedPrims.h # rebuild sqExtPrims (VM_LIBDIR) sqXWin (VM_VERSION) if config.h changes sqUnixExternalPrims$o sqXWindow$o : ../config.h $(topdir)/platforms/unix/vm/dlfcn-dyld.c # GNUify the interpreter if needed gnu-interp$o : gnu-interp.c $(COMPILE) $@ gnu-interp.c gnu-interp.c : $(srcdir)/vm/interp.c $(AWK) -f $(topdir)/platforms/unix/config/gnuify $(srcdir)/vm/interp.c > $@.out mv $@.out $@ [make_targets] .force : --- NEW FILE: aio.c --- /* aio.c -- asynchronous file i/o * * Copyright (C) 1996-2002 Ian Piumarta and other authors/contributors * as listed elsewhere in this file. * All rights reserved. * * This file is part of Unix Squeak. * * This file is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. * * You may use and/or distribute this file ONLY as part of Squeak, under * the terms of the Squeak License as described in `LICENSE' in the base of * this distribution, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment to the original author(s) (and any * other contributors mentioned herein) in the product documentation * would be appreciated but is not required. * * 2. This notice must not be removed or altered in any source distribution. * * Using (or modifying this file for use) in any context other than Squeak * changes these copyright conditions. Read the file `COPYING' in the * directory `platforms/unix/doc' before proceeding with any such use. * * You are not allowed to distribute a modified version of this file * under its original name without explicit permission to do so. If * you change it, rename it. */ /* Author: Ian...@in... * * Last edited: 2003-02-06 16:36:13 by piumarta on emilia.local. */ #include "aio.h" #ifdef HAVE_CONFIG_H # include "config.h" # ifdef HAVE_UNISTD_H # include <sys/types.h> # include <unistd.h> # endif /* HAVE_UNISTD_H */ # ifdef NEED_GETHOSTNAME_P extern int gethostname(); # endif # include <stdio.h> # include <signal.h> # include <errno.h> # include <sys/ioctl.h> # ifdef HAVE_SYS_TIME_H # include <sys/time.h> # else # include <time.h> # endif # ifdef HAS_SYS_SELECT_H # include <sys/select.h> # endif # ifndef FIONBIO # ifdef HAVE_SYS_FILIO_H # include <sys/filio.h> # endif # ifndef FIONBIO # ifdef FIOSNBIO # define FIONBIO FIOSNBIO # else # error: FIONBIO is not defined # endif # endif # endif #else /* !HAVE_CONFIG_H -- assume lowest common demoninator */ # include <stdio.h> # include <stdlib.h> # include <unistd.h> # include <errno.h> # include <signal.h> # include <sys/types.h> # include <sys/time.h> # include <sys/select.h> # include <sys/ioctl.h> #endif #undef DEBUG #ifdef DEBUG # define FPRINTF(X) fprintf X static char *ticks= "-\\|/"; static char *ticker= ""; #define DO_TICK() \ { \ fprintf(stderr, "\r%c\r", *ticker); \ if (!*ticker++) ticker= ticks; \ } #else /* !DEBUG */ # define FPRINTF(X) # define DO_TICK() #endif #define _DO_FLAG_TYPE() _DO(AIO_R, rd) _DO(AIO_W, wr) _DO(AIO_X, ex) static int one= 1; static aioHandler rdHandler[FD_SETSIZE]; static aioHandler wrHandler[FD_SETSIZE]; static aioHandler exHandler[FD_SETSIZE]; static void *clientData[FD_SETSIZE]; static int maxFd; static fd_set fdMask; /* handled by aio */ static fd_set rdMask; /* handle read */ static fd_set wrMask; /* handle write */ static fd_set exMask; /* handle exception */ static fd_set xdMask; /* external descriptor */ static void undefinedHandler(int fd, void *clientData, int flags) { fprintf(stderr, "undefined handler called (fd %d, flags %x)\n", fd, flags); } #ifdef DEBUG static char *handlerName(aioHandler h) { if (h == undefinedHandler) return "undefinedHandler"; #ifdef DEBUG_SOCKETS { extern char *socketHandlerName(aioHandler); return socketHandlerName(h); } #endif return "***unknown***"; } #endif /* initialise asynchronous i/o */ void aioInit(void) { FD_ZERO(&fdMask); FD_ZERO(&rdMask); FD_ZERO(&wrMask); FD_ZERO(&exMask); FD_ZERO(&xdMask); maxFd= 0; signal(SIGPIPE, SIG_IGN); } /* disable handlers and close all handled non-exteral descriptors */ void aioFini(void) { int fd; for (fd= 0; fd < maxFd; fd++) if (FD_ISSET(fd, &fdMask) && !(FD_ISSET(fd, &xdMask))) { aioDisable(fd); close(fd); FD_CLR(fd, &fdMask); FD_CLR(fd, &rdMask); FD_CLR(fd, &wrMask); FD_CLR(fd, &exMask); } while (maxFd && !FD_ISSET(maxFd - 1, &fdMask)) --maxFd; signal(SIGPIPE, SIG_DFL); } /* poll for i/o activity, with microSeconds wait */ int aioPoll(int microSeconds) { int fd; fd_set rd, wr, ex; struct timeval tv; DO_TICK(); /* get out early if there is no pending i/o and no need to relinquish cpu */ if ((maxFd == 0) && (microSeconds == 0)) return 0; rd= rdMask; wr= wrMask; ex= exMask; tv.tv_sec= microSeconds / 1000000; tv.tv_usec= microSeconds % 1000000; { int result; do { result= select(maxFd, &rd, &wr, &ex, &tv); } while ((result < 0) && (errno == EINTR)); if (result < 0) perror("select"); else if (result > 0) { for (fd= 0; fd < maxFd; ++fd) { # define _DO(FLAG, TYPE) \ { \ if (FD_ISSET(fd, &TYPE)) \ { \ aioHandler handler= TYPE##Handler[fd]; \ FD_CLR(fd, &TYPE##Mask); \ TYPE##Handler[fd]= undefinedHandler; \ handler(fd, clientData[fd], FLAG); \ } \ } _DO_FLAG_TYPE(); # undef _DO } } } return 0; } /* enable asynchronous notification for a descriptor */ void aioEnable(int fd, void *data, int flags) { FPRINTF((stderr, "aioEnable(%d)\n", fd)); if (FD_ISSET(fd, &fdMask)) { fprintf(stderr, "aioEnable: descriptor %d already enabled\n", fd); return; } clientData[fd]= data; rdHandler[fd]= wrHandler[fd]= exHandler[fd]= undefinedHandler; FD_SET(fd, &fdMask); FD_CLR(fd, &rdMask); FD_CLR(fd, &wrMask); FD_CLR(fd, &exMask); if (fd >= maxFd) maxFd= fd + 1; if (flags & AIO_EXT) { FD_SET(fd, &xdMask); /* we should not set NBIO ourselves on external descriptors! */ } else { FD_CLR(fd, &xdMask); if (ioctl(fd, FIONBIO, (char *)&one) < 0) perror("ioctl(FIONBIO, 1)"); } } /* install/change the handler for a descriptor */ void aioHandle(int fd, aioHandler handlerFn, int mask) { FPRINTF((stderr, "aioHandle(%d, %s, %d)\n", fd, handlerName(handlerFn), mask)); # define _DO(FLAG, TYPE) \ if (mask & FLAG) { \ FD_SET(fd, &TYPE##Mask); \ TYPE##Handler[fd]= handlerFn; \ } _DO_FLAG_TYPE(); # undef _DO } /* temporarily suspend asynchronous notification for a descriptor */ void aioSuspend(int fd, int mask) { FPRINTF((stderr, "aioSuspend(%d)\n", fd)); # define _DO(FLAG, TYPE) \ { \ if (mask & FLAG) \ { \ FD_CLR(fd, &TYPE##Mask); \ TYPE##Handler[fd]= undefinedHandler; \ } \ } _DO_FLAG_TYPE(); # undef _DO } /* definitively disable asynchronous notification for a descriptor */ void aioDisable(int fd) { FPRINTF((stderr, "aioDisable(%d)\n", fd)); aioSuspend(fd, AIO_RWX); FD_CLR(fd, &xdMask); FD_CLR(fd, &fdMask); rdHandler[fd]= wrHandler[fd]= exHandler[fd]= 0; clientData[fd]= 0; /* keep maxFd accurate (drops to zero if no more sockets) */ while (maxFd && !FD_ISSET(maxFd - 1, &fdMask)) --maxFd; } --- NEW FILE: aio.h --- /* aio.h -- asynchronous file i/o * * Copyright (C) 1996-2002 Ian Piumarta and other authors/contributors * as listed elsewhere in this file. * All rights reserved. * * This file is part of Unix Squeak. * * This file is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. * * You may use and/or distribute this file ONLY as part of Squeak, under * the terms of the Squeak License as described in `LICENSE' in the base of * this distribution, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment to the original author(s) (and any * other contributors mentioned herein) in the product documentation * would be appreciated but is not required. * * 2. This notice must not be removed or altered in any source distribution. * * Using (or modifying this file for use) in any context other than Squeak * changes these copyright conditions. Read the file `COPYING' in the * directory `platforms/unix/doc' before proceeding with any such use. * * You are not allowed to distribute a modified version of this file * under its original name without explicit permission to do so. If * you change it, rename it. */ /* author: ian...@in... * * last edited: 2003-02-06 16:34:35 by piumarta on emilia.local. */ #ifndef __aio_h #define __aio_h #define AIO_X (1<<0) /* handle for exceptions */ #define AIO_R (1<<1) /* handle for read */ #define AIO_W (1<<2) /* handle for write */ #define AIO_SEQ (1<<3) /* call handlers sequentially */ #define AIO_EXT (1<<4) /* external fd -- don't close on aio shutdown */ #define AIO_RW (AIO_R | AIO_W) #define AIO_RX (AIO_R | AIO_X) #define AIO_WX (AIO_W | AIO_X) #define AIO_RWX (AIO_R | AIO_W | AIO_X) extern void aioInit(void); extern void aioFini(void); /* Initialise `fd' for handling by AIO. `flags' can be 0 (aio takes * over the descriptor entirely and the application should not assume * anything about its subsequent behaviour) or AIO_EXT (aio will never * set NBIO on `fd' or close it on behalf of the client). */ extern void aioEnable(int fd, void *clientData, int flags); /* Declare an interest in one or more events on `fd'. `mask' can be * any combination in AIO_[R][W][X]. `handlerFn' will be called the * next time any event in `mask' arrives on `fd' and will receive * `fd', the original `clientData' (see aioEnable) and a `flag' * containing ONE of AIO_{R,W,X} indicating which event occurred. In * the event that the same handler is set for multiple events (either * by setting more than one bit in `mask', or by calling aioHandle * several times with different `mask's) and several events arrive * simultaneously for the descriptor, then `handlerFn' is called * multiple times -- once for each event in `mask'. The `handlerFn' * will NOT be called again for the same event until the client calls * aioHandle with an appropriate `mask' (the handled event is removed * implicitly from the current mask before calling `handlerFn') . * (Calls to aioHandle are cumulative: successive `mask's are ORed * with the mask currently in effect for `fd'.) */ typedef void (*aioHandler)(int fd, void *clientData, int flag); extern void aioHandle(int fd, aioHandler handlerFn, int mask); /* Suspend handling of the events in `mask' for `fd'. */ extern void aioSuspend(int fd, int mask); /* Disable further AIO handling of `fd'. The descriptor is reset to its * default state (w.r.t. NBIO, etc.) but is NOT closed. */ extern void aioDisable(int fd); /* Sleep for at most `microSeconds'. Any event(s) arriving for any * handled fd(s) will terminate the sleep, with the appropriate * handler(s) being called before returning. */ extern int aioPoll(int microSeconds); #endif /* __aio_h */ --- NEW FILE: dlfcn-dyld.c --- /* dlfcn-darwin.c -- provides dlopen() and friends as wrappers to Mach's dylib * * Author: Ian...@IN... * * Copyright (C) 1996-2002 Ian Piumarta and other authors/contributors * as listed elsewhere in this file. * All rights reserved. * * This file is part of Unix Squeak. * * This file is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. * * You may use and/or distribute this file ONLY as part of Squeak, under * the terms of the Squeak License as described in `LICENSE' in the base of * this distribution, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment to the original author(s) (and any * other contributors mentioned herein) in the product documentation * would be appreciated but is not required. * * 2. This notice must not be removed or altered in any source distribution. * * Using (or modifying this file for use) in any context other than Squeak * changes these copyright conditions. Read the file `COPYING' in the * directory `platforms/unix/doc' before proceeding with any such use. * * You are not allowed to distribute a modified version of this file * under its original name without explicit permission to do so. If * you change it, rename it. * * Last edited: 2002-12-01 10:28:43 by piumarta on calvin.inria.fr */ #include <stdio.h> #include <stdarg.h> #include <mach-o/dyld.h> #define RTLD_NOW 0 #define RTLD_GLOBAL 0 #define DL_APP_CONTEXT ((void *)-1) static char dlErrorString[256]; static int dlErrorSet= 0; static void dlSetError(const char *fmt, ...) { va_list ap; va_start(ap, fmt); vsnprintf(dlErrorString, sizeof(dlErrorString), fmt, ap); va_end(ap); dlErrorSet= 1; } static const char *dlerror(void) { if (dlErrorSet) { dlErrorSet= 0; return (const char *)dlErrorString; } return 0; } static void *dlopen(const char *path, int mode) { void *handle= 0; NSObjectFileImage ofi= 0; if (!path) return DL_APP_CONTEXT; switch (NSCreateObjectFileImageFromFile(path, &ofi)) { case NSObjectFileImageSuccess: handle= NSLinkModule(ofi, path, NSLINKMODULE_OPTION_RETURN_ON_ERROR); NSDestroyObjectFileImage(ofi); break; case NSObjectFileImageInappropriateFile: handle= (void *)NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR); break; default: handle= 0; break; } if (!handle) dlSetError("could not load shared object: %s", path); return handle; } void *dlsym(void *handle, const char *symbol) { char _symbol[256]; NSSymbol *nsSymbol= 0; snprintf(_symbol, sizeof(_symbol), "_%s", symbol); dprintf((stderr, "dlsym: looking for %s (%s) in %d\n", symbol, _symbol, (int)handle)); if (!handle) { dprintf((stderr, "dlsym: setting app context for this handle\n")); handle= DL_APP_CONTEXT; } if (DL_APP_CONTEXT == handle) { dprintf((stderr, "dlsym: looking in app context\n")); if (NSIsSymbolNameDefined(_symbol)) nsSymbol= NSLookupAndBindSymbol(_symbol); } else { if (( (MH_MAGIC == ((struct mach_header *)handle)->magic)) /* ppc */ || (MH_CIGAM == ((struct mach_header *)handle)->magic)) /* 386 */ { if (NSIsSymbolNameDefinedInImage((struct mach_header *)handle, _symbol)) nsSymbol= NSLookupSymbolInImage ((struct mach_header *)handle, _symbol, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); dprintf((stderr, "dlsym: bundle (image) lookup returned %p\n", nsSymbol)); } else { nsSymbol= NSLookupSymbolInModule(handle, _symbol); dprintf((stderr, "dlsym: dylib (module) lookup returned %p\n", nsSymbol)); } } if (!nsSymbol) { dlSetError("symbol not found: %s", _symbol); return 0; } return NSAddressOfSymbol(nsSymbol); } int dlclose(void *handle) { if (( (MH_MAGIC == ((struct mach_header *)handle)->magic)) /* ppc */ || (MH_CIGAM == ((struct mach_header *)handle)->magic)) /* 386 */ return 0; /* can't unlink, but pretend we did */ if (!NSUnLinkModule(handle, 0)) { dlSetError("could not unlink shared object: %s", NSNameOfModule(handle)); return -1; } return 0; } /* autoconf has bugs */ #ifdef HAVE_DLFCN_H # undef HAVE_DLFCN_H #endif #ifndef HAVE_LIBDL # define HAVE_LIBDL #endif |