[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/15: build: syscalls: Add clone syscall wrapper.
From: |
David Thompson |
Subject: |
01/15: build: syscalls: Add clone syscall wrapper. |
Date: |
Fri, 03 Jul 2015 19:34:55 +0000 |
davexunit pushed a commit to branch wip-container
in repository guix.
commit f9b0c92162289af3aa87ede63eee7695e61f9e17
Author: David Thompson <address@hidden>
Date: Sun May 31 20:26:47 2015 -0400
build: syscalls: Add clone syscall wrapper.
* guix/build/syscalls.scm (clone): New procedure.
(CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC, CLONE_NEWUSER, CLONE_NEWPID,
CLONE_NEWNET): New variables.
---
guix/build/syscalls.scm | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 3585bf2..3346358 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015 Ludovic Courtès <address@hidden>
+;;; Copyright © 2015 David Thompson <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -37,6 +38,14 @@
swapoff
processes
+ CLONE_NEWNS
+ CLONE_NEWUTS
+ CLONE_NEWIPC
+ CLONE_NEWUSER
+ CLONE_NEWPID
+ CLONE_NEWNET
+ clone
+
IFF_UP
IFF_BROADCAST
IFF_LOOPBACK
@@ -247,6 +256,29 @@ user-land process."
(scandir "/proc"))
<))
+;; Linux clone flags, from linux/sched.h
+(define CLONE_NEWNS #x00020000)
+(define CLONE_NEWUTS #x04000000)
+(define CLONE_NEWIPC #x08000000)
+(define CLONE_NEWUSER #x10000000)
+(define CLONE_NEWPID #x20000000)
+(define CLONE_NEWNET #x40000000)
+
+;; The libc interface to sys_clone is not useful for Scheme programs, so the
+;; low-level system call is wrapped instead.
+(define clone
+ (let* ((ptr (dynamic-func "syscall" (dynamic-link)))
+ (proc (pointer->procedure int ptr (list int int '*)))
+ ;; TODO: Handle all supported architectures
+ (syscall-id (match (utsname:machine (uname))
+ ("x86_64" 56)
+ (_ 120))))
+ (lambda (flags)
+ "Create a new child process by duplicating the current parent process.
+Unlike the fork system call, clone accepts FLAGS that specify which resources
+are shared between the parent and child processes."
+ (proc syscall-id flags %null-pointer))))
+
;;;
;;; Packed structures.
- branch wip-container created (now 33f2e7a), David Thompson, 2015/07/03
- 02/15: build: syscalls: Add setns syscall wrapper., David Thompson, 2015/07/03
- 01/15: build: syscalls: Add clone syscall wrapper.,
David Thompson <=
- 03/15: build: syscalls: Add additional mount flags., David Thompson, 2015/07/03
- 06/15: build: syscalls: Add mkdtemp!, David Thompson, 2015/07/03
- 07/15: utils: Add call-with-temporary-directory., David Thompson, 2015/07/03
- 04/15: build: syscalls: Add unmount flags., David Thompson, 2015/07/03
- 05/15: build: syscalls: Add pivot-root., David Thompson, 2015/07/03
- 09/15: gnu: system: Move <file-system-mapping> into (gnu system file-systems)., David Thompson, 2015/07/03
- 10/15: gnu: system: Move file-system->spec to (gnu system file-systems)., David Thompson, 2015/07/03
- 08/15: gnu: build: Add Linux container module., David Thompson, 2015/07/03
- 11/15: gnu: system: Add Linux container module., David Thompson, 2015/07/03
- 12/15: gnu: system: Add Linux container file systems., David Thompson, 2015/07/03