Index: trunk/kernel/mm/vseg.h
===================================================================
--- trunk/kernel/mm/vseg.h	(revision 690)
+++ trunk/kernel/mm/vseg.h	(revision 1)
@@ -2,5 +2,7 @@
  * vseg.h - virtual segment (vseg) related operations
  *
- * Authors  Alain Greiner (2016,2017,2018,2019,2020)
+ * Authors   Ghassan Almaless (2008,2009,2010,2011, 2012)
+ *           Mohamed Lamine Karaoui (2015)
+ *           Alain Greiner (2016)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -25,5 +27,6 @@
 #define _VSEG_H_
 
-#include <hal_kernel_types.h>
+#include <hal_types.h>
+#include <spinlock.h>
 #include <vfs.h>
 
@@ -32,105 +35,129 @@
 struct vmm_s;
 
-/*******************************************************************************************
- * This enum defines the vseg types.
- * Note : the KDATA and KDEV types are not used by the TSAR HAL, because the accesses
- *        to kernel data or kernel devices are done through the DATA extension address
- *        register, but these types are probably required by the I86 HAL [AG].
- ******************************************************************************************/
+/**********************************************************************************************
+ * This enum defines the vseg types
+ *********************************************************************************************/
 
-typedef enum
+enum
 {
-    VSEG_TYPE_CODE   = 1,          /*! executable user code     / private / localized     */
-    VSEG_TYPE_DATA   = 2,          /*! initialized user data    / public  / distributed   */
-    VSEG_TYPE_STACK  = 3,          /*! execution user stack     / private / localized     */
-    VSEG_TYPE_ANON   = 4,          /*! anonymous mmap           / public  / localized     */
-    VSEG_TYPE_FILE   = 5,          /*! file mmap                / public  / localized     */
-    VSEG_TYPE_REMOTE = 6,          /*! remote mmap              / public  / localized     */
+    VSEG_TYPE_CODE   = 0,          /*! executable code        / private / localized          */
+    VSEG_TYPE_DATA   = 1,          /*! initialized data       / public  / distributed        */
+    VSEG_TYPE_HEAP   = 2,          /*! standard malloc        / public  / distributed        */
+    VSEG_TYPE_STACK  = 3,          /*! execution stack        / private / localized          */
+    VSEG_TYPE_ANON   = 4,          /*! anonymous mmap         / public  / localized          */
+    VSEG_TYPE_FILE   = 5,          /*! file mmap              / public  / localized          */
+    VSEG_TYPE_REMOTE = 6,          /*! remote mmap            / public  / localized          */
+    VSEG_TYPE_KCODE  = 7,          /*! kernel code            / private / localized          */
+    VSEG_TYPE_KDATA  = 8,          /*! kernel data            / private / localized          */
+    VSEG_TYPE_KDEV   = 9,          /*! device segment         / public  / localized          */
 
-    VSEG_TYPE_KCODE  = 7,          /*! executable kernel code   / private / localized     */
-    VSEG_TYPE_KDATA  = 8,          /*! initialized kernel data  / private / localized     */
-    VSEG_TYPE_KDEV   = 9,          /*! kernel peripheral device / public  / localized     */
-}
-vseg_type_t;
+    VSEG_TYPES_NR    = 10,
+};
 
 
-/*******************************************************************************************
- * These masks define the vseg generic (hardware independent) flags.
- ******************************************************************************************/
+/**********************************************************************************************
+ * These masks define the vseg generic (hardware independant) flags.
+ *********************************************************************************************/
 
-#define VSEG_USER     0x0001       /*! user accessible                                    */
-#define VSEG_WRITE    0x0002       /*! writeable                                          */
-#define VSEG_EXEC     0x0004       /*! executable                                         */
-#define VSEG_CACHE    0x0008       /*! cachable                                           */
-#define VSEG_PRIVATE  0x0010       /*! should not be accessed from another cluster        */
-#define VSEG_DISTRIB  0x0020       /*! physically distributed on all clusters             */
+#define VSEG_USER     0x0001       /*! user accessible                                       */
+#define VSEG_WRITE    0x0002       /*! writeable                                             */
+#define VSEG_EXEC     0x0004       /*! executable                                            */
+#define VSEG_CACHE    0x0008       /*! cachable                                              */
+#define VSEG_PRIVATE  0x0010       /*! should not be accessed from another cluster           */
+#define VSEG_DISTRIB  0x0020       /*! physically distributed on all clusters                */
 
-/*******************************************************************************************
+/**********************************************************************************************
  * This structure defines a virtual segment descriptor.
- * The VSL contains only local vsegs, but is implemented as an xlist, because it can be
- * accessed by a thread running in a remote cluster.
- * The xlist field is also used to implement the zombi lists used by the MMAP allocator.
- ******************************************************************************************/
+ *********************************************************************************************/
 
 typedef struct vseg_s
 {
-    xlist_entry_t     xlist;        /*! all vsegs in same VSL                             */
-    struct vmm_s    * vmm;          /*! pointer on associated VM manager                  */
-    uint32_t          type;         /*! vseg type                                         */
-    intptr_t          min;          /*! segment min virtual address                       */
-    intptr_t          max;          /*! segment max virtual address (excluded)            */
-    vpn_t             vpn_base;     /*! first page of vseg                                */
-    vpn_t             vpn_size;     /*! number of pages occupied                          */
-    xptr_t            mapper_xp;    /*! xptr on remote mapper (for types CODE/DATA/FILE)  */
-    uint32_t          flags;        /*! vseg attributes                                   */
-    intptr_t          file_offset;  /*! vseg offset in file (for types CODE/DATA/FILE)    */
-    intptr_t          file_size;    /*! max segment size in mapper (for type CODE/DATA)   */
-    cxy_t             cxy;          /*! physical mapping (for non distributed vseg)       */ 
+	list_entry_t      list;         /*! all vsegs in same process / same free list if mmap   */
+	struct vmm_s    * vmm;          /*! pointer on associated VM manager                     */
+    uint32_t          type;         /*! vseg type                                            */
+	intptr_t          min;          /*! segment min virtual address                          */
+	intptr_t          max;          /*! segment max virtual address (excluded)               */
+	vpn_t             vpn_base;     /*! first page of vseg                                   */
+	vpn_t             vpn_size;     /*! numbre of pages occupied                             */
+	uint32_t          flags;        /*! vseg attributes                                      */
+	xptr_t            mapper;       /*! extended pointer on associated mapper                */
+	fdid_t            fdid;         /*! associated fdid for a VSEG_TYPE_FILE                 */
+	uint32_t          offset;       /*! offset in file for a VSEG_TYPE_FILE                  */
+    cxy_t             cxy;          /*! target cluster for physical mapping                  */
 }
 vseg_t;
 
-/*******************************************************************************************
- * This function returns a printable string for the vseg type. 
- *******************************************************************************************
- * @ vseg_type  : type of vseg
- * @ return pointer on string
- ******************************************************************************************/
-char * vseg_type_str( uint32_t vseg_type );
-
-/*******************************************************************************************
+/**********************************************************************************************
  * This function allocates physical memory for a new vseg descriptor from the local cluster
  * physical memory allocator.
- *******************************************************************************************
+ **********************************************************************************************
  * @ return pointer on allocated vseg descriptor if success / return NULL if failure.
- ******************************************************************************************/
-vseg_t * vseg_alloc( void );
+ *********************************************************************************************/
+vseg_t * vseg_alloc();
 
-/*******************************************************************************************
- * This function releases the physical memory allocated for a vseg descriptor 
- * to the local cluster physical memory allocator.
- *******************************************************************************************
+/**********************************************************************************************
+ * This function releases physical memory allocated for a vseg descriptor to the local cluster
+ * physical memory allocator.
+ **********************************************************************************************
  * @ vseg   : local pointer on released vseg descriptor.
- ******************************************************************************************/
+ *********************************************************************************************/
 void vseg_free( vseg_t * vseg );
 
-/*******************************************************************************************
- * This function initializes the "flags" field for a local <vseg> descriptor,
- * depending on the vseg <type>. 
- *******************************************************************************************
+/**********************************************************************************************
+ * This function initializes a local vseg descriptor, from the arguments values.
+ * It does NOT register the vseg in the local VMM.
+ **********************************************************************************************
  * @ vseg      : pointer on the vseg descriptor.
+ * @ base      : vseg base address.
+ * @ size      : vseg size (bytes).
+ * @ vpn_base  : first page index.
+ * @ vpn_size  : number of pages.
  * @ type      : vseg type.
- ******************************************************************************************/
-void vseg_init_flags( vseg_t      * vseg,
-	                  vseg_type_t   type );
+ * @ cxy       : target cluster for physical mapping.
+ * @ fdid      : file descriptor index if VSEG_TYPE_FILE.
+ * @ offset    : offset in file if VSEG_TYPE_FILE.
+ *********************************************************************************************/
+void vseg_init( vseg_t      * vseg,
+                intptr_t      base, 
+	            intptr_t      size, 
+                vpn_t         vpn_base,
+                vpn_t         vpn_size,
+	            uint32_t      type,
+                cxy_t         cxy,
+                fdid_t        fdid,
+	            uint32_t      offset );
 
-/*******************************************************************************************
+/**********************************************************************************************
  * This function initializes a local vseg descriptor from values contained in a reference
  * remote vseg descriptor. It does NOT register the vseg in the local VMM.
- *******************************************************************************************
+ **********************************************************************************************
  * @ vseg      : pointer on the vseg descriptor.
- * @ ref_xp    : extended pointer on the reference vseg descriptor.
- ******************************************************************************************/
+ * @ src       : extended pointer on the reference vseg descriptor.
+ *********************************************************************************************/
 void vseg_init_from_ref( vseg_t * vseg,
-                         xptr_t   ref_xp );
+                         xptr_t   ref );
+
+/**********************************************************************************************
+ * This function add a vseg descriptor in the set of vsegs controled by a given VMM,
+ * and update the vmm field in the vseg descriptor. 
+ * The lock protecting the vsegs list in VMM must be taken by the caller.
+ **********************************************************************************************
+ * @ vmm       : pointer on the VMM
+ * @ vseg      : pointer on the vseg descriptor
+ * @ returns 0 if success / returns ENOMEM if failure.
+ *********************************************************************************************/
+error_t vseg_attach( struct vmm_s  * vmm, 
+                     vseg_t        * vseg );
+
+/**********************************************************************************************
+ * This function removes a vseg descriptor from the set of vsegs controled by a given VMM,
+ * and update the vmm field in the vseg descriptor. No memory is released.
+ * The lock protecting the vsegs list in VMM must be taken by the caller.
+ **********************************************************************************************
+ * @ vmm       : pointer on the VMM
+ * @ vseg      : pointer on the vseg descriptor
+ *********************************************************************************************/
+void vseg_detach( struct vmm_s  * vmm, 
+                  vseg_t        * vseg );
 
 
