modlib_unload.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /****************************************************************************
  2. * libs/libc/modlib/modlib_unload.c
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <stdlib.h>
  25. #include <debug.h>
  26. #include <nuttx/lib/modlib.h>
  27. #include "libc.h"
  28. #include "modlib/modlib.h"
  29. /****************************************************************************
  30. * Public Functions
  31. ****************************************************************************/
  32. /****************************************************************************
  33. * Name: modlib_unload
  34. *
  35. * Description:
  36. * This function unloads the object from memory. This essentially undoes
  37. * the actions of modlib_load(). It is called only under certain error
  38. * conditions after the module has been loaded but not yet started.
  39. *
  40. * Returned Value:
  41. * 0 (OK) is returned on success and a negated errno is returned on
  42. * failure.
  43. *
  44. ****************************************************************************/
  45. int modlib_unload(struct mod_loadinfo_s *loadinfo)
  46. {
  47. /* Free all working buffers */
  48. modlib_freebuffers(loadinfo);
  49. /* Release memory holding the relocated ELF image */
  50. #if defined(CONFIG_ARCH_USE_MODULE_TEXT)
  51. if (loadinfo->textalloc != 0)
  52. {
  53. up_module_text_free((FAR void *)loadinfo->textalloc);
  54. }
  55. if (loadinfo->datastart != 0)
  56. {
  57. lib_free((FAR void *)loadinfo->datastart);
  58. }
  59. #else
  60. if (loadinfo->textalloc != 0)
  61. {
  62. lib_free((FAR void *)loadinfo->textalloc);
  63. }
  64. #endif
  65. /* Clear out all indications of the allocated address environment */
  66. loadinfo->textalloc = 0;
  67. loadinfo->datastart = 0;
  68. loadinfo->textsize = 0;
  69. loadinfo->datasize = 0;
  70. return OK;
  71. }