View Javadoc
1   /*
2    * junixsocket
3    *
4    * Copyright 2009-2026 Christian Kohlschütter
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.newsclub.net.unix.memory;
19  
20  import org.newsclub.net.unix.MemoryImplUtilInternal;
21  
22  /**
23   * Options for {@link SharedMemory}s.
24   *
25   * @author Christian Kohlschütter
26   */
27  public enum SharedMemoryOption {
28    /**
29     * Open for reading only (instead of read-write).
30     */
31    READ_ONLY(MemoryImplUtilInternal.MOPT_RDONLY), //
32  
33    /**
34     * Allow sealing operations (only supported on Linux).
35     */
36    SEALABLE(MemoryImplUtilInternal.MOPT_SEALABLE), //
37  
38    /**
39     * Require a more "secret" memory area.
40     * <p>
41     * On Linux, this uses {@code memfd_secret}, which needs to be enabled via a kernel option
42     * ({@code secretmem.enable=1}). Note that this feature may impact overall system performance,
43     * such as disabling hibernation.
44     */
45    SECRET(MemoryImplUtilInternal.MOPT_SECRET), //
46  
47    /**
48     * Unlink the object upon calling {@link SharedMemory#close}.
49     */
50    UNLINK_UPON_CLOSE(MemoryImplUtilInternal.MOPT_UNLINK_UPON_CLOSE), //
51    ;
52  
53    private final int opt;
54  
55    SharedMemoryOption(int opt) {
56      this.opt = opt;
57    }
58  
59    /**
60     * An value only used by junixsocket internals; do not use.
61     *
62     * @return The value.
63     */
64    public int getOpt() {
65      return opt;
66    }
67  }