Annotation of freem/src/shmmgr.h, revision 1.1
1.1 ! snw 1: /*
! 2: * *
! 3: * * *
! 4: * * *
! 5: * ***************
! 6: * * * * *
! 7: * * MUMPS *
! 8: * * * * *
! 9: * ***************
! 10: * * *
! 11: * * *
! 12: * *
! 13: *
! 14: * shmmgr.h
! 15: * shared memory manager data structures
! 16: *
! 17: *
! 18: * Author: Serena Willis <jpw@coherent-logic.com>
! 19: * Copyright (C) 1998 MUG Deutschland
! 20: * Copyright (C) 2021 Coherent Logic Development LLC
! 21: *
! 22: *
! 23: * This file is part of FreeM.
! 24: *
! 25: * FreeM is free software: you can redistribute it and/or modify
! 26: * it under the terms of the GNU Affero Public License as published by
! 27: * the Free Software Foundation, either version 3 of the License, or
! 28: * (at your option) any later version.
! 29: *
! 30: * FreeM is distributed in the hope that it will be useful,
! 31: * but WITHOUT ANY WARRANTY; without even the implied warranty of
! 32: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 33: * GNU Affero Public License for more details.
! 34: *
! 35: * You should have received a copy of the GNU Affero Public License
! 36: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
! 37: *
! 38: **/
! 39:
! 40: #if !defined(__shmmgr_h)
! 41: # define __shmmgr_h
! 42:
! 43: #include <stdlib.h>
! 44: #if defined(HAVE_STDINT_H)
! 45: # include <stdint.h>
! 46: #endif
! 47: #include <sys/ipc.h>
! 48: #include <sys/shm.h>
! 49: #include <sys/sem.h>
! 50: #include <sys/types.h>
! 51:
! 52: #include "locktab.h"
! 53: #include "jobtab.h"
! 54:
! 55: /* allocation states */
! 56: #define PG_FREE 0
! 57: #define PG_ALLOC 1
! 58:
! 59: /* size of a page */
! 60: #define PG_SIZE 1024
! 61:
! 62: /* shm_init return values */
! 63: #define SHMS_SUCCESS 1
! 64: #define SHMS_GET_ERR 0
! 65: #define SHMS_ATTACH_ERR -1
! 66:
! 67: #define SEMK_SHM 0xBBDD21
! 68: #define SEMK_LOCKTAB 0xBBDD22
! 69: #define SEMK_JOBTAB 0xBBDD23
! 70: #define SEMK_TP 0xBBDD24
! 71:
! 72: #define SHMALIGN(a) (void *) (((unsigned long) a + sysconf (_SC_PAGESIZE)) & ~(sysconf (_SC_PAGESIZE) - 1))
! 73:
! 74: /* data structures */
! 75:
! 76: /* alloc map entry */
! 77: typedef struct shm_page_t {
! 78:
! 79: /* is this the first entry for this allocation? */
! 80: short is_first;
! 81:
! 82: /* can be PG_FREE or PG_ALLOC */
! 83: short pg_state;
! 84:
! 85: /* to which pid does this page belong? */
! 86: pid_t pid;
! 87:
! 88: /* is this the last entry for this allocation? */
! 89: short is_last;
! 90:
! 91: } shm_page_t;
! 92:
! 93:
! 94: /* segment header */
! 95: typedef struct shm_hdr_t {
! 96:
! 97: /* will be set to shm_key to identify whether or not the segment is initialized */
! 98: key_t magic;
! 99:
! 100: /* pid of the first process that attached to the segment */
! 101: pid_t first_process;
! 102:
! 103: /* shm address */
! 104: void *shmad;
! 105:
! 106: /* HEAD of lock table linked list */
! 107: locktab_ent_t *locktab_head;
! 108:
! 109: /* HEAD of job table linked list */
! 110: job_slot_t *jobtab_head;
! 111:
! 112: /* locks out non-fmadm processes when set to 1 */
! 113: short maintenance_mode;
! 114:
! 115: unsigned long max_locks;
! 116: unsigned long max_jobs;
! 117: unsigned long max_ipcs;
! 118:
! 119: /* shared symbol table */
! 120: char *partition;
! 121: unsigned long alphptr[128];
! 122: char *s;
! 123: char *argptr;
! 124: long PSIZE;
! 125: long symlen;
! 126:
! 127: /* pid of process currently in transaction */
! 128: /* zero if nobody owns these exclusive rights */
! 129: pid_t tp_owner;
! 130:
! 131: /* counter for the tp semaphore */
! 132: unsigned long long tp_semctr;
! 133:
! 134: /* monotonically-incrementing serial number for DB operations:
! 135: * all ops inside of transactions have the same tp_serial_number.
! 136: *
! 137: * used in journaling.
! 138: */
! 139: unsigned long long tp_serial_number;
! 140:
! 141: /* allocation map */
! 142: shm_page_t alloc_map[1];
! 143:
! 144: } shm_hdr_t;
! 145:
! 146: typedef struct shm_config_t {
! 147:
! 148: /* segment size */
! 149: size_t segsiz;
! 150:
! 151: /* page size */
! 152: size_t pgsiz;
! 153:
! 154: /* page count */
! 155: int pgct;
! 156:
! 157: /* shared memory key */
! 158: key_t key;
! 159:
! 160: /* segment ID */
! 161: int seg_id;
! 162:
! 163: /* segment data area */
! 164: void *dta;
! 165:
! 166: /* pointer to the header */
! 167: shm_hdr_t *hdr;
! 168:
! 169: /* actual buffer */
! 170: void *buf;
! 171:
! 172: } shm_config_t;
! 173:
! 174: /* global variables */
! 175: extern shm_config_t *shm_config;
! 176:
! 177: /* function prototypes */
! 178: extern short shm_init(const size_t seg_size);
! 179: extern short shm_exit(void);
! 180: extern short shm_get_sem(void);
! 181: extern short shm_release_sem(void);
! 182: extern shm_page_t *shm_get_alloc_map_entry(const int page_number);
! 183: extern void *shm_page_num_to_address(const int page_num);
! 184: extern int shm_address_to_page_num(const void *address);
! 185: extern void *shm_alloc_pages(const int page_count);
! 186: extern void *shm_alloc(const size_t bytes);
! 187: extern void shm_free_page(const int page_number);
! 188: extern void shm_free(const void *addr);
! 189: extern void shm_dump(void);
! 190: extern void shm_dump_pages(void);
! 191: #endif
! 192:
! 193:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>