Back to index

plt-scheme  4.2.1
Defines | Typedefs | Functions
vm_win.c File Reference

Go to the source code of this file.

Defines

#define CACHE_SLOTS   0

Typedefs

typedef unsigned long size_type
typedef BOOL(WINAPI * QueryInformationJobObject_Proc )(HANDLE hJob, JOBOBJECTINFOCLASS JobObjectInfoClass, LPVOID lpJobObjectInfo, DWORD cbJobObjectInfoLength, LPDWORD lpReturnLength)

Functions

static voidvm_malloc_pages (VM *vm, size_t len, size_t alignment, int dirty_ok)
static void vm_free_pages (VM *vm, void *p, size_t len)
static void vm_flush_freed_pages (VM *vm)
static void vm_protect_pages (void *p, size_t len, int writeable)
static size_type determine_max_heap_size (void)

Define Documentation

#define CACHE_SLOTS   0

Definition at line 11 of file vm_win.c.


Typedef Documentation

typedef BOOL(WINAPI * QueryInformationJobObject_Proc)(HANDLE hJob, JOBOBJECTINFOCLASS JobObjectInfoClass, LPVOID lpJobObjectInfo, DWORD cbJobObjectInfoLength, LPDWORD lpReturnLength)

Definition at line 107 of file vm_win.c.

typedef unsigned long size_type

Definition at line 105 of file vm_win.c.


Function Documentation

static size_type determine_max_heap_size ( void  ) [static]

Definition at line 113 of file vm_win.c.

{
  JOBOBJECT_EXTENDED_LIMIT_INFORMATION info;
  HMODULE hm;
  SYSTEM_INFO si;

  hm = LoadLibrary("kernel32.dll");
  if (hm) {
    DWORD size;
    QueryInformationJobObject_Proc qijo = NULL;
    qijo = (QueryInformationJobObject_Proc)GetProcAddress(hm, "QueryInformationJobObject");
    if (qijo) {
      if (qijo(NULL, JobObjectExtendedLimitInformation, &info, sizeof(info), &size)) {
        if (info.BasicLimitInformation.LimitFlags & JOB_OBJECT_LIMIT_PROCESS_MEMORY) {
          return info.ProcessMemoryLimit;
        }
      }
    }
  }

  GetSystemInfo(&si);
  return (size_type)si.lpMaximumApplicationAddress - (size_type)si.lpMinimumApplicationAddress;
}
static void vm_flush_freed_pages ( VM vm) [static]

Definition at line 76 of file vm_win.c.

{
#if CACHE_SLOTS
  int i;
  void *p, *next;

  for (i = 0; i < CACHE_SLOTS; i++) {
    if (cache[1][i].len) {
      for (p = cache[1][i].page; p; p = next) {
        next = *(void **)p;
        vm_memory_allocated_dec(vm, cache[i].len);
        VirtualFree(p, 0, MEM_RELEASE);
      }
    }
    cache[1][i].len = cache[0][i].len;
    cache[1][i].page = cache[0][i].page;
    cache[0][i].len = 0;
    cache[0][i].page = NULL;
  }
#endif
}

Here is the call graph for this function:

static void vm_free_pages ( VM vm,
void p,
size_t  len 
) [static]

Definition at line 53 of file vm_win.c.

{

#if CACHE_SLOTS
  {
    int i;

    for (i = 0; i < CACHE_SLOTS; i++) {
      if (!cache[0][i].len)
        cache[0][i].len = len;
      if (cache[0][i].len == len) {
        *(void **)p = cache[0][i].page;
        cache[0][i].page = p;
        return;
      }
    }
  }
#endif

  vm_memory_allocated_dec(vm, len);
  VirtualFree(p, 0, MEM_RELEASE);
}

Here is the call graph for this function:

static void* vm_malloc_pages ( VM vm,
size_t  len,
size_t  alignment,
int  dirty_ok 
) [static]

Definition at line 23 of file vm_win.c.

{
#if CACHE_SLOTS
  {
    int i, j;

    for (j = 0; j < 2; j++) {
      for (i = 0; i < CACHE_SLOTS; i++) {
        if (cache[j][i].len == len) {
          if (cache[j][i].page) {
            void *result = cache[j][i].page;
            cache[j][i].page = *(void **)result;
            memset(result, 0, len);
            return result;
          }
          break;
        }
      }
    }
  }
#endif

  vm_memory_allocated_inc(vm, len);

  /* VirtualAlloc MEM_COMMIT always zeros memory */
  return (void *)VirtualAlloc(NULL, len, 
      MEM_COMMIT | MEM_RESERVE, 
      PAGE_READWRITE);
}

Here is the call graph for this function:

static void vm_protect_pages ( void p,
size_t  len,
int  writeable 
) [static]

Definition at line 98 of file vm_win.c.

{
  DWORD old;
  VirtualProtect(p, len, (writeable ? PAGE_READWRITE : PAGE_READONLY), &old);
}