svr4_util.h revision 150663
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1998 Mark Newton 31556Srgrimes * Copyright (c) 1994 Christos Zoulas 41556Srgrimes * All rights reserved. 51556Srgrimes * 61556Srgrimes * Redistribution and use in source and binary forms, with or without 71556Srgrimes * modification, are permitted provided that the following conditions 81556Srgrimes * are met: 91556Srgrimes * 1. Redistributions of source code must retain the above copyright 101556Srgrimes * notice, this list of conditions and the following disclaimer. 111556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 121556Srgrimes * notice, this list of conditions and the following disclaimer in the 131556Srgrimes * documentation and/or other materials provided with the distribution. 141556Srgrimes * 3. The name of the author may not be used to endorse or promote products 151556Srgrimes * derived from this software without specific prior written permission 161556Srgrimes * 171556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 181556Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 191556Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 201556Srgrimes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 211556Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 221556Srgrimes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231556Srgrimes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241556Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251556Srgrimes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 261556Srgrimes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271556Srgrimes * 281556Srgrimes * $FreeBSD: head/sys/compat/svr4/svr4_util.h 150663 2005-09-28 07:03:03Z rwatson $ 291556Srgrimes */ 301556Srgrimes 311556Srgrimes#ifndef _SVR4_UTIL_H_ 3217987Speter#define _SVR4_UTIL_H_ 3350471Speter 341556Srgrimes/*#include <compat/common/compat_util.h>*/ 351556Srgrimes#include <vm/vm.h> 361556Srgrimes#include <vm/vm_param.h> 371556Srgrimes#include <vm/pmap.h> 3817987Speter#include <machine/vmparam.h> 39215303Sjilles#include <sys/exec.h> 4017987Speter#include <sys/sysent.h> 411556Srgrimes#include <sys/cdefs.h> 421556Srgrimes#include <sys/uio.h> 431556Srgrimes 441556Srgrimes#ifdef DEBUG_SVR4 451556Srgrimes#define DPRINTF(a) uprintf a; 461556Srgrimes#else 471556Srgrimes#define DPRINTF(a) 481556Srgrimes#endif 491556Srgrimes 50201366Sjilles 51201366Sjillesstatic __inline caddr_t stackgap_init(void); 521556Srgrimesstatic __inline void *stackgap_alloc(caddr_t *, size_t); 53201366Sjilles 54201366Sjillesstatic __inline caddr_t 55201366Sjillesstackgap_init() 561556Srgrimes{ 57215567Sjilles#define szsigcode (*(curthread->td_proc->p_sysent->sv_szsigcode)) 5890111Simp return (caddr_t)(((caddr_t)PS_STRINGS) - szsigcode - SPARE_USRSPACE); 5997817Stjr} 6090111Simp 6197817Stjrstatic __inline void * 6290111Simpstackgap_alloc(sgp, sz) 6397817Stjr caddr_t *sgp; 64215303Sjilles size_t sz; 6590111Simp{ 6690111Simp void *p = (void *) *sgp; 6790111Simp sz = ALIGN(sz); 6890111Simp if (*sgp + sz > (caddr_t)(PS_STRINGS - szsigcode)) 69244162Sjilles return NULL; 70244162Sjilles *sgp += sz; 7190111Simp return p; 7290111Simp} 73199629Sjilles 7490111Simpint svr4_emul_find(struct thread *, char *, enum uio_seg, char **, int); 7590111Simp 76200956Sjilles#define CHECKALT(td, upath, pathp, i) \ 771556Srgrimes do { \ 781556Srgrimes int _error; \ 791556Srgrimes \ 80215567Sjilles _error = svr4_emul_find(td, upath, UIO_USERSPACE, pathp, i); \ 811556Srgrimes if (*(pathp) == NULL) \ 821556Srgrimes return (_error); \ 831556Srgrimes } while (0) 84 85#define CHECKALTEXIST(td, upath, pathp) CHECKALT(td, upath, pathp, 0) 86#define CHECKALTCREAT(td, upath, pathp) CHECKALT(td, upath, pathp, 1) 87 88#endif /* !_SVR4_UTIL_H_ */ 89