diff --git a/Documentation/NuttxUserGuide.html b/Documentation/NuttxUserGuide.html index 07246ff7e8..480c7daf7b 100644 --- a/Documentation/NuttxUserGuide.html +++ b/Documentation/NuttxUserGuide.html @@ -13,7 +13,7 @@
User's Manual
by
Gregory Nutt
-
Last Updated: August 21, 2014
+Last Updated: September 22, 2014
@@ -63,6 +63,7 @@NuttX includes a simple interface layer based on uIP (see http://www.sics.se). -NuttX supports subset of a standard socket interface to uIP. -These network feature can be enabled by settings in the architecture -configuration file. -Those socket APIs are discussed in the following paragraphs.
++ NuttX includes a simple interface layer based on uIP (see http://www.sics.se). + NuttX supports subset of a standard socket interface to uIP. + These network feature can be enabled by settings in the architecture configuration file. + Those socket APIs are discussed in the following paragraphs. +
socket#include <sys/socket.h> -int getsockopt(int sockfd, int level, int option, - void *value, socklen_t *value_len); +int getsockopt(int sockfd, int level, int option, void *value, socklen_t *value_len);
Description: @@ -9032,6 +9031,309 @@ int getsockopt(int sockfd, int level, int option, Insufficient resources are available in the system to complete the call.
+ 2.12 Shared Memory Interfaces+ |
+
+ Shared memory interfaces are only available with the NuttX kernel build (CONFIG_BUILD_KERNEL=y).
+ These interfaces support user memory regions that can be shared between multiple user processes.
+ Shared memory interfaces:
+
+ NOTE: This is advance documentation. These interfaces are not yet available as of this writing. If you are reading this note, then double check; since these interfaces are under development now, I may have simply failed to remove it. +
+ +shmget+ Function Prototype: +
++#include <sys/shm.h> +#include <sys/ipc.h> +int shmget(key_t key, size_t size, int shmflg); ++
+ Description:
+ The shmget() function will return the shared memory identifier associated with key.
+
+ A shared memory identifier, associated data structure, and shared memory segment of at least size bytes is created for key if one of the following is true:
+
+ The argument key is equal to IPC_PRIVATE.
+
+ The argument key does not already have a shared memory identifier associated with it and (shmflg & IPC_CREAT) is non-zero.
+
+ The values of shm_perm.cuid, shm_perm.uid, shm_perm.cgid, and shm_perm.gid are set equal to the effective user ID and effective group ID, respectively, of the calling process.
+
+ The low-order nine bits of shm_perm.mode are set equal to the low-order nine bits of shmflg.
+
+ The value of shm_segsz is set equal to the value of size.
+
+ The values of shm_lpid, shm_nattch, shm_atime, and shm_dtime are set equal to 0.
+
+ The value of shm_ctime is set equal to the current time.
+
+ When the shared memory segment is created, it will be initialized with all zero values. +
++ Input Parameters: +
+key: The key that is used to access the unique shared memory identifier.
+ size: The shared memory region that is created will be at least this size in bytes.
+ shmflg: See IPC_* definitions in sys/ipc.h. Only the values IPC_PRIVATE or IPC_CREAT are supported.
+
+ Returned Value:
+ Upon successful completion, shmget() will return a non-negative integer, namely a shared memory identifier; otherwise, it will return -1 and set errno to indicate the error.
+
EACCES.
+ A shared memory identifier exists for key but operation permission as specified by the low-order nine bits of shmflg would not be granted.
+ EEXIST.
+ A shared memory identifier exists for the argument key but (shmflg & IPC_CREAT) && (shmflg & IPC_EXCL) are non-zero.
+ EINVAL.
+ A shared memory segment is to be created and the value of size is less than the system-imposed minimum or greater than the system-imposed maximum.
+ EINVAL.
+ No shared memory segment is to be created and a shared memory segment exists for key but the size of the segment associated with it is less than size and size is not 0.
+ ENOENT.
+ A shared memory identifier does not exist for the argument key and (shmflg & IPC_CREAT) is 0.
+ ENOMEM.
+ A shared memory identifier and associated shared memory segment will be created, but the amount of available physical memory is not sufficient to fill the request.
+ ENOSPC.
+ A shared memory identifier is to be created, but the system-imposed limit on the maximum number of allowed shared memory identifiers system-wide would be exceeded.
+ shmat+ Function Prototype: +
++#include <sys/shm.h> +void *shmat(int shmid, FAR const void *shmaddr, int shmflg); ++
+ Description:
+ The shmat() function attaches the shared memory segment associated with the shared memory identifier specified by shmid to the address space of the calling process. The segment is attached at the address specified by one of the following criteria:
+
+ If shmaddr is a null pointer, the segment is attached at the first available address as selected by the system.
+
+ If shmaddr is not a null pointer and (shmflg & SHM_RND) is non-zero, the segment is attached at the address given by (shmaddr - ((uintptr_t)shmaddr % SHMLBA)).
+
+ If shmaddr is not a null pointer and (shmflg & SHM_RND) is 0, the segment is attached at the address given by shmaddr.
+
+ The segment is attached for reading if (shmflg & SHM_RDONLY) is non-zero and the calling process has read permission; otherwise, if it is 0 and the calling process has read and write permission, the segment is attached for reading and writing.
+
+ Input Parameters: +
+shmid: Shared memory identifiersmaddr: Determines mapping of the shared memory regionshmflg: See SHM_* definitions in include/sys/shm.h. Only SHM_RDONLY and SHM_RND are supported.
+ Returned Value:
+ Upon successful completion, shmat() will increment the value of shm_nattch in the data structure associated with the shared memory ID of the attached shared memory segment and return the segment's start address.
+
+ Otherwise, the shared memory segment will not be attached, shmat() will return -1, and errno will be set to indicate the error.
+
EACCES.
+ Operation permission is denied to the calling process
+ EINVAL.
+ The value of shmid is not a valid shared memory identifier, the shmaddr is not a null pointer, and the value of (shmaddr -((uintptr_t)shmaddr % SHMLBA)) is an illegal address for attaching shared memory; or the shmaddr is not a null pointer, (shmflg & SHM_RND) is 0, and the value of shmaddr is an illegal address for attaching shared memory.
+ EMFILE.
+ The number of shared memory segments attached to the calling process would exceed the system-imposed limit.
+ ENOMEM.
+ The available data space is not large enough to accommodate the shared memory segment.
+ shmctl+ Function Prototype: +
++#include <sys/shm.h> +#include <sys/ipc.h> +int shmctl(int shmid, int cmd, FAR struct shmid_ds *buf); ++
+ Description:
+ The shmctl() function provides a variety of shared memory control operations as specified by cmd. The following values for cmd are available:
+
+ IPC_STAT.
+ Place the current value of each member of the shmid_ds data structure associated with shmid into the structure pointed to by buf.
+
+ IPC_SET.
+ Set the value of the following members of the shmid_ds data structure associated with shmid to the corresponding value found in the structure pointed to by buf:
+
shm_perm.uidshm_perm.gidshm_perm.mode (Low-order nine bits).
+
+ IPC_SET can only be executed by a process that has an effective user ID equal to either that of a process with appropriate privileges or to the value of shm_perm.cuid or shm_perm.uid in the shmid_ds data structure associated with shmid.
+
+ IPC_RMID.
+ Remove the shared memory identifier specified by shmid from the system and destroy the shared memory segment and shmid_ds data structure associated with it. IPC_RMID can only be executed by a process that has an effective user ID equal to either that of a process with appropriate privileges or to the value of shm_perm.cuid or shm_perm.uid in the shmid_ds data structure associated with shmid.
+
+ Input Parameters: +
+shmid: Shared memory identifiercmd: shmctl() commandbuf: Data associated with the shmctl() command
+ Returned Value:
+ Upon successful completion, shmctl() will return 0; otherwise, it will return -1 and set errno to indicate the error.
+
EACCES.
+ The argument cmd is equal to IPC_STAT and the calling process does not have read permission.
+ EINVAL.
+ The value of shmid is not a valid shared memory identifier, or the value of cmd is not a valid command.
+ EPERM.
+ The argument cmd is equal to IPC_RMID or IPC_SET and the effective user ID of the calling process is not equal to that of a process with appropriate privileges and it is not equal to the value of shm_perm.cuid or shm_perm.uid in the data structure associated with shmid.
+ EOVERFLOW.
+ The cmd argument is IPC_STAT and the gid or uid value is too large to be stored in the structure pointed to by the buf argument.
+ shmdt+ Function Prototype: +
++#include <sys/shm.h> +int shmdt(FAR const void *shmaddr); ++
+ Description:
+ The shmdt() function detaches the shared memory segment located at the address specified by shmaddr from the address space of the calling process.
+
+ Input Parameters: +
+shmid: Shared memory identifier
+ Returned Value:
+ Upon successful completion, shmdt() will decrement the value of shm_nattch in the data structure associated with the shared memory ID of the attached shared memory segment and return 0.
+
+ Otherwise, the shared memory segment will not be detached, shmdt() will return -1, and errno will be set to indicate the error.
+
EINVAL.
+ The value of shmaddr is not the data segment start address of a shared memory segment.
+ |
diff --git a/configs/mikroe-stm32f4/src/up_nsh.c b/configs/mikroe-stm32f4/src/up_nsh.c
index 8346f49082..31e9be21dc 100644
--- a/configs/mikroe-stm32f4/src/up_nsh.c
+++ b/configs/mikroe-stm32f4/src/up_nsh.c
@@ -280,9 +280,9 @@ int nsh_archinitialize(void)
}
#else /* CONFIG_MIKROE_FLASH_PART */
- /* Configure the device with no partition support */
+ /* Configure the device with no partition support */
- smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd, NULL);
+ smart_initialize(CONFIG_MIKROE_FLASH_MINOR, mtd, NULL);
#endif /* CONFIG_MIKROE_FLASH_PART */
}
diff --git a/include/sys/ipc.h b/include/sys/ipc.h
index e30e599865..a1340dc248 100644
--- a/include/sys/ipc.h
+++ b/include/sys/ipc.h
@@ -56,7 +56,7 @@
/* Keys: */
-#define IPC_PRIVATE 0 /* Private key */
+#define IPC_PRIVATE 0 /* Private key */
/* Control commands: */
@@ -89,11 +89,12 @@ extern "C"
struct ipc_perm
{
- uid_t uid /* Owner's user ID */
- gid_t gid /* Owner's group ID */
- uid_t cuid /* Creator's user ID */
- gid_t cgid /* Creator's group ID */
- mode_t mode /* Read/write permission */
+ uid_t uid; /* Owner's user ID */
+ gid_t gid; /* Owner's group ID */
+ uid_t cuid; /* Creator's user ID */
+ gid_t cgid; /* Creator's group ID */
+ mode_t mode; /* Read/write permission */
+};
/****************************************************************************
* Public Function Prototypes
diff --git a/include/sys/shm.h b/include/sys/shm.h
index 99faf22516..c59b3e143a 100644
--- a/include/sys/shm.h
+++ b/include/sys/shm.h
@@ -51,7 +51,7 @@
****************************************************************************/
#define SHM_RDONLY 0x01 /* Attach read-only (else read-write) */
-#defube SHM_RND 0x02 /* Round attach address to SHMLBA */
+#define SHM_RND 0x02 /* Round attach address to SHMLBA */
/* Segment low boundary address multiple */
diff --git a/mm/Kconfig b/mm/Kconfig
index fd01ad5cef..38288a8451 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -79,6 +79,15 @@ config HEAP2_SIZE
endif # ARCH_HAVE_HEAP2
+
+config MM_SHM
+ bool "Shared memory support"
+ default n
+ depends on BUILD_KERNEL && EXPERIMENTAL
+ ---help---
+ Build in support for the shared memory interfaces shmget(), shmat(),
+ shmctl(), and shmdt().
+
config GRAN
bool "Enable Granule Allocator"
default n
diff --git a/mm/shm/Make.defs b/mm/shm/Make.defs
index 66aee85026..c0fb12a81d 100644
--- a/mm/shm/Make.defs
+++ b/mm/shm/Make.defs
@@ -36,6 +36,7 @@
# Shared memory allocator
ifeq ($(CONFIG_MM_SHM),y)
+CSRCS += shmat.c shmctl.c shmdt.c shmget.c
# Add the shared memory directory to the build
diff --git a/mm/shm/shmat.c b/mm/shm/shmat.c
new file mode 100755
index 0000000000..4f4cf89e94
--- /dev/null
+++ b/mm/shm/shmat.c
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * mm/shm/shmat.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt |