Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion util/ass/ass00.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ int main(int argc, char** argv)
* The d flag can be repeated several times, resulting in more
* debugging information.
*/
char workspace[6000];
/* Given to the allocator (asscm.c): aligned as its areas must be. */
_Alignas(max_align_t) char workspace[6000];
char* cp;
int argno;

Expand Down
23 changes: 20 additions & 3 deletions util/ass/asscm.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
The algorithm is first fit.
*/

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "ass00.h"
Expand All @@ -41,13 +42,29 @@ static struct freeblock freexx[2] = { { freexx, 0 }, { freexx + 1, 0 } };

#define CHUNK 2048 /* Smallest chunk to be gotten from UNIX */

/*
* Every area and every free block starts at a multiple of ALIGN, so that
* the structs kept in them (line_t, relc_t, locl_t, ... with pointers: 8
* bytes on a 64-bit host) are aligned: malloc() returns such addresses,
* and all sizes are rounded up to ALIGN. A free block must also have room
* for its own header.
*/
#define ALIGN _Alignof(max_align_t)

static unsigned int roundsize(unsigned int size)
{
if (size < sizeof(struct freeblock))
size = sizeof(struct freeblock);
return (size + (ALIGN - 1)) & ~(unsigned int)(ALIGN - 1);
}

area_t getarea(unsigned int size)
{
struct freeblock *c_ptr, *l_ptr;
char* ptr;
unsigned rqsize;

size = ((size + (sizeof(int) - 1)) / sizeof(int)) * sizeof(int);
size = roundsize(size);
#ifdef MEMUSE
m_used += size;
m_free -= size;
Expand Down Expand Up @@ -75,7 +92,7 @@ area_t getarea(unsigned int size)
if (ptr)
break; /* request succesfull */
rqsize /= 2;
rqsize -= rqsize % sizeof(int);
rqsize -= rqsize % ALIGN;
if (rqsize < sizeof freehead)
{
fatal("Out of memory");
Expand All @@ -93,7 +110,7 @@ void freearea(area_t ptr, unsigned int size)
{
struct freeblock *c_ptr, *l_ptr;

size = ((size + (sizeof(int) - 1)) / sizeof(int)) * sizeof(int);
size = roundsize(size);
#ifdef MEMUSE
m_free += size;
m_used -= size;
Expand Down
Loading