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

Function sys_timer_create

components/lwp/lwp_syscall.c:3037–3077  ·  view source on GitHub ↗

* @brief Creates a per-process timer. * * This system call creates a new timer associated with the specified clock, and * initializes the timer with the provided event notification attributes. * Once created, the timer can be started, stopped, or controlled as needed. * The timer will trigger when the specified expiration time or interval is reached. * * @param[in] clockid The clock to b

Source from the content-addressed store, hash-verified

3035 * unsupported notification types may result in unexpected behavior.
3036 */
3037sysret_t sys_timer_create(clockid_t clockid, struct sigevent *restrict sevp, timer_t *restrict timerid)
3038{
3039 int ret = 0;
3040#ifdef ARCH_MM_MMU
3041 struct sigevent sevp_k;
3042 timer_t timerid_k;
3043 int utimer;
3044
3045 if (sevp == NULL)
3046 {
3047 sevp_k.sigev_notify = SIGEV_SIGNAL;
3048 sevp_k.sigev_signo = SIGALRM;
3049 sevp = &sevp_k;
3050 }
3051 else
3052 {
3053 /* clear extra bytes if any */
3054 if (sizeof(struct ksigevent) < sizeof(struct sigevent))
3055 memset(&sevp_k, 0, sizeof(sevp_k));
3056
3057 /* musl passes `struct ksigevent` to kernel, we shoule only get size of that bytes */
3058 if (!lwp_get_from_user(&sevp_k, (void *)sevp, sizeof(struct ksigevent)))
3059 {
3060 return -EINVAL;
3061 }
3062 }
3063
3064 ret = _SYS_WRAP(timer_create(clockid, &sevp_k, &timerid_k));
3065
3066 if (ret != -RT_ERROR)
3067 {
3068 utimer = (rt_ubase_t)timerid_k;
3069 if (!lwp_put_to_user(sevp, (void *)&sevp_k, sizeof(struct ksigevent)) ||
3070 !lwp_put_to_user(timerid, (void *)&utimer, sizeof(utimer)))
3071 ret = -EINVAL;
3072 }
3073#else
3074 ret = _SYS_WRAP(timer_create(clockid, sevp, timerid));
3075#endif
3076 return ret;
3077}
3078
3079/**
3080 * @brief Deletes a timer.

Callers

nothing calls this directly

Calls 3

lwp_get_from_userFunction · 0.85
timer_createFunction · 0.85
lwp_put_to_userFunction · 0.85

Tested by

no test coverage detected