00001 /* @(#)root/clib:$Id: keys.c 20882 2007-11-19 11:31:26Z rdm $ */ 00002 /* Author: */ 00003 00004 /* Access for application keys in mmap'd malloc managed region. 00005 Copyright 1992 Free Software Foundation, Inc. 00006 00007 Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com 00008 00009 This file is part of the GNU C Library. 00010 00011 The GNU C Library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU Library General Public License as 00013 published by the Free Software Foundation; either version 2 of the 00014 License, or (at your option) any later version. 00015 00016 The GNU C Library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Library General Public License for more details. 00020 00021 You should have received a copy of the GNU Library General Public 00022 License along with the GNU C Library; see the file COPYING.LIB. If 00023 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00024 Boston, MA 02111-1307, USA. */ 00025 00026 /* This module provides access to some keys that the application can use to 00027 provide persistent access to locations in the mapped memory section. 00028 The intent is that these keys are to be used sparingly as sort of 00029 persistent global variables which the application can use to reinitialize 00030 access to data in the mapped region. 00031 00032 For the moment, these keys are simply stored in the malloc descriptor 00033 itself, in an array of fixed length. This should be fixed so that there 00034 can be an unlimited number of keys, possibly using a multilevel access 00035 scheme of some sort. */ 00036 00037 #ifndef WIN32 00038 # include <sys/types.h> 00039 # include <sys/mman.h> 00040 #endif /* WIN32 */ 00041 00042 #include "mmprivate.h" 00043 00044 int 00045 mmalloc_setkey (md, keynum, key) 00046 PTR md; 00047 int keynum; 00048 PTR key; 00049 { 00050 struct mdesc *mdp = (struct mdesc *) md; 00051 int result = 0; 00052 00053 if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS)) 00054 { 00055 mdp -> keys [keynum] = key; 00056 #ifndef WIN32 00057 #ifndef VMS 00058 #ifndef R__LYNXOS 00059 #ifndef R__HURD 00060 /* We should really test for _POSIX_SYNCRONIZED_IO here */ 00061 msync((void *)mdp, sizeof(struct mdesc), MS_ASYNC); 00062 #endif 00063 #endif 00064 #endif 00065 #endif 00066 result++; 00067 } 00068 return (result); 00069 } 00070 00071 PTR 00072 mmalloc_getkey (md, keynum) 00073 PTR md; 00074 int keynum; 00075 { 00076 struct mdesc *mdp = (struct mdesc *) md; 00077 PTR keyval = NULL; 00078 00079 if ((mdp != NULL) && (keynum >= 0) && (keynum < MMALLOC_KEYS)) 00080 { 00081 keyval = (PTR)((long)mdp -> keys [keynum] + mdp->offset); 00082 } 00083 return (keyval); 00084 }