[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tyndur-devel] [PATCH 3/3] kernel2: mmc_destroy implementieren



On Fri, Jan 01 14:58, Kevin Wolf wrote:
> + kernel2: mmc_destroy implementiert. Damit wird jetzt nach Prozessende
>   der Speicher auch wieder freigegeben.
> 
> Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
> ---
>  src/kernel2/src/arch/i386/mm/mm_context.c |   38 +++++++++++++++++++++++++++-
>  1 files changed, 36 insertions(+), 2 deletions(-)
> 
> diff --git a/src/kernel2/src/arch/i386/mm/mm_context.c b/src/kernel2/src/arch/i386/mm/mm_context.c
> index 34ac946..b5d8d3f 100644
> --- a/src/kernel2/src/arch/i386/mm/mm_context.c
> +++ b/src/kernel2/src/arch/i386/mm/mm_context.c
> @@ -61,6 +61,9 @@ bool use_phys_addr = TRUE;
>   */
>  static void mmc_sync(mmc_context_t* context);
>  
> +static inline vaddr_t get_pagetable(mmc_context_t* context, size_t index);
> +static inline void free_pagetable(mmc_context_t* context, vaddr_t page_table);
> +
>  /**
>   * Erstellt einen neuen MM-Kontext (Page Directory)
>   */
> @@ -142,11 +145,40 @@ void mmc_activate(mmc_context_t* context)
>  /**
>   * Kontext zerstoeren und Userspace-Speicher freigeben
>   *
> + * Achtung: Der noch gemappte Speicher darf nur zu diesem Kontext gehoeren, er
> + * wird physisch freigegeben! Shared Memory muss vorher freigegeben werden.
> + *
>   * @param context Kontext
>   */
>  void mmc_destroy(mmc_context_t* context)
>  {
> -    // TODO
> +    page_directory_t page_directory = context->page_directory_virt;
> +    page_table_t page_table;
> +    int i, n;
> +
> +    for (i = (MM_USER_START >> PGDIR_SHIFT);
> +         i < (MM_USER_END >> PGDIR_SHIFT);
> +         i++)
> +    {
> +        page_table = get_pagetable(context, i);
> +        if (page_table == NULL) {
> +            continue;
> +        }
> +
> +        // Alle Page-Table-Eintraege freigeben
> +        for(n = 0; n < 1024; n++) {
> +            if(page_table[n] & PTE_P) {
> +                pmm_free((paddr_t) (page_table[n] & PAGE_MASK), 1);
> +            }
> +        }
> +        free_pagetable(context, page_table);
> +
> +        // Page Table freigeben
> +        pmm_free((paddr_t) (page_directory[i] & PAGE_MASK), 1);
> +    }
> +
> +    // Page Directory freigeben
> +    pmm_free(context->page_directory_virt, 1);

Also dieses virt kommt mir etwas seltsam vor...

>  }
>  
>  /**
> @@ -160,7 +192,9 @@ static inline vaddr_t get_pagetable(mmc_context_t* context, size_t index)
>      page_table_t page_table;
>  
>      if (context->page_directory == mmc_current_context().page_directory) {
> -        if (!use_phys_addr) {
> +        if ((pagedir[index] & PTE_P) == 0) {
> +            page_table = NULL;
> +        } else if (!use_phys_addr) {
>              page_table = (page_table_t) 
>                  (PAGETABLES_MEM_START + (PAGE_TABLE_LENGTH * 4 * index));
>          } else {

Der Rest sieht gut aus.

-- 
Antoine Kaufmann
<toni@xxxxxxxxxxxxxxxx>

Attachment: pgpKK9H3YKB8w.pgp
Description: PGP signature