Deleted Added
full compact
monitor_mm.c (99060) monitor_mm.c (106121)
1/*
2 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
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

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

19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "includes.h"
1/*
2 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
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

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

19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "includes.h"
27RCSID("$OpenBSD: monitor_mm.c,v 1.6 2002/06/04 23:05:49 markus Exp $");
27RCSID("$OpenBSD: monitor_mm.c,v 1.8 2002/08/02 14:43:15 millert Exp $");
28
29#ifdef HAVE_SYS_MMAN_H
30#include <sys/mman.h>
31#endif
32
28
29#ifdef HAVE_SYS_MMAN_H
30#include <sys/mman.h>
31#endif
32
33#include "openbsd-compat/xmmap.h"
33#include "ssh.h"
34#include "xmalloc.h"
35#include "log.h"
36#include "monitor_mm.h"
37
38static int
39mm_compare(struct mm_share *a, struct mm_share *b)
40{
34#include "ssh.h"
35#include "xmalloc.h"
36#include "log.h"
37#include "monitor_mm.h"
38
39static int
40mm_compare(struct mm_share *a, struct mm_share *b)
41{
41 return ((char *)a->address - (char *)b->address);
42 long diff = (char *)a->address - (char *)b->address;
43
44 if (diff == 0)
45 return (0);
46 else if (diff < 0)
47 return (-1);
48 else
49 return (1);
42}
43
44RB_GENERATE(mmtree, mm_share, next, mm_compare)
45
46static struct mm_share *
47mm_make_entry(struct mm_master *mm, struct mmtree *head,
48 void *address, size_t size)
49{

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

79
80 /*
81 * If the memory map has a mm_master it can be completely
82 * shared including authentication between the child
83 * and the client.
84 */
85 mm->mmalloc = mmalloc;
86
50}
51
52RB_GENERATE(mmtree, mm_share, next, mm_compare)
53
54static struct mm_share *
55mm_make_entry(struct mm_master *mm, struct mmtree *head,
56 void *address, size_t size)
57{

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

87
88 /*
89 * If the memory map has a mm_master it can be completely
90 * shared including authentication between the child
91 * and the client.
92 */
93 mm->mmalloc = mmalloc;
94
87#ifdef HAVE_MMAP_ANON_SHARED
88 address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED,
89 -1, 0);
95 address = xmmap(size);
90 if (address == MAP_FAILED)
91 fatal("mmap(%lu): %s", (u_long)size, strerror(errno));
96 if (address == MAP_FAILED)
97 fatal("mmap(%lu): %s", (u_long)size, strerror(errno));
92#else
93 fatal("%s: UsePrivilegeSeparation=yes and Compression=yes not supported",
94 __func__);
95#endif
96
97 mm->address = address;
98 mm->size = size;
99
100 RB_INIT(&mm->rb_free);
101 RB_INIT(&mm->rb_allocated);
102
103 mm_make_entry(mm, &mm->rb_free, address, size);

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

125/* Destroys a memory mapped area */
126
127void
128mm_destroy(struct mm_master *mm)
129{
130 mm_freelist(mm->mmalloc, &mm->rb_free);
131 mm_freelist(mm->mmalloc, &mm->rb_allocated);
132
98
99 mm->address = address;
100 mm->size = size;
101
102 RB_INIT(&mm->rb_free);
103 RB_INIT(&mm->rb_allocated);
104
105 mm_make_entry(mm, &mm->rb_free, address, size);

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

127/* Destroys a memory mapped area */
128
129void
130mm_destroy(struct mm_master *mm)
131{
132 mm_freelist(mm->mmalloc, &mm->rb_free);
133 mm_freelist(mm->mmalloc, &mm->rb_allocated);
134
133#ifdef HAVE_MMAP_ANON_SHARED
135#ifdef HAVE_MMAP
134 if (munmap(mm->address, mm->size) == -1)
135 fatal("munmap(%p, %lu): %s", mm->address, (u_long)mm->size,
136 strerror(errno));
137#else
138 fatal("%s: UsePrivilegeSeparation=yes and Compression=yes not supported",
139 __func__);
140#endif
141 if (mm->mmalloc == NULL)

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

160
161void *
162mm_malloc(struct mm_master *mm, size_t size)
163{
164 struct mm_share *mms, *tmp;
165
166 if (size == 0)
167 fatal("mm_malloc: try to allocate 0 space");
136 if (munmap(mm->address, mm->size) == -1)
137 fatal("munmap(%p, %lu): %s", mm->address, (u_long)mm->size,
138 strerror(errno));
139#else
140 fatal("%s: UsePrivilegeSeparation=yes and Compression=yes not supported",
141 __func__);
142#endif
143 if (mm->mmalloc == NULL)

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

162
163void *
164mm_malloc(struct mm_master *mm, size_t size)
165{
166 struct mm_share *mms, *tmp;
167
168 if (size == 0)
169 fatal("mm_malloc: try to allocate 0 space");
170 if (size > SIZE_T_MAX - MM_MINSIZE + 1)
171 fatal("mm_malloc: size too big");
168
172
169 size = ((size + MM_MINSIZE - 1) / MM_MINSIZE) * MM_MINSIZE;
173 size = ((size + (MM_MINSIZE - 1)) / MM_MINSIZE) * MM_MINSIZE;
170
171 RB_FOREACH(mms, mmtree, &mm->rb_free) {
172 if (mms->size >= size)
173 break;
174 }
175
176 if (mms == NULL)
177 return (NULL);

--- 165 unchanged lines hidden ---
174
175 RB_FOREACH(mms, mmtree, &mm->rb_free) {
176 if (mms->size >= size)
177 break;
178 }
179
180 if (mms == NULL)
181 return (NULL);

--- 165 unchanged lines hidden ---