jlaitine commented on code in PR #8109:
URL: https://github.com/apache/nuttx/pull/8109#discussion_r1072482358


##########
fs/shm/shmfs_alloc.c:
##########
@@ -0,0 +1,143 @@
+/****************************************************************************
+ * fs/shm/shmfs_alloc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <nuttx/pgalloc.h>
+
+#include "inode/inode.h"
+#include "shm/shmfs.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR struct shmfs_object_s *shmfs_alloc_object(size_t length)
+{
+  FAR struct shmfs_object_s *object;
+  bool allocated = false;
+
+#if defined(CONFIG_BUILD_FLAT)
+  /* in FLAT build, allocate the object metadata and the data in the same
+   * chunk in kernel heap
+   */
+
+  object = kmm_zalloc(sizeof(struct shmfs_object_s) + length);
+  if (object)
+    {
+      object->paddr = (&object->paddr) + 1;
+      allocated = true;
+    }
+
+#elif defined(CONFIG_BUILD_PROTECTED)
+  /* in PROTECTED build, allocate the shm object in kernel heap, and shared
+   * memory in user heap
+   */
+
+  object = kmm_zalloc(sizeof(struct shmfs_object_s));
+  if (object)
+    {
+      object->paddr = kumm_zalloc(length);
+
+      if (object->paddr)
+        {
+           allocated = true;
+        }
+    }
+
+#elif defined(CONFIG_BUILD_KERNEL)
+  /* in KERNEL build, allocate the shared memory from page pool and store the
+   * physical address
+   */
+
+  size_t i = 0;
+  void **pages;
+  size_t n_pages = MM_NPAGES(length);
+
+  object = kmm_zalloc(sizeof(struct shmfs_object_s) +
+                      (n_pages - 1) * sizeof(object->paddr));
+
+  if (object)
+    {
+      pages = &object->paddr;
+      for (; i < n_pages; i++)
+        {
+          pages[i] = (void *)mm_pgalloc(1);
+          if (!pages[i])
+            {
+              break;
+            }
+        }
+    }
+
+  if (i == n_pages)
+    {
+      allocated = true;
+    }
+#endif
+
+  if (allocated)
+    {
+      object->length = length;
+    }
+  else
+    {
+      /* delete any partial allocation */
+
+      shmfs_free_object(object);
+      object = NULL;
+    }
+
+  return object;
+}
+
+void shmfs_free_object(FAR struct shmfs_object_s *object)
+{
+#if defined(CONFIG_BUILD_KERNEL)
+  size_t i;
+  size_t n_pages = MM_NPAGES(object->length);
+  void **pages;

Review Comment:
   done



##########
fs/shm/shmfs_alloc.c:
##########
@@ -0,0 +1,143 @@
+/****************************************************************************
+ * fs/shm/shmfs_alloc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <nuttx/pgalloc.h>
+
+#include "inode/inode.h"

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to