mapping.c

来自「一个操作系统的源代码」· C语言 代码 · 共 71 行

C
71
字号
/** mapping.c
 **
 ** Original Author: Guido de Jong
 ** Date: 11/16/99
 **
 ** Description:
 ** Binary tree implementation for page mapping.
 ** 
 ** This program is free software, you can redistribute it and/or
 ** modify it under the terms of the GNU General Public License
 ** as published by the Free Software Foundation; either version
 ** 2 of the License, or (at your option) any later version.
 **
 ** This program is distributed in the hope that it will be
 ** useful, but WITHOUT ANY WARRANTY; without even the implied
 ** warranty or MERCHANTABILITY or FITNESS FOR A PARTICULAR
 ** PURPOSE.  See the GNU General Public License for more
 ** details.
 **
 ** You should have received a copy of the GNU General Public
 ** License along with this program; if not, write to the
 ** Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 ** Boston, MA 02111-1307 USA
 **
 *********************************************************Apostle OS**/

#include <types.h>
#include <mapping.h>
#include <mem.h>

/* Allocate memory and initialize a new node */
MappingNode *NewMappingNode(dword *addrSp, void *addr)
{
  MappingNode *node;

  node = (MappingNode *) malloc(sizeof(MappingNode));
  node->addrSpace = addrSp;
  node->address = addr;
  node->parent = node->next = node->child = NULL;
  return node;
}


/* Add child_node as a child to parent_node */
void AddNode(MappingNode *parentNode, MappingNode *childNode)
{
  childNode->next = parentNode->child;
  parentNode->child = childNode;
  childNode->parent = parentNode;
}


/* Remove node from the tree and from memory */
void DeleteNode(MappingNode *node)
{
  MappingNode *p;

  /* Assume node has no children */
  p = node->parent->child;
  if (p == node)
    node->parent->child = node->next;
  else
    {
      while (p->next != node)
        p = p->next;
      p->next = node->next;
    }
  free(node);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?