source: trunk/kernel/mm/vseg.h @ 408

Last change on this file since 408 was 408, checked in by alain, 4 years ago

Fix several bugs in the fork() syscall.

File size: 9.0 KB
Line 
1/*
2 * vseg.h - virtual segment (vseg) related operations
3 *
4 * Authors   Ghassan Almaless (2008,2009,2010,2011, 2012)
5 *           Mohamed Lamine Karaoui (2015)
6 *           Alain Greiner (2016)
7 *
8 * Copyright (c) UPMC Sorbonne Universites
9 *
10 * This file is part of ALMOS-MKH.
11 *
12 * ALMOS-MKH is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2.0 of the License.
15 *
16 * ALMOS-MKH is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef _VSEG_H_
27#define _VSEG_H_
28
29#include <hal_types.h>
30#include <spinlock.h>
31#include <vfs.h>
32
33/****  Forward declarations  ****/
34
35struct vmm_s;
36
37/**********************************************************************************************
38 * This enum defines the vseg types for an user process.
39 *********************************************************************************************/
40
41typedef enum
42{
43    VSEG_TYPE_CODE   = 0,          /*! executable user code   / private / localized          */
44    VSEG_TYPE_DATA   = 1,          /*! initialized user data  / public  / distributed        */
45    VSEG_TYPE_STACK  = 2,          /*! execution user stack   / private / localized          */
46    VSEG_TYPE_ANON   = 3,          /*! anonymous mmap         / public  / localized          */
47    VSEG_TYPE_FILE   = 4,          /*! file mmap              / public  / localized          */
48    VSEG_TYPE_REMOTE = 5,          /*! remote mmap            / public  / localized          */
49
50    VSEG_TYPE_KDATA  = 10,
51    VSEG_TYPE_KCODE  = 11,
52    VSEG_TYPE_KDEV   = 12,
53}
54vseg_type_t;
55
56
57/**********************************************************************************************
58 * These masks define the vseg generic (hardware independent) flags.
59 *********************************************************************************************/
60
61#define VSEG_USER     0x0001       /*! user accessible                                       */
62#define VSEG_WRITE    0x0002       /*! writeable                                             */
63#define VSEG_EXEC     0x0004       /*! executable                                            */
64#define VSEG_CACHE    0x0008       /*! cachable                                              */
65#define VSEG_PRIVATE  0x0010       /*! should not be accessed from another cluster           */
66#define VSEG_DISTRIB  0x0020       /*! physically distributed on all clusters                */
67
68/**********************************************************************************************
69 * This structure defines a virtual segment descriptor.
70 * - The VSL contains only local vsegs, but is implemented as an xlist, because it can be
71 *   accessed by thread running in a remote cluster.
72 * - The zombi list is used by the local MMAP allocator. It is implemented as a local list.
73 *********************************************************************************************/
74
75typedef struct vseg_s
76{
77        xlist_entry_t     xlist;        /*! all vsegs in same VSL (or same zombi list)           */
78        list_entry_t      zlist;        /*! all vsegs in same zombi list                         */
79        struct vmm_s    * vmm;          /*! pointer on associated VM manager                     */
80    uint32_t          type;         /*! vseg type                                            */
81        intptr_t          min;          /*! segment min virtual address                          */
82        intptr_t          max;          /*! segment max virtual address (excluded)               */
83        vpn_t             vpn_base;     /*! first page of vseg                                   */
84        vpn_t             vpn_size;     /*! number of pages occupied                             */
85        uint32_t          flags;        /*! vseg attributes                                      */
86        xptr_t            mapper_xp;    /*! xptr on remote mapper (for types CODE/DATA/FILE)     */
87        intptr_t          file_offset;  /*! vseg offset in file (for types CODE/DATA/FILE        */
88    intptr_t          file_size;    /*! max segment size in mapper (for type CODE/DATA)      */
89    cxy_t             cxy;          /*! physical mapping (for non distributed vseg)          */ 
90}
91vseg_t;
92
93/**********************************************************************************************
94 * This function returns a printable string for the vseg type.
95 **********************************************************************************************
96 * @ vseg_type  : type of vseg
97 * @ return pointer on string
98 *********************************************************************************************/
99char * vseg_type_str( uint32_t vseg_type );
100
101/**********************************************************************************************
102 * This function allocates physical memory for a new vseg descriptor from the local cluster
103 * physical memory allocator.
104 **********************************************************************************************
105 * @ return pointer on allocated vseg descriptor if success / return NULL if failure.
106 *********************************************************************************************/
107vseg_t * vseg_alloc();
108
109/**********************************************************************************************
110 * This function releases physical memory allocated for a vseg descriptor to the local cluster
111 * physical memory allocator.
112 **********************************************************************************************
113 * @ vseg   : local pointer on released vseg descriptor.
114 *********************************************************************************************/
115void vseg_free( vseg_t * vseg );
116
117/**********************************************************************************************
118 * This function initializes a local vseg descriptor, from the arguments values.
119 * It does NOT register the vseg in the local VMM.
120 **********************************************************************************************
121 * @ vseg      : pointer on the vseg descriptor.
122 * @ base      : vseg base address.
123 * @ size      : vseg size (bytes).
124 * @ vpn_base  : first page index.
125 * @ vpn_size  : number of pages.
126 * @ type      : vseg type.
127 * @ cxy       : target cluster for physical mapping.
128 *********************************************************************************************/
129void vseg_init( vseg_t      * vseg,
130                    vseg_type_t   type,
131                intptr_t      base,
132                    uint32_t      size,
133                vpn_t         vpn_base,
134                vpn_t         vpn_size,
135                uint32_t      file_offset,
136                uint32_t      file_size,
137                xptr_t        mapper_xp,
138                cxy_t         cxy );
139
140/**********************************************************************************************
141 * This function initializes a local vseg descriptor from values contained in a reference
142 * remote vseg descriptor. It does NOT register the vseg in the local VMM.
143 **********************************************************************************************
144 * @ vseg      : pointer on the vseg descriptor.
145 * @ ref_xp    : extended pointer on the reference vseg descriptor.
146 *********************************************************************************************/
147void vseg_init_from_ref( vseg_t * vseg,
148                         xptr_t   ref_xp );
149
150/**********************************************************************************************
151 * This function adds a vseg descriptor in the set of vsegs controlled by a given VMM,
152 * and updates the vmm field in the vseg descriptor.
153 * The lock protecting the vsegs list in VMM must be taken by the caller.
154 **********************************************************************************************
155 * @ vmm       : pointer on the VMM
156 * @ vseg      : pointer on the vseg descriptor
157 *********************************************************************************************/
158void vseg_attach( struct vmm_s  * vmm,
159                  vseg_t        * vseg );
160
161/**********************************************************************************************
162 * This function removes a vseg descriptor from the set of vsegs controlled by a given VMM,
163 * and updates the vmm field in the vseg descriptor. No memory is released.
164 * The lock protecting the vsegs list in VMM must be taken by the caller.
165 **********************************************************************************************
166 * @ vmm       : pointer on the VMM
167 * @ vseg      : pointer on the vseg descriptor
168 *********************************************************************************************/
169void vseg_detach( struct vmm_s  * vmm,
170                  vseg_t        * vseg );
171
172
173#endif /* _VSEG_H_ */
Note: See TracBrowser for help on using the repository browser.