/* * Empty code injection macros, override when testing. * It is important to consider that the ASM injection macros need to be * fully reentrant (e.g. do not modify the stack).
*/ #ifndef RSEQ_INJECT_ASM #define RSEQ_INJECT_ASM(n) #endif
/* Offset from the thread pointer to the rseq area. */ extern ptrdiff_t rseq_offset;
/* * The rseq ABI is composed of extensible feature fields. The extensions * are done by appending additional fields at the end of the structure. * The rseq_size defines the size of the active feature set which can be * used by the application for the current rseq registration. Features * starting at offset >= rseq_size are inactive and should not be used. * * The rseq_size is the intersection between the available allocation * size for the rseq area and the feature size supported by the kernel. * unsuccessful.
*/ externunsignedint rseq_size;
/* Flags used during rseq registration. */ externunsignedint rseq_flags;
/* * Register rseq for the current thread. This needs to be called once * by any thread which uses restartable sequences, before they start * using restartable sequences, to ensure restartable sequences * succeed. A restartable sequence executed from a non-registered * thread will always fail.
*/ int rseq_register_current_thread(void);
/* * Unregister rseq for current thread.
*/ int rseq_unregister_current_thread(void);
/* * Restartable sequence fallback for reading the current CPU number.
*/
int32_t rseq_fallback_current_cpu(void);
/* * Restartable sequence fallback for reading the current node number.
*/
int32_t rseq_fallback_current_node(void);
/* * Returns true if rseq is supported.
*/ bool rseq_available(void);
/* * Values returned can be either the current CPU number, -1 (rseq is * uninitialized), or -2 (rseq initialization has failed).
*/ staticinline int32_t rseq_current_cpu_raw(void)
{ return RSEQ_ACCESS_ONCE(rseq_get_abi()->cpu_id);
}
/* * Returns a possible CPU number, which is typically the current CPU. * The returned CPU number can be used to prepare for an rseq critical * section, which will confirm whether the cpu number is indeed the * current one, and whether rseq is initialized. * * The CPU number returned by rseq_cpu_start should always be validated * by passing it to a rseq asm sequence, or by comparing it to the * return value of rseq_current_cpu_raw() if the rseq asm sequence * does not need to be invoked.
*/ staticinline uint32_t rseq_cpu_start(void)
{ return RSEQ_ACCESS_ONCE(rseq_get_abi()->cpu_id_start);
}
/* * rseq_prepare_unload() should be invoked by each thread executing a rseq * critical section at least once between their last critical section and * library unload of the library defining the rseq critical section (struct * rseq_cs) or the code referred to by the struct rseq_cs start_ip and * post_commit_offset fields. This also applies to use of rseq in code * generated by JIT: rseq_prepare_unload() should be invoked at least once by * each thread executing a rseq critical section before reclaim of the memory * holding the struct rseq_cs or reclaim of the code pointed to by struct * rseq_cs start_ip and post_commit_offset fields.
*/ staticinlinevoid rseq_prepare_unload(void)
{
rseq_clear_rseq_cs();
}
staticinline __attribute__((always_inline)) int rseq_cmpeqv_storev(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
intptr_t *v, intptr_t expect,
intptr_t newv, int cpu)
{ if (rseq_mo != RSEQ_MO_RELAXED) return -1; switch (percpu_mode) { case RSEQ_PERCPU_CPU_ID: return rseq_cmpeqv_storev_relaxed_cpu_id(v, expect, newv, cpu); case RSEQ_PERCPU_MM_CID: return rseq_cmpeqv_storev_relaxed_mm_cid(v, expect, newv, cpu);
} return -1;
}
/* * Compare @v against @expectnot. When it does _not_ match, load @v * into @load, and store the content of *@v + voffp into @v.
*/ staticinline __attribute__((always_inline)) int rseq_cmpnev_storeoffp_load(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
intptr_t *v, intptr_t expectnot, long voffp, intptr_t *load, int cpu)
{ if (rseq_mo != RSEQ_MO_RELAXED) return -1; switch (percpu_mode) { case RSEQ_PERCPU_CPU_ID: return rseq_cmpnev_storeoffp_load_relaxed_cpu_id(v, expectnot, voffp, load, cpu); case RSEQ_PERCPU_MM_CID: return rseq_cmpnev_storeoffp_load_relaxed_mm_cid(v, expectnot, voffp, load, cpu);
} return -1;
}
staticinline __attribute__((always_inline)) int rseq_addv(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
intptr_t *v, intptr_t count, int cpu)
{ if (rseq_mo != RSEQ_MO_RELAXED) return -1; switch (percpu_mode) { case RSEQ_PERCPU_CPU_ID: return rseq_addv_relaxed_cpu_id(v, count, cpu); case RSEQ_PERCPU_MM_CID: return rseq_addv_relaxed_mm_cid(v, count, cpu);
} return -1;
}
#ifdef RSEQ_ARCH_HAS_OFFSET_DEREF_ADDV /* * pval = *(ptr+off) * *pval += inc;
*/ staticinline __attribute__((always_inline)) int rseq_offset_deref_addv(enum rseq_mo rseq_mo, enum rseq_percpu_mode percpu_mode,
intptr_t *ptr, long off, intptr_t inc, int cpu)
{ if (rseq_mo != RSEQ_MO_RELAXED) return -1; switch (percpu_mode) { case RSEQ_PERCPU_CPU_ID: return rseq_offset_deref_addv_relaxed_cpu_id(ptr, off, inc, cpu); case RSEQ_PERCPU_MM_CID: return rseq_offset_deref_addv_relaxed_mm_cid(ptr, off, inc, cpu);
} return -1;
} #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.