Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/Unipisa/CMM
13 July 2022, 09:41:13 UTC
  • Code
  • Branches (2)
  • Releases (8)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/SourceCode
    • refs/heads/master
    • 1.9
    • 1.8
    • 1.7
    • 1.6
    • 1.5
    • 1.4
    • 1.3
    • 1.1
  • db1a798
  • /
  • cmm
  • /
  • memory.cpp
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
  • release
origin badgecontent badge Iframe embedding
swh:1:cnt:280a1400e07ba71a62974552da677b974b9ee766
origin badgedirectory badge Iframe embedding
swh:1:dir:78af2ccbb0a8bb0b518d4ba147a0eec0624b1f97
origin badgerevision badge
swh:1:rev:55778ad8b99c136e1886959c1f1333c776df14e1
origin badgesnapshot badge
swh:1:snp:4ac4ed834489429d51fc0fd004f10ddbf78d807a
origin badgerelease badge
swh:1:rel:a6a00f689665e8e5b730fb4706b03c463146259a
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
  • release
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 55778ad8b99c136e1886959c1f1333c776df14e1 authored by Giuseppe Attardi on 15 May 1997, 06:24:54 UTC
1.8 -
Tip revision: 55778ad
memory.cpp
/*---------------------------------------------------------------------------*
 *
 *  memory.c:	Memory areas
 *  date:	16 February 1996
 *  authors:	Giuseppe Attardi
 *  email:	cmm@di.unipi.it
 *  address:	Dipartimento di Informatica
 *		Corso Italia 40
 *		I-56125 Pisa, Italy
 *
 *  Copyright (C) 1996 Giuseppe Attardi.
 *
 *  This file is part of the PoSSo Customizable Memory Manager (CMM).
 *
 * Permission to use, copy, and modify this software and its documentation is
 * hereby granted only under the following terms and conditions.  Both the
 * above copyright notice and this permission notice must appear in all copies
 * of the software, derivative works or modified versions, and any portions
 * thereof, and both notices must appear in supporting documentation.
 *
 * Users of this software agree to the terms and conditions set forth herein,
 * and agree to license at no charge to all parties under these terms and
 * conditions any derivative works or modified versions of this software.
 * 
 * This software may be distributed (but not offered for sale or transferred
 * for compensation) to third parties, provided such third parties agree to
 * abide by the terms and conditions of this notice.  
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE COPYRIGHT HOLDERS DISCLAIM ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL THE COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR
 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 *---------------------------------------------------------------------------*/

#include <stdio.h>
#include "machine.h"

void *		globalHeapStart = 0; // start of global heap
static void *	globalHeapEnd;

/*---------------------------------------------------------------------------*
 * -- MS Windows
 *---------------------------------------------------------------------------*/
#ifdef _WIN32

/* Code contributed by H. Boehm of Xerox PARC
   Modified by G. Attardi

   Under win32, all writable pages outside of the heaps and stack are
   scanned for roots.  Thus the collector sees pointers in DLL data
   segments.  Under win32s, only the main data segment is scanned.

 */
/*
 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
 *
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 *
 * Permission is hereby granted to use or copy this program
 * for any purpose,  provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 */

#include <windows.h>

/* Get the page size.	*/
static unsigned long CmmPageSize = 0;

unsigned long
CmmGetPageSize(void)
{
    SYSTEM_INFO sysinfo;

    if (CmmPageSize == 0) {
        GetSystemInfo(&sysinfo);
        CmmPageSize = sysinfo.dwPageSize;
    }
    return(CmmPageSize);
}

# define is_writable(prot) ((prot) == PAGE_READWRITE \
			    || (prot) == PAGE_WRITECOPY \
			    || (prot) == PAGE_EXECUTE_READWRITE \
			    || (prot) == PAGE_EXECUTE_WRITECOPY)
/* Return the number of bytes that are writable starting at p.	*/
/* The pointer p is assumed to be page aligned.			*/
unsigned long
CmmGetWritableLength(void *p)
{
    MEMORY_BASIC_INFORMATION info;
    unsigned long result;
    unsigned long protect;
    
    result = VirtualQuery(p, &info, sizeof(info));
    if (result != sizeof(info)) {
      fprintf(stderr, "Weird VirtualQuery result\n");
      exit(-1);
    }
    protect = (info.Protect & ~(PAGE_GUARD | PAGE_NOCACHE));
    if (!is_writable(protect)) {
        return(0);
    }
    if (info.State != MEM_COMMIT) return(0);
    return(info.RegionSize);
}

void *
CmmGetStackBase(void)
{
    int dummy;
    void *sp = (void *)(&dummy);
    char *trunc_sp = (char *)((unsigned long)sp & ~(CmmGetPageSize() - 1));
    unsigned long size = CmmGetWritableLength(trunc_sp);
   
    return (void *) (trunc_sp + size);
}

/*
 * Unfortunately, we have to handle win32s very differently from NT,
 * Since VirtualQuery has very different semantics.  In particular,
 * under win32s a VirtualQuery call on an unmapped page returns an
 * invalid result.  Under NT CmmExamineStaticAreas is a noop and
 * all real work is done by GC_register_dynamic_libraries.  Under
 * win32s, we cannot find the data segments associated with dll's.
 * We examine the main data segment here.

 * Return the smallest address p such that VirtualQuery
 * returns correct results for all addresses between p and start.
 */
void *
CmmLeastDescribedAddress(void * start)
{  
  MEMORY_BASIC_INFORMATION info;
  SYSTEM_INFO sysinfo;
  DWORD result;
  LPVOID limit;
  LPVOID p;
  LPVOID q;
  
  GetSystemInfo(&sysinfo);
  limit = sysinfo.lpMinimumApplicationAddress;
  p = (LPVOID)((unsigned long)start & ~(CmmGetPageSize() - 1));
  for (;;) {
  	q = (LPVOID)((char *)p - CmmGetPageSize());
  	if (q > p /* underflow */ || q < limit) break;
  	result = VirtualQuery(q, &info, sizeof(info));
  	if (result != sizeof(info) || info.AllocationBase == 0) break;
  	p = info.AllocationBase;
  }
  return p;
}

void *
getGlobalHeapStart()
{
  MEMORY_BASIC_INFORMATION info;
  DWORD result;
  /* need here a location allocated by malloc() */
  if (globalHeapStart == 0)
	  globalHeapStart = malloc(1);
  result = VirtualQuery((LPCVOID)(globalHeapStart), &info, sizeof(info));
  if (result != sizeof(info)) {
    fprintf(stderr, "Weird VirtualQuery result\n");
    exit(-1);
  }
  globalHeapEnd = globalHeapStart = info.AllocationBase;
  return globalHeapStart;
}

void *
getGlobalHeapEnd()
{
  MEMORY_BASIC_INFORMATION info;
  DWORD result;
  char * limit;
  char * p;
  
  VirtualQuery((LPVOID)globalHeapStart, &info, sizeof(info));
  limit = (char *)globalHeapStart + info.RegionSize;
  for (p = (char *)globalHeapEnd; p < limit; p += CmmPageSize) {
    result = VirtualQuery((LPVOID)p, &info, sizeof(info));
    if (info.State != MEM_COMMIT
	|| !is_writable(info.Protect))
	break;
  }
  globalHeapEnd = p;
  return(globalHeapEnd);
}

void
CmmExamineStaticAreas(void (*ExamineArea)(GCP, GCP))
{
  /* static_root is any static variable */
#define static_root globalHeapStart
  MEMORY_BASIC_INFORMATION info;
  SYSTEM_INFO sysinfo;
  DWORD result;
  LPVOID p;
  char *base, *limit, *new_limit;
#ifdef win3_1
  unsigned long v = GetVersion();

  /* Check that this is not NT, and Windows major version <= 3	*/
  if (!((v & 0x80000000) && (v & 0xff) <= 3))
    return;
#endif
  /* find base of region used by malloc()	*/
  getGlobalHeapStart();
  p = base = limit = (char *)CmmLeastDescribedAddress(&static_root);
  GetSystemInfo(&sysinfo);
  while (p < sysinfo.lpMaximumApplicationAddress) {
    result = VirtualQuery(p, &info, sizeof(info));
    if (result != sizeof(info) || info.AllocationBase == globalHeapStart)
      break;
    new_limit = (char *)p + info.RegionSize;
    if (info.State == MEM_COMMIT
	&& is_writable(info.Protect)) {
      if ((char *)p == limit)
	limit = new_limit;
      else {
	if (base != limit)
	  (*ExamineArea)((GCP)base, (GCP)limit);
	base = (char *)p;
	limit = new_limit;
      }
    }
    if (p > (LPVOID)new_limit)	/* overflow */
	break;
    p = (LPVOID)new_limit;
  }
  if (base != limit)
    (*ExamineArea)((GCP)base, (GCP)limit);
}

#else

void *
getGlobalHeapEnd()
{
	return sbrk(0);
}

void
CmmExamineStaticAreas(void (*ExamineArea)(GCP, GCP))
{
  extern int end;
  (*ExamineArea)((GCP)DATASTART, (GCP)&end);
}

#endif /* _WIN32 */

/*---------------------------------------------------------------------------*
 * -- Stack Bottom
 *---------------------------------------------------------------------------*/

Word stackBottom;	/* The base of the stack	*/

void
CmmSetStackBottom(Word bottom)
{
#ifdef STACKBOTTOM
	stackBottom = (Word) STACKBOTTOM;
#else
#	define STACKBOTTOM_ALIGNMENT_M1 0xffffff
#	ifdef STACK_GROWS_DOWNWARD
	stackBottom = (bottom + STACKBOTTOM_ALIGNMENT_M1)
	& ~STACKBOTTOM_ALIGNMENT_M1;
#	else
	stackBottom = bottom & ~STACKBOTTOM_ALIGNMENT_M1;
#	endif
#endif
}

/*---------------------------------------------------------------------------*
 * -- Data Start
 *---------------------------------------------------------------------------*/

#ifdef __svr4__

char *
CmmSVR4DataStart(int max_page_size)
{
  Word text_end = ((Word)(&etext) + sizeof(Word) - 1) & ~(sizeof(Word) - 1);
  /* etext rounded to word boundary	*/
  Word next_page = (text_end + (Word)max_page_size - 1)
    & ~((Word)max_page_size - 1);
  Word page_offset = (text_end & ((Word)max_page_size - 1));
  char * result = (char *)(next_page + page_offset);
  /* Note that this isn't equivalent to just adding
   * max_page_size to &etext if &etext is at a page boundary
   */
  return(result);
}
#endif

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top