1/* 2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#ifndef _MACHO_KLD_H_ 25#define _MACHO_KLD_H_ 26 27#include <mach-o/loader.h> 28#include <stdarg.h> 29 30/* 31 * These API's are in libkld. Both kextload(8) and /mach_kernel should 32 * link with -lkld and then ld(1) will expand -lkld to libkld.dylib or 33 * libkld.a depending on if -dynamic or -static is in effect. 34 * 35 * Note: we are using the __DYNAMIC__ flag to indicate user space kernel 36 * linking and __STATIC__ as a synonym of KERNEL. 37 */ 38 39/* 40 * Note that you must supply the following function for error reporting when 41 * using any of the functions listed here. 42 */ 43extern void kld_error_vprintf(const char *format, va_list ap); 44 45/* 46 * These two are only in libkld.dylib for use by kextload(8) (user code compiled 47 * with the default -dynamic). 48 */ 49#ifdef __DYNAMIC__ 50extern long kld_load_basefile( 51 const char *base_filename); 52 53/* Note: this takes only one object file name */ 54extern long kld_load( 55 struct mach_header **header_addr, 56 const char *object_filename, 57 const char *output_filename); 58 59extern long kld_load_from_memory( 60 struct mach_header **header_addr, 61 const char *object_name, 62 char *object_addr, 63 long object_size, 64 const char *output_filename); 65#endif /* __DYNAMIC__ */ 66 67/* 68 * This one is only in libkld.a use by /mach_kernel (kernel code compiled with 69 * -static). 70 */ 71#ifdef __STATIC__ 72/* Note: this api does not write an output file */ 73extern long kld_load_from_memory( 74 struct mach_header **header_addr, 75 const char *object_name, 76 char *object_addr, 77 long object_size); 78#endif /* __STATIC__ */ 79 80extern long kld_load_basefile_from_memory( 81 const char *base_filename, 82 char *base_addr, 83 long base_size); 84 85extern long kld_unload_all( 86 long deallocate_sets); 87 88extern long kld_lookup( 89 const char *symbol_name, 90 unsigned long *value); 91 92extern long kld_forget_symbol( 93 const char *symbol_name); 94 95extern void kld_address_func( 96 unsigned long (*func)(unsigned long size, unsigned long headers_size)); 97 98#define KLD_STRIP_ALL 0x00000000 99#define KLD_STRIP_NONE 0x00000001 100 101extern void kld_set_link_options( 102 unsigned long link_options); 103 104#endif /* _MACHO_KLD_H_ */ 105