os.c revision 059f354a6b7b116e4469ff7fe99c1142affa0ad6
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny/* ====================================================================
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * The Apache Software License, Version 1.1
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Copyright (c) 2000 The Apache Software Foundation. All rights
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * reserved.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Redistribution and use in source and binary forms, with or without
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * modification, are permitted provided that the following conditions
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * are met:
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * 1. Redistributions of source code must retain the above copyright
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * notice, this list of conditions and the following disclaimer.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * 2. Redistributions in binary form must reproduce the above copyright
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * notice, this list of conditions and the following disclaimer in
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * the documentation and/or other materials provided with the
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * distribution.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * 3. The end-user documentation included with the redistribution,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * if any, must include the following acknowledgment:
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * "This product includes software developed by the
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Apache Software Foundation (http://www.apache.org/)."
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Alternately, this acknowledgment may appear in the software itself,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * if and wherever such third-party acknowledgments normally appear.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * 4. The names "Apache" and "Apache Software Foundation" must
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * not be used to endorse or promote products derived from this
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * software without prior written permission. For written
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * permission, please contact apache@apache.org.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * 5. Products derived from this software may not be called "Apache",
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * nor may "Apache" appear in their name, without prior written
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * permission of the Apache Software Foundation.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek *
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * SUCH DAMAGE.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * ====================================================================
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * This software consists of voluntary contributions made by many
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * individuals on behalf of the Apache Software Foundation. For more
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * information on the Apache Software Foundation, please see
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * <http://www.apache.org/>.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Portions of this software are based upon public domain software
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * originally written at the National Center for Supercomputing Applications,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * University of Illinois, Urbana-Champaign.
bdbf4f169e4d5d00b0616df19f7a55debb407f78Pavel Březina */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny/*
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * This file will include OS specific functions which are not inlineable.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * Any inlineable functions should be defined in os-inline.c instead.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "ap_config.h"
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "os.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenyint ap_os_is_path_absolute(const char *file)
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek{
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return file[0] == '/';
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny/* some linkers complain unless there's at least one function in each
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * .o file... and extra prototype is for gcc -Wmissing-prototypes
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekextern void ap_is_not_here(void);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekvoid ap_is_not_here(void) {}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny/*
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Abstraction layer for loading
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Apache modules under run-time via
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * dynamic shared object (DSO) mechanism
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenyvoid ap_os_dso_init(void)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /* Nothing required to be done! */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenyvoid* ap_os_dso_load(const char *path)
b668c77874c6fed325471bdcf5954979a0d734e2Stef Walter{
b668c77874c6fed325471bdcf5954979a0d734e2Stef Walter return (void*) load_add_on(path);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenyvoid ap_os_dso_unload(void* handle)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny unload_add_on((image_id)handle);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
ef2455b63380ecd17bea94270ceaabe15dcf6456Jakub Hrozek
ef2455b63380ecd17bea94270ceaabe15dcf6456Jakub Hrozekvoid *ap_os_dso_sym(void *handle, const char *symname)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny void * retval = 0;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#if defined(DLSYM_NEEDS_UNDERSCORE)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny char *symbol = (char*)malloc(sizeof(char)*(strlen(symname)+2));
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny sprintf(symbol, "_%s", symname);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny get_image_symbol((image_id)handle, symbol, B_SYMBOL_TYPE_ANY, (void **)&retval);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny free(symbol);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return retval;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#endif
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov get_image_symbol((image_id)handle, symname, B_SYMBOL_TYPE_ANY, (void **)&retval);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return retval;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenyconst char *ap_os_dso_error(void)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return NULL;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek