You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/04/11 06:29:07 UTC

[GitHub] [incubator-nuttx] jlaitine commented on a diff in pull request #6025: Add vm map

jlaitine commented on code in PR #6025:
URL: https://github.com/apache/incubator-nuttx/pull/6025#discussion_r846983886


##########
mm/vm_map/vm_map.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * mm/vm_map/vm_map.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.
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <queue.h>
+#include <nuttx/sched.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/mm/vm_map.h>
+#include <nuttx/kmalloc.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+bool vaddr_in_area(FAR const void *addr, FAR const void *start,
+                   size_t length)
+{
+  uintptr_t u_addr = (uintptr_t)addr;
+  uintptr_t u_start = (uintptr_t)start;
+  return (u_addr >= u_start) && (u_addr < u_start + length);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: vm_map_initialize
+ *
+ * Description:
+ *   Allocates a task group specific vm_map stucture. Called when the group
+ *   is initialized
+ *
+ ****************************************************************************/
+
+void vm_map_initialize(FAR struct vm_map *mm)
+{
+  sq_init(&mm->vm_map_sq);
+  nxsem_init(&mm->vm_map_sem, 0, 1);
+}
+
+/****************************************************************************
+ * Name: vm_map_add
+ *
+ * Description:
+ *   Add a mapping to task group's vm_map list
+ *
+ ****************************************************************************/
+
+int vm_map_add(enum vm_map_type type, union vm_map_id id,
+               FAR const void *vaddr, size_t length)
+{
+  FAR struct tcb_s *tcb = nxsched_self();
+  FAR struct task_group_s *group = tcb->group;
+  FAR struct vm_map *mm = &group->tg_vm_map;
+  FAR struct vm_map_entry *map = kmm_zalloc(sizeof(struct vm_map));
+  if (!map)
+    {
+      return -ENOMEM;
+    }
+
+  map->type = type;
+  map->id = id;
+  map->vaddr = vaddr;
+  map->length = length;
+
+  if (nxsem_wait(&mm->vm_map_sem) < 0)
+    {
+      kmm_free(map);
+      return ERROR;
+    }
+
+  sq_addlast((sq_entry_t *)map, &mm->vm_map_sq);
+
+  nxsem_post(&mm->vm_map_sem);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: vm_map_find
+ *
+ * Description:
+ *   Find the first mapping containing an address from the task group's list
+ *
+ ****************************************************************************/
+
+FAR const struct vm_map_entry *vm_map_find(FAR const void *vaddr)
+{
+  FAR struct tcb_s *tcb = nxsched_self();
+  FAR struct task_group_s *group = tcb->group;
+  FAR struct vm_map *mm = &group->tg_vm_map;
+  FAR struct vm_map_entry *map =

Review Comment:
   This needs to be mutexed with the sem, will add that still



-- 
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-unsubscribe@nuttx.apache.org

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