File: map.c

package info (click to toggle)
ibcs 971113-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,108 kB
  • ctags: 2,061
  • sloc: ansic: 14,910; makefile: 280; sh: 203; asm: 47; perl: 18; pascal: 2
file content (101 lines) | stat: -rw-r--r-- 2,300 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 *  linux/ibcs/map.c
 *
 *  Copyright (C) 1994  Mike Jagdis (jaggy@purplet.demon.co.uk)
 *
 * $Id: map.c,v 1.11 1997/08/16 14:05:59 jaggy Exp $
 * $Source: /usr/CVS/ibcs/iBCSemul/map.c,v $
 */
#include <linux/config.h>

#include <linux/module.h>
#include <linux/version.h>

#include <linux/sched.h>
#include <linux/net.h>
#include <linux/socket.h>
#include <linux/signal.h>
#include <linux/errno.h>
#include <linux/personality.h>

#include <ibcs/socket.h>
#include <ibcs/map.h>

#ifndef NULL
#define NULL	((void *)0)
#endif


/* Error code maps. */
#include "maps/errmap.inc"

/* Signal maps - these are pulled in to emulate.c where they are need to
 * initialise the execution domain descriptors with 1.1 kernels.
 */
#ifndef INIT_MM
#include "maps/signal.inc"
#endif

/* Socket subsystem maps. */
#include "maps/sockaf.inc"		/* Address families/formats */
#include "maps/sockopt.inc"		/* Socket options */
#include "maps/socktype.inc"		/* Socket types */


long
map_bitvec(unsigned long vec, long map[])
{
	unsigned long newvec, m;
	int i;

	newvec = 0;
	for (m=1,i=1; i<=32; m<<=1,i++)
		if ((vec & m) && map[i] != -1)
			newvec |= (1 << map[i]);

	return newvec;
}


int
map_value(struct map_segment *m[], int val, int def) {
	int pers;
	struct map_segment *seg;

	pers = current->personality & PER_MASK;

	/* If no mapping exists in this personality just return the
	 * number we were given.
	 */
	if (!m[pers])
		return val;

	/* Search the map looking for a mapping for the given number. */
	for (seg=m[pers]; seg->start != -1; seg++) {
		if (seg->start <= val && val <= seg->end) {
			/* If the start and end are the same then this
			 * segment has one entry and the map is the value
			 * it maps to. Otherwise if we have a vector we
			 * pick out the relevant value, if we don't have
			 * a vector we give identity mapping.
			 */
			if (seg->start == seg->end)
				return (int)seg->map;
			else
				return (seg->map ? seg->map[val-seg->start] : val);
		}
	}

	/* Number isn't mapped. Returned the requested default. */
	return def;
}


/* Translate the errno numbers from linux to current personality.
 * This should be removed and all other sources changed to call the
 * map function above directly.
 */
int iABI_errors(int lnx_errno)
{
	return map_value(err_map, lnx_errno, 1);
}