|
| 1 | +/* |
| 2 | + dldi.h |
| 3 | +
|
| 4 | + Copyright (c) 2006 Michael "Chishm" Chisholm |
| 5 | +
|
| 6 | + Redistribution and use in source and binary forms, with or without modification, |
| 7 | + are permitted provided that the following conditions are met: |
| 8 | +
|
| 9 | + 1. Redistributions of source code must retain the above copyright notice, |
| 10 | + this list of conditions and the following disclaimer. |
| 11 | + 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | + this list of conditions and the following disclaimer in the documentation and/or |
| 13 | + other materials provided with the distribution. |
| 14 | + 3. The name of the author may not be used to endorse or promote products derived |
| 15 | + from this software without specific prior written permission. |
| 16 | +
|
| 17 | + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 18 | + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
| 19 | + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE |
| 20 | + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 25 | + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | +*/ |
| 27 | + |
| 28 | +#pragma once |
| 29 | + |
| 30 | +#ifdef __cplusplus |
| 31 | +extern "C" { |
| 32 | +#endif |
| 33 | + |
| 34 | +#include <calico/dev/disc_io.h> |
| 35 | +#include <calico/dev/dldi.h> |
| 36 | + |
| 37 | +typedef DldiHeader DLDI_INTERFACE; |
| 38 | + |
| 39 | +/// Determine if a given DLDI driver structure is valid |
| 40 | +bool dldiIsValid(const DLDI_INTERFACE* io); |
| 41 | + |
| 42 | +/// Find a DLDI driver area within a given binary |
| 43 | +DLDI_INTERFACE* dldiFindDriverArea(void* bin, size_t bin_size); |
| 44 | + |
| 45 | +/// Adjust the pointer addresses within a DLDI driver for the target virtual address |
| 46 | +void dldiFixDriverAddresses(DLDI_INTERFACE* io, uptr dldi_vaddr); |
| 47 | + |
| 48 | +/// Patch a DLDI driver into a given area |
| 49 | +bool dldiApplyPatch(DLDI_INTERFACE* area, const DLDI_INTERFACE* io); |
| 50 | + |
| 51 | +/// Patch a binary using a given DLDI driver |
| 52 | +MK_INLINE bool dldiPatchBinary(void* bin, size_t bin_size, const DLDI_INTERFACE* io) |
| 53 | +{ |
| 54 | + DLDI_INTERFACE* area = dldiFindDriverArea(bin, bin_size); |
| 55 | + return area ? dldiApplyPatch(area, io) : false; |
| 56 | +} |
| 57 | + |
| 58 | +#ifdef __cplusplus |
| 59 | +} |
| 60 | +#endif |
0 commit comments