changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > plan9front / sys/src/cmd/gs/src/zvmem.c

revision 7253: 986e26228cfe
parent 0: eaccc3e8d226
     1.1--- a/sys/src/cmd/gs/src/zvmem.c
     1.2+++ b/sys/src/cmd/gs/src/zvmem.c
     1.3@@ -102,35 +102,52 @@ zsave(i_ctx_t *i_ctx_p)
     1.4 private int restore_check_operand(os_ptr, alloc_save_t **, gs_dual_memory_t *);
     1.5 private int restore_check_stack(const ref_stack_t *, const alloc_save_t *, bool);
     1.6 private void restore_fix_stack(ref_stack_t *, const alloc_save_t *, bool);
     1.7+
     1.8 int
     1.9-zrestore(i_ctx_t *i_ctx_p)
    1.10+restore_check_save(i_ctx_t *i_ctx_p, alloc_save_t **asave)
    1.11 {
    1.12     os_ptr op = osp;
    1.13-    alloc_save_t *asave;
    1.14-    bool last;
    1.15-    vm_save_t *vmsave;
    1.16-    int code = restore_check_operand(op, &asave, idmemory);
    1.17-
    1.18+    int code = restore_check_operand(op, asave, idmemory);
    1.19     if (code < 0)
    1.20 	return code;
    1.21     if_debug2('u', "[u]vmrestore 0x%lx, id = %lu\n",
    1.22-	      (ulong) alloc_save_client_data(asave),
    1.23+	      (ulong) alloc_save_client_data(*asave),
    1.24 	      (ulong) op->value.saveid);
    1.25     if (I_VALIDATE_BEFORE_RESTORE)
    1.26 	ivalidate_clean_spaces(i_ctx_p);
    1.27     /* Check the contents of the stacks. */
    1.28     osp--;
    1.29-    {
    1.30-	int code;
    1.31+    if ((code = restore_check_stack(&o_stack, *asave, false)) < 0 ||
    1.32+        (code = restore_check_stack(&e_stack, *asave, true)) < 0 ||
    1.33+        (code = restore_check_stack(&d_stack, *asave, false)) < 0
    1.34+        ) {
    1.35+        osp++;
    1.36+        return code;
    1.37+    }
    1.38+    osp++;
    1.39+    return 0;
    1.40+}
    1.41 
    1.42-	if ((code = restore_check_stack(&o_stack, asave, false)) < 0 ||
    1.43-	    (code = restore_check_stack(&e_stack, asave, true)) < 0 ||
    1.44-	    (code = restore_check_stack(&d_stack, asave, false)) < 0
    1.45-	    ) {
    1.46-	    osp++;
    1.47-	    return code;
    1.48-	}
    1.49-    }
    1.50+/*
    1.51+ * the emantics of restore differ slightly between Level 1 and
    1.52+ * Level 2 and later - the latter inclues restoring the device
    1.53+ * state (whilst Level 1 didn't have "page devices" as such).
    1.54+ * Hence we have two restore operators - one here (Level 1)
    1.55+ * and one in zdevice2.c (Level 2+). For that reason, the
    1.56+ * operand checking and guts of the restore operation are
    1.57+ * separated so both implementations can use them to best
    1.58+ * effect.
    1.59+ */
    1.60+int
    1.61+dorestore(i_ctx_t *i_ctx_p, alloc_save_t *asave)
    1.62+{
    1.63+    os_ptr op = osp;
    1.64+    bool last;
    1.65+    vm_save_t *vmsave;
    1.66+    int code;
    1.67+
    1.68+    osp--;
    1.69+
    1.70     /* Reset l_new in all stack entries if the new save level is zero. */
    1.71     /* Also do some special fixing on the e-stack. */
    1.72     restore_fix_stack(&o_stack, asave, false);
    1.73@@ -170,9 +187,23 @@ zrestore(i_ctx_t *i_ctx_p)
    1.74     /* cause an 'invalidaccess' in setuserparams. Temporarily set     */
    1.75     /* LockFilePermissions false until the gs_lev2.ps can do a        */
    1.76     /* setuserparams from the restored userparam dictionary.          */
    1.77+    /* NOTE: This is safe to do here, since the restore has           */
    1.78+    /* successfully completed - this should never come before any     */
    1.79+    /* operation that can trigger an error                            */
    1.80     i_ctx_p->LockFilePermissions = false;
    1.81     return 0;
    1.82 }
    1.83+
    1.84+int
    1.85+zrestore(i_ctx_t *i_ctx_p)
    1.86+{
    1.87+    alloc_save_t *asave;
    1.88+    int code = restore_check_save(i_ctx_p, &asave);
    1.89+    if (code < 0)
    1.90+        return code;
    1.91+    return dorestore(i_ctx_p, asave);
    1.92+}
    1.93+
    1.94 /* Check the operand of a restore. */
    1.95 private int
    1.96 restore_check_operand(os_ptr op, alloc_save_t ** pasave,