xiaoxiang781216 commented on code in PR #8000: URL: https://github.com/apache/nuttx/pull/8000#discussion_r1059939614
########## include/nuttx/mm/mm_map.h: ########## @@ -0,0 +1,83 @@ +/**************************************************************************** + * include/nuttx/mm/mm_map.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_MM_MM_MAP_H +#define __INCLUDE_NUTTX_MM_MM_MAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/fs/fs.h> +#include <nuttx/queue.h> + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* Type of the mapping */ + +enum mm_map_type +{ + MM_MAP_ANONYMOUS, + MM_MAP_NAMED, + MM_MAP_INODE, + MM_MAP_SHM +}; + +/* Id of the mapping */ + +union mm_map_id_u +{ + FAR const char *name; /* For MM_MAP_NAMED */ + FAR struct inode *inode; /* For MM_MAP_INODE */ + int shmid; /* FOR MM_MAP_SHM */ + uintptr_t val; +}; + +/* A memory mapping list item */ + +struct mm_map_entry_s +{ + FAR struct mm_map_entry *flink; /* this is used as sq_entry_t */ + enum mm_map_type type; + union mm_map_id_u id; + FAR const void *vaddr; + size_t length; + off_t offset; + int prot; + int flags; + void *priv; Review Comment: add FAR ########## include/nuttx/fs/fs.h: ########## @@ -298,6 +305,11 @@ struct mountpt_operations size_t buflen); off_t (*seek)(FAR struct file *filep, off_t offset, int whence); int (*ioctl)(FAR struct file *filep, int cmd, unsigned long arg); + int (*truncate)(FAR struct file *filep, off_t length); + int (*mmap)(FAR struct file *filep, FAR struct mm_map_entry_s *map); + int (*munmap)(FAR struct task_group_s *group, + FAR struct mm_map_entry_s *map, void *start, + size_t length); Review Comment: don't need start/length since mm_map_entry_s already has these fields ########## include/nuttx/mm/mm_map.h: ########## @@ -0,0 +1,83 @@ +/**************************************************************************** + * include/nuttx/mm/mm_map.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_MM_MM_MAP_H +#define __INCLUDE_NUTTX_MM_MM_MAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/fs/fs.h> +#include <nuttx/queue.h> + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* Type of the mapping */ + +enum mm_map_type +{ + MM_MAP_ANONYMOUS, + MM_MAP_NAMED, + MM_MAP_INODE, + MM_MAP_SHM +}; + +/* Id of the mapping */ + +union mm_map_id_u +{ + FAR const char *name; /* For MM_MAP_NAMED */ + FAR struct inode *inode; /* For MM_MAP_INODE */ + int shmid; /* FOR MM_MAP_SHM */ + uintptr_t val; +}; + +/* A memory mapping list item */ + +struct mm_map_entry_s +{ + FAR struct mm_map_entry *flink; /* this is used as sq_entry_t */ + enum mm_map_type type; + union mm_map_id_u id; Review Comment: User may call close before munmap, so it's better to move munmap callback to mm_map_entry_s and remove type and id field. ########## include/nuttx/mm/mm_map.h: ########## @@ -0,0 +1,83 @@ +/**************************************************************************** + * include/nuttx/mm/mm_map.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_MM_MM_MAP_H +#define __INCLUDE_NUTTX_MM_MM_MAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/fs/fs.h> +#include <nuttx/queue.h> + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* Type of the mapping */ + +enum mm_map_type +{ + MM_MAP_ANONYMOUS, + MM_MAP_NAMED, + MM_MAP_INODE, + MM_MAP_SHM +}; + +/* Id of the mapping */ + +union mm_map_id_u +{ + FAR const char *name; /* For MM_MAP_NAMED */ + FAR struct inode *inode; /* For MM_MAP_INODE */ + int shmid; /* FOR MM_MAP_SHM */ + uintptr_t val; +}; + +/* A memory mapping list item */ + +struct mm_map_entry_s +{ + FAR struct mm_map_entry *flink; /* this is used as sq_entry_t */ + enum mm_map_type type; + union mm_map_id_u id; + FAR const void *vaddr; + size_t length; + off_t offset; + int prot; + int flags; + void *priv; +}; + +/* A structure for the task group */ + +struct mm_map_s +{ + sq_queue_t mm_map_sq; + sem_t mm_map_sem; Review Comment: sem_t to nxmutex_t -- 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