1 /* $Id: phys.c,v 1.5 1994/06/24 11:18:03 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
11 /* Physical manipulations.
12 The blocks concerned are not in any logical chain.
20 /* The newly acquired piece of memory at p, of length n,
21 is turned into a free chunk, properly chained in the
23 The address of the chunk is returned.
26 /* All of malloc memory is followed by a virtual chunk, the
27 mallink of which starts mallink_size() bytes past the last
29 Its use is prevented by testing for ml == ml_last first.
31 register mallink *last = ml_last;
33 assert(!last || p == (char *)phys_next_of(last) - mallink_size());
34 ml = (mallink *)(p + mallink_size()); /* bump ml */
36 started_working_on(ml);
38 set_phys_prev(ml, last);
41 set_phys_next(ml, (mallink *)((char *)ml + n));
43 assert(size_of(ml) + mallink_size() == n);
44 if (last && free_of(last)) {
45 coalesce_backw(ml, last);
48 check_mallinks("create_chunk, phys. linked");
57 /* The chunk ml is truncated.
58 The chunk at ml is split in two.
59 The remaining part is then freed.
61 register mallink *new = (mallink *)((char *)ml + size);
62 register mallink *ph_next = phys_next_of(ml);
66 set_phys_prev(new, ml);
67 set_phys_next(new, ph_next);
69 if (! last_mallink(ml)) {
70 set_phys_prev(ph_next, new);
71 calc_checksum(ph_next);
72 if (free_of(ph_next)) coalesce_forw(new, ph_next);
75 set_phys_next(ml, new);
78 started_working_on(new);
80 stopped_working_on(new);
81 check_mallinks("truncate");
85 combine_chunks(ml1, ml2)
86 register mallink *ml1, *ml2;
88 /* The chunks ml1 and ml2 are combined.
90 register mallink *ml3 = phys_next_of(ml2);
92 set_phys_next(ml1, ml3);
94 if (!last_mallink(ml2)) {
95 set_phys_prev(ml3, ml1);