MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_mq_open

Function sys_mq_open

components/lwp/lwp_syscall.c:9057–9102  ·  view source on GitHub ↗

* @brief Open a message queue. * * This function opens a message queue for communication between processes. * It can create a new message queue or open an existing one, depending on the specified * flags. * * @param[in] name The name of the message queue. The name should be a null-terminated * string and is subject to system-specific naming conventions. * @param[in] flags

Source from the content-addressed store, hash-verified

9055 * return `-1`.
9056 */
9057mqd_t sys_mq_open(const char *name, int flags, mode_t mode, struct mq_attr *attr)
9058{
9059 mqd_t mqdes;
9060 sysret_t ret = 0;
9061#ifdef ARCH_MM_MMU
9062 char *kname = RT_NULL;
9063 rt_size_t len = 0;
9064 struct mq_attr attr_k;
9065
9066 len = lwp_user_strlen(name);
9067 if (!len)
9068 return (mqd_t)-EINVAL;
9069
9070 kname = (char *)kmem_get(len + 1);
9071 if (!kname)
9072 return (mqd_t)-ENOMEM;
9073
9074 if (attr == NULL)
9075 {
9076 attr_k.mq_maxmsg = 10;
9077 attr_k.mq_msgsize = 8192;
9078 attr_k.mq_flags = 0;
9079 attr = &attr_k;
9080 }
9081 else
9082 {
9083 if (!lwp_get_from_user(&attr_k, (void *)attr, sizeof(struct mq_attr)))
9084 return -EINVAL;
9085 }
9086
9087 lwp_get_from_user(kname, (void *)name, len + 1);
9088 mqdes = mq_open(kname, flags, mode, &attr_k);
9089 if (mqdes == -1)
9090 {
9091 ret = GET_ERRNO();
9092 }
9093 lwp_put_to_user(attr, &attr_k, sizeof(struct mq_attr));
9094 kmem_put(kname);
9095#else
9096 mqdes = mq_open(name, flags, mode, attr);
9097#endif
9098 if (mqdes == -1)
9099 return (mqd_t)ret;
9100 else
9101 return mqdes;
9102}
9103
9104/**
9105 * @brief Remove a message queue.

Callers

nothing calls this directly

Calls 6

lwp_user_strlenFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
mq_openFunction · 0.85
lwp_put_to_userFunction · 0.85
kmem_putFunction · 0.85

Tested by

no test coverage detected