Changeset 81 for trunk/kLdr/kLdrMod.c


Ignore:
Timestamp:
Aug 19, 2016, 12:10:38 AM (9 years ago)
Author:
bird
Message:

kLdr: some refactoring and fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdrMod.c

    r79 r81  
    736736
    737737/**
    738  * Allocates Thread Local Storage for module mapped by kLdrModMap().
    739  *
    740  * Calling kLdrModAllocTLS() more than once without calling kLdrModFreeTLS()
    741  * between each invocation is not supported.
    742  *
    743  * @returns 0 on success, non-zero OS or kLdr status code on failure.
    744  * @param   pMod            The module.
    745  */
    746 int     kLdrModAllocTLS(PKLDRMOD pMod)
    747 {
    748     KLDRMOD_VALIDATE(pMod);
    749     return pMod->pOps->pfnAllocTLS(pMod);
    750 }
    751 
    752 
    753 /**
    754  * Frees Thread Local Storage previously allocated by kLdrModAllocTLS().
    755  *
    756  * The caller is responsible for only calling kLdrModFreeTLS() once
    757  * after calling kLdrModAllocTLS().
    758  *
    759  * @returns 0 on success, non-zero OS or kLdr status code on failure.
    760  * @param   pMod            The module.
    761  */
    762 void    kLdrModFreeTLS(PKLDRMOD pMod)
    763 {
    764     KLDRMOD_VALIDATE_VOID(pMod);
    765     pMod->pOps->pfnFreeTLS(pMod);
    766 }
    767 
    768 
    769 /**
    770738 * Reloads all dirty pages in a module previously mapped by kLdrModMap().
    771739 *
     
    800768    KLDRMOD_VALIDATE(pMod);
    801769    return pMod->pOps->pfnFixupMapping(pMod, pfnGetImport, pvUser);
    802 }
    803 
    804 
    805 /**
    806  * Call the module initializiation function of a mapped module (if any).
    807  *
    808  * @returns 0 on success or no init function, non-zero on init function failure or invalid pMod.
    809  * @param   pMod            The module.
    810  * @param   uHandle         The module handle to use if any of the init functions requires the module handle.
    811  */
    812 int     kLdrModCallInit(PKLDRMOD pMod, KUPTR uHandle)
    813 {
    814     KLDRMOD_VALIDATE(pMod);
    815     return pMod->pOps->pfnCallInit(pMod, uHandle);
    816 }
    817 
    818 
    819 /**
    820  * Call the module termination function of a mapped module (if any).
    821  *
    822  * @returns 0 on success or no term function, non-zero on invalid pMod.
    823  * @param   pMod            The module.
    824  * @param   uHandle         The module handle to use if any of the term functions requires the module handle.
    825  *
    826  * @remark  Termination function failure will be ignored by the module interpreter.
    827  */
    828 int     kLdrModCallTerm(PKLDRMOD pMod, KUPTR uHandle)
    829 {
    830     KLDRMOD_VALIDATE(pMod);
    831     return pMod->pOps->pfnCallTerm(pMod, uHandle);
    832 }
    833 
    834 
    835 /**
    836  * Call the thread attach or detach function of a mapped module (if any).
    837  *
    838  * Any per-thread TLS initialization/termination will have to be done at this time too.
    839  *
    840  * @returns 0 on success or no attach/detach function, non-zero on attach failure or invalid pMod.
    841  * @param   pMod            The module.
    842  * @param   uHandle         The module handle to use if any of the thread attach/detach functions
    843  *                          requires the module handle.
    844  *
    845  * @remark  Detach function failure will be ignored by the module interpreter.
    846  */
    847 int     kLdrModCallThread(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching)
    848 {
    849     KLDRMOD_VALIDATE(pMod);
    850     K_VALIDATE_FLAGS(fAttachingOrDetaching, 1);
    851     return pMod->pOps->pfnCallThread(pMod, uHandle, fAttachingOrDetaching);
    852770}
    853771
     
    906824}
    907825
     826
     827/**
     828 * Allocates Thread Local Storage for module mapped by kLdrModMap().
     829 *
     830 * Calling kLdrModAllocTLS() more than once without calling kLdrModFreeTLS()
     831 * between each invocation is not supported.
     832 *
     833 * @returns 0 on success, non-zero OS or kLdr status code on failure.
     834 * @param   pMod            The module.
     835 * @param   pvMapping       The external mapping address or RTLDRMOD_INT_MAP.
     836 */
     837int     kLdrModAllocTLS(PKLDRMOD pMod, void *pvMapping)
     838{
     839    KLDRMOD_VALIDATE(pMod);
     840    return pMod->pOps->pfnAllocTLS(pMod, pvMapping);
     841}
     842
     843
     844/**
     845 * Frees Thread Local Storage previously allocated by kLdrModAllocTLS().
     846 *
     847 * The caller is responsible for only calling kLdrModFreeTLS() once
     848 * after calling kLdrModAllocTLS().
     849 *
     850 * @returns 0 on success, non-zero OS or kLdr status code on failure.
     851 * @param   pMod            The module.
     852 * @param   pvMapping       The external mapping address or RTLDRMOD_INT_MAP.
     853 */
     854void    kLdrModFreeTLS(PKLDRMOD pMod, void *pvMapping)
     855{
     856    KLDRMOD_VALIDATE_VOID(pMod);
     857    pMod->pOps->pfnFreeTLS(pMod, pvMapping);
     858}
     859
     860
     861
     862
     863/**
     864 * Call the module initializiation function of a mapped module (if any).
     865 *
     866 * @returns 0 on success or no init function, non-zero on init function failure or invalid pMod.
     867 * @param   pMod            The module.
     868 * @param   pvMapping       The external mapping address or RTLDRMOD_INT_MAP.
     869 * @param   uHandle         The module handle to use if any of the init functions requires the module handle.
     870 */
     871int     kLdrModCallInit(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle)
     872{
     873    KLDRMOD_VALIDATE(pMod);
     874    return pMod->pOps->pfnCallInit(pMod, pvMapping, uHandle);
     875}
     876
     877
     878/**
     879 * Call the module termination function of a mapped module (if any).
     880 *
     881 * @returns 0 on success or no term function, non-zero on invalid pMod.
     882 * @param   pMod            The module.
     883 * @param   pvMapping       The external mapping address or RTLDRMOD_INT_MAP.
     884 * @param   uHandle         The module handle to use if any of the term functions requires the module handle.
     885 *
     886 * @remark  Termination function failure will be ignored by the module interpreter.
     887 */
     888int     kLdrModCallTerm(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle)
     889{
     890    KLDRMOD_VALIDATE(pMod);
     891    return pMod->pOps->pfnCallTerm(pMod, pvMapping, uHandle);
     892}
     893
     894
     895/**
     896 * Call the thread attach or detach function of a mapped module (if any).
     897 *
     898 * Any per-thread TLS initialization/termination will have to be done at this time too.
     899 *
     900 * @returns 0 on success or no attach/detach function, non-zero on attach failure or invalid pMod.
     901 * @param   pMod            The module.
     902 * @param   pvMapping       The external mapping address or RTLDRMOD_INT_MAP.
     903 * @param   uHandle         The module handle to use if any of the thread attach/detach functions
     904 *                          requires the module handle.
     905 *
     906 * @remark  Detach function failure will be ignored by the module interpreter.
     907 */
     908int     kLdrModCallThread(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching)
     909{
     910    KLDRMOD_VALIDATE(pMod);
     911    K_VALIDATE_FLAGS(fAttachingOrDetaching, 1);
     912    return pMod->pOps->pfnCallThread(pMod, pvMapping, uHandle, fAttachingOrDetaching);
     913}
     914
Note: See TracChangeset for help on using the changeset viewer.