Skip to content

Commit 80e731e

Browse files
committed
feat: lock process memory with mlockall
1 parent 69a2138 commit 80e731e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,10 @@ func waitUntilAvailable(path string, maximum time.Duration) error {
888888
}
889889

890890
func main() {
891+
if err := lockMemory(); err != nil {
892+
exitWithError("%v", err)
893+
}
894+
891895
globalConfig, err := gitConfig.LoadConfig(gitConfig.GlobalScope)
892896
if err == nil {
893897
defaultGitEmail = globalConfig.User.Email

mlockall.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// pago - a command-line password manager.
2+
//
3+
// License: MIT.
4+
// See the file LICENSE.
5+
6+
package main
7+
8+
import (
9+
"fmt"
10+
11+
"golang.org/x/sys/unix"
12+
)
13+
14+
func lockMemory() error {
15+
if err := unix.Mlockall(unix.MCL_CURRENT | unix.MCL_FUTURE); err != nil {
16+
return fmt.Errorf("failed to lock memory: %v", err)
17+
}
18+
19+
return nil
20+
}

0 commit comments

Comments
 (0)