Xenomai API  2.6.5
Collaboration diagram for Utility Services:

Functions

int rtdm_mmap_to_user (rtdm_user_info_t *user_info, void *src_addr, size_t len, int prot, void **pptr, struct vm_operations_struct *vm_ops, void *vm_private_data)
 Map a kernel memory range into the address space of the user. More...
 
int rtdm_iomap_to_user (rtdm_user_info_t *user_info, phys_addr_t src_addr, size_t len, int prot, void **pptr, struct vm_operations_struct *vm_ops, void *vm_private_data)
 Map an I/O memory range into the address space of the user. More...
 
int rtdm_munmap (rtdm_user_info_t *user_info, void *ptr, size_t len)
 Unmap a user memory range. More...
 
int rtdm_ratelimit (struct rtdm_ratelimit_state *rs, const char *func)
 Enforces a rate limit. More...
 
void rtdm_printk_ratelimited (const char *format,...)
 Real-time safe rate-limited message printing on kernel console. More...
 
void rtdm_printk (const char *format,...)
 Real-time safe message printing on kernel console. More...
 
void * rtdm_malloc (size_t size)
 Allocate memory block in real-time context. More...
 
void rtdm_free (void *ptr)
 Release real-time memory block. More...
 
int rtdm_read_user_ok (rtdm_user_info_t *user_info, const void __user *ptr, size_t size)
 Check if read access to user-space memory block is safe. More...
 
int rtdm_rw_user_ok (rtdm_user_info_t *user_info, const void __user *ptr, size_t size)
 Check if read/write access to user-space memory block is safe. More...
 
int rtdm_copy_from_user (rtdm_user_info_t *user_info, void *dst, const void __user *src, size_t size)
 Copy user-space memory block to specified buffer. More...
 
int rtdm_safe_copy_from_user (rtdm_user_info_t *user_info, void *dst, const void __user *src, size_t size)
 Check if read access to user-space memory block and copy it to specified buffer. More...
 
int rtdm_copy_to_user (rtdm_user_info_t *user_info, void __user *dst, const void *src, size_t size)
 Copy specified buffer to user-space memory block. More...
 
int rtdm_safe_copy_to_user (rtdm_user_info_t *user_info, void __user *dst, const void *src, size_t size)
 Check if read/write access to user-space memory block is safe and copy specified buffer to it. More...
 
int rtdm_strncpy_from_user (rtdm_user_info_t *user_info, char *dst, const char __user *src, size_t count)
 Copy user-space string to specified buffer. More...
 
int rtdm_in_rt_context (void)
 Test if running in a real-time task. More...
 
int rtdm_rt_capable (rtdm_user_info_t *user_info)
 Test if the caller is capable of running in real-time context. More...
 

Detailed Description

Function Documentation

int rtdm_copy_from_user ( rtdm_user_info_t *  user_info,
void *  dst,
const void __user *  src,
size_t  size 
)

Copy user-space memory block to specified buffer.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
[in]dstDestination buffer address
[in]srcAddress of the user-space memory block
[in]sizeSize of the memory block
Returns
0 on success, otherwise:
  • -EFAULT is returned if an invalid memory area was accessed.
Note
Before invoking this service, verify via rtdm_read_user_ok() that the provided user-space address can securely be accessed.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

int rtdm_copy_to_user ( rtdm_user_info_t *  user_info,
void __user *  dst,
const void *  src,
size_t  size 
)

Copy specified buffer to user-space memory block.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
[in]dstAddress of the user-space memory block
[in]srcSource buffer address
[in]sizeSize of the memory block
Returns
0 on success, otherwise:
  • -EFAULT is returned if an invalid memory area was accessed.
Note
Before invoking this service, verify via rtdm_rw_user_ok() that the provided user-space address can securely be accessed.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

void rtdm_free ( void *  ptr)

Release real-time memory block.

Parameters
[in]ptrPointer to memory block as returned by rtdm_malloc()

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Interrupt service routine (consider the overhead!)
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

int rtdm_in_rt_context ( void  )

Test if running in a real-time task.

Returns
Non-zero is returned if the caller resides in real-time context, 0 otherwise.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

int rtdm_iomap_to_user ( rtdm_user_info_t *  user_info,
phys_addr_t  src_addr,
size_t  len,
int  prot,
void **  pptr,
struct vm_operations_struct *  vm_ops,
void *  vm_private_data 
)

Map an I/O memory range into the address space of the user.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
[in]src_addrphysical I/O address to be mapped
[in]lenLength of the memory range
[in]protProtection flags for the user's memory range, typically either PROT_READ or PROT_READ|PROT_WRITE
[in,out]pptrAddress of a pointer containing the desired user address or NULL on entry and the finally assigned address on return
[in]vm_opsvm_operations to be executed on the vma_area of the user memory range or NULL
[in]vm_private_dataPrivate data to be stored in the vma_area, primarily useful for vm_operation handlers
Returns
0 on success, otherwise (most common values):
  • -EINVAL is returned if an invalid start address, size, or destination address was passed.
  • -ENOMEM is returned if there is insufficient free memory or the limit of memory mapping for the user process was reached.
  • -EAGAIN is returned if too much memory has been already locked by the user process.
  • -EPERM may be returned if an illegal invocation environment is detected.
Note
RTDM supports two models for unmapping the user memory range again. One is explicit unmapping via rtdm_munmap(), either performed when the user requests it via an IOCTL etc. or when the related device is closed. The other is automatic unmapping, triggered by the user invoking standard munmap() or by the termination of the related process. To track release of the mapping and therefore relinquishment of the referenced physical memory, the caller of rtdm_iomap_to_user() can pass a vm_operations_struct on invocation, defining a close handler for the vm_area. See Linux documentaion (e.g. Linux Device Drivers book) on virtual memory management for details.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • User-space task (non-RT)

Rescheduling: possible.

void* rtdm_malloc ( size_t  size)

Allocate memory block in real-time context.

Parameters
[in]sizeRequested size of the memory block
Returns
The pointer to the allocated block is returned on success, NULL otherwise.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Interrupt service routine (consider the overhead!)
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

int rtdm_mmap_to_user ( rtdm_user_info_t *  user_info,
void *  src_addr,
size_t  len,
int  prot,
void **  pptr,
struct vm_operations_struct *  vm_ops,
void *  vm_private_data 
)

Map a kernel memory range into the address space of the user.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
[in]src_addrKernel virtual address to be mapped
[in]lenLength of the memory range
[in]protProtection flags for the user's memory range, typically either PROT_READ or PROT_READ|PROT_WRITE
[in,out]pptrAddress of a pointer containing the desired user address or NULL on entry and the finally assigned address on return
[in]vm_opsvm_operations to be executed on the vma_area of the user memory range or NULL
[in]vm_private_dataPrivate data to be stored in the vma_area, primarily useful for vm_operation handlers
Returns
0 on success, otherwise (most common values):
  • -EINVAL is returned if an invalid start address, size, or destination address was passed.
  • -ENOMEM is returned if there is insufficient free memory or the limit of memory mapping for the user process was reached.
  • -EAGAIN is returned if too much memory has been already locked by the user process.
  • -EPERM may be returned if an illegal invocation environment is detected.
Note
This service only works on memory regions allocated via kmalloc() or vmalloc(). To map physical I/O memory to user-space use rtdm_iomap_to_user() instead.
RTDM supports two models for unmapping the user memory range again. One is explicit unmapping via rtdm_munmap(), either performed when the user requests it via an IOCTL etc. or when the related device is closed. The other is automatic unmapping, triggered by the user invoking standard munmap() or by the termination of the related process. To track release of the mapping and therefore relinquishment of the referenced physical memory, the caller of rtdm_mmap_to_user() can pass a vm_operations_struct on invocation, defining a close handler for the vm_area. See Linux documentaion (e.g. Linux Device Drivers book) on virtual memory management for details.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • User-space task (non-RT)

Rescheduling: possible.

int rtdm_munmap ( rtdm_user_info_t *  user_info,
void *  ptr,
size_t  len 
)

Unmap a user memory range.

Parameters
[in]user_infoUser information pointer as passed to rtdm_mmap_to_user() when requesting to map the memory range
[in]ptrUser address or the memory range
[in]lenLength of the memory range
Returns
0 on success, otherwise:
  • -EINVAL is returned if an invalid address or size was passed.
  • -EPERM may be returned if an illegal invocation environment is detected.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • User-space task (non-RT)

Rescheduling: possible.

void rtdm_printk ( const char *  format,
  ... 
)

Real-time safe message printing on kernel console.

Parameters
[in]formatFormat string (conforming standard printf())
...Arguments referred by format
Returns
On success, this service returns the number of characters printed. Otherwise, a negative error code is returned.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Interrupt service routine (consider the overhead!)
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never in real-time context, possible in non-real-time environments.

void rtdm_printk_ratelimited ( const char *  format,
  ... 
)

Real-time safe rate-limited message printing on kernel console.

Parameters
[in]formatFormat string (conforming standard printf())
...Arguments referred by format
Returns
On success, this service returns the number of characters printed. Otherwise, a negative error code is returned.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Interrupt service routine (consider the overhead!)
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never in real-time context, possible in non-real-time environments.

int rtdm_ratelimit ( struct rtdm_ratelimit_state *  rs,
const char *  func 
)

Enforces a rate limit.

This function enforces a rate limit: not more than ->burst callbacks in every ->interval.

Parameters
[in,out]rtdm_ratelimit_statedata
[in]nameof calling function
Returns
0 means callback will be suppressed and 1 means go ahead and do it

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: possible.

References rtdm_clock_read(), rtdm_lock_get_irqsave, and rtdm_lock_put_irqrestore.

int rtdm_read_user_ok ( rtdm_user_info_t *  user_info,
const void __user *  ptr,
size_t  size 
)

Check if read access to user-space memory block is safe.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
[in]ptrAddress of the user-provided memory block
[in]sizeSize of the memory block
Returns
Non-zero is return when it is safe to read from the specified memory block, 0 otherwise.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

int rtdm_rt_capable ( rtdm_user_info_t *  user_info)

Test if the caller is capable of running in real-time context.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
Returns
Non-zero is returned if the caller is able to execute in real-time context (independent of its current execution mode), 0 otherwise.
Note
This function can be used by drivers that provide different implementations for the same service depending on the execution mode of the caller. If a caller requests such a service in non-real-time context but is capable of running in real-time as well, it might be appropriate for the driver to reject the request via -ENOSYS so that RTDM can switch the caller and restart the request in real-time context.

Environments:

This service can be called from:

  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

int rtdm_rw_user_ok ( rtdm_user_info_t *  user_info,
const void __user *  ptr,
size_t  size 
)

Check if read/write access to user-space memory block is safe.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
[in]ptrAddress of the user-provided memory block
[in]sizeSize of the memory block
Returns
Non-zero is return when it is safe to read from or write to the specified memory block, 0 otherwise.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

int rtdm_safe_copy_from_user ( rtdm_user_info_t *  user_info,
void *  dst,
const void __user *  src,
size_t  size 
)

Check if read access to user-space memory block and copy it to specified buffer.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
[in]dstDestination buffer address
[in]srcAddress of the user-space memory block
[in]sizeSize of the memory block
Returns
0 on success, otherwise:
  • -EFAULT is returned if an invalid memory area was accessed.
Note
This service is a combination of rtdm_read_user_ok and rtdm_copy_from_user.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

int rtdm_safe_copy_to_user ( rtdm_user_info_t *  user_info,
void __user *  dst,
const void *  src,
size_t  size 
)

Check if read/write access to user-space memory block is safe and copy specified buffer to it.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
[in]dstAddress of the user-space memory block
[in]srcSource buffer address
[in]sizeSize of the memory block
Returns
0 on success, otherwise:
  • -EFAULT is returned if an invalid memory area was accessed.
Note
This service is a combination of rtdm_rw_user_ok and rtdm_copy_to_user.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.

int rtdm_strncpy_from_user ( rtdm_user_info_t *  user_info,
char *  dst,
const char __user *  src,
size_t  count 
)

Copy user-space string to specified buffer.

Parameters
[in]user_infoUser information pointer as passed to the invoked device operation handler
[in]dstDestination buffer address
[in]srcAddress of the user-space string
[in]countMaximum number of bytes to copy, including the trailing '0'
Returns
Length of the string on success (not including the trailing '0'), otherwise:
  • -EFAULT is returned if an invalid memory area was accessed.
Note
This services already includes a check of the source address, calling rtdm_read_user_ok() for src explicitly is not required.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code
  • Kernel-based task
  • User-space task (RT, non-RT)

Rescheduling: never.