Changeset 096c0786 in mainline


Ignore:
Timestamp:
2024-09-16T11:54:47Z (3 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
1bbc6dc
Parents:
bec6379
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-15 18:51:13)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-16 11:54:47)
Message:

Ensure ALIGN_UP/DOWN() work with any size arguments

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/align.h

    rbec6379 r096c0786  
    3939#define KERN_ALIGN_H_
    4040
     41#ifdef __ASSEMBLER__
     42#define ALIGN_DOWN(s, a)  ((s) & ~((a) - 1))
     43#define ALIGN_UP(s, a)    (((s) + ((a) - 1)) & ~((a) - 1))
     44#else
     45
    4146/** Align to the nearest lower address.
    4247 *
     
    4449 * @param a Size of alignment, must be a power of 2.
    4550 */
    46 #define ALIGN_DOWN(s, a)  ((s) & ~((a) - 1))
     51#define ALIGN_DOWN(s, a)  ((s) & ~((typeof(s))(a) - 1))
    4752
    4853/** Align to the nearest higher address.
     
    5156 * @param a Size of alignment, must be a power of 2.
    5257 */
    53 #define ALIGN_UP(s, a)  (((s) + ((a) - 1)) & ~((a) - 1))
     58#define ALIGN_UP(s, a)  (((s) + ((a) - 1)) & ~((typeof(s))(a) - 1))
     59
     60#endif
    5461
    5562/** Check alignment.
  • uspace/lib/c/include/align.h

    rbec6379 r096c0786  
    4141 * @param a             Size of alignment, must be power of 2.
    4242 */
    43 #define ALIGN_DOWN(s, a)        ((s) & ~((a) - 1))
     43#define ALIGN_DOWN(s, a)        ((s) & ~((typeof(s))(a) - 1))
    4444
    4545/** Align to the nearest higher address which is a power of two.
     
    4848 * @param a             Size of alignment, must be power of 2.
    4949 */
    50 #define ALIGN_UP(s, a)          ((long)((s) + ((a) - 1)) & ~((long) (a) - 1))
     50#define ALIGN_UP(s, a)          ((((s) + ((a) - 1)) & ~((typeof(s))(a) - 1)))
    5151
    5252/** Round up to the nearest higher boundary.
Note: See TracChangeset for help on using the changeset viewer.