xmalloc.c (9bc21aae6961a1c93a306414552f8966d8656635) xmalloc.c (eab68f795a5cfe398a635980176572357983e53e)
1/*-
2 * Copyright 1996-1998 John D. Polstra.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 59 unchanged lines hidden (view full) ---

68 return (copy);
69}
70
71void *
72malloc_aligned(size_t size, size_t align)
73{
74 void *mem, *res;
75
1/*-
2 * Copyright 1996-1998 John D. Polstra.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 59 unchanged lines hidden (view full) ---

68 return (copy);
69}
70
71void *
72malloc_aligned(size_t size, size_t align)
73{
74 void *mem, *res;
75
76 if (align & (sizeof(void *) -1)) {
77 rtld_fdputstr(STDERR_FILENO, "Invalid alignment\n");
78 _exit(1);
79 }
76 if (align < sizeof(void *))
77 align = sizeof(void *);
80
81 mem = xmalloc(size + sizeof(void *) + align - 1);
82 res = (void *)round((uintptr_t)mem + sizeof(void *), align);
83 *(void **)((uintptr_t)res - sizeof(void *)) = mem;
84 return (res);
85}
86
87void

--- 12 unchanged lines hidden ---
78
79 mem = xmalloc(size + sizeof(void *) + align - 1);
80 res = (void *)round((uintptr_t)mem + sizeof(void *), align);
81 *(void **)((uintptr_t)res - sizeof(void *)) = mem;
82 return (res);
83}
84
85void

--- 12 unchanged lines hidden ---