binfmt_unregister.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /****************************************************************************
  2. * binfmt/binfmt_unregister.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 <string.h>
  25. #include <sched.h>
  26. #include <debug.h>
  27. #include <errno.h>
  28. #include <nuttx/binfmt/binfmt.h>
  29. #include "binfmt.h"
  30. #ifndef CONFIG_BINFMT_DISABLE
  31. /****************************************************************************
  32. * Public Functions
  33. ****************************************************************************/
  34. /****************************************************************************
  35. * Name: unregister_binfmt
  36. *
  37. * Description:
  38. * Unregister a loader for a binary format
  39. *
  40. * Returned Value:
  41. * This is a NuttX internal function so it follows the convention that
  42. * 0 (OK) is returned on success and a negated errno is returned on
  43. * failure.
  44. *
  45. ****************************************************************************/
  46. int unregister_binfmt(FAR struct binfmt_s *binfmt)
  47. {
  48. FAR struct binfmt_s *curr;
  49. FAR struct binfmt_s *prev;
  50. int ret = -EINVAL;
  51. if (binfmt)
  52. {
  53. /* Disabling pre-emption should be sufficient protection while
  54. * accessing the list of registered binary format handlers.
  55. */
  56. sched_lock();
  57. /* Search the list of registered binary format handlers for the
  58. * one to be unregistered.
  59. */
  60. for (prev = NULL, curr = g_binfmts;
  61. curr && curr != binfmt;
  62. prev = curr, curr = curr->next);
  63. /* Was it in the list? */
  64. if (curr)
  65. {
  66. /* Yes.. was it at the head of the list? */
  67. if (!prev)
  68. {
  69. /* Yes.. remove it from the head of the list */
  70. g_binfmts = binfmt->next;
  71. }
  72. else
  73. {
  74. /* No.. remove it from the middle/end of the list */
  75. prev->next = binfmt->next;
  76. }
  77. binfmt->next = NULL;
  78. ret = OK;
  79. }
  80. sched_unlock();
  81. }
  82. return ret;
  83. }
  84. #endif /* CONFIG_BINFMT_DISABLE */