Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Align address on a page boundary.
[simgrid.git] / src / xbt / mmalloc / keys.c
1 /* Access for application keys in mmap'd malloc managed region.
2    Copyright 1992 Free Software Foundation, Inc.
3
4    Contributed by Fred Fish at Cygnus Support.   fnf@cygnus.com
5    This file was then part of the GNU C Library. */
6
7 /* Copyright (c) 2010. The SimGrid Team.
8  * All rights reserved.                                                     */
9
10 /* This program is free software; you can redistribute it and/or modify it
11  * under the terms of the license (GNU LGPL) which comes with this package. */
12
13
14
15
16 /* This module provides access to some keys that the application can use to
17    provide persistent access to locations in the mapped memory section.
18    The intent is that these keys are to be used sparingly as sort of
19    persistent global variables which the application can use to reinitialize
20    access to data in the mapped region.
21
22    For the moment, these keys are simply stored in the malloc descriptor
23    itself, in an array of fixed length.  This should be fixed so that there
24    can be an unlimited number of keys, possibly using a multilevel access
25    scheme of some sort. */
26
27 #include "mmprivate.h"
28
29 int mmalloc_setkey(void *md, int keynum, void *key)
30 {
31   struct mdesc *mdp = (struct mdesc *) md;
32   int result = 0;
33
34   LOCK(mdp);
35   if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS)) {
36     mdp->keys[keynum] = key;
37     result++;
38   }
39   UNLOCK(mdp);
40   return (result);
41 }
42
43 void *mmalloc_getkey(void *md, int keynum)
44 {
45   struct mdesc *mdp = (struct mdesc *) md;
46   void *keyval = NULL;
47
48   if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS)) {
49     keyval = mdp->keys[keynum];
50   }
51   return (keyval);
52 }