ibcs2_util.h revision 141488
1139799Simp/*- 211394Sswallace * Copyright (c) 1994 Christos Zoulas 311394Sswallace * Copyright (c) 1995 Frank van der Linden 411394Sswallace * Copyright (c) 1995 Scott Bartram 511394Sswallace * All rights reserved. 611394Sswallace * 711394Sswallace * Redistribution and use in source and binary forms, with or without 811394Sswallace * modification, are permitted provided that the following conditions 911394Sswallace * are met: 1011394Sswallace * 1. Redistributions of source code must retain the above copyright 1111394Sswallace * notice, this list of conditions and the following disclaimer. 1211394Sswallace * 2. Redistributions in binary form must reproduce the above copyright 1311394Sswallace * notice, this list of conditions and the following disclaimer in the 1411394Sswallace * documentation and/or other materials provided with the distribution. 1511394Sswallace * 3. The name of the author may not be used to endorse or promote products 1611394Sswallace * derived from this software without specific prior written permission 1711394Sswallace * 1811394Sswallace * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1911394Sswallace * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2011394Sswallace * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2111394Sswallace * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2211394Sswallace * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2311394Sswallace * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2411394Sswallace * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2511394Sswallace * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2611394Sswallace * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2711394Sswallace * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2811394Sswallace * 2911394Sswallace * from: svr4_util.h,v 1.5 1994/11/18 02:54:31 christos Exp 3011394Sswallace * from: linux_util.h,v 1.2 1995/03/05 23:23:50 fvdl Exp 3183366Sjulian * 3283366Sjulian * $FreeBSD: head/sys/i386/ibcs2/ibcs2_util.h 141488 2005-02-07 22:02:18Z jhb $ 3311394Sswallace */ 3411394Sswallace 3511394Sswallace/* 3611394Sswallace * This file is pretty much the same as Christos' svr4_util.h 3711394Sswallace * (for now). 3811394Sswallace */ 3911394Sswallace 4011394Sswallace#ifndef _IBCS2_UTIL_H_ 4111394Sswallace#define _IBCS2_UTIL_H_ 4211394Sswallace 4328750Sbde/* 4428750Sbde * XXX the inlines have obnoxious prerequisites, only some of which are 4528750Sbde * included here. 4628750Sbde */ 4711397Sswallace#include <vm/vm.h> 4812662Sdg#include <vm/pmap.h> 4911394Sswallace#include <machine/vmparam.h> 5011394Sswallace#include <sys/exec.h> 5114331Speter#include <sys/sysent.h> 5214331Speter#include <sys/proc.h> 53141488Sjhb#include <sys/uio.h> 5411394Sswallace 5511397Sswallacestatic __inline caddr_t stackgap_init(void); 5611397Sswallacestatic __inline void *stackgap_alloc(caddr_t *, size_t); 5711397Sswallace 5811394Sswallacestatic __inline caddr_t 5911394Sswallacestackgap_init() 6011394Sswallace{ 6183366Sjulian#define szsigcode (*(curthread->td_proc->p_sysent->sv_szsigcode)) 6241871Sbde return (caddr_t)(PS_STRINGS - szsigcode - SPARE_USRSPACE); 6311394Sswallace} 6411394Sswallace 6511394Sswallacestatic __inline void * 6611394Sswallacestackgap_alloc(sgp, sz) 6711394Sswallace caddr_t *sgp; 6811394Sswallace size_t sz; 6911394Sswallace{ 7011394Sswallace void *p = (void *) *sgp; 71121016Stjr sz = ALIGN(sz); 72121016Stjr if (*sgp + sz > (caddr_t)(PS_STRINGS - szsigcode)) 73121016Stjr return NULL; 74121016Stjr *sgp += sz; 7511394Sswallace return p; 7611394Sswallace} 7711394Sswallace 7811394Sswallace#ifdef DEBUG_IBCS2 7911394Sswallace#define DPRINTF(a) printf a; 8011394Sswallace#else 8111394Sswallace#define DPRINTF(a) 8211394Sswallace#endif 8311394Sswallace 8411394Sswallaceextern const char ibcs2_emul_path[]; 8511394Sswallace 86141488Sjhbint ibcs2_emul_find(struct thread *, char *, enum uio_seg, char **, int); 8711394Sswallace 88141488Sjhb#define CHECKALT(td, upath, pathp, i) \ 89141488Sjhb do { \ 90141488Sjhb int _error; \ 91141488Sjhb \ 92141488Sjhb _error = ibcs2_emul_find(td, upath, UIO_USERSPACE, pathp, i); \ 93141488Sjhb if (*(pathp) == NULL) \ 94141488Sjhb return (_error); \ 95141488Sjhb } while (0) 9611394Sswallace 97141488Sjhb#define CHECKALTEXIST(td, upath, pathp) CHECKALT(td, upath, pathp, 0) 98141488Sjhb#define CHECKALTCREAT(td, upath, pathp) CHECKALT(td, upath, pathp, 1) 9911394Sswallace 10020652Sbde#ifdef SPX_HACK 101141488Sjhbint spx_open(struct thread *td); 10220652Sbde#endif 10320652Sbde 10411394Sswallace#endif /* !_IBCS2_UTIL_H_ */ 105