binfmt_exit.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /****************************************************************************
  2. * binfmt/binfmt_exit.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/types.h>
  25. #include <assert.h>
  26. #include <debug.h>
  27. #include <nuttx/kmalloc.h>
  28. #include <nuttx/binfmt/binfmt.h>
  29. #include "binfmt.h"
  30. #ifdef CONFIG_BINFMT_LOADABLE
  31. /****************************************************************************
  32. * Public Functions
  33. ****************************************************************************/
  34. /****************************************************************************
  35. * Name: binfmt_exit
  36. *
  37. * Description:
  38. * This function may be called when a tasked loaded into RAM exits.
  39. * This function will unload the module when the task exits and reclaim
  40. * all resources used by the module.
  41. *
  42. * Input Parameters:
  43. * bin - This structure must have been allocated with kmm_malloc() and must
  44. * persist until the task unloads
  45. *
  46. * Returned Value:
  47. * This is a NuttX internal function so it follows the convention that
  48. * 0 (OK) is returned on success and a negated errno is returned on
  49. * failure.
  50. *
  51. ****************************************************************************/
  52. int binfmt_exit(FAR struct binary_s *bin)
  53. {
  54. int ret;
  55. DEBUGASSERT(bin != NULL);
  56. /* Unload the module */
  57. ret = unload_module(bin);
  58. if (ret < 0)
  59. {
  60. berr("ERROR: unload_module() failed: %d\n", ret);
  61. }
  62. /* Free the load structure */
  63. kmm_free(bin);
  64. return ret;
  65. }
  66. #endif /* CONFIG_BINFMT_LOADABLE */