this repo has no description
1#!/usr/bin/env python3
2# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com)
3# $builtin-init-module$
4
5from _builtins import _builtin, _int_guard, _type_subclass_guard, _unimplemented
6
7
8def _mmap_new(cls, fileno, length, flags, prot, offset):
9 _builtin()
10
11
12ACCESS_READ = 1
13ACCESS_WRITE = 2
14ACCESS_COPY = 3
15
16
17class mmap(bootstrap=True):
18 @staticmethod
19 def __new__(cls, fileno, length, flags=1, prot=3, access=0, offset=0):
20 """
21 Creates a new mmap object.
22
23 Values for flags are ints:
24 * MAP_SHARED = 1
25 * MAP_PRIVATE = 2
26
27 Values for prot are ints:
28 * PROT_READ = 1
29 * PROT_WRITE = 2
30 * PROT_EXEC = 4
31
32 Some operating systems / file systems could provide additional values.
33 """
34 _type_subclass_guard(cls, mmap)
35 _int_guard(fileno)
36 _int_guard(length)
37 _int_guard(flags)
38 _int_guard(prot)
39 _int_guard(access)
40 _int_guard(offset)
41 if length < 0:
42 raise OverflowError("memory mapped length must be positive")
43 if offset < 0:
44 raise OverflowError("memory mapped offset must be positive")
45 if access != 0 and (flags != 1 or prot != 3):
46 raise ValueError("mmap can't specify both access and flags, prot.")
47 if access == ACCESS_READ:
48 flags = 1
49 prot = 1
50 elif access == ACCESS_WRITE:
51 flags = 1
52 prot = 3
53 elif access == ACCESS_COPY:
54 flags = 2
55 prot = 3
56 elif access != 0:
57 raise ValueError("mmap invalid access parameter.")
58 return _mmap_new(cls, fileno, length, flags, prot, offset)
59
60 def close(self):
61 _builtin()