You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "casaroli (via GitHub)" <gi...@apache.org> on 2026/10/17 17:18:19 UTC
[PR] libs/libc/machine/arm64: Add the ucontext functions. [nuttx]
casaroli opened a new pull request, #20724:
URL: https://github.com/apache/nuttx/pull/20724
## Summary
Adds the ucontext functions (`getcontext()`, `setcontext()`, `makecontext()`, `swapcontext()`) and `include/ucontext.h`, with an arm64 implementation that selects the new `ARCH_HAVE_UCONTEXT`. Programs that switch between their own stacks, such as coroutine libraries, need them.
A context holds the callee-saved registers, the stack pointer, the program counter, the arguments of `makecontext()`, the callee-saved FP registers when there is an FPU, and the signal mask. A context from `makecontext()` continues with `uc_link` when its function returns, or the task exits if `uc_link` is NULL.
## Impact
New header and functions, arm64 only. Nothing else changes.
## Testing
Builds: `qemu-armv8a:nsh`, `qemu-armv8a:knsh`, `lm3s6965-ek:qemu-flat`.
`tools/checkpatch.sh -c -u -m -g` passes.
A test program on `qemu-armv8a:knsh`: a `getcontext()`/`setcontext()` loop, chained contexts with arguments, `uc_link`, a function with 10 arguments, and FP registers preserved across `swapcontext()`.
--
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
Re: [PR] libs/libc/machine/arm64: Add the ucontext functions. [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #20724:
URL: https://github.com/apache/nuttx/pull/20724#discussion_r4303986184
##########
Kconfig:
##########
@@ -654,6 +654,13 @@ config ARCH_HAVE_SETJMP
bool
default n
+config ARCH_HAVE_UCONTEXT
Review Comment:
move after line 683
##########
arch/arm64/include/ucontext.h:
##########
@@ -0,0 +1,52 @@
+/****************************************************************************
+ * arch/arm64/include/ucontext.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 __ARCH_ARM64_INCLUDE_UCONTEXT_H
+#define __ARCH_ARM64_INCLUDE_UCONTEXT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* The machine context of getcontext() and makecontext(). The assembly code
+ * in libs/libc/machine/arm64/arch_ucontext.S knows this layout.
+ */
+
+typedef struct mcontext_s
Review Comment:
should we move to irq.h near xcptcontext
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
Review Comment:
remove ALL FAR from this file
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
+ ...)
+{
+ FAR uint64_t *stack;
+ uintptr_t sp;
+ va_list ap;
+ int i;
+
+ sp = ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~15;
+
+ /* The first eight arguments go in x0-x7, the others on the stack */
+
+ if (argc > 8)
+ {
+ sp = (sp - (argc - 8) * sizeof(uint64_t)) & ~15;
Review Comment:
ditto
##########
arch/arm64/include/ucontext.h:
##########
@@ -0,0 +1,52 @@
+/****************************************************************************
+ * arch/arm64/include/ucontext.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 __ARCH_ARM64_INCLUDE_UCONTEXT_H
+#define __ARCH_ARM64_INCLUDE_UCONTEXT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* The machine context of getcontext() and makecontext(). The assembly code
+ * in libs/libc/machine/arm64/arch_ucontext.S knows this layout.
+ */
+
+typedef struct mcontext_s
+{
+ uint64_t regs[31]; /* x0-x30 */
Review Comment:
why not remove the first half caller-saved register
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
+ ...)
+{
+ FAR uint64_t *stack;
+ uintptr_t sp;
+ va_list ap;
+ int i;
+
+ sp = ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~15;
+
+ /* The first eight arguments go in x0-x7, the others on the stack */
+
+ if (argc > 8)
+ {
+ sp = (sp - (argc - 8) * sizeof(uint64_t)) & ~15;
+ }
+
+ stack = (FAR uint64_t *)sp;
+
+ va_start(ap, argc);
+ for (i = 0; i < argc; i++)
+ {
+ if (i < 8)
+ {
+ ucp->uc_mcontext.regs[i] = (uint64_t)va_arg(ap, int);
Review Comment:
should we use int64_t
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
+ ...)
+{
+ FAR uint64_t *stack;
+ uintptr_t sp;
+ va_list ap;
+ int i;
+
+ sp = ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~15;
+
+ /* The first eight arguments go in x0-x7, the others on the stack */
+
+ if (argc > 8)
+ {
+ sp = (sp - (argc - 8) * sizeof(uint64_t)) & ~15;
+ }
+
+ stack = (FAR uint64_t *)sp;
+
+ va_start(ap, argc);
+ for (i = 0; i < argc; i++)
+ {
+ if (i < 8)
+ {
+ ucp->uc_mcontext.regs[i] = (uint64_t)va_arg(ap, int);
+ }
+ else
+ {
+ stack[i - 8] = (uint64_t)va_arg(ap, int);
Review Comment:
remove (uint64_t) cast
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
+ ...)
+{
+ FAR uint64_t *stack;
+ uintptr_t sp;
+ va_list ap;
+ int i;
+
+ sp = ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~15;
Review Comment:
use STACK_ALIGNMENT macro
--
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
Re: [PR] libs/libc/machine/arm64: Add the ucontext functions. [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #20724:
URL: https://github.com/apache/nuttx/pull/20724
--
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
Re: [PR] libs/libc/machine/arm64: Add the ucontext functions. [nuttx]
Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli commented on code in PR #20724:
URL: https://github.com/apache/nuttx/pull/20724#discussion_r4307019020
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(ucontext_t *ucp);
+void arm64_ucontext_setmask(const ucontext_t *ucp);
+void arm64_ucontext_swapmask(const ucontext_t *ucp,
+ ucontext_t *oucp);
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-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] libs/libc/machine/arm64: Add the ucontext functions. [nuttx]
Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli commented on code in PR #20724:
URL: https://github.com/apache/nuttx/pull/20724#discussion_r4304230023
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
+ ...)
+{
+ FAR uint64_t *stack;
+ uintptr_t sp;
+ va_list ap;
+ int i;
+
+ sp = ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~15;
+
+ /* The first eight arguments go in x0-x7, the others on the stack */
+
+ if (argc > 8)
+ {
+ sp = (sp - (argc - 8) * sizeof(uint64_t)) & ~15;
+ }
+
+ stack = (FAR uint64_t *)sp;
+
+ va_start(ap, argc);
+ for (i = 0; i < argc; i++)
+ {
+ if (i < 8)
+ {
+ ucp->uc_mcontext.regs[i] = (uint64_t)va_arg(ap, int);
Review Comment:
Done.
##########
arch/arm64/include/ucontext.h:
##########
@@ -0,0 +1,52 @@
+/****************************************************************************
+ * arch/arm64/include/ucontext.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 __ARCH_ARM64_INCLUDE_UCONTEXT_H
+#define __ARCH_ARM64_INCLUDE_UCONTEXT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* The machine context of getcontext() and makecontext(). The assembly code
+ * in libs/libc/machine/arm64/arch_ucontext.S knows this layout.
+ */
+
+typedef struct mcontext_s
+{
+ uint64_t regs[31]; /* x0-x30 */
Review Comment:
Done for x8-x18. x0-x7 stay, because `makecontext()` gives the arguments in them.
--
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
Re: [PR] libs/libc/machine/arm64: Add the ucontext functions. [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #20724:
URL: https://github.com/apache/nuttx/pull/20724#discussion_r4305411492
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(ucontext_t *ucp);
+void arm64_ucontext_setmask(const ucontext_t *ucp);
+void arm64_ucontext_swapmask(const ucontext_t *ucp,
+ ucontext_t *oucp);
Review Comment:
```suggestion
void arm64_ucontext_swapmask(ucontext_t *oucp,
const ucontext_t *ucp);
```
--
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
Re: [PR] libs/libc/machine/arm64: Add the ucontext functions. [nuttx]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #20724:
URL: https://github.com/apache/nuttx/pull/20724#issuecomment-6237581833
<!-- membrowse-pr-comment -->
## <img src="https://membrowse.com/membrowse-logo.svg" height="24" align="top"> MemBrowse Memory Report
*No memory changes detected for:*
- [arduino-mega2560](https://membrowse.com/public/apache/nuttx/target/arduino-mega2560/compare?head=9879a91e9cb03a7b7e02e0c8235802c655caf287&base=17747ded0aaba11af1dd07422c15354200e65e3e)
- [esp32-devkitc](https://membrowse.com/public/apache/nuttx/target/esp32-devkitc/compare?head=9879a91e9cb03a7b7e02e0c8235802c655caf287&base=17747ded0aaba11af1dd07422c15354200e65e3e)
- [hifive1-revb](https://membrowse.com/public/apache/nuttx/target/hifive1-revb/compare?head=9879a91e9cb03a7b7e02e0c8235802c655caf287&base=17747ded0aaba11af1dd07422c15354200e65e3e)
- [mirtoo](https://membrowse.com/public/apache/nuttx/target/mirtoo/compare?head=9879a91e9cb03a7b7e02e0c8235802c655caf287&base=17747ded0aaba11af1dd07422c15354200e65e3e)
- [qemu-armv8a](https://membrowse.com/public/apache/nuttx/target/qemu-armv8a/compare?head=9879a91e9cb03a7b7e02e0c8235802c655caf287&base=17747ded0aaba11af1dd07422c15354200e65e3e)
- [qemu-intel64](https://membrowse.com/public/apache/nuttx/target/qemu-intel64/compare?head=9879a91e9cb03a7b7e02e0c8235802c655caf287&base=17747ded0aaba11af1dd07422c15354200e65e3e)
- [rx65n-rsk2mb](https://membrowse.com/public/apache/nuttx/target/rx65n-rsk2mb/compare?head=9879a91e9cb03a7b7e02e0c8235802c655caf287&base=17747ded0aaba11af1dd07422c15354200e65e3e)
- [s698pm-dkit](https://membrowse.com/public/apache/nuttx/target/s698pm-dkit/compare?head=9879a91e9cb03a7b7e02e0c8235802c655caf287&base=17747ded0aaba11af1dd07422c15354200e65e3e)
- [stm32-nucleo-f103rb](https://membrowse.com/public/apache/nuttx/target/stm32-nucleo-f103rb/compare?head=9879a91e9cb03a7b7e02e0c8235802c655caf287&base=17747ded0aaba11af1dd07422c15354200e65e3e)
--
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
Re: [PR] libs/libc/machine/arm64: Add the ucontext functions. [nuttx]
Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli commented on code in PR #20724:
URL: https://github.com/apache/nuttx/pull/20724#discussion_r4304229461
##########
Kconfig:
##########
@@ -654,6 +654,13 @@ config ARCH_HAVE_SETJMP
bool
default n
+config ARCH_HAVE_UCONTEXT
Review Comment:
Done.
##########
arch/arm64/include/ucontext.h:
##########
@@ -0,0 +1,52 @@
+/****************************************************************************
+ * arch/arm64/include/ucontext.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 __ARCH_ARM64_INCLUDE_UCONTEXT_H
+#define __ARCH_ARM64_INCLUDE_UCONTEXT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* The machine context of getcontext() and makecontext(). The assembly code
+ * in libs/libc/machine/arm64/arch_ucontext.S knows this layout.
+ */
+
+typedef struct mcontext_s
Review Comment:
Done.
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
+ ...)
+{
+ FAR uint64_t *stack;
+ uintptr_t sp;
+ va_list ap;
+ int i;
+
+ sp = ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~15;
Review Comment:
With `CONFIG_TLS_ALIGNED`, `STACK_ALIGNMENT` is `TLS_STACK_ALIGN`, the maximum stack size. The caller gives the stack in `uc_stack`, so we must not align it down that much. I use `STACKFRAME_ALIGN` from `arch/irq.h`.
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
+ ...)
+{
+ FAR uint64_t *stack;
+ uintptr_t sp;
+ va_list ap;
+ int i;
+
+ sp = ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~15;
+
+ /* The first eight arguments go in x0-x7, the others on the stack */
+
+ if (argc > 8)
+ {
+ sp = (sp - (argc - 8) * sizeof(uint64_t)) & ~15;
Review Comment:
Same as above: `STACKFRAME_ALIGN`.
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
Review Comment:
Done.
##########
libs/libc/machine/arm64/arch_makecontext.c:
##########
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/arch_makecontext.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+
+#include <signal.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <ucontext.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* In arch_ucontext.S, and called from there */
+
+void arm64_ucontext_start(void);
+int arm64_ucontext_getmask(FAR ucontext_t *ucp);
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp);
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_ucontext_getmask, arm64_ucontext_setmask and
+ * arm64_ucontext_swapmask
+ *
+ * Description:
+ * Save and restore the signal mask of a context, for getcontext(),
+ * setcontext() and swapcontext().
+ *
+ ****************************************************************************/
+
+int arm64_ucontext_getmask(FAR ucontext_t *ucp)
+{
+ return sigprocmask(SIG_BLOCK, NULL, &ucp->uc_sigmask);
+}
+
+void arm64_ucontext_setmask(FAR const ucontext_t *ucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
+}
+
+void arm64_ucontext_swapmask(FAR const ucontext_t *ucp,
+ FAR ucontext_t *oucp)
+{
+ sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask);
+}
+
+/****************************************************************************
+ * Name: makecontext
+ *
+ * Description:
+ * Make ucp run func(argc integer arguments) on ucp->uc_stack. When func
+ * returns, the context continues with ucp->uc_link, or the task exits if
+ * it is NULL.
+ *
+ ****************************************************************************/
+
+void makecontext(FAR ucontext_t *ucp, CODE void (*func)(void), int argc,
+ ...)
+{
+ FAR uint64_t *stack;
+ uintptr_t sp;
+ va_list ap;
+ int i;
+
+ sp = ((uintptr_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ~15;
+
+ /* The first eight arguments go in x0-x7, the others on the stack */
+
+ if (argc > 8)
+ {
+ sp = (sp - (argc - 8) * sizeof(uint64_t)) & ~15;
+ }
+
+ stack = (FAR uint64_t *)sp;
+
+ va_start(ap, argc);
+ for (i = 0; i < argc; i++)
+ {
+ if (i < 8)
+ {
+ ucp->uc_mcontext.regs[i] = (uint64_t)va_arg(ap, int);
+ }
+ else
+ {
+ stack[i - 8] = (uint64_t)va_arg(ap, int);
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-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org