4 #include <minix/callnr.h>
6 #include <minix/config.h>
7 #include <minix/const.h>
9 #include <minix/endpoint.h>
10 #include <minix/minlib.h>
11 #include <minix/type.h>
12 #include <minix/ipc.h>
13 #include <minix/sysutil.h>
14 #include <minix/syslib.h>
15 #include <minix/const.h>
16 #include <minix/bitmap.h>
18 #include <minix/vfsif.h>
34 #include "sanitycheck.h"
36 extern int missing_spares
;
38 #include <machine/archtypes.h>
39 #include <sys/param.h>
40 #include "kernel/const.h"
41 #include "kernel/config.h"
42 #include "kernel/proc.h"
47 /* Table of calls and a macro to test for being in range. */
49 int (*vmc_func
)(message
*); /* Call handles message. */
50 const char *vmc_name
; /* Human-readable string. */
51 } vm_calls
[NR_VM_CALLS
];
53 /* Macro to verify call range and map 'high' range to 'base' range
54 * (starting at 0) in one. Evaluates to zero-based call number if call
55 * number is valid, returns -1 otherwise.
57 #define CALLNUMBER(c) (((c) >= VM_RQ_BASE && \
58 (c) < VM_RQ_BASE + ELEMENTS(vm_calls)) ? \
59 ((c) - VM_RQ_BASE) : -1)
61 static int map_service(struct rprocpub
*rpub
);
63 static struct rprocpub rprocpub
[NR_SYS_PROCS
];
66 /* SEF functions and variables. */
67 static void sef_local_startup(void);
68 static int sef_cb_init_lu_restart(int type
, sef_init_info_t
*info
);
69 static int sef_cb_init_fresh(int type
, sef_init_info_t
*info
);
70 static void sef_cb_signal_handler(int signo
);
74 int do_sef_init_request(message
*);
76 /*===========================================================================*
78 *===========================================================================*/
79 static int is_first_time(void)
84 if ((r
= sys_getproc(&rs_proc
, RS_PROC_NR
)) != OK
)
85 panic("VM: couldn't get RS process data: %d", r
);
87 return RTS_ISSET(&rs_proc
, RTS_BOOTINHIBIT
);
90 /*===========================================================================*
92 *===========================================================================*/
96 int result
, who_e
, rcv_sts
;
99 /* Initialize system so that all processes are runnable the first time. */
100 if (is_first_time()) {
105 /* SEF local startup. */
109 SANITYCHECK(SCL_TOP
);
111 /* This is VM's main loop. */
115 int transid
= 0; /* VFS transid if any */
117 SANITYCHECK(SCL_TOP
);
118 if(missing_spares
> 0) {
119 alloc_cycle(); /* mem alloc code wants to be called */
122 if ((r
=sef_receive_status(ANY
, &msg
, &rcv_sts
)) != OK
)
123 panic("sef_receive_status() error: %d", r
);
125 if (is_ipc_notify(rcv_sts
)) {
126 /* Unexpected ipc_notify(). */
127 printf("VM: ignoring ipc_notify() from %d\n", msg
.m_source
);
130 who_e
= msg
.m_source
;
131 if(vm_isokendpt(who_e
, &caller_slot
) != OK
)
132 panic("invalid caller %d", who_e
);
134 /* We depend on this being false for the initialized value. */
135 assert(!IS_VFS_FS_TRANSID(transid
));
138 c
= CALLNUMBER(type
);
139 result
= ENOSYS
; /* Out of range or restricted calls return this. */
141 transid
= TRNS_GET_ID(msg
.m_type
);
143 if((msg
.m_source
== VFS_PROC_NR
) && IS_VFS_FS_TRANSID(transid
)) {
144 /* If it's a request from VFS, it might have a transaction id. */
145 msg
.m_type
= TRNS_DEL_ID(msg
.m_type
);
147 /* Calls that use the transid */
148 result
= do_procctl(&msg
, transid
);
149 } else if(msg
.m_type
== RS_INIT
&& msg
.m_source
== RS_PROC_NR
) {
150 result
= do_sef_init_request(&msg
);
151 if(result
!= OK
) panic("do_sef_init_request failed!\n");
152 result
= SUSPEND
; /* do not reply to RS */
153 } else if (msg
.m_type
== VM_PAGEFAULT
) {
154 if (!IPC_STATUS_FLAGS_TEST(rcv_sts
, IPC_FLG_MSG_FROM_KERNEL
)) {
155 printf("VM: process %d faked VM_PAGEFAULT "
156 "message!\n", msg
.m_source
);
160 * do not reply to this call, the caller is unblocked by
161 * a sys_vmctl() call in do_pagefaults if success. VM panics
165 } else if(c
< 0 || !vm_calls
[c
].vmc_func
) {
166 /* out of range or missing callnr */
168 if (acl_check(&vmproc
[caller_slot
], c
) != OK
) {
169 printf("VM: unauthorized %s by %d\n",
170 vm_calls
[c
].vmc_name
, who_e
);
172 SANITYCHECK(SCL_FUNCTIONS
);
173 result
= vm_calls
[c
].vmc_func(&msg
);
174 SANITYCHECK(SCL_FUNCTIONS
);
178 /* Send reply message, unless the return code is SUSPEND,
179 * which is a pseudo-result suppressing the reply message.
181 if(result
!= SUSPEND
) {
184 assert(!IS_VFS_FS_TRANSID(transid
));
186 if((r
=ipc_send(who_e
, &msg
)) != OK
) {
187 printf("VM: couldn't send %d to %d (err %d)\n",
188 msg
.m_type
, who_e
, r
);
189 panic("ipc_send() error");
196 static void sef_cb_lu_state_changed(int old_state
, int state
)
198 /* Called whenever the live-update state changes. We need to restore certain
199 * state in the old VM instance after a live update has failed, because some
200 * but not all memory is shared between the two VM instances.
204 if (state
== SEF_LU_STATE_NULL
) {
205 /* Undo some of the changes that may have been made by the new VM
206 * instance. If the new VM instance is us, nothing happens.
208 vmp
= &vmproc
[VM_PROC_NR
];
210 /* Rebind page tables. */
211 pt_bind(&vmp
->vm_pt
, vmp
);
214 /* Readjust process references. */
219 static void sef_local_startup(void)
221 /* Register init callbacks. */
222 sef_setcb_init_fresh(sef_cb_init_fresh
);
223 sef_setcb_init_lu(sef_cb_init_lu_restart
);
224 sef_setcb_init_restart(sef_cb_init_lu_restart
);
225 /* In order to avoid a deadlock at boot time, send the first RS_INIT
226 * reply to RS asynchronously. After that, use sendrec as usual.
229 sef_setcb_init_response(sef_cb_init_response_rs_asyn_once
);
231 /* Register live update callbacks. */
232 sef_setcb_lu_state_changed(sef_cb_lu_state_changed
);
234 /* Register signal callbacks. */
235 sef_setcb_signal_handler(sef_cb_signal_handler
);
237 /* Let SEF perform startup. */
241 static int sef_cb_init_fresh(int type
, sef_init_info_t
*info
)
245 /* Map all the services in the boot image. */
246 if((s
= sys_safecopyfrom(RS_PROC_NR
, info
->rproctab_gid
, 0,
247 (vir_bytes
) rprocpub
, sizeof(rprocpub
))) != OK
) {
248 panic("vm: sys_safecopyfrom (rs) failed: %d", s
);
251 for(i
=0;i
< NR_BOOT_PROCS
;i
++) {
252 if(rprocpub
[i
].in_use
) {
253 if((s
= map_service(&rprocpub
[i
])) != OK
) {
254 panic("unable to map service: %d", s
);
262 static struct vmproc
*init_proc(endpoint_t ep_nr
)
264 struct boot_image
*ip
;
266 for (ip
= &kernel_boot_info
.boot_procs
[0];
267 ip
< &kernel_boot_info
.boot_procs
[NR_BOOT_PROCS
]; ip
++) {
270 if(ip
->proc_nr
!= ep_nr
) continue;
272 if(ip
->proc_nr
>= _NR_PROCS
|| ip
->proc_nr
< 0)
273 panic("proc: %d", ip
->proc_nr
);
275 vmp
= &vmproc
[ip
->proc_nr
];
276 assert(!(vmp
->vm_flags
& VMF_INUSE
)); /* no double procs */
278 vmp
->vm_flags
= VMF_INUSE
;
279 vmp
->vm_endpoint
= ip
->endpoint
;
285 panic("no init_proc");
288 struct vm_exec_info
{
289 struct exec_info execi
;
290 struct boot_image
*ip
;
294 static int libexec_copy_physcopy(struct exec_info
*execi
,
295 off_t off
, vir_bytes vaddr
, size_t len
)
298 struct vm_exec_info
*ei
= execi
->opaque
;
299 end
= ei
->ip
->start_addr
+ ei
->ip
->len
;
300 assert(ei
->ip
->start_addr
+ off
+ len
<= end
);
301 return sys_physcopy(NONE
, ei
->ip
->start_addr
+ off
,
302 execi
->proc_e
, vaddr
, len
, 0);
305 static void boot_alloc(struct exec_info
*execi
, off_t vaddr
,
306 size_t len
, int flags
)
308 struct vmproc
*vmp
= ((struct vm_exec_info
*) execi
->opaque
)->vmp
;
310 if(!(map_page_region(vmp
, vaddr
, 0, len
,
311 VR_ANON
| VR_WRITABLE
| VR_UNINITIALIZED
, flags
,
313 panic("VM: exec: map_page_region for boot process failed");
317 static int libexec_alloc_vm_prealloc(struct exec_info
*execi
,
318 vir_bytes vaddr
, size_t len
)
320 boot_alloc(execi
, vaddr
, len
, MF_PREALLOC
);
324 static int libexec_alloc_vm_ondemand(struct exec_info
*execi
,
325 vir_bytes vaddr
, size_t len
)
327 boot_alloc(execi
, vaddr
, len
, 0);
331 static void exec_bootproc(struct vmproc
*vmp
, struct boot_image
*ip
)
333 struct vm_exec_info vmexeci
;
334 struct exec_info
*execi
= &vmexeci
.execi
;
335 /* libexec need proper alignment for casting to structures */
336 char hdr
[VM_PAGE_SIZE
] __aligned(8);
338 size_t frame_size
= 0; /* Size of the new initial stack. */
339 int argc
= 0; /* Argument count. */
340 int envc
= 0; /* Environment count */
341 char overflow
= 0; /* No overflow yet. */
342 struct ps_strings
*psp
;
344 int vsp
= 0; /* (virtual) Stack pointer in new address space. */
345 char *argv
[] = { ip
->proc_name
, NULL
};
346 char *envp
[] = { NULL
};
347 char *path
= ip
->proc_name
;
348 char frame
[VM_PAGE_SIZE
] __aligned(sizeof(void *));
350 memset(&vmexeci
, 0, sizeof(vmexeci
));
352 if(pt_new(&vmp
->vm_pt
) != OK
)
353 panic("VM: no new pagetable");
355 if(pt_bind(&vmp
->vm_pt
, vmp
) != OK
)
356 panic("VM: pt_bind failed");
358 if(sys_physcopy(NONE
, ip
->start_addr
, SELF
,
359 (vir_bytes
) hdr
, sizeof(hdr
), 0) != OK
)
360 panic("can't look at boot proc header");
362 execi
->stack_high
= kernel_boot_info
.user_sp
;
363 execi
->stack_size
= DEFAULT_STACK_LIMIT
;
364 execi
->proc_e
= vmp
->vm_endpoint
;
366 execi
->hdr_len
= sizeof(hdr
);
367 strlcpy(execi
->progname
, ip
->proc_name
, sizeof(execi
->progname
));
368 execi
->frame_len
= 0;
369 execi
->opaque
= &vmexeci
;
370 execi
->filesize
= ip
->len
;
375 /* callback functions and data */
376 execi
->copymem
= libexec_copy_physcopy
;
377 execi
->clearproc
= NULL
;
378 execi
->clearmem
= libexec_clear_sys_memset
;
379 execi
->allocmem_prealloc_junk
= libexec_alloc_vm_prealloc
;
380 execi
->allocmem_prealloc_cleared
= libexec_alloc_vm_prealloc
;
381 execi
->allocmem_ondemand
= libexec_alloc_vm_ondemand
;
383 if (libexec_load_elf(execi
) != OK
)
384 panic("vm: boot process load of process %s (ep=%d) failed\n",
385 execi
->progname
, vmp
->vm_endpoint
);
387 /* Setup a minimal stack. */
388 minix_stack_params(path
, argv
, envp
, &frame_size
, &overflow
, &argc
,
391 /* The party is off if there is an overflow, or it is too big for our
392 * pre-allocated space. */
393 if(overflow
|| frame_size
> sizeof(frame
))
394 panic("vm: could not alloc stack for boot process %s (ep=%d)\n",
395 execi
->progname
, vmp
->vm_endpoint
);
397 minix_stack_fill(path
, argc
, argv
, envc
, envp
, frame_size
, frame
, &vsp
,
400 if(handle_memory_once(vmp
, vsp
, frame_size
, 1) != OK
)
401 panic("vm: could not map stack for boot process %s (ep=%d)\n",
402 execi
->progname
, vmp
->vm_endpoint
);
404 if(sys_datacopy(SELF
, (vir_bytes
)frame
, vmp
->vm_endpoint
, vsp
, frame_size
) != OK
)
405 panic("vm: could not copy stack for boot process %s (ep=%d)\n",
406 execi
->progname
, vmp
->vm_endpoint
);
408 if(sys_exec(vmp
->vm_endpoint
, (vir_bytes
)vsp
,
409 (vir_bytes
)execi
->progname
, execi
->pc
,
410 vsp
+ ((int)psp
- (int)frame
)) != OK
)
411 panic("vm: boot process exec of process %s (ep=%d) failed\n",
412 execi
->progname
,vmp
->vm_endpoint
);
414 /* make it runnable */
415 if(sys_vmctl(vmp
->vm_endpoint
, VMCTL_BOOTINHIBIT_CLEAR
, 0) != OK
)
416 panic("VMCTL_BOOTINHIBIT_CLEAR failed");
419 static int do_procctl_notrans(message
*msg
)
423 assert(!IS_VFS_FS_TRANSID(transid
));
425 return do_procctl(msg
, transid
);
431 static struct memory mem_chunks
[NR_MEMS
];
432 struct boot_image
*ip
;
433 extern void __minix_init(void);
434 multiboot_module_t
*mod
;
435 vir_bytes kern_dyn
, kern_static
;
438 incheck
= nocheck
= 0;
441 /* Retrieve various crucial boot parameters */
442 if(OK
!= (s
=sys_getkinfo(&kernel_boot_info
))) {
443 panic("couldn't get bootinfo: %d", s
);
446 /* Turn file mmap on? */
447 enable_filemap
=1; /* yes by default */
448 env_parse("filemap", "d", 0, &enable_filemap
, 0, 1);
451 assert(kernel_boot_info
.mmap_size
> 0);
452 assert(kernel_boot_info
.mods_with_kernel
> 0);
454 /* Get chunks of available memory. */
455 get_mem_chunks(mem_chunks
);
457 /* Set table to 0. This invalidates all slots (clear VMF_INUSE). */
458 memset(vmproc
, 0, sizeof(vmproc
));
460 for(i
= 0; i
< ELEMENTS(vmproc
); i
++) {
461 vmproc
[i
].vm_slot
= i
;
464 /* Initialize ACL data structures. */
467 /* region management initialization. */
470 /* Initialize tables to all physical memory. */
471 mem_init(mem_chunks
);
473 /* Architecture-dependent initialization. */
474 init_proc(VM_PROC_NR
);
477 /* Acquire kernel ipc vectors that weren't available
478 * before VM had determined kernel mappings
482 /* The kernel's freelist does not include boot-time modules; let
483 * the allocator know that the total memory is bigger.
485 for (mod
= &kernel_boot_info
.module_list
[0];
486 mod
< &kernel_boot_info
.module_list
[kernel_boot_info
.mods_with_kernel
-1]; mod
++) {
487 phys_bytes len
= mod
->mod_end
-mod
->mod_start
+1;
488 len
= roundup(len
, VM_PAGE_SIZE
);
489 mem_add_total_pages(len
/VM_PAGE_SIZE
);
492 kern_dyn
= kernel_boot_info
.kernel_allocated_bytes_dynamic
;
493 kern_static
= kernel_boot_info
.kernel_allocated_bytes
;
494 kern_static
= roundup(kern_static
, VM_PAGE_SIZE
);
495 mem_add_total_pages((kern_dyn
+ kern_static
)/VM_PAGE_SIZE
);
497 /* Give these processes their own page table. */
498 for (ip
= &kernel_boot_info
.boot_procs
[0];
499 ip
< &kernel_boot_info
.boot_procs
[NR_BOOT_PROCS
]; ip
++) {
502 if(ip
->proc_nr
< 0) continue;
504 assert(ip
->start_addr
);
506 /* VM has already been set up by the kernel and pt_init().
507 * Any other boot process is already in memory and is set up
510 if(ip
->proc_nr
== VM_PROC_NR
) continue;
512 vmp
= init_proc(ip
->proc_nr
);
514 exec_bootproc(vmp
, ip
);
516 /* Free the file blob */
517 assert(!(ip
->start_addr
% VM_PAGE_SIZE
));
518 ip
->len
= roundup(ip
->len
, VM_PAGE_SIZE
);
519 free_mem(ABS2CLICK(ip
->start_addr
), ABS2CLICK(ip
->len
));
522 /* Set up table of calls. */
523 #define CALLMAP(code, func) { int _cmi; \
524 _cmi=CALLNUMBER(code); \
526 assert(_cmi < NR_VM_CALLS); \
527 vm_calls[_cmi].vmc_func = (func); \
528 vm_calls[_cmi].vmc_name = #code; \
531 /* Set call table to 0. This invalidates all calls (clear
534 memset(vm_calls
, 0, sizeof(vm_calls
));
536 /* Basic VM calls. */
537 CALLMAP(VM_MMAP
, do_mmap
);
538 CALLMAP(VM_MUNMAP
, do_munmap
);
539 CALLMAP(VM_MAP_PHYS
, do_map_phys
);
540 CALLMAP(VM_UNMAP_PHYS
, do_munmap
);
543 CALLMAP(VM_EXIT
, do_exit
);
544 CALLMAP(VM_FORK
, do_fork
);
545 CALLMAP(VM_BRK
, do_brk
);
546 CALLMAP(VM_WILLEXIT
, do_willexit
);
548 CALLMAP(VM_PROCCTL
, do_procctl_notrans
);
550 /* Calls from VFS. */
551 CALLMAP(VM_VFS_REPLY
, do_vfs_reply
);
552 CALLMAP(VM_VFS_MMAP
, do_vfs_mmap
);
555 CALLMAP(VM_RS_SET_PRIV
, do_rs_set_priv
);
556 CALLMAP(VM_RS_PREPARE
, do_rs_prepare
);
557 CALLMAP(VM_RS_UPDATE
, do_rs_update
);
558 CALLMAP(VM_RS_MEMCTL
, do_rs_memctl
);
561 CALLMAP(VM_REMAP
, do_remap
);
562 CALLMAP(VM_REMAP_RO
, do_remap
);
563 CALLMAP(VM_GETPHYS
, do_get_phys
);
564 CALLMAP(VM_SHM_UNMAP
, do_munmap
);
565 CALLMAP(VM_GETREF
, do_get_refcount
);
566 CALLMAP(VM_INFO
, do_info
);
569 CALLMAP(VM_MAPCACHEPAGE
, do_mapcache
);
570 CALLMAP(VM_SETCACHEPAGE
, do_setcache
);
571 CALLMAP(VM_FORGETCACHEPAGE
, do_forgetcache
);
572 CALLMAP(VM_CLEARCACHE
, do_clearcache
);
575 CALLMAP(VM_GETRUSAGE
, do_getrusage
);
577 /* Mark VM instances. */
578 num_vm_instances
= 1;
579 vmproc
[VM_PROC_NR
].vm_flags
|= VMF_VM_INSTANCE
;
581 /* Let SEF know about VM mmapped regions. */
582 s
= sef_llvm_add_special_mem_region((void*)VM_OWN_HEAPBASE
,
583 VM_OWN_MMAPTOP
-VM_OWN_HEAPBASE
, "%MMAP_ALL");
585 printf("VM: st_add_special_mmapped_region failed %d\n", s
);
589 /*===========================================================================*
590 * sef_cb_init_vm_multi_lu *
591 *===========================================================================*/
592 static int sef_cb_init_vm_multi_lu(int type
, sef_init_info_t
*info
)
596 ipc_filter_el_t ipc_filter
[IPCF_MAX_ELEMENTS
];
599 if(type
!= SEF_INIT_LU
|| !(info
->flags
& SEF_LU_MULTI
)) {
603 /* If this is a multi-component update, we need to perform the update
604 * for services that need to be updated. In addition, make sure VM
605 * can only receive messages from RS, tasks, and other services being
606 * updated until RS specifically sends a special update cancel message.
607 * This is necessary to limit the number of VM state changes to support
608 * rollback. Allow only safe message types for safe updates.
610 memset(ipc_filter
, 0, sizeof(ipc_filter
));
612 ipc_filter
[num_elements
].flags
= IPCF_MATCH_M_SOURCE
;
613 ipc_filter
[num_elements
++].m_source
= RS_PROC_NR
;
614 if((r
= sys_safecopyfrom(RS_PROC_NR
, info
->rproctab_gid
, 0,
615 (vir_bytes
) rprocpub
, NR_SYS_PROCS
*sizeof(struct rprocpub
))) != OK
) {
616 panic("sys_safecopyfrom failed: %d", r
);
618 m
.m_source
= VM_PROC_NR
;
619 for(i
=0;i
< NR_SYS_PROCS
;i
++) {
620 if(rprocpub
[i
].in_use
&& rprocpub
[i
].old_endpoint
!= NONE
) {
621 if(num_elements
<= IPCF_MAX_ELEMENTS
-5) {
622 /* VM_BRK is needed for normal operation during the live
623 * update. VM_INFO is needed for state transfer in the
624 * light of holes. Pagefaults and handle-memory requests
625 * are blocked intentionally, as handling these would
626 * prevent VM from being able to roll back.
628 ipc_filter
[num_elements
].flags
= IPCF_MATCH_M_SOURCE
| IPCF_MATCH_M_TYPE
;
629 ipc_filter
[num_elements
].m_source
= rprocpub
[i
].old_endpoint
;
630 ipc_filter
[num_elements
++].m_type
= VM_BRK
;
631 ipc_filter
[num_elements
].flags
= IPCF_MATCH_M_SOURCE
| IPCF_MATCH_M_TYPE
;
632 ipc_filter
[num_elements
].m_source
= rprocpub
[i
].new_endpoint
;
633 ipc_filter
[num_elements
++].m_type
= VM_BRK
;
634 ipc_filter
[num_elements
].flags
= IPCF_MATCH_M_SOURCE
| IPCF_MATCH_M_TYPE
;
635 ipc_filter
[num_elements
].m_source
= rprocpub
[i
].old_endpoint
;
636 ipc_filter
[num_elements
++].m_type
= VM_INFO
;
637 ipc_filter
[num_elements
].flags
= IPCF_MATCH_M_SOURCE
| IPCF_MATCH_M_TYPE
;
638 ipc_filter
[num_elements
].m_source
= rprocpub
[i
].new_endpoint
;
639 ipc_filter
[num_elements
++].m_type
= VM_INFO
;
640 /* Make sure we can talk to any RS instance. */
641 if(rprocpub
[i
].old_endpoint
== RS_PROC_NR
) {
642 ipc_filter
[num_elements
].flags
= IPCF_MATCH_M_SOURCE
;
643 ipc_filter
[num_elements
++].m_source
= rprocpub
[i
].new_endpoint
;
645 else if(rprocpub
[i
].new_endpoint
== RS_PROC_NR
) {
646 ipc_filter
[num_elements
].flags
= IPCF_MATCH_M_SOURCE
;
647 ipc_filter
[num_elements
++].m_source
= rprocpub
[i
].old_endpoint
;
651 printf("sef_cb_init_vm_multi_lu: skipping ipc filter elements for %d and %d\n",
652 rprocpub
[i
].old_endpoint
, rprocpub
[i
].new_endpoint
);
654 if(rprocpub
[i
].sys_flags
& SF_VM_UPDATE
) {
655 m
.m_lsys_vm_update
.src
= rprocpub
[i
].new_endpoint
;
656 m
.m_lsys_vm_update
.dst
= rprocpub
[i
].old_endpoint
;
657 m
.m_lsys_vm_update
.flags
= rprocpub
[i
].sys_flags
;
658 r
= do_rs_update(&m
);
659 if(r
!= OK
&& r
!= SUSPEND
) {
660 printf("sef_cb_init_vm_multi_lu: do_rs_update failed: %d", r
);
666 r
= sys_statectl(SYS_STATE_ADD_IPC_WL_FILTER
, ipc_filter
, num_elements
*sizeof(ipc_filter_el_t
));
668 printf("sef_cb_init_vm_multi_lu: sys_statectl failed: %d", r
);
674 /*===========================================================================*
675 * sef_cb_init_lu_restart *
676 *===========================================================================*/
677 static int sef_cb_init_lu_restart(int type
, sef_init_info_t
*info
)
679 /* Restart the vm server. */
683 struct vmproc
*old_vmp
, *new_vmp
;
685 /* Perform default state transfer first. */
686 if(type
== SEF_INIT_LU
) {
687 sef_setcb_init_restart(SEF_CB_INIT_RESTART_STATEFUL
);
688 r
= SEF_CB_INIT_LU_DEFAULT(type
, info
);
691 r
= SEF_CB_INIT_RESTART_STATEFUL(type
, info
);
697 /* Lookup slots for old process. */
698 old_e
= info
->old_endpoint
;
699 if(vm_isokendpt(old_e
, &old_p
) != OK
) {
700 printf("sef_cb_init_lu_restart: bad old endpoint %d\n", old_e
);
703 old_vmp
= &vmproc
[old_p
];
704 new_vmp
= &vmproc
[VM_PROC_NR
];
706 /* Swap proc slots and dynamic data. */
707 if((r
= swap_proc_slot(old_vmp
, new_vmp
)) != OK
) {
708 printf("sef_cb_init_lu_restart: swap_proc_slot failed\n");
711 if((r
= swap_proc_dyn_data(old_vmp
, new_vmp
, 0)) != OK
) {
712 printf("sef_cb_init_lu_restart: swap_proc_dyn_data failed\n");
716 /* Rebind page tables. */
717 pt_bind(&new_vmp
->vm_pt
, new_vmp
);
718 pt_bind(&old_vmp
->vm_pt
, old_vmp
);
721 /* Adjust process references. */
724 /* Handle multi-component live update when necessary. */
725 return sef_cb_init_vm_multi_lu(type
, info
);
728 /*===========================================================================*
729 * sef_cb_signal_handler *
730 *===========================================================================*/
731 static void sef_cb_signal_handler(int signo
)
733 /* Check for known kernel signals, ignore anything else. */
735 /* There is a pending memory request from the kernel. */
741 /* It can happen that we get stuck receiving signals
742 * without sef_receive() returning. We could need more memory
745 if(missing_spares
> 0) {
746 alloc_cycle(); /* pagetable code wants to be called */
752 /*===========================================================================*
754 *===========================================================================*/
755 static int map_service(struct rprocpub
*rpub
)
757 /* Map a new service by initializing its call mask. */
760 if ((r
= vm_isokendpt(rpub
->endpoint
, &proc_nr
)) != OK
) {
764 /* Copy the call mask. */
765 acl_set(&vmproc
[proc_nr
], rpub
->vm_call_mask
, !IS_RPUB_BOOT_USR(rpub
));