1be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner/* 2be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * Copyright (C) 2010 The Android Open Source Project 3be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * All rights reserved. 4be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * 5be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * Redistribution and use in source and binary forms, with or without 6be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * modification, are permitted provided that the following conditions 7be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * are met: 8be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * * Redistributions of source code must retain the above copyright 9be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * notice, this list of conditions and the following disclaimer. 10be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * * Redistributions in binary form must reproduce the above copyright 11be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * notice, this list of conditions and the following disclaimer in 12be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * the documentation and/or other materials provided with the 13be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * distribution. 14be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * 15be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * SUCH DAMAGE. 27be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner */ 28be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner#ifndef LINKER_ENVIRON_H 29be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner#define LINKER_ENVIRON_H 30be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner 314688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes#ifdef __cplusplus 324688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughesextern "C" { 334688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes#endif 344688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes 35be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner/* Call this function before anything else. 'vecs' must be the pointer 36be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * to the environment block in the ELF data block. The function returns 37be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * the start of the aux vectors after the env block. 38be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner */ 39be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turnerextern unsigned* linker_env_init(unsigned* vecs); 40be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner 41be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner/* Unset a given environment variable. In case the variable is defined 42be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * multiple times, unset all instances. This modifies the environment 43be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * block, so any pointer returned by linker_env_get() after this call 44be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * might become invalid */ 45be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turnerextern void linker_env_unset(const char* name); 46be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner 47be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner 48be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner/* Returns the value of environment variable 'name' if defined and not 49be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * empty, or NULL otherwise. Note that the returned pointer may become 50be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * invalid if linker_env_unset() or linker_env_secure() are called 51be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * after this function. */ 52be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turnerextern const char* linker_env_get(const char* name); 53be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner 544688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes/* Remove insecure environment variables. This should be used when 55be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner * running setuid programs. */ 56be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turnerextern void linker_env_secure(void); 57be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner 584688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes#ifdef __cplusplus 594688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes}; 604688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes#endif 614688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes 62be5755969d70668bbab0e0c0ed75ebd867189723David 'Digit' Turner#endif /* LINKER_ENVIRON_H */ 63