From b2de4260c5c71e518742731a8cdebe3411937181 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 6 Aug 2018 11:53:42 +0200 Subject: score: Fix _Addresses_Subtract() Use architecture-specific integer type for an address difference. Update #3486. --- cpukit/include/rtems/rtems/partimpl.h | 4 ++-- cpukit/include/rtems/score/address.h | 9 +++------ cpukit/rtems/src/dpmemexternal2internal.c | 8 ++++---- cpukit/rtems/src/dpmeminternal2external.c | 8 ++++---- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/cpukit/include/rtems/rtems/partimpl.h b/cpukit/include/rtems/rtems/partimpl.h index ff857708f0..02d3ff8b44 100644 --- a/cpukit/include/rtems/rtems/partimpl.h +++ b/cpukit/include/rtems/rtems/partimpl.h @@ -77,9 +77,9 @@ RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_on_boundary ( Partition_Control *the_partition ) { - uint32_t offset; + intptr_t offset; - offset = (uint32_t) _Addresses_Subtract( + offset = _Addresses_Subtract( the_buffer, the_partition->starting_address ); diff --git a/cpukit/include/rtems/score/address.h b/cpukit/include/rtems/score/address.h index 8f38f7c2dc..fb88230d18 100644 --- a/cpukit/include/rtems/score/address.h +++ b/cpukit/include/rtems/score/address.h @@ -77,7 +77,7 @@ RTEMS_INLINE_ROUTINE void *_Addresses_Subtract_offset ( } /** - * @brief Subtract two offsets. + * @brief Subtract two addresses. * * This function is used to subtract two addresses. It returns the * resulting offset. @@ -86,16 +86,13 @@ RTEMS_INLINE_ROUTINE void *_Addresses_Subtract_offset ( * @param[in] right is the address on the right hand side of the subtraction. * * @return This method returns the resulting address. - * - * @note The cast of an address to an uint32_t makes this code - * dependent on an addresses being thirty two bits. */ -RTEMS_INLINE_ROUTINE int32_t _Addresses_Subtract ( +RTEMS_INLINE_ROUTINE intptr_t _Addresses_Subtract( const void *left, const void *right ) { - return (int32_t) ((const char *) left - (const char *) right); + return (intptr_t) ( (const char *) left - (const char *) right ); } /** diff --git a/cpukit/rtems/src/dpmemexternal2internal.c b/cpukit/rtems/src/dpmemexternal2internal.c index 0456010675..0d9a754b23 100644 --- a/cpukit/rtems/src/dpmemexternal2internal.c +++ b/cpukit/rtems/src/dpmemexternal2internal.c @@ -29,7 +29,7 @@ rtems_status_code rtems_port_external_to_internal( { Dual_ported_memory_Control *the_port; ISR_lock_Context lock_context; - uint32_t ending; + uintptr_t length; if ( internal == NULL ) { return RTEMS_INVALID_ADDRESS; @@ -41,12 +41,12 @@ rtems_status_code rtems_port_external_to_internal( return RTEMS_INVALID_ID; } - ending = _Addresses_Subtract( external, the_port->external_base ); + length = (uintptr_t) _Addresses_Subtract( external, the_port->external_base ); - if ( ending > the_port->length ) { + if ( length > the_port->length ) { *internal = external; } else { - *internal = _Addresses_Add_offset( the_port->internal_base, ending ); + *internal = _Addresses_Add_offset( the_port->internal_base, length ); } _ISR_lock_ISR_enable( &lock_context ); diff --git a/cpukit/rtems/src/dpmeminternal2external.c b/cpukit/rtems/src/dpmeminternal2external.c index bd66ee45cb..9cd1a5d2f8 100644 --- a/cpukit/rtems/src/dpmeminternal2external.c +++ b/cpukit/rtems/src/dpmeminternal2external.c @@ -29,7 +29,7 @@ rtems_status_code rtems_port_internal_to_external( { Dual_ported_memory_Control *the_port; ISR_lock_Context lock_context; - uint32_t ending; + uintptr_t length; if ( external == NULL ) { return RTEMS_INVALID_ADDRESS; @@ -41,12 +41,12 @@ rtems_status_code rtems_port_internal_to_external( return RTEMS_INVALID_ID; } - ending = _Addresses_Subtract( internal, the_port->internal_base ); + length = (uintptr_t) _Addresses_Subtract( internal, the_port->internal_base ); - if ( ending > the_port->length ) { + if ( length > the_port->length ) { *external = internal; } else { - *external = _Addresses_Add_offset( the_port->external_base, ending ); + *external = _Addresses_Add_offset( the_port->external_base, length ); } _ISR_lock_ISR_enable( &lock_context ); -- cgit v1.2.3