File: amm_split.c

package info (click to toggle)
oskit 0.97.20000202-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 58,008 kB
  • ctags: 172,612
  • sloc: ansic: 832,827; asm: 7,640; sh: 3,920; yacc: 3,664; perl: 1,457; lex: 427; makefile: 337; csh: 141; awk: 78
file content (83 lines) | stat: -rw-r--r-- 2,810 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright (c) 1996, 1998 University of Utah and the Flux Group.
 * All rights reserved.
 * 
 * This file is part of the Flux OSKit.  The OSKit is free software, also known
 * as "open source;" you can redistribute it and/or modify it under the terms
 * of the GNU General Public License (GPL), version 2, as published by the Free
 * Software Foundation (FSF).  To explore alternate licensing terms, contact
 * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
 * 
 * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have
 * received a copy of the GPL along with the OSKit; see the file COPYING.  If
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
 */

/*
 * Split an address map entry into two pieces
 */
#include <errno.h>
#include "amm.h"

/*
 * Called whenever the AMM needs to split an entry due to conflicting flags.
 * Calls the user-set split routine if available.  Otherwise performs a
 * simple split here.  Either should split the entries and return zero or
 * return non-zero if the split could not be done.  A non-zero return value
 * is propogated on to whoever performed the action which triggered the split
 * request.
 *
 * ``pentry'' is a pointer to the next field of the entry previous to the
 * one being split.
 *
 * ``entry'' is the entry to be split.
 *
 * ``addr'' is the address at which the split should be made.  Addr is
 * guarenteed to fall in the range of the entry.
 *
 * ``headp'' and ``tailp'' should be set to everything before addr and
 * everything from addr on respectively.  One or both of *headp and *tailp
 * will be a new entry allocated and initialized here or in the user split
 * routine.  If both are new entries, we deallocate the original entry.
 *
 * This routine links the new entries into the map list.
 */
int
amm_split(struct amm *amm, struct amm_entry **pentry, struct amm_entry *entry,
	  oskit_addr_t addr, struct amm_entry **headp, struct amm_entry **tailp)
{
	struct amm_entry *head, *tail;
	int rc;

	assert(addr >= entry->start && addr < entry->end);

	if (amm->split) {
		rc = (*amm->split)(amm, entry, addr, &head, &tail);
		if (rc)
			return rc;
	} else {
		tail = amm_alloc_entry(amm, addr, entry->end - addr,
				       entry->flags);
		if (tail == 0)
			return ENOMEM;
		head = entry;
	}
	head->start = entry->start;
	tail->end = entry->end;
	tail->start = addr;
	head->end = addr;
	head->flags = entry->flags;
	tail->flags = entry->flags;
	tail->next = entry->next;
	head->next = tail;
	*pentry = head;
	if (head != entry && tail != entry)
		amm_free_entry(amm, entry);

	*headp = head;
	*tailp = tail;
	return 0;
}