libnxflat_unload.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /****************************************************************************
  2. * binfmt/libnxflat/libnxflat_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 <sys/mman.h>
  25. #include <stdlib.h>
  26. #include <debug.h>
  27. #include <nuttx/kmalloc.h>
  28. #include <nuttx/binfmt/nxflat.h>
  29. #include "libnxflat.h"
  30. /****************************************************************************
  31. * Pre-processor Definitions
  32. ****************************************************************************/
  33. /****************************************************************************
  34. * Private Constant Data
  35. ****************************************************************************/
  36. /****************************************************************************
  37. * Private Functions
  38. ****************************************************************************/
  39. /****************************************************************************
  40. * Public Functions
  41. ****************************************************************************/
  42. /****************************************************************************
  43. * Name: nxflat_unload
  44. *
  45. * Description:
  46. * This function unloads the object from memory. This essentially undoes
  47. * the actions of nxflat_load. It is called only under certain error
  48. * conditions after the module has been loaded but not yet started.
  49. *
  50. * Returned Value:
  51. * 0 (OK) is returned on success and a negated errno is returned on
  52. * failure.
  53. *
  54. ****************************************************************************/
  55. int nxflat_unload(FAR struct nxflat_loadinfo_s *loadinfo)
  56. {
  57. /* Release the memory segments */
  58. /* Release the I-Space mmap'ed file */
  59. if (loadinfo->ispace)
  60. {
  61. munmap((FAR void *)loadinfo->ispace, loadinfo->isize);
  62. loadinfo->ispace = 0;
  63. }
  64. /* Release the D-Space address environment */
  65. nxflat_addrenv_free(loadinfo);
  66. return OK;
  67. }