Skip to contentSkip to conversation

Patch review

PATCH New Steve Sakoman 1 participant 8 messages May 30, 2024

lore
Share & tools
lore
#0 lore raw

cover Patch review

Please review this set of changes for kirktsone and have comments back by end of day Saturday, June 1

Passed a-full on autobuilder:

https://autobuilder.yoctoproject.org/typhoon/#/builders/83/builds/6984

The following changes since commit e0a1ed7aa1f2b12d985414db9a75d6e151ae8d21:

initscripts: Add custom mount args for /var/lib (2024-05-22 05:07:30 -0700)

are available in the Git repository at:

https://git.openembedded.org/openembedded-core-contrib stable/kirkstone-nut
https://git.openembedded.org/openembedded-core-contrib/log/?h=stable/kirkstone-nut

Archana Polampalli (5):
ghostscript: fix CVE-2024-33870
ghostscript: fix CVE-2024-33869
ghostscript: fix CVE-2024-33871
ghostscript: fix CVE-2024-29510
ghostscript: fix CVE-2023-52722

Soumya Sambu (2):
util-linux: Fix CVE-2024-28085
git: Fix multiple CVEs

 meta/recipes-core/util-linux/util-linux.inc   |    5 +
 .../util-linux/CVE-2024-28085-0001.patch      |  202 +
 .../util-linux/CVE-2024-28085-0002.patch      |  172 +
 .../util-linux/CVE-2024-28085-0003.patch      |  223 +
 .../util-linux/CVE-2024-28085-0004.patch      |   36 +
 .../util-linux/CVE-2024-28085-0005.patch      |   34 +
 .../git/git/CVE-2024-32002-0001.patch         |   69 +
 .../git/git/CVE-2024-32002-0002.patch         |  213 +
 .../git/git/CVE-2024-32002-0003.patch         |  141 +
 .../git/git/CVE-2024-32002-0004.patch         |  150 +
 .../git/git/CVE-2024-32004-0001.patch         |   95 +
 .../git/git/CVE-2024-32004-0002.patch         |  187 +
 .../git/git/CVE-2024-32004-0003.patch         |  158 +
 .../git/git/CVE-2024-32020.patch              |  114 +
 .../git/git/CVE-2024-32021-0001.patch         |   89 +
 .../git/git/CVE-2024-32021-0002.patch         |   65 +
 .../git/git/CVE-2024-32465.patch              |  206 +
 meta/recipes-devtools/git/git_2.35.7.bb       |   11 +
 .../ghostscript/CVE-2023-52722.patch          |   43 +
 .../ghostscript/CVE-2024-29510.patch          |   84 +
 .../ghostscript/CVE-2024-33869-0001.patch     |   39 +
 .../ghostscript/CVE-2024-33869-0002.patch     |   52 +
 .../ghostscript/CVE-2024-33870.patch          |   92 +
 .../ghostscript/CVE-2024-33871-0001.patch     | 4863 +++++++++++++++++
 .../ghostscript/CVE-2024-33871-0002.patch     |   43 +
 .../ghostscript/ghostscript_9.55.0.bb         |    7 +
 26 files changed, 7393 insertions(+)
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0001.patch
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0002.patch
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0003.patch
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0004.patch
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0005.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32002-0001.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32002-0002.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32002-0003.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32002-0004.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32004-0001.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32004-0002.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32004-0003.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32020.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32021-0001.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32021-0002.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32465.patch
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2023-52722.patch
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-29510.patch
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33869-0001.patch
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33869-0002.patch
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33870.patch
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33871-0001.patch
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33871-0002.patch
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/7 ghostscript: fix CVE-2024-33870

From: Archana Polampalli <[email protected]>

---
 .../ghostscript/CVE-2024-33870.patch          | 92 +++++++++++++++++++
 .../ghostscript/ghostscript_9.55.0.bb         |  1 +
 2 files changed, 93 insertions(+)
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33870.patch
meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33870.patch new file +92 -0
new file mode 100644
index 0000000000..0d289b6d07
@@ -0,0 +1,92 @@
+From 79aef19c685984dc3da2dc090450407d9fbcff80 Mon Sep 17 00:00:00 2001
+From: Ken Sharp <[email protected]>
+Date: Tue, 26 Mar 2024 12:00:14 +0000
+Subject: [PATCH 1/5] Bug #707686
+
+See bug thread for details
+
+In addition to the noted bug; an error path (return from
+gp_file_name_reduce not successful) could elad to a memory leak as we
+did not free 'bufferfull'. Fix that too.
+
+This addresses CVE-2024-33870
+
+CVE: CVE-2024-33870
+
+Upstream-Status: Backport [https://cgit.ghostscript.com/cgi-bin/cgit.cgi/ghostpdl.git/commit/?id=79aef19c685984dc]
+
+Signed-off-by: Archana Polampalli <[email protected]>
+---
+ base/gpmisc.c | 33 ++++++++++++++++++++++++++++++---
+ 1 file changed, 30 insertions(+), 3 deletions(-)
+
+diff --git a/base/gpmisc.c b/base/gpmisc.c
+index f9a9230..3b6fffa 100644
+--- a/base/gpmisc.c
++++ b/base/gpmisc.c
+@@ -1042,7 +1042,7 @@ gp_validate_path_len(const gs_memory_t *mem,
+                      const uint         len,
+                      const char        *mode)
+ {
+-    char *buffer, *bufferfull;
++    char *buffer, *bufferfull = NULL;
+     uint rlen;
+     int code = 0;
+     const char *cdirstr = gp_file_name_current();
+@@ -1095,8 +1095,10 @@ gp_validate_path_len(const gs_memory_t *mem,
+             return gs_error_VMerror;
+
+         buffer = bufferfull + prefix_len;
+-        if (gp_file_name_reduce(path, (uint)len, buffer, &rlen) != gp_combine_success)
+-            return gs_error_invalidfileaccess;
++	if (gp_file_name_reduce(path, (uint)len, buffer, &rlen) != gp_combine_success) {
++           code = gs_note_error(gs_error_invalidfileaccess);
++            goto exit;
++        }
+         buffer[rlen] = 0;
+     }
+     while (1) {
+@@ -1131,9 +1133,33 @@ gp_validate_path_len(const gs_memory_t *mem,
+             code = gs_note_error(gs_error_invalidfileaccess);
+         }
+         if (code < 0 && prefix_len > 0 && buffer > bufferfull) {
++            uint newlen = rlen + cdirstrl + dirsepstrl;
++            char *newbuffer;
++            int code;
++
+             buffer = bufferfull;
+             memcpy(buffer, cdirstr, cdirstrl);
+             memcpy(buffer + cdirstrl, dirsepstr, dirsepstrl);
++	    /* We've prepended a './' or similar for the current working directory. We need
++             * to execute file_name_reduce on that, to eliminate any '../' or similar from
++             * the (new) full path.
++             */
++            newbuffer = (char *)gs_alloc_bytes(mem->thread_safe_memory, newlen + 1, "gp_validate_path");
++            if (newbuffer == NULL) {
++                code = gs_note_error(gs_error_VMerror);
++                goto exit;
++            }
++
++            memcpy(newbuffer, buffer, rlen + cdirstrl + dirsepstrl);
++            newbuffer[newlen] = 0x00;
++
++            code = gp_file_name_reduce(newbuffer, (uint)newlen, buffer, &newlen);
++            gs_free_object(mem->thread_safe_memory, newbuffer, "gp_validate_path");
++            if (code != gp_combine_success) {
++                code = gs_note_error(gs_error_invalidfileaccess);
++                goto exit;
++            }
++
+             continue;
+         }
+         else if (code < 0 && cdirstrl > 0 && prefix_len == 0 && buffer == bufferfull) {
+@@ -1152,6 +1178,7 @@ gp_validate_path_len(const gs_memory_t *mem,
+                                            gs_path_control_flag_is_scratch_file);
+     }
+
++exit:
+     gs_free_object(mem->thread_safe_memory, bufferfull, "gp_validate_path");
+ #ifdef EACCES
+     if (code == gs_error_invalidfileaccess)
+--
+2.40.0
meta/recipes-extended/ghostscript/ghostscript_9.55.0.bb +1 -0
index e99c740685..5fa4da0fb8 100644
@@ -43,6 +43,7 @@ SRC_URI_BASE = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/d
                 file://CVE-2023-38559.patch \
                 file://CVE-2023-43115.patch \
                 file://CVE-2023-46751.patch \
+                file://CVE-2024-33870.patch \
 "
 
 SRC_URI = "${SRC_URI_BASE} \
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/7 ghostscript: fix CVE-2024-33869

In reply to Steve Sakoman

From: Archana Polampalli <[email protected]>

---
 .../ghostscript/CVE-2024-33869-0001.patch     | 39 ++++++++++++++
 .../ghostscript/CVE-2024-33869-0002.patch     | 52 +++++++++++++++++++
 .../ghostscript/ghostscript_9.55.0.bb         |  2 +
 3 files changed, 93 insertions(+)
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33869-0001.patch
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33869-0002.patch
meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33869-0001.patch new file +39 -0
new file mode 100644
index 0000000000..2e60ae6048
@@ -0,0 +1,39 @@
+From 5ae2e320d69a7d0973011796bd388cd5befa1a43 Mon Sep 17 00:00:00 2001
+From: Ken Sharp <[email protected]>
+Date: Tue, 26 Mar 2024 12:02:57 +0000
+Subject: [PATCH 2/5] Bug #707691
+
+Part 1; when stripping a potential Current Working Dirctory specifier
+from a path, make certain it really is a CWD, and not simply large
+ebough to be a CWD.
+
+Reasons are in the bug thread, this is not (IMO) serious.
+
+This is part of the fix for CVE-2024-33869
+
+CVE: CVE-2024-33869
+
+Upstream-Status: Backport [https://cgit.ghostscript.com/cgi-bin/cgit.cgi/ghostpdl.git/commit/?id=5ae2e320d69a7d0973]
+
+Signed-off-by: Archana Polampalli <[email protected]>
+---
+ base/gpmisc.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/base/gpmisc.c b/base/gpmisc.c
+index 3b6fffa..a0b58c8 100644
+--- a/base/gpmisc.c
++++ b/base/gpmisc.c
+@@ -1162,8 +1162,8 @@ gp_validate_path_len(const gs_memory_t *mem,
+
+             continue;
+         }
+-        else if (code < 0 && cdirstrl > 0 && prefix_len == 0 && buffer == bufferfull) {
+-            buffer = bufferfull + cdirstrl + dirsepstrl;
++        else if (code < 0 && cdirstrl > 0 && prefix_len == 0 && buffer == bufferfull
++            && memcmp(buffer, cdirstr, cdirstrl) && !memcmp(buffer + cdirstrl, dirsepstr, dirsepstrl)) {
+             continue;
+         }
+         break;
+--
+2.40.0
meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33869-0002.patch new file +52 -0

52 lines not on this page · raw message

meta/recipes-extended/ghostscript/ghostscript_9.55.0.bb +2 -0
index 5fa4da0fb8..083ee4b337 100644
@@ -44,6 +44,8 @@ SRC_URI_BASE = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/d
                 file://CVE-2023-43115.patch \
                 file://CVE-2023-46751.patch \
                 file://CVE-2024-33870.patch \
+                file://CVE-2024-33869-0001.patch \
+                file://CVE-2024-33869-0002.patch \
 "
 
 SRC_URI = "${SRC_URI_BASE} \
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/7 ghostscript: fix CVE-2024-33871

In reply to Steve Sakoman

From: Archana Polampalli <[email protected]>

Added dependent patch [1] for backporting this CVE

[1] https://github.com/ArtifexSoftware/ghostpdl/commit/8b47f269b83b172b22606806fe5ec272d974e797

---
 .../ghostscript/CVE-2024-33871-0001.patch     | 4863 +++++++++++++++++
 .../ghostscript/CVE-2024-33871-0002.patch     |   43 +
 .../ghostscript/ghostscript_9.55.0.bb         |    2 +
 3 files changed, 4908 insertions(+)
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33871-0001.patch
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33871-0002.patch
meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33871-0001.patch new file +4863 -0
new file mode 100644
index 0000000000..008f588bff
@@ -0,0 +1,4863 @@
+From 8b47f269b83b172b22606806fe5ec272d974e797 Mon Sep 17 00:00:00 2001
+From: Michael Vrhel <[email protected]>
+Date: Mon, 22 Nov 2021 12:13:10 -0800
+Subject: [PATCH 6/7] Removal of globals in opvp device
+
+Thanks to Robin for suggesting the structure form
+to get the globals at a common offset for the
+raster and vector forms of the device. That coupled
+with pushing the device through all the methods and
+doing initialization was the biggest effort.
+
+Thanks also to Chris for his help in providing
+understanding as to what this device was actually doing.
+
+This commit includes a test harness for the opvp
+device, which uses the device client API to write
+out the commands it receives to a text file for
+comparison.  To build the driver use  ./build_opv_harness.sh
+To use the driver use a command line like
+-sDEVICE=opvp -sDriver=libopv.so -o output.txt -f ./examples/tiger.eps
+The command lines are always dumped to the same
+file which is opvp_command_dump.txt.   Note that the
+harness itself has to rely upon globals due to our
+inability to change the client API.
+
+CVE: CVE-2024-33871
+
+Upstream-Status: Backport [https://github.com/ArtifexSoftware/ghostpdl/commit/8b47f269b83b172b22606]
+
+Signed-off-by: Archana Polampalli <[email protected]>
+---
+ contrib/opvp/README.txt           |   18 +
+ contrib/opvp/build_opv_harness.sh |    4 +
+ contrib/opvp/gdevopvp.c           | 1879 +++++++++++++++++------------
+ contrib/opvp/opvp.h               |    9 +-
+ contrib/opvp/opvp_0_2_0.h         |    4 +-
+ contrib/opvp/opvpharness.c        |  947 +++++++++++++++
+ 6 files changed, 2070 insertions(+), 791 deletions(-)
+ create mode 100644 contrib/opvp/README.txt
+ create mode 100755 contrib/opvp/build_opv_harness.sh
+ create mode 100644 contrib/opvp/opvpharness.c
+
+diff --git a/contrib/opvp/README.txt b/contrib/opvp/README.txt
+new file mode 100644
+index 0000000..fd2250e
+--- /dev/null
++++ b/contrib/opvp/README.txt
+@@ -0,0 +1,18 @@
++In an effort to remove globals in devices
++that ship with Ghostscript, the opvp device was updated
++to place it's global values into the device structure.
++
++As part of that commit, a harness was added to enable
++testing of the opvp device client API to test for any
++issues. To build the harness use  ./build_opv_harness.sh
++This will create a debug version of the shared object
++libopv.so. The command line
++gs -sDEVICE=opvp -sDriver=./contrib/opvp/libopv.so -o output.txt -f ./examples/tiger.eps
++can then be used.
++
++This command should create a file called
++opvp_command_dump.txt that contains the calls and
++the parameters made to the client API. Note that the
++harness itself has to rely upon globals. To do otherwise
++would require a to change the client API, which we
++do not own.
+\ No newline at end of file
+diff --git a/contrib/opvp/build_opv_harness.sh b/contrib/opvp/build_opv_harness.sh
+new file mode 100755
+index 0000000..8d10f05
+--- /dev/null
++++ b/contrib/opvp/build_opv_harness.sh
+@@ -0,0 +1,4 @@
++#!/bin/bash
++
++gcc -Werror -Wall -c -fpic -g opvpharness.c
++gcc -shared -o libopv.so opvpharness.o
+\ No newline at end of file
+diff --git a/contrib/opvp/gdevopvp.c b/contrib/opvp/gdevopvp.c
+index 844b46c..64afbfe 100644
+--- a/contrib/opvp/gdevopvp.c
++++ b/contrib/opvp/gdevopvp.c
+@@ -115,14 +115,62 @@ typedef struct {
+
+ #define MAX_PATH_POINTS 1000
+
+-/* driver */
+-typedef struct  gx_device_opvp_s {
++/* To remove the existing globals from this device,
++   we place the current globals into a structure
++   and place them at the same offset location
++   for the opvp and oprp devices, allowing easy
++   access regardless of the device type. */
++
++typedef struct opXp_globals_s {
++    bool vector;
++    bool inkjet;
++    bool zoomAuto;
++    bool zooming;
++    bool beginPage;
++    float margins[4];
++    float zoom[2];
++    float shift[2];
++    opvp_int_t outputFD;
++    opvp_int_t nApiEntry;
++    opvp_dc_t printerContext;
++    opvp_cspace_t colorSpace;
++    opvp_cspace_t savedColorSpace;
++    char* vectorDriver;
++    char* printerModel;
++    void* handle;
++    opvp_brush_t* vectorFillColor;
++    opvp_int_t* ErrorNo;
++    opvp_api_procs_t* apiEntry;
++    OPVP_api_procs* apiEntry_0_2;
++    char* jobInfo;
++    char* docInfo;
++    opvp_dc_t(*OpenPrinter)(opvp_int_t, const opvp_char_t*,
++        const opvp_int_t[2], opvp_api_procs_t**);
++    int (*OpenPrinter_0_2)(int, char*, int*,
++        OPVP_api_procs**);
++    int (*GetLastError)(gx_device*);
++} opXp_globals;
++
++typedef struct base_opvp_s {
+     gx_device_vector_common;
++} base_opvp;
++
++typedef struct base_oprp_s {
++    gx_device_common;
++    gx_prn_device_common;
++} base_oprp;
++
++typedef struct gx_device_opvp_s {
++    gx_device_vector_common;
++    char padding[1 + (sizeof(base_oprp) > sizeof(base_opvp) ? sizeof(base_oprp) - sizeof(base_opvp) : 0)];
++    opXp_globals globals;
+ } gx_device_opvp;
+
+-typedef struct  gx_device_oprp_s {
++typedef struct gx_device_oprp_s {
+     gx_device_common;
+     gx_prn_device_common;
++    char padding[1 + (sizeof(base_opvp) > sizeof(base_oprp) ? sizeof(base_opvp) - sizeof(base_oprp) : 0)];
++    opXp_globals globals;
+ } gx_device_oprp;
+
+ /* point (internal) */
+@@ -135,15 +183,16 @@ typedef struct {
+
+ /* Utilities */
+ static  int opvp_startpage(gx_device *);
+-static  int opvp_endpage(void);
++static  int opvp_endpage(gx_device*);
+ static  char *opvp_alloc_string(char **, const char *);
+ static  char *opvp_cat_string(char **, const char *);
+ static  char *opvp_adjust_num_string(char *);
+-static  char **opvp_gen_dynamic_lib_name(void);
++static  char **opvp_gen_dynamic_lib_name(gx_device*);
+ static  char *opvp_to_utf8(char *);
+-#define opvp_check_in_page(pdev)        \
+-                ((beginPage) || (inkjet) ? 0 \
+-                    : (*vdev_proc(pdev, beginpage))((gx_device_vector*)pdev))
++#define opvp_check_in_page(opdev)        \
++                 ((((gx_device_opvp*)(opdev))->globals.beginPage) || \
++                  (((gx_device_opvp*)(opdev))->globals.inkjet) ? 0  \
++                    : (*vdev_proc(opdev, beginpage))((gx_device_vector*)opdev))
+ static  int opvp_get_papertable_index(gx_device *);
+ static  char *opvp_get_sizestring(float, float);
+ /* not used     static  const char *opvp_get_papersize_region(gx_device *);*/
+@@ -160,8 +209,8 @@ static  int opvp_draw_image(gx_device_opvp *, int,
+                             int, int, int, int, int, int, const byte *);
+
+ /* load/unload vector driver */
+-static  int opvp_load_vector_driver(void);
+-static  int opvp_unload_vector_driver(void);
++static  int opvp_load_vector_driver(gx_device*);
++static  int opvp_unload_vector_driver(gx_device*);
+ static  int prepare_open(gx_device *);
+
+ /* driver procs */
+@@ -177,10 +226,10 @@ static  int opvp_copy_mono(gx_device *, const byte *, int, int,
+                            gx_color_index, gx_color_index);
+ static  int opvp_copy_color(gx_device *, const byte *, int, int,
+                             gx_bitmap_id, int, int, int, int);
+-static  int _get_params(gs_param_list *);
++static  int _get_params(gx_device*, gs_param_list *);
+ static  int opvp_get_params(gx_device *, gs_param_list *);
+ static  int oprp_get_params(gx_device *, gs_param_list *);
+-static  int _put_params(gs_param_list *);
++static  int _put_params(gx_device*, gs_param_list *);
+ static  int opvp_put_params(gx_device *, gs_param_list *);
+ static  int oprp_put_params(gx_device *, gs_param_list *);
+ static  int opvp_fill_path(gx_device *, const gs_gstate *, gx_path *,
+@@ -295,6 +344,53 @@ gs_public_st_suffix_add0_final(
+     NULL, /* *jobInfo */\
+     NULL /* *docInfo */
+
++
++static int
++GetLastError_1_0(gx_device* dev)
++{
++    gx_device_opvp* pdev = (gx_device_opvp*)dev;
++
++    return *(pdev->globals.ErrorNo);
++}
++
++/* Initialize the globals */
++static void
++InitGlobals(gx_device* dev)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    opdev->globals.vector = true;
++    opdev->globals.inkjet = false;
++    opdev->globals.zoomAuto = false;
++    opdev->globals.zooming = false;
++    opdev->globals.beginPage = false;
++    opdev->globals.margins[0] = 0;
++    opdev->globals.margins[1] = 0;
++    opdev->globals.margins[2] = 0;
++    opdev->globals.margins[3] = 0;
++    opdev->globals.zoom[0] = 1;
++    opdev->globals.zoom[1] = 1;
++    opdev->globals.shift[0] = 0;
++    opdev->globals.shift[1] = 0;
++    opdev->globals.outputFD = -1;
++    opdev->globals.nApiEntry = 0;
++    opdev->globals.printerContext = -1;
++    opdev->globals.colorSpace = OPVP_CSPACE_STANDARDRGB;
++    opdev->globals.savedColorSpace = OPVP_CSPACE_STANDARDRGB;
++    opdev->globals.vectorDriver = NULL;
++    opdev->globals.printerModel = NULL;
++    opdev->globals.handle = NULL;
++    opdev->globals.vectorFillColor = NULL;
++    opdev->globals.ErrorNo = NULL;
++    opdev->globals.apiEntry = NULL;
++    opdev->globals.apiEntry_0_2 = NULL;
++    opdev->globals.jobInfo = NULL;
++    opdev->globals.docInfo = NULL;
++    opdev->globals.OpenPrinter = NULL;
++    opdev->globals.OpenPrinter_0_2 = NULL;
++    opdev->globals.GetLastError = GetLastError_1_0;
++}
++
+ /* device procs */
+ static void
+ opvp_initialize_device_procs(gx_device *dev)
+@@ -325,6 +421,9 @@ opvp_initialize_device_procs(gx_device *dev)
+      * by the system to the default. For compatibility we do the same. */
+     set_dev_proc(dev, encode_color, NULL);
+     set_dev_proc(dev, decode_color, NULL);
++
++    /* And the device globals */
++    InitGlobals(dev);
+ }
+
+ /* vector procs */
+@@ -394,6 +493,9 @@ oprp_initialize_device_procs(gx_device *dev)
+      * by the system to the default. For compatibility we do the same. */
+     set_dev_proc(dev, encode_color, NULL);
+     set_dev_proc(dev, decode_color, NULL);
++
++    /* And the device globals */
++    InitGlobals(dev);
+ }
+
+ const gx_device_oprp gs_oprp_device =
+@@ -412,43 +514,6 @@ const gx_device_oprp gs_oprp_device =
+     )
+ };
+
+-/* driver mode */
+-static bool vector = true;
+-static bool inkjet = false;
+-static char *vectorDriver = NULL;
+-static char *printerModel = NULL;
+-static void *handle = NULL;
+-static opvp_dc_t (*OpenPrinter)(opvp_int_t,const opvp_char_t*,
+-                                  const opvp_int_t[2],
+-                                  opvp_api_procs_t**) = NULL;
+-static int (*OpenPrinter_0_2)(int,char*,int*,
+-                                  OPVP_api_procs**) = NULL;
+-static opvp_int_t *ErrorNo = NULL;
+-static opvp_int_t outputFD = -1;
+-static opvp_int_t nApiEntry = 0;
+-static opvp_api_procs_t *apiEntry = NULL;
+-static OPVP_api_procs *apiEntry_0_2 = NULL;
+-static opvp_dc_t printerContext = -1;
+-static char *jobInfo = NULL;
+-static char *docInfo = NULL;
+-static opvp_cspace_t colorSpace = OPVP_CSPACE_STANDARDRGB;
+-static opvp_cspace_t savedColorSpace;
+-static opvp_brush_t *vectorFillColor = NULL;
+-static float margins[4] = {0, 0, 0, 0};
+-static float zoom[2] = {1, 1};
+-static float shift[2] = {0, 0};
+-static bool zoomAuto = false;
+-static bool zooming = false;
+-static bool beginPage = false;
+-
+-static int
+-GetLastError_1_0(void)
+-{
+-    return *ErrorNo;
+-}
+-
+-static int (*GetLastError)(void) = GetLastError_1_0;
+-
+ /* Wrapper functions that keep compatible with 0.2 */
+
+ /* color space mapping 0.2 to 1.0 */
+@@ -496,9 +561,11 @@ static int colorDepth_0_2[] = {
+
+ /* translate error code */
+ static int
+-GetLastError_0_2(void)
++GetLastError_0_2(gx_device* dev)
+ {
+-    switch(*ErrorNo) {
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
++
++    switch(*(opdev->globals.ErrorNo)) {
+     case OPVP_FATALERROR_0_2:
+         return OPVP_FATALERROR;
+         break;
+@@ -526,48 +593,51 @@ GetLastError_0_2(void)
+ }
+
+ static opvp_result_t
+-StartPageWrapper(opvp_dc_t printerContext, const opvp_char_t *pageInfo)
++StartPageWrapper(gx_device *dev, opvp_dc_t printerContext, const opvp_char_t *pageInfo)
+ {
+     int r;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+-    if ((r = apiEntry_0_2->StartPage(printerContext,
++    if ((r = opdev->globals.apiEntry_0_2->StartPage(printerContext,
+            /* discard const */(char *)pageInfo)) != OPVP_OK) {
+           /* error */
+         return r;
+     }
+     /* initialize ROP */
+-    if (apiEntry_0_2->SetROP != NULL) {
+-        apiEntry_0_2->SetROP(printerContext,
++    if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++        opdev->globals.apiEntry_0_2->SetROP(printerContext,
+           OPVP_0_2_ROP_P);
+     }
+     return OPVP_OK;
+ }
+
+ static opvp_result_t
+-InitGSWrapper(opvp_dc_t printerContext)
++InitGSWrapper(gx_device *dev, opvp_dc_t printerContext)
+ {
+     int r;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+-    if ((r = apiEntry_0_2->InitGS(printerContext)) != OPVP_OK) {
++    if ((r = opdev->globals.apiEntry_0_2->InitGS(printerContext)) != OPVP_OK) {
+           /* error */
+         return r;
+     }
+     /* initialize ROP */
+-    if (apiEntry_0_2->SetROP != NULL) {
+-        apiEntry_0_2->SetROP(printerContext,
++    if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++        opdev->globals.apiEntry_0_2->SetROP(printerContext,
+           OPVP_0_2_ROP_P);
+     }
+     return OPVP_OK;
+ }
+
+ static opvp_result_t
+-QueryColorSpaceWrapper( opvp_dc_t printerContext, opvp_int_t *pnum,
++QueryColorSpaceWrapper(gx_device *dev, opvp_dc_t printerContext, opvp_int_t *pnum,
+     opvp_cspace_t *pcspace)
+ {
+     int r;
+     int i;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+-    if ((r = apiEntry_0_2->QueryColorSpace(printerContext,
++    if ((r = opdev->globals.apiEntry_0_2->QueryColorSpace(printerContext,
+          (OPVP_ColorSpace *)pcspace,pnum)) != OPVP_OK) {
+         /* error */
+         return r;
+@@ -587,51 +657,54 @@ QueryColorSpaceWrapper( opvp_dc_t printerContext, opvp_int_t *pnum,
+ }
+
+ static opvp_result_t
+-SetColorSpaceWrapper(opvp_dc_t printerContext, opvp_cspace_t cspace)
++SetColorSpaceWrapper(gx_device *dev, opvp_dc_t printerContext, opvp_cspace_t cspace)
+ {
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
++
+     if (cspace == OPVP_CSPACE_DEVICEKRGB) {
+         /* 0.2 doesn't have OPVP_CSPACE_DEVICEKRGB */
+-        *ErrorNo = OPVP_NOTSUPPORTED_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_NOTSUPPORTED_0_2;
+         return -1;
+     }
+     if ((int)cspace
+          >= sizeof(cspace_1_0_to_0_2)/sizeof(OPVP_ColorSpace)) {
+         /* unknown color space */
+-        *ErrorNo = OPVP_PARAMERROR_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_PARAMERROR_0_2;
+         return -1;
+     }
+-    return  apiEntry_0_2->SetColorSpace(printerContext,
++    return  opdev->globals.apiEntry_0_2->SetColorSpace(printerContext,
+       cspace_1_0_to_0_2[cspace]);
+ }
+
++/* Not used
+ static opvp_result_t
+-GetColorSpaceWrapper(opvp_dc_t printerContext, opvp_cspace_t *pcspace)
++GetColorSpaceWrapper(gx_device *dev, opvp_dc_t printerContext, opvp_cspace_t *pcspace)
+ {
+     int r;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+-    if ((r = apiEntry_0_2->GetColorSpace(printerContext,
++    if ((r = opdev->globals.apiEntry_0_2->GetColorSpace(printerContext,
+       (OPVP_ColorSpace *)pcspace)) != OPVP_OK) {
+-        /* error */
+         return r;
+     }
+     if (*pcspace
+          >= sizeof(cspace_0_2_to_1_0)/sizeof(opvp_cspace_t)) {
+-        /* unknown color space */
+-        /* set DEVICERGB instead */
+         *pcspace = OPVP_CSPACE_DEVICERGB;
+     } else {
+         *pcspace = cspace_0_2_to_1_0[*pcspace];
+     }
+     return r;
+ }
++*/
+
+ static opvp_result_t
+-SetStrokeColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
++SetStrokeColorWrapper(gx_device *dev, opvp_dc_t printerContext, const opvp_brush_t *brush)
+ {
+     OPVP_Brush brush_0_2;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     if (brush == NULL) {
+-        *ErrorNo = OPVP_PARAMERROR_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_PARAMERROR_0_2;
+         return -1;
+     }
+     if (brush->colorSpace == OPVP_CSPACE_DEVICEKRGB) {
+@@ -641,7 +714,7 @@ SetStrokeColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
+     if ((int)brush->colorSpace
+          >= sizeof(cspace_1_0_to_0_2)/sizeof(OPVP_ColorSpace)) {
+         /* unknown color space */
+-        *ErrorNo = OPVP_PARAMERROR_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_PARAMERROR_0_2;
+         return -1;
+     }
+     brush_0_2.colorSpace = cspace_1_0_to_0_2[brush->colorSpace];
+@@ -649,16 +722,17 @@ SetStrokeColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
+     brush_0_2.yorg = brush->yorg;
+     brush_0_2.pbrush = (OPVP_BrushData *)brush->pbrush;
+     memcpy(brush_0_2.color,brush->color,sizeof(brush_0_2.color));
+-    return apiEntry_0_2->SetStrokeColor(printerContext,&brush_0_2);
++    return opdev->globals.apiEntry_0_2->SetStrokeColor(printerContext, &brush_0_2);
+ }
+
+ static opvp_result_t
+-SetFillColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
++SetFillColorWrapper(gx_device *dev, opvp_dc_t printerContext, const opvp_brush_t *brush)
+ {
+     OPVP_Brush brush_0_2;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     if (brush == NULL) {
+-        *ErrorNo = OPVP_PARAMERROR_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_PARAMERROR_0_2;
+         return -1;
+     }
+     if (brush->colorSpace == OPVP_CSPACE_DEVICEKRGB) {
+@@ -668,7 +742,7 @@ SetFillColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
+     if ((int)brush->colorSpace
+          >= sizeof(cspace_1_0_to_0_2)/sizeof(OPVP_ColorSpace)) {
+         /* unknown color space */
+-        *ErrorNo = OPVP_PARAMERROR_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_PARAMERROR_0_2;
+         return -1;
+     }
+     brush_0_2.colorSpace = cspace_1_0_to_0_2[brush->colorSpace];
+@@ -676,27 +750,28 @@ SetFillColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
+     brush_0_2.yorg = brush->yorg;
+     brush_0_2.pbrush = (OPVP_BrushData *)brush->pbrush;
+     memcpy(brush_0_2.color,brush->color,sizeof(brush_0_2.color));
+-    return apiEntry_0_2->SetFillColor(printerContext,&brush_0_2);
++    return opdev->globals.apiEntry_0_2->SetFillColor(printerContext, &brush_0_2);
+ }
+
+ static opvp_result_t
+-SetBgColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
++SetBgColorWrapper(gx_device *dev, opvp_dc_t printerContext, const opvp_brush_t *brush)
+ {
+     OPVP_Brush brush_0_2;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     if (brush == NULL) {
+-        *ErrorNo = OPVP_PARAMERROR_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_PARAMERROR_0_2;
+         return -1;
+     }
+     if (brush->colorSpace == OPVP_CSPACE_DEVICEKRGB) {
+         /* 0.2 doesn't have OPVP_CSPACE_DEVICEKRGB */
+-        *ErrorNo = OPVP_NOTSUPPORTED_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_NOTSUPPORTED_0_2;
+         return -1;
+     }
+     if ((int)brush->colorSpace
+          >= sizeof(cspace_1_0_to_0_2)/sizeof(OPVP_ColorSpace)) {
+         /* unknown color space */
+-        *ErrorNo = OPVP_PARAMERROR_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_PARAMERROR_0_2;
+         return -1;
+     }
+     brush_0_2.colorSpace = cspace_1_0_to_0_2[brush->colorSpace];
+@@ -704,11 +779,12 @@ SetBgColorWrapper(opvp_dc_t printerContext, const opvp_brush_t *brush)
+     brush_0_2.yorg = brush->yorg;
+     brush_0_2.pbrush = (OPVP_BrushData *)brush->pbrush;
+     memcpy(brush_0_2.color,brush->color,sizeof(brush_0_2.color));
+-    return apiEntry_0_2->SetBgColor(printerContext,&brush_0_2);
++    return opdev->globals.apiEntry_0_2->SetBgColor(printerContext, &brush_0_2);
+ }
+
+ static opvp_result_t
+ DrawImageWrapper(
++    gx_device *dev,
+     opvp_dc_t printerContext,
+     opvp_int_t sourceWidth,
+     opvp_int_t sourceHeight,
+@@ -723,30 +799,31 @@ DrawImageWrapper(
+     OPVP_ImageFormat iformat_0_2;
+     OPVP_PaintMode paintmode_0_2 = OPVP_paintModeTransparent;
+     int depth;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     if (imageFormat == OPVP_IFORMAT_MASK) {
+-        if (apiEntry_0_2->GetPaintMode != NULL) {
+-            apiEntry_0_2->GetPaintMode(printerContext,
++        if (opdev->globals.apiEntry_0_2->GetPaintMode != NULL) {
++            opdev->globals.apiEntry_0_2->GetPaintMode(printerContext,
+               &paintmode_0_2);
+         }
+         if (paintmode_0_2 != OPVP_paintModeTransparent) {
+-            if (apiEntry_0_2->SetROP != NULL) {
+-                apiEntry_0_2->SetROP(printerContext,
++            if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++                opdev->globals.apiEntry_0_2->SetROP(printerContext,
+                     OPVP_0_2_ROP_S);
+             }
+         }
+         else {
+-            if (apiEntry_0_2->SetROP != NULL) {
+-                apiEntry_0_2->SetROP(printerContext,
++            if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++                opdev->globals.apiEntry_0_2->SetROP(printerContext,
+                     OPVP_0_2_ROP_OR);
+             }
+         }
+         depth = 1;
+     } else {
+-        if (apiEntry_0_2->SetROP != NULL) {
+-            apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_S);
++        if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++            opdev->globals.apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_S);
+         }
+-        depth = colorDepth_0_2[colorSpace];
++        depth = colorDepth_0_2[opdev->globals.colorSpace];
+     }
+
+     OPVP_I2FIX(0,rect.p0.x);
+@@ -755,17 +832,17 @@ DrawImageWrapper(
+     OPVP_I2FIX(destinationHeight,rect.p1.y);
+     if (imageFormat >= sizeof(iformat_1_0_to_0_2)/sizeof(OPVP_ImageFormat)) {
+         /* illegal image format */
+-        *ErrorNo = OPVP_PARAMERROR_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_PARAMERROR_0_2;
+         return -1;
+     }
+     iformat_0_2 = iformat_1_0_to_0_2[imageFormat];
+-    r = apiEntry_0_2->DrawImage(printerContext,sourceWidth,sourceHeight,
++    r = opdev->globals.apiEntry_0_2->DrawImage(printerContext,sourceWidth,sourceHeight,
+             depth,iformat_0_2,rect,
+             sourcePitch*sourceHeight,
+             /* remove const */ (void *)imagedata);
+
+-    if (apiEntry_0_2->SetROP != NULL) {
+-        apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_P);
++    if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++        opdev->globals.apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_P);
+     }
+
+     return r;
+@@ -773,6 +850,7 @@ DrawImageWrapper(
+
+ static opvp_result_t
+ StartDrawImageWrapper(
++    gx_device *dev,
+     opvp_dc_t printerContext,
+     opvp_int_t sourceWidth,
+     opvp_int_t sourceHeight,
+@@ -786,28 +864,29 @@ StartDrawImageWrapper(
+     OPVP_ImageFormat iformat_0_2;
+     OPVP_PaintMode paintmode_0_2 = OPVP_paintModeTransparent;
+     int depth;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     if (imageFormat == OPVP_IFORMAT_MASK) {
+-        if (apiEntry_0_2->GetPaintMode != NULL) {
+-            apiEntry_0_2->GetPaintMode(printerContext,
++        if (opdev->globals.apiEntry_0_2->GetPaintMode != NULL) {
++            opdev->globals.apiEntry_0_2->GetPaintMode(printerContext,
+               &paintmode_0_2);
+         }
+         if (paintmode_0_2 != OPVP_paintModeTransparent) {
+-            if (apiEntry_0_2->SetROP != NULL) {
+-                apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_S);
++            if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++                opdev->globals.apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_S);
+             }
+         }
+         else {
+-            if (apiEntry_0_2->SetROP != NULL) {
+-                apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_OR);
++            if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++                opdev->globals.apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_OR);
+             }
+         }
+         depth = 1;
+     } else {
+-        if (apiEntry_0_2->SetROP != NULL) {
+-            apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_S);
++        if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++            opdev->globals.apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_S);
+         }
+-        depth = colorDepth_0_2[colorSpace];
++        depth = colorDepth_0_2[opdev->globals.colorSpace];
+     }
+
+     OPVP_I2FIX(0,rect.p0.x);
+@@ -816,310 +895,518 @@ StartDrawImageWrapper(
+     OPVP_I2FIX(destinationHeight,rect.p1.y);
+     if (imageFormat >= sizeof(iformat_1_0_to_0_2)/sizeof(OPVP_ImageFormat)) {
+         /* illegal image format */
+-        *ErrorNo = OPVP_PARAMERROR_0_2;
++        *(opdev->globals.ErrorNo) = OPVP_PARAMERROR_0_2;
+         return -1;
+     }
+     iformat_0_2 = iformat_1_0_to_0_2[imageFormat];
+-    r = apiEntry_0_2->StartDrawImage(printerContext,
+-            sourceWidth,sourceHeight,
+-            depth,iformat_0_2,rect);
++    r = opdev->globals.apiEntry_0_2->StartDrawImage(printerContext,
++            sourceWidth, sourceHeight,
++            depth, iformat_0_2, rect);
+
+     return r;
+ }
+
+ static opvp_result_t
+-EndDrawImageWrapper(opvp_dc_t printerContext)
++EndDrawImageWrapper(gx_device *dev, opvp_dc_t printerContext)
+ {
+     int r;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+-    r = apiEntry_0_2->EndDrawImage(printerContext);
++    r = opdev->globals.apiEntry_0_2->EndDrawImage(printerContext);
+
+     /* make sure rop is pattern copy */
+-    if (apiEntry_0_2->SetROP != NULL) {
+-        apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_P);
++    if (opdev->globals.apiEntry_0_2->SetROP != NULL) {
++        opdev->globals.apiEntry_0_2->SetROP(printerContext,OPVP_0_2_ROP_P);
+     }
+
+     return r;
+ }
+
++/* Not used
+ static opvp_result_t
+ QueryDeviceCapabilityWrapper(
++    gx_device *dev,
+     opvp_dc_t printerContext,
+     opvp_queryinfoflags_t queryflag,
+     opvp_int_t *buflen,
+     opvp_char_t *infoBuf)
+ {
+-    return apiEntry_0_2->QueryDeviceCapability(printerContext,queryflag,
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
++
++    return opdev->globals.apiEntry_0_2->QueryDeviceCapability(printerContext,queryflag,
+       *buflen,(char *)infoBuf);
+ }
+
+ static opvp_result_t
+ QueryDeviceInfoWrapper(
++    gx_device *dev,
+     opvp_dc_t printerContext,
+     opvp_queryinfoflags_t queryflag,
+     opvp_int_t *buflen,
+     opvp_char_t *infoBuf)
+ {
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
++
+     if (queryflag & OPVP_QF_MEDIACOPY) {
+-        *ErrorNo = OPVP_NOTSUPPORTED;
++        *(opdev->globals.ErrorNo) = OPVP_NOTSUPPORTED;
+         return -1;
+     }
+     if (queryflag & OPVP_QF_PRINTREGION) {
+         queryflag &= ~OPVP_QF_PRINTREGION;
+         queryflag |= 0x0020000;
+     }
+-    return apiEntry_0_2->QueryDeviceInfo(printerContext,queryflag,
+-      *buflen,(char *)infoBuf);
++    return opdev->globals.apiEntry_0_2->QueryDeviceInfo(printerContext, queryflag,
++      *buflen, (char *)infoBuf);
+ }
++*/
+
+ static opvp_result_t
+-SetLineDashWrapper(opvp_dc_t printerContext, opvp_int_t num,
++SetLineDashWrapper(gx_device *dev, opvp_dc_t printerContext, opvp_int_t num,
+     const opvp_fix_t *pdash)
+ {
+-    return apiEntry_0_2->SetLineDash(printerContext,
+-      /* remove const */ (OPVP_Fix *)pdash,num);
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
++
++    return opdev->globals.apiEntry_0_2->SetLineDash(printerContext, num,
++      /* remove const */ (OPVP_Fix *)pdash);
+ }
+
++/* Not used
+ static opvp_result_t
+-GetLineDashWrapper(opvp_dc_t printerContext, opvp_int_t *pnum,
++GetLineDashWrapper(gx_device* dev, opvp_dc_t printerContext, opvp_int_t *pnum,
+     opvp_fix_t *pdash)
+ {
+-    return apiEntry_0_2->GetLineDash(printerContext,
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
++
++    return opdev->globals.apiEntry_0_2->GetLineDash(printerContext,
+       pdash,pnum);
+ }
++*/
+
+ static opvp_dc_t
+ OpenPrinterWrapper(
++    gx_device *dev,
+     opvp_int_t outputFD,
+     const opvp_char_t *printerModel,
+     const opvp_int_t apiVersion[2],
+     opvp_api_procs_t **apiProcs)
+ {
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
++
+     opvp_dc_t dc = -1;
+
+-    if (OpenPrinter != NULL) {
+-        dc = (*OpenPrinter)(outputFD,printerModel,apiVersion,apiProcs);
++    if (opdev->globals.OpenPrinter != NULL) {
++        dc = (*(opdev->globals.OpenPrinter))(outputFD, printerModel, apiVersion, apiProcs);
+     } else {
+         /* try version 0.2 */
+
+-        if (OpenPrinter_0_2 != NULL) {
++        if (opdev->globals.OpenPrinter_0_2 != NULL) {
+             static opvp_api_procs_t tEntry;
+-            int nApiEntry;
++            int nApiEntry;  /* Alias with prior global. Kept as is */
+
+-            dc = (*OpenPrinter_0_2)(outputFD,
++            dc = (*(opdev->globals.OpenPrinter_0_2))(outputFD,
+                     /* remove const */
+                     (char *)printerModel,
+-                    &nApiEntry,&apiEntry_0_2);
++                    &nApiEntry,
++                    &(opdev->globals.apiEntry_0_2));
+             /* setting functions */
+             tEntry.opvpClosePrinter
+-                    = apiEntry_0_2->ClosePrinter;
++                    = opdev->globals.apiEntry_0_2->ClosePrinter;
+             tEntry.opvpStartJob
+                     = (opvp_result_t (*)(opvp_int_t,
+                        const opvp_char_t*))
+-                       apiEntry_0_2->StartJob;
+-            tEntry.opvpEndJob = apiEntry_0_2->EndJob;
++                       opdev->globals.apiEntry_0_2->StartJob;
++            tEntry.opvpEndJob = opdev->globals.apiEntry_0_2->EndJob;
+             tEntry.opvpAbortJob = NULL;
+             tEntry.opvpStartDoc
+                     = (opvp_result_t (*)(opvp_dc_t,
+                        const opvp_char_t*))
+-                       apiEntry_0_2->StartDoc;
+-            tEntry.opvpEndDoc = apiEntry_0_2->EndDoc;
+-            if (apiEntry_0_2->StartPage != NULL) {
+-                tEntry.opvpStartPage = StartPageWrapper;
+-            } else {
+-                tEntry.opvpStartPage = NULL;
+-            }
+-            tEntry.opvpEndPage = apiEntry_0_2->EndPage;
+-
+-            if (apiEntry_0_2->QueryDeviceCapability != NULL) {
+-                tEntry.opvpQueryDeviceCapability
+-                  = QueryDeviceCapabilityWrapper;
+-            } else {
+-                tEntry.opvpQueryDeviceCapability = NULL;
+-            }
+-
+-            if (apiEntry_0_2->QueryDeviceInfo != NULL) {
+-                tEntry.opvpQueryDeviceInfo = QueryDeviceInfoWrapper;
+-            } else {
+-                tEntry.opvpQueryDeviceInfo = NULL;
+-            }
+-
+-            tEntry.opvpResetCTM = apiEntry_0_2->ResetCTM;
++                       opdev->globals.apiEntry_0_2->StartDoc;
++            tEntry.opvpEndDoc = opdev->globals.apiEntry_0_2->EndDoc;
++            tEntry.opvpStartPage = NULL;
++            tEntry.opvpEndPage = opdev->globals.apiEntry_0_2->EndPage;
++            tEntry.opvpQueryDeviceCapability = NULL;
++            tEntry.opvpQueryDeviceInfo = NULL;
++            tEntry.opvpResetCTM = opdev->globals.apiEntry_0_2->ResetCTM;
+             tEntry.opvpSetCTM = (opvp_result_t (*)(opvp_dc_t,
+                        const opvp_ctm_t*))
+-                       apiEntry_0_2->SetCTM;
++                       opdev->globals.apiEntry_0_2->SetCTM;
+             tEntry.opvpGetCTM = (opvp_result_t (*)(opvp_dc_t,opvp_ctm_t*))
+-                       apiEntry_0_2->GetCTM;
+-            if (apiEntry_0_2->InitGS != NULL) {
+-                tEntry.opvpInitGS = InitGSWrapper;
+-            } else {
+-                tEntry.opvpInitGS = NULL;
+-            }
+-            tEntry.opvpSaveGS = apiEntry_0_2->SaveGS;
+-            tEntry.opvpRestoreGS = apiEntry_0_2->RestoreGS;
+-            if (apiEntry_0_2->QueryColorSpace != NULL) {
+-                tEntry.opvpQueryColorSpace = QueryColorSpaceWrapper;
+-            } else {
+-                tEntry.opvpQueryColorSpace = NULL;
+-            }
+-            if (apiEntry_0_2->SetColorSpace != NULL) {
+-                tEntry.opvpSetColorSpace = SetColorSpaceWrapper;
+-            } else {
+-                tEntry.opvpSetColorSpace = NULL;
+-            }
+-            if (apiEntry_0_2->GetColorSpace != NULL) {
+-                tEntry.opvpGetColorSpace = GetColorSpaceWrapper;
+-            } else {
+-                tEntry.opvpGetColorSpace = NULL;
+-            }
++                opdev->globals.apiEntry_0_2->GetCTM;
++            tEntry.opvpInitGS = NULL;
++            tEntry.opvpSaveGS = opdev->globals.apiEntry_0_2->SaveGS;
++            tEntry.opvpRestoreGS = opdev->globals.apiEntry_0_2->RestoreGS;
++            tEntry.opvpQueryColorSpace = NULL;
++            tEntry.opvpSetColorSpace = NULL;
++            tEntry.opvpGetColorSpace = NULL;
++
+             tEntry.opvpSetFillMode
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_fillmode_t))
+-                       apiEntry_0_2->SetFillMode;
++                opdev->globals.apiEntry_0_2->SetFillMode;
+             tEntry.opvpGetFillMode
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_fillmode_t*))
+-                       apiEntry_0_2->GetFillMode;
+-            tEntry.opvpSetAlphaConstant = apiEntry_0_2->SetAlphaConstant;
+-            tEntry.opvpGetAlphaConstant = apiEntry_0_2->GetAlphaConstant;
+-            tEntry.opvpSetLineWidth = apiEntry_0_2->SetLineWidth;
+-            tEntry.opvpGetLineWidth = apiEntry_0_2->GetLineWidth;
+-            if (apiEntry_0_2->SetLineDash != NULL) {
+-                tEntry.opvpSetLineDash = SetLineDashWrapper;
+-            } else {
+-                tEntry.opvpSetLineDash = NULL;
+-            }
+-            if (apiEntry_0_2->GetLineDash != NULL) {
+-                tEntry.opvpGetLineDash = GetLineDashWrapper;
+-            } else {
+-                tEntry.opvpGetLineDash = NULL;
+-            }
++                opdev->globals.apiEntry_0_2->GetFillMode;
++            tEntry.opvpSetAlphaConstant = opdev->globals.apiEntry_0_2->SetAlphaConstant;
++            tEntry.opvpGetAlphaConstant = opdev->globals.apiEntry_0_2->GetAlphaConstant;
++            tEntry.opvpSetLineWidth = opdev->globals.apiEntry_0_2->SetLineWidth;
++            tEntry.opvpGetLineWidth = opdev->globals.apiEntry_0_2->GetLineWidth;
++            tEntry.opvpSetLineDash = NULL;
++            tEntry.opvpGetLineDash = NULL;
++
+             tEntry.opvpSetLineDashOffset
+-                    = apiEntry_0_2->SetLineDashOffset;
++                    = opdev->globals.apiEntry_0_2->SetLineDashOffset;
+             tEntry.opvpGetLineDashOffset
+-                    = apiEntry_0_2->GetLineDashOffset;
++                    = opdev->globals.apiEntry_0_2->GetLineDashOffset;
+             tEntry.opvpSetLineStyle
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_linestyle_t))
+-                       apiEntry_0_2->SetLineStyle;
++                opdev->globals.apiEntry_0_2->SetLineStyle;
+             tEntry.opvpGetLineStyle
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_linestyle_t*))
+-                       apiEntry_0_2->GetLineStyle;
++                opdev->globals.apiEntry_0_2->GetLineStyle;
+             tEntry.opvpSetLineCap
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_linecap_t))
+-                       apiEntry_0_2->SetLineCap;
++                opdev->globals.apiEntry_0_2->SetLineCap;
+             tEntry.opvpGetLineCap
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_linecap_t*))
+-                       apiEntry_0_2->GetLineCap;
++                opdev->globals.apiEntry_0_2->GetLineCap;
+             tEntry.opvpSetLineJoin
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_linejoin_t))
+-                       apiEntry_0_2->SetLineJoin;
++                opdev->globals.apiEntry_0_2->SetLineJoin;
+             tEntry.opvpGetLineJoin
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_linejoin_t*))
+-                       apiEntry_0_2->GetLineJoin;
+-            tEntry.opvpSetMiterLimit = apiEntry_0_2->SetMiterLimit;
+-            tEntry.opvpGetMiterLimit = apiEntry_0_2->GetMiterLimit;
++                opdev->globals.apiEntry_0_2->GetLineJoin;
++            tEntry.opvpSetMiterLimit = opdev->globals.apiEntry_0_2->SetMiterLimit;
++            tEntry.opvpGetMiterLimit = opdev->globals.apiEntry_0_2->GetMiterLimit;
+             tEntry.opvpSetPaintMode
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_paintmode_t))
+-                       apiEntry_0_2->SetPaintMode;
++                opdev->globals.apiEntry_0_2->SetPaintMode;
+             tEntry.opvpGetPaintMode
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_paintmode_t*))
+-                       apiEntry_0_2->GetPaintMode;
+-            if (apiEntry_0_2->SetStrokeColor != NULL) {
+-                tEntry.opvpSetStrokeColor = SetStrokeColorWrapper;
+-            } else {
+-                tEntry.opvpSetStrokeColor = NULL;
+-            }
+-            if (apiEntry_0_2->SetFillColor != NULL) {
+-                tEntry.opvpSetFillColor = SetFillColorWrapper;
+-            } else {
+-                tEntry.opvpSetFillColor = NULL;
+-            }
+-            if (apiEntry_0_2->SetBgColor != NULL) {
+-                tEntry.opvpSetBgColor = SetBgColorWrapper;
+-            } else {
+-                tEntry.opvpSetBgColor = NULL;
+-            }
+-            tEntry.opvpNewPath = apiEntry_0_2->NewPath;
+-            tEntry.opvpEndPath = apiEntry_0_2->EndPath;
+-            tEntry.opvpStrokePath = apiEntry_0_2->StrokePath;
+-            tEntry.opvpFillPath = apiEntry_0_2->FillPath;
+-            tEntry.opvpStrokeFillPath = apiEntry_0_2->StrokeFillPath;
++                opdev->globals.apiEntry_0_2->GetPaintMode;
++            tEntry.opvpSetStrokeColor = NULL;
++            tEntry.opvpSetFillColor = NULL;
++            tEntry.opvpSetBgColor = NULL;
++            tEntry.opvpNewPath = opdev->globals.apiEntry_0_2->NewPath;
++            tEntry.opvpEndPath = opdev->globals.apiEntry_0_2->EndPath;
++            tEntry.opvpStrokePath = opdev->globals.apiEntry_0_2->StrokePath;
++            tEntry.opvpFillPath = opdev->globals.apiEntry_0_2->FillPath;
++            tEntry.opvpStrokeFillPath = opdev->globals.apiEntry_0_2->StrokeFillPath;
+             tEntry.opvpSetClipPath
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_cliprule_t))
+-                       apiEntry_0_2->SetClipPath;
+-            tEntry.opvpResetClipPath = apiEntry_0_2->ResetClipPath;
+-            tEntry.opvpSetCurrentPoint = apiEntry_0_2->SetCurrentPoint;
++                opdev->globals.apiEntry_0_2->SetClipPath;
++            tEntry.opvpResetClipPath = opdev->globals.apiEntry_0_2->ResetClipPath;
++            tEntry.opvpSetCurrentPoint = opdev->globals.apiEntry_0_2->SetCurrentPoint;
+             tEntry.opvpLinePath
+                     = (opvp_result_t (*)(opvp_dc_t,
+                        opvp_pathmode_t,opvp_int_t,
+                        const opvp_point_t*))
+-                       apiEntry_0_2->LinePath;
++                opdev->globals.apiEntry_0_2->LinePath;
+             tEntry.opvpPolygonPath
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
+                        const opvp_int_t*,
+                        const opvp_point_t*))
+-                       apiEntry_0_2->PolygonPath;
++                opdev->globals.apiEntry_0_2->PolygonPath;
+             tEntry.opvpRectanglePath
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
+                        const opvp_rectangle_t*))
+-                       apiEntry_0_2->RectanglePath;
++                opdev->globals.apiEntry_0_2->RectanglePath;
+             tEntry.opvpRoundRectanglePath
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
+                        const opvp_roundrectangle_t*))
+-                       apiEntry_0_2->RoundRectanglePath;
++                opdev->globals.apiEntry_0_2->RoundRectanglePath;
+             tEntry.opvpBezierPath
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
+                        const opvp_point_t*))
+-                       apiEntry_0_2->BezierPath;
++                opdev->globals.apiEntry_0_2->BezierPath;
+             tEntry.opvpArcPath
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_arcmode_t,
+                        opvp_arcdir_t,opvp_fix_t,opvp_fix_t,opvp_fix_t,
+                        opvp_fix_t,opvp_fix_t,opvp_fix_t,opvp_fix_t,
+-                       opvp_fix_t))apiEntry_0_2->ArcPath;
+-            if (apiEntry_0_2->DrawImage != NULL) {
+-                tEntry.opvpDrawImage = DrawImageWrapper;
+-            } else {
+-                tEntry.opvpDrawImage = NULL;
+-            }
+-            if (apiEntry_0_2->StartDrawImage != NULL) {
+-                tEntry.opvpStartDrawImage = StartDrawImageWrapper;
+-            } else {
+-                tEntry.opvpStartDrawImage = NULL;
+-            }
++                       opvp_fix_t))opdev->globals.apiEntry_0_2->ArcPath;
++            tEntry.opvpDrawImage = NULL;
++            tEntry.opvpStartDrawImage = NULL;
+             tEntry.opvpTransferDrawImage =
+                (opvp_result_t (*)(opvp_dc_t,opvp_int_t,const void*))
+-               apiEntry_0_2->TransferDrawImage;
+-            if (apiEntry_0_2->EndDrawImage != NULL) {
+-                tEntry.opvpEndDrawImage = EndDrawImageWrapper;
+-            } else {
+-                tEntry.opvpEndDrawImage = NULL;
+-            }
+-            tEntry.opvpStartScanline = apiEntry_0_2->StartScanline;
++                opdev->globals.apiEntry_0_2->TransferDrawImage;
++            tEntry.opvpEndDrawImage = NULL;
++            tEntry.opvpStartScanline = opdev->globals.apiEntry_0_2->StartScanline;
+             tEntry.opvpScanline
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
+                        const opvp_int_t*))
+-                       apiEntry_0_2->Scanline;
+-            tEntry.opvpEndScanline = apiEntry_0_2->EndScanline;
+-            tEntry.opvpStartRaster = apiEntry_0_2->StartRaster;
++                opdev->globals.apiEntry_0_2->Scanline;
++            tEntry.opvpEndScanline = opdev->globals.apiEntry_0_2->EndScanline;
++            tEntry.opvpStartRaster = opdev->globals.apiEntry_0_2->StartRaster;
+             tEntry.opvpTransferRasterData
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
+                        const opvp_byte_t*))
+-                       apiEntry_0_2->TransferRasterData;
+-            tEntry.opvpSkipRaster = apiEntry_0_2->SkipRaster;
+-            tEntry.opvpEndRaster = apiEntry_0_2->EndRaster;
+-            tEntry.opvpStartStream = apiEntry_0_2->StartStream;
++                opdev->globals.apiEntry_0_2->TransferRasterData;
++            tEntry.opvpSkipRaster = opdev->globals.apiEntry_0_2->SkipRaster;
++            tEntry.opvpEndRaster = opdev->globals.apiEntry_0_2->EndRaster;
++            tEntry.opvpStartStream = opdev->globals.apiEntry_0_2->StartStream;
+             tEntry.opvpTransferStreamData
+                     = (opvp_result_t (*)(opvp_dc_t,opvp_int_t,
+                        const void *))
+-                       apiEntry_0_2->TransferStreamData;
+-            tEntry.opvpEndStream = apiEntry_0_2->EndStream;
++                opdev->globals.apiEntry_0_2->TransferStreamData;
++            tEntry.opvpEndStream = opdev->globals.apiEntry_0_2->EndStream;
+
+             *apiProcs = &tEntry;
+
+-            GetLastError = GetLastError_0_2;
++            opdev->globals.GetLastError = GetLastError_0_2;
+         }
+     }
+     return dc;
+ }
+
++/* Set of methods to separate the 0.2 and 1.0 calls AND deal with the prior use of globals */
++static opvp_result_t
++gsopvpStartPage(gx_device* dev, opvp_dc_t printerContext, const opvp_char_t* pageInfo)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->StartPage) {
++        return StartPageWrapper(dev, printerContext, pageInfo);
++    } else if (opdev->globals.apiEntry->opvpStartPage) {
++        return opdev->globals.apiEntry->opvpStartPage(printerContext, pageInfo);
++    } else
++        return OPVP_FATALERROR;
++}
++
++/* Not used
++static opvp_result_t
++gsopvpQueryDeviceCapability(
++    gx_device* dev,
++    opvp_dc_t printerContext,
++    opvp_queryinfoflags_t queryflag,
++    opvp_int_t* buflen,
++    opvp_char_t* infoBuf)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->QueryDeviceCapability) {
++        return QueryDeviceCapabilityWrapper(dev, printerContext, queryflag, buflen, infoBuf);
++    } else if (opdev->globals.apiEntry->opvpQueryDeviceCapability) {
++        return opdev->globals.apiEntry->opvpQueryDeviceCapability(printerContext, queryflag, buflen, infoBuf);
++    } else
++        return OPVP_FATALERROR;
++}
++
++static opvp_result_t
++gsopvpQueryDeviceInfo(
++    gx_device* dev,
++    opvp_dc_t printerContext,
++    opvp_queryinfoflags_t queryflag,
++    opvp_int_t* buflen,
++    opvp_char_t* infoBuf)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->QueryDeviceCapability) {
++        return QueryDeviceInfoWrapper(dev, printerContext, queryflag, buflen, infoBuf);
++    } else if (opdev->globals.apiEntry->opvpQueryDeviceCapability) {
++        return opdev->globals.apiEntry->opvpQueryDeviceInfo(printerContext, queryflag, buflen, infoBuf);
++    } else
++        return OPVP_FATALERROR;
++}
++*/
++
++static opvp_result_t
++gsopvpInitGS(gx_device* dev, opvp_dc_t printerContext)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->InitGS) {
++        return InitGSWrapper(dev, printerContext);
++    } else if (opdev->globals.apiEntry->opvpInitGS) {
++        return opdev->globals.apiEntry->opvpInitGS(printerContext);
++    } else
++        return OPVP_FATALERROR;
++}
++
++static opvp_result_t
++gsopvpQueryColorSpace(gx_device* dev, opvp_dc_t printerContext, opvp_int_t* pnum,
++    opvp_cspace_t* pcspace)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->QueryColorSpace) {
++        return QueryColorSpaceWrapper(dev, printerContext, pnum, pcspace);
++    } else if (opdev->globals.apiEntry->opvpQueryColorSpace) {
++        return opdev->globals.apiEntry->opvpQueryColorSpace(printerContext, pnum, pcspace);
++    } else
++        return OPVP_FATALERROR;
++}
++
++static opvp_result_t
++gsopvpSetColorSpace(gx_device* dev, opvp_dc_t printerContext, opvp_cspace_t cspace)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->SetColorSpace) {
++        return SetColorSpaceWrapper(dev, printerContext, cspace);
++    } else if (opdev->globals.apiEntry->opvpQueryColorSpace) {
++        return opdev->globals.apiEntry->opvpSetColorSpace(printerContext, cspace);
++    } else
++        return OPVP_FATALERROR;
++}
++
++/* Not used
++static opvp_result_t
++gsopvpGetColorSpace(gx_device* dev, opvp_dc_t printerContext, opvp_cspace_t* pcspace)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->GetColorSpace) {
++        return GetColorSpaceWrapper(dev, printerContext, pcspace);
++    } else if (opdev->globals.apiEntry->opvpGetColorSpace) {
++        return opdev->globals.apiEntry->opvpGetColorSpace(printerContext, pcspace);
++    } else
++        return OPVP_FATALERROR;
++}
++*/
++
++static opvp_result_t
++gsopvpSetLineDash(gx_device* dev, opvp_dc_t printerContext, opvp_int_t num,
++    const opvp_fix_t* pdash)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->SetLineDash) {
++        return SetLineDashWrapper(dev, printerContext, num, pdash);
++    } else if (opdev->globals.apiEntry->opvpSetLineDash) {
++        return opdev->globals.apiEntry->opvpSetLineDash(printerContext, num, pdash);
++    } else
++        return OPVP_FATALERROR;
++}
++
++/* Not used
++static opvp_result_t
++gsopvpGetLineDash(gx_device* dev, opvp_dc_t printerContext, opvp_int_t* pnum,
++    opvp_fix_t* pdash)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->GetLineDash) {
++        return GetLineDashWrapper(dev, printerContext, pnum, pdash);
++    } else if (opdev->globals.apiEntry->opvpGetLineDash) {
++        return opdev->globals.apiEntry->opvpGetLineDash(printerContext, pnum, pdash);
++    } else
++        return OPVP_FATALERROR;
++}
++*/
++
++static opvp_result_t
++gsopvpSetStrokeColor(gx_device* dev, opvp_dc_t printerContext, const opvp_brush_t* brush)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->SetStrokeColor) {
++        return SetStrokeColorWrapper(dev, printerContext, brush);
++    } else if (opdev->globals.apiEntry->opvpSetStrokeColor) {
++        return opdev->globals.apiEntry->opvpSetStrokeColor(printerContext, brush);
++    } else
++        return OPVP_FATALERROR;
++}
++
++static opvp_result_t
++gsopvpSetFillColor(gx_device* dev, opvp_dc_t printerContext, const opvp_brush_t* brush)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->SetFillColor) {
++        return SetFillColorWrapper(dev, printerContext, brush);
++    } else if (opdev->globals.apiEntry->opvpSetFillColor) {
++        return opdev->globals.apiEntry->opvpSetFillColor(printerContext, brush);
++    } else
++        return OPVP_FATALERROR;
++}
++
++static opvp_result_t
++gsopvpSetBgColor(gx_device* dev, opvp_dc_t printerContext, const opvp_brush_t* brush)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->SetBgColor) {
++        return SetBgColorWrapper(dev, printerContext, brush);
++    } else if (opdev->globals.apiEntry->opvpSetBgColor) {
++        return opdev->globals.apiEntry->opvpSetBgColor(printerContext, brush);
++    } else
++        return OPVP_FATALERROR;
++}
++
++static opvp_result_t
++gsopvpDrawImage(
++    gx_device* dev,
++    opvp_dc_t printerContext,
++    opvp_int_t sourceWidth,
++    opvp_int_t sourceHeight,
++    opvp_int_t sourcePitch,
++    opvp_imageformat_t imageFormat,
++    opvp_int_t destinationWidth,
++    opvp_int_t destinationHeight,
++    const void* imagedata)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->DrawImage) {
++        return DrawImageWrapper(dev, printerContext, sourceWidth, sourceHeight,
++            sourcePitch, imageFormat, destinationWidth, destinationHeight, imagedata);
++    } else if (opdev->globals.apiEntry->opvpDrawImage) {
++        return opdev->globals.apiEntry->opvpDrawImage(printerContext, sourceWidth, sourceHeight,
++            sourcePitch, imageFormat, destinationWidth, destinationHeight, imagedata);
++    } else
++        return OPVP_FATALERROR;
++}
++
++static opvp_result_t
++gsopvpStartDrawImage(
++    gx_device* dev,
++    opvp_dc_t printerContext,
++    opvp_int_t sourceWidth,
++    opvp_int_t sourceHeight,
++    opvp_int_t sourcePitch,
++    opvp_imageformat_t imageFormat,
++    opvp_int_t destinationWidth,
++    opvp_int_t destinationHeight)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->StartDrawImage) {
++        return StartDrawImageWrapper(dev, printerContext, sourceWidth, sourceHeight,
++            sourcePitch, imageFormat, destinationWidth, destinationHeight);
++    } else if (opdev->globals.apiEntry->opvpStartDrawImage) {
++        return opdev->globals.apiEntry->opvpStartDrawImage(printerContext, sourceWidth, sourceHeight,
++            sourcePitch, imageFormat, destinationWidth, destinationHeight);
++    } else
++        return OPVP_FATALERROR;
++}
++
++static opvp_result_t
++gsopvpEndDrawImage(gx_device* dev, opvp_dc_t printerContext)
++{
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.apiEntry_0_2 != NULL &&
++        opdev->globals.apiEntry_0_2->EndDrawImage) {
++        return EndDrawImageWrapper(dev, printerContext);
++    } else if (opdev->globals.apiEntry->opvpEndDrawImage) {
++        return opdev->globals.apiEntry->opvpEndDrawImage(printerContext);
++    } else
++        return OPVP_FATALERROR;
++}
++
+ /* for image */
+ static  const
+ gx_image_enum_procs_t opvp_image_enum_procs =
+@@ -1167,27 +1454,28 @@ typedef struct bbox_image_enum_s {
+ /* initialize Graphic State */
+ /* No defaults in OPVP 1.0 */
+ static int
+-InitGS(void)
++InitGS(gx_device* dev)
+ {
+-    if (apiEntry->opvpInitGS != NULL) {
+-        if (apiEntry->opvpInitGS(printerContext) != OPVP_OK) {
+-            return -1;
+-        }
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
++
++    if (gsopvpInitGS(dev, opdev->globals.printerContext) != OPVP_OK) {
++        return -1;
+     }
+-    if (apiEntry->opvpSetColorSpace != NULL) {
+-        if (apiEntry->opvpSetColorSpace(printerContext,colorSpace)
+-           != OPVP_OK) {
++
++    if (opdev->globals.apiEntry->opvpSetColorSpace != NULL) {
++        if (opdev->globals.apiEntry->opvpSetColorSpace(opdev->globals.printerContext,
++            opdev->globals.colorSpace) != OPVP_OK){
+             return -1;
+         }
+     }
+-    if (apiEntry->opvpSetPaintMode != NULL) {
+-        if (apiEntry->opvpSetPaintMode(printerContext,
++    if (opdev->globals.apiEntry->opvpSetPaintMode != NULL) {
++        if (opdev->globals.apiEntry->opvpSetPaintMode(opdev->globals.printerContext,
+             OPVP_PAINTMODE_TRANSPARENT) != OPVP_OK) {
+             return -1;
+         }
+     }
+-    if (apiEntry->opvpSetAlphaConstant != NULL) {
+-        if (apiEntry->opvpSetAlphaConstant(printerContext,1.0)
++    if (opdev->globals.apiEntry->opvpSetAlphaConstant != NULL) {
++        if (opdev->globals.apiEntry->opvpSetAlphaConstant(opdev->globals.printerContext,1.0)
+            != OPVP_OK) {
+             return -1;
+         }
+@@ -1203,20 +1491,20 @@ opvp_startpage(gx_device *dev)
+     int ecode = 0;
+     opvp_result_t r = -1;
+     static char *page_info = NULL;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     /* page info */
+     page_info = opvp_alloc_string(&page_info, OPVP_INFO_PREFIX);
+     page_info = opvp_cat_string(&page_info, opvp_gen_page_info(dev));
+
+     /* call StartPage */
+-    if (printerContext != -1) {
+-        if (apiEntry->opvpStartPage)
+-            r = apiEntry->opvpStartPage(printerContext,
+-                       (opvp_char_t *)opvp_to_utf8(page_info));
++    if (opdev->globals.printerContext != -1) {
++        r = gsopvpStartPage(dev, opdev->globals.printerContext,
++                (opvp_char_t*)opvp_to_utf8(page_info));
+         if (r != OPVP_OK) {
+             ecode = -1;
+         } else {
+-            ecode = InitGS();
++            ecode = InitGS(dev);
+         }
+     }
+
+@@ -1224,15 +1512,16 @@ opvp_startpage(gx_device *dev)
+ }
+
+ static  int
+-opvp_endpage(void)
++opvp_endpage(gx_device* dev)
+ {
+     int ecode = 0;
+     opvp_result_t r = -1;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     /* call EndPage */
+-    if (printerContext != -1) {
+-        if (apiEntry->opvpEndPage)
+-            r = apiEntry->opvpEndPage(printerContext);
++    if (opdev->globals.printerContext != -1) {
++        if (opdev->globals.apiEntry->opvpEndPage)
++            r = opdev->globals.apiEntry->opvpEndPage(opdev->globals.printerContext);
+         if (r != OPVP_OK) {
+             ecode = -1;
+         }
+@@ -1304,32 +1593,33 @@ opvp_adjust_num_string(char *num_string)
+ }
+
+ static  char **
+-opvp_gen_dynamic_lib_name(void)
++opvp_gen_dynamic_lib_name(gx_device* dev)
+ {
+     static char *buff[5] = {NULL,NULL,NULL,NULL,NULL};
+     char tbuff[OPVP_BUFF_SIZE];
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+-    if (!vectorDriver) {
++    if (!(opdev->globals.vectorDriver)) {
+         return NULL;
+     }
+
+     memset((void*)tbuff, 0, OPVP_BUFF_SIZE);
+-    strncpy(tbuff, vectorDriver, OPVP_BUFF_SIZE - 1);
++    strncpy(tbuff, opdev->globals.vectorDriver, OPVP_BUFF_SIZE - 1);
+     opvp_alloc_string(&(buff[0]), tbuff);
+
+     memset((void*)tbuff, 0, OPVP_BUFF_SIZE);
+-    strncpy(tbuff, vectorDriver, OPVP_BUFF_SIZE - 4);
++    strncpy(tbuff, opdev->globals.vectorDriver, OPVP_BUFF_SIZE - 4);
+     strcat(tbuff, ".so");
+     opvp_alloc_string(&(buff[1]), tbuff);
+
+     memset((void*)tbuff, 0, OPVP_BUFF_SIZE);
+-    strncpy(tbuff, vectorDriver, OPVP_BUFF_SIZE - 5);
++    strncpy(tbuff, opdev->globals.vectorDriver, OPVP_BUFF_SIZE - 5);
+     strcat(tbuff, ".dll");
+     opvp_alloc_string(&(buff[2]), tbuff);
+
+     memset((void*)tbuff, 0, OPVP_BUFF_SIZE);
+     strcpy(tbuff, "lib");
+-    strncat(tbuff, vectorDriver, OPVP_BUFF_SIZE - 7);
++    strncat(tbuff, opdev->globals.vectorDriver, OPVP_BUFF_SIZE - 7);
+     strcat(tbuff, ".so");
+     opvp_alloc_string(&(buff[3]), tbuff);
+
+@@ -1387,7 +1677,7 @@ opvp_to_utf8(char *string)
+ }
+
+ static float
+-opvp_fabsf(float f)
++opvp_fabsf(gx_device* dev, float f)
+ {
+     return (float)fabs((double)f);
+ }
+@@ -1429,7 +1719,7 @@ opvp_get_papertable_index(gx_device *pdev)
+                 paper = i;
+                 match = true;
+                 break;
+-            } else if ((f = opvp_fabsf(height - paper_h)) < TOLERANCE) {
++            } else if ((f = opvp_fabsf(pdev, height - paper_h)) < TOLERANCE) {
+                 if (f < h_delta) {
+                     h_delta = f;
+                     candidate = i;
+@@ -1442,14 +1732,14 @@ opvp_get_papertable_index(gx_device *pdev)
+         } else if (prev != paper_w) {
+             prev = paper_w;
+             if (paper_w < width) {
+-                if ((f = opvp_fabsf(width - paper_w)) < TOLERANCE) {
++                if ((f = opvp_fabsf(pdev, width - paper_w)) < TOLERANCE) {
+                     if (f < sw_delta) {
+                         sw_delta = f;
+                         smaller  = i;
+                     }
+                 }
+             } else {
+-                if ((f = opvp_fabsf(width - paper_w)) < TOLERANCE) {
++                if ((f = opvp_fabsf(pdev, width - paper_w)) < TOLERANCE) {
+                     if (f < lw_delta) {
+                         lw_delta = f;
+                         larger   = i;
+@@ -1468,7 +1758,7 @@ opvp_get_papertable_index(gx_device *pdev)
+                     sh_delta = 0;
+                     s_candi  = i;
+                     break;
+-                } else if ((f = opvp_fabsf(height - paper_h)) < TOLERANCE) {
++                } else if ((f = opvp_fabsf(pdev, height - paper_h)) < TOLERANCE) {
+                     if (f < sh_delta) {
+                         sh_delta = f;
+                         s_candi  = i;
+@@ -1484,7 +1774,7 @@ opvp_get_papertable_index(gx_device *pdev)
+                     lh_delta = 0;
+                     l_candi  = i;
+                     break;
+-                } else if ((f = opvp_fabsf(height - paper_h)) < TOLERANCE) {
++                } else if ((f = opvp_fabsf(pdev, height - paper_h)) < TOLERANCE) {
+                     if (f < lh_delta) {
+                         lh_delta = f;
+                         l_candi  = i;
+@@ -1560,8 +1850,8 @@ opvp_get_mediasize(gx_device *pdev)
+            (strcmp(region, "oe"  ) == 0)) {
+             unit    = "in";
+         } else {
+-            width  *= MMPI;
+-            height *= MMPI;
++            width  *= (float) MMPI;
++            height *= (float) MMPI;
+             unit    = "mm";
+         }
+     } else {
+@@ -1591,9 +1881,10 @@ opvp_gen_page_info(gx_device *dev)
+     int num_copies = 1;
+     bool landscape;
+     char tbuff[OPVP_BUFF_SIZE];
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     /* copies */
+-    if (!inkjet) {
++    if (!(opdev->globals.inkjet)) {
+         if (dev->IgnoreNumCopies) {
+             num_copies = 1;
+         } else if (dev->NumCopies_set > 0) {
+@@ -1642,14 +1933,13 @@ opvp_set_brush_color(gx_device_opvp *pdev, gx_color_index color,
+         ecode = -1;
+     } else {
+ #if ENABLE_SIMPLE_MODE
+-        brush->colorSpace = colorSpace;
++        brush->colorSpace = pdev->globals.colorSpace;
+ #else
+         opvp_result_t           r = -1;
+         /* call GetColorSpace */
+-        if (apiEntry->opvpGetColorSpace) {
+-            r = apiEntry->opvpGetColorSpace(printerContext,
+-                                   &(brush->colorSpace));
+-        }
++
++        r = gsopvpGetColorSpace((gx_device*)pdev, printerContext,
++                                &(brush->colorSpace));
+         if (r != OPVP_OK) {
+             brush->colorSpace = OPVP_CSPACE_DEVICEKRGB;
+         }
+@@ -1667,7 +1957,7 @@ opvp_set_brush_color(gx_device_opvp *pdev, gx_color_index color,
+
+ static  int
+ opvp_draw_image(
+-    gx_device_opvp *pdev,
++    gx_device_opvp *opdev,
+     int depth,
+     int sw,
+     int sh,
+@@ -1682,35 +1972,36 @@ opvp_draw_image(
+     int                 count;
+
+     /* check page-in */
+-    if (opvp_check_in_page(pdev)) return -1;
++    if (opvp_check_in_page(opdev))
++        return -1;
+
+     /* image size */
+     count = raster * sh;
+
+     /* call DrawImage */
+-    if (apiEntry->opvpDrawImage) {
+-        r = apiEntry->opvpDrawImage(printerContext,
+-               sw,sh,
+-               raster,
+-               mask ? OPVP_IFORMAT_MASK : OPVP_IFORMAT_RAW,
+-               dw,dh,
+-               /* discard 'const' qualifier */
+-               (void *)data);
+-    }
++    r = gsopvpDrawImage((gx_device*) opdev,
++            opdev->globals.printerContext,
++            sw,sh,
++            raster,
++            mask ? OPVP_IFORMAT_MASK : OPVP_IFORMAT_RAW,
++            dw,dh,
++            /* discard 'const' qualifier */
++            (void *)data);
++
+     if (r != OPVP_OK) {
+         /* call StartDrawImage */
+-        if (apiEntry->opvpStartDrawImage) {
+-            r = apiEntry->opvpStartDrawImage(printerContext,
+-                    sw,sh,
+-                    raster,
+-                    mask ? OPVP_IFORMAT_MASK : OPVP_IFORMAT_RAW,
+-                    dw,dh);
+-        }
++        r = gsopvpStartDrawImage((gx_device*)opdev,
++                opdev->globals.printerContext,
++                sw,sh,
++                raster,
++                mask ? OPVP_IFORMAT_MASK : OPVP_IFORMAT_RAW,
++                dw,dh);
++
+         if (r == OPVP_OK) {
+             /* call TansferDrawImage */
+-            if (apiEntry->opvpTransferDrawImage) {
+-                r = apiEntry->opvpTransferDrawImage(
+-                       printerContext,
++            if (opdev->globals.apiEntry->opvpTransferDrawImage) {
++                r = opdev->globals.apiEntry->opvpTransferDrawImage(
++                       opdev->globals.printerContext,
+                        count,
+                         /* discard 'const' qualifier */
+                        (void *)data);
+@@ -1718,9 +2009,8 @@ opvp_draw_image(
+             if (r != OPVP_OK) ecode = -1;
+
+             /* call EndDrawImage */
+-            if (apiEntry->opvpEndDrawImage) {
+-                apiEntry->opvpEndDrawImage(printerContext);
+-            }
++            gsopvpEndDrawImage((gx_device*)opdev, opdev->globals.printerContext);
++
+         } else {
+             ecode = 0;  /* continue... */
+         }
+@@ -1735,48 +2025,49 @@ opvp_draw_image(
+  * load vector-driver
+  */
+ static  int
+-opvp_load_vector_driver(void)
++opvp_load_vector_driver(gx_device* dev)
+ {
+     char **list = NULL;
+     int i;
+     void *h;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+-    if (handle) {
+-        opvp_unload_vector_driver();
++    if (opdev->globals.handle) {
++        opvp_unload_vector_driver(dev);
+     }
+
+-    if (vectorDriver) {
+-        list = opvp_gen_dynamic_lib_name();
++    if (opdev->globals.vectorDriver) {
++        list = opvp_gen_dynamic_lib_name(dev);
+     }
+
+     if (list) {
+         i = 0;
+         while (list[i]) {
+             if ((h = dlopen(list[i],RTLD_NOW))) {
+-                OpenPrinter = dlsym(h,"opvpOpenPrinter");
+-                ErrorNo = dlsym(h,"opvpErrorNo");
+-                if (OpenPrinter && ErrorNo) {
+-                    handle = h;
++                opdev->globals.OpenPrinter = dlsym(h,"opvpOpenPrinter");
++                opdev->globals.ErrorNo = dlsym(h,"opvpErrorNo");
++                if (opdev->globals.OpenPrinter && opdev->globals.ErrorNo) {
++                    opdev->globals.handle = h;
+                     break;
+                 }
+-                OpenPrinter = NULL;
+-                ErrorNo = NULL;
++                opdev->globals.OpenPrinter = NULL;
++                opdev->globals.ErrorNo = NULL;
+                 /* try version 0.2 driver */
+-                OpenPrinter_0_2 = dlsym(h,"OpenPrinter");
+-                ErrorNo = dlsym(h,"errorno");
+-                if (OpenPrinter_0_2 && ErrorNo) {
+-                    handle = h;
++                opdev->globals.OpenPrinter_0_2 = dlsym(h,"OpenPrinter");
++                opdev->globals.ErrorNo = dlsym(h,"errorno");
++                if (opdev->globals.OpenPrinter_0_2 && opdev->globals.ErrorNo) {
++                    opdev->globals.handle = h;
+                     break;
+                 }
+-                OpenPrinter_0_2 = NULL;
+-                ErrorNo = NULL;
++                opdev->globals.OpenPrinter_0_2 = NULL;
++                opdev->globals.ErrorNo = NULL;
+                 dlclose(h);
+             }
+             i++;
+         }
+     }
+
+-    if (handle) {
++    if (opdev->globals.handle) {
+         return 0;
+     } else {
+         return -1;
+@@ -1787,13 +2078,15 @@ opvp_load_vector_driver(void)
+  * unload vector-driver
+  */
+ static  int
+-opvp_unload_vector_driver(void)
++opvp_unload_vector_driver(gx_device* dev)
+ {
+-    if (handle) {
+-        dlclose(handle);
+-        handle = NULL;
+-        OpenPrinter = NULL;
+-        ErrorNo = NULL;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
++
++    if (opdev->globals.handle) {
++        dlclose(opdev->globals.handle);
++        opdev->globals.handle = NULL;
++        opdev->globals.OpenPrinter = NULL;
++        opdev->globals.ErrorNo = NULL;
+     }
+     return 0;
+ }
+@@ -1810,6 +2103,7 @@ prepare_open(gx_device *dev)
+     int dumFD = -1;
+     opvp_dc_t dumContext = -1;
+     opvp_cspace_t cspace = OPVP_CSPACE_STANDARDRGB;
++    gx_device_opvp *opdev = (gx_device_opvp*) dev;
+
+     /* open dummy device */
+     code = open("/dev/null", O_RDWR);
+@@ -1818,19 +2112,19 @@ prepare_open(gx_device *dev)
+
+     /* load vector driver */
+     if (!ecode) {
+-        if ((code = opvp_load_vector_driver())) {
++        if ((code = opvp_load_vector_driver(dev))) {
+             ecode = code;
+         }
+     }
+
+     /* prepare array of function pointer for PDAPI */
+     if (!ecode) {
+-        if (!apiEntry) {
+-            if (!(apiEntry = calloc(sizeof(opvp_api_procs_t), 1))) {
++        if (!(opdev->globals.apiEntry)) {
++            if (!(opdev->globals.apiEntry = calloc(sizeof(opvp_api_procs_t), 1))) {
+                 ecode = -1;
+             }
+         } else {
+-            memset(apiEntry, 0, sizeof(opvp_api_procs_t));
++            memset(opdev->globals.apiEntry, 0, sizeof(opvp_api_procs_t));
+         }
+     }
+
+@@ -1842,8 +2136,8 @@ prepare_open(gx_device *dev)
+         /* require version 1.0 */
+         apiVersion[0] = 1;
+         apiVersion[1] = 0;
+-        dc = OpenPrinterWrapper(dumFD, (opvp_char_t *)printerModel,
+-          apiVersion,&api_entry);
++        dc = OpenPrinterWrapper(dev, dumFD, (opvp_char_t *)(opdev->globals.printerModel),
++          apiVersion, &api_entry);
+         if (dc == -1) {
+             ecode = -1;
+         } else {
+@@ -1853,33 +2147,33 @@ prepare_open(gx_device *dev)
+
+     /* set apiEntry */
+     if (!ecode) {
+-        nApiEntry = sizeof(opvp_api_procs_t)/sizeof(void *);
+-        memcpy(apiEntry, api_entry, nApiEntry*sizeof(void *));
++        opdev->globals.nApiEntry = sizeof(opvp_api_procs_t)/sizeof(void *);
++        memcpy(opdev->globals.apiEntry, api_entry, opdev->globals.nApiEntry*sizeof(void *));
+     } else {
+-        if (apiEntry) free(apiEntry);
+-        apiEntry = NULL;
++        if (opdev->globals.apiEntry) free(opdev->globals.apiEntry);
++        opdev->globals.apiEntry = NULL;
+     }
+
+     /* check vector fucntion */
+-    if (apiEntry) {
+-        if (!inkjet) {
+-            if (!(apiEntry->opvpNewPath) ||
+-                !(apiEntry->opvpEndPath) ||
+-                !(apiEntry->opvpStrokePath) ||
+-                !(apiEntry->opvpSetCurrentPoint) ||
+-                !(apiEntry->opvpLinePath) ||
+-                !(apiEntry->opvpBezierPath)) {
++    if (opdev->globals.apiEntry) {
++        if (!(opdev->globals.inkjet)) {
++            if (!(opdev->globals.apiEntry->opvpNewPath) ||
++                !(opdev->globals.apiEntry->opvpEndPath) ||
++                !(opdev->globals.apiEntry->opvpStrokePath) ||
++                !(opdev->globals.apiEntry->opvpSetCurrentPoint) ||
++                !(opdev->globals.apiEntry->opvpLinePath) ||
++                !(opdev->globals.apiEntry->opvpBezierPath)) {
+                 /* NOT avail vector drawing mode */
+-                vector = false;
++                opdev->globals.vector = false;
+             }
+         }
+         /* call GetColorSpace */
+-        if (apiEntry->opvpGetColorSpace) {
+-            (void)apiEntry->opvpGetColorSpace(dumContext, &cspace);
++        if (opdev->globals.apiEntry->opvpGetColorSpace) {
++            (void)(opdev->globals.apiEntry->opvpGetColorSpace)(dumContext, &cspace);
+         }
+         if (cspace == OPVP_CSPACE_BW) {
+             /* mono-color */
+-            colorSpace = cspace;
++            opdev->globals.colorSpace = cspace;
+             dev->color_info.num_components = 1;
+             dev->color_info.depth = 1;
+             dev->color_info.max_gray = 0;
+@@ -1888,7 +2182,7 @@ prepare_open(gx_device *dev)
+             dev->color_info.dither_colors = 1;
+         } else if (cspace == OPVP_CSPACE_DEVICEGRAY) {
+             /* gray-scale */
+-            colorSpace = cspace;
++            opdev->globals.colorSpace = cspace;
+             dev->color_info.num_components = 1;
+             dev->color_info.depth = 8;
+             dev->color_info.max_gray = 255;
+@@ -1897,7 +2191,7 @@ prepare_open(gx_device *dev)
+             dev->color_info.dither_colors = 256;
+         } else {
+             /* rgb color */
+-            colorSpace = OPVP_CSPACE_STANDARDRGB;
++            opdev->globals.colorSpace = OPVP_CSPACE_STANDARDRGB;
+             dev->color_info.num_components = 3;
+             dev->color_info.depth = 24;
+             dev->color_info.max_gray = 255;
+@@ -1913,8 +2207,8 @@ prepare_open(gx_device *dev)
+     /* call Closerinter as dummy */
+     if (dumContext != -1) {
+         /* call ClosePrinter */
+-        if (apiEntry->opvpClosePrinter) {
+-            apiEntry->opvpClosePrinter(dumContext);
++        if (opdev->globals.apiEntry->opvpClosePrinter) {
++            opdev->globals.apiEntry->opvpClosePrinter(dumContext);
+         }
+         dumContext = -1;
+     }
+@@ -1926,7 +2220,7 @@ prepare_open(gx_device *dev)
+     }
+
+     /* un-load vector driver */
+-    opvp_unload_vector_driver();
++    opvp_unload_vector_driver(dev);
+
+     return ecode;
+ }
+@@ -1961,51 +2255,52 @@ opvp_open(gx_device *dev)
+     }
+
+     /* set margins */
+-    if (zoomAuto) {
+-        margin_width = (margins[0] + margins[2])
++    if (pdev->globals.zoomAuto) {
++        margin_width = (pdev->globals.margins[0] + pdev->globals.margins[2])
+                      * dev->HWResolution[0];
+-        margin_height = (margins[1] + margins[3])
++        margin_height = (pdev->globals.margins[1] + pdev->globals.margins[3])
+                       * dev->HWResolution[1];
+-        zoom[0] = (dev->width - margin_width) / dev->width;
+-        zoom[1] = (dev->height - margin_height) / dev->height;
+-        if (zoom[0] < zoom[1]) {
+-            zoom[1] = zoom[0];
++        pdev->globals.zoom[0] = (dev->width - margin_width) / dev->width;
++        pdev->globals.zoom[1] = (dev->height - margin_height) / dev->height;
++        if (pdev->globals.zoom[0] < pdev->globals.zoom[1]) {
++            pdev->globals.zoom[1] = pdev->globals.zoom[0];
+         } else {
+-            zoom[0] = zoom[1];
++            pdev->globals.zoom[0] = pdev->globals.zoom[1];
+         }
+     }
+-    if (inkjet) {
+-        if ((margins[0] != 0) ||
+-            (margins[1] != 0) || (margins[3] != 0)) {
+-            shift[0] = margins[0] * dev->HWResolution[0];
+-            shift[1] = (margins[1] + margins[3])
++    if (pdev->globals.inkjet) {
++        if ((pdev->globals.margins[0] != 0) ||
++            (pdev->globals.margins[1] != 0) || (pdev->globals.margins[3] != 0)) {
++            pdev->globals.shift[0] = pdev->globals.margins[0] * dev->HWResolution[0];
++            pdev->globals.shift[1] = (pdev->globals.margins[1] + pdev->globals.margins[3])
+                      * dev->HWResolution[1];
+-            zooming = true;
++            pdev->globals.zooming = true;
+         }
+-        dev->width -= margins[2] * dev->HWResolution[0];
+-        dev->height -= margins[1] * dev->HWResolution[1];
++        dev->width -= (int) (pdev->globals.margins[2] * dev->HWResolution[0]);
++        dev->height -= (int) (pdev->globals.margins[1] * dev->HWResolution[1]);
+     } else {
+-            if ((margins[0] != 0) || (margins[1] != 0)) {
+-                shift[0] = margins[0] * dev->HWResolution[0];
+-                shift[1] = margins[3] * dev->HWResolution[1];
+-                zooming = true;
++            if ((pdev->globals.margins[0] != 0) || (pdev->globals.margins[1] != 0)) {
++                pdev->globals.shift[0] = pdev->globals.margins[0] * dev->HWResolution[0];
++                pdev->globals.shift[1] = pdev->globals.margins[3] * dev->HWResolution[1];
++                pdev->globals.zooming = true;
+             }
+             adj_margins[0] = 0;
+             adj_margins[3] = 0;
+-            adj_margins[1] = dev->height * zoom[1] / dev->HWResolution[1]
++            adj_margins[1] = dev->height * pdev->globals.zoom[1] / dev->HWResolution[1]
+                             - (dev->MediaSize[1] / PS_DPI
+-                             - (margins[1] + margins[3]));
++                             - (pdev->globals.margins[1] + pdev->globals.margins[3]));
+             if (adj_margins[1] < 0) adj_margins[0] = 0;
+-            adj_margins[2] = dev->width * zoom[0] / dev->HWResolution[0]
++            adj_margins[2] = dev->width * pdev->globals.zoom[0] / dev->HWResolution[0]
+                             - (dev->MediaSize[0] / PS_DPI
+-                             - (margins[0] + margins[2]));
++                             - (pdev->globals.margins[0] + pdev->globals.margins[2]));
+             if (adj_margins[2] < 0) adj_margins[2] = 0;
+             gx_device_set_margins(dev, adj_margins, true);
+     }
+-    if ((zoom[0] != 1) || (zoom[1] != 1)) zooming = true;
++    if ((pdev->globals.zoom[0] != 1) || (pdev->globals.zoom[1] != 1))
++        pdev->globals.zooming = true;
+
+     /* open file for output device */
+-    if (!inkjet) {
++    if (!(pdev->globals.inkjet)) {
+         pdev->v_memory = gs_memory_stable(pdev->memory);
+         /* open output stream */
+         code = gdev_vector_open_file_options((gx_device_vector*)dev,
+@@ -2027,7 +2322,7 @@ opvp_open(gx_device *dev)
+                 pdev->bbox_device->memory = gs_memory_stable(dev->memory);
+             }
+         }
+-        outputFD = fileno(gp_get_file(pdev->file));
++        pdev->globals.outputFD = fileno(gp_get_file(pdev->file));
+     } else {
+         /* open printer device */
+         code = gdev_prn_open(dev);
+@@ -2044,13 +2339,13 @@ opvp_open(gx_device *dev)
+         if (code < 0) {
+             return code;
+         }
+-        outputFD = fileno(gp_get_file(rdev->file));
++        pdev->globals.outputFD = fileno(gp_get_file(rdev->file));
+     }
+-    if (outputFD < 0)
+-        return outputFD;
++    if (pdev->globals.outputFD < 0)
++        return pdev->globals.outputFD;
+
+     /* RE-load vector driver */
+-    if ((code = opvp_load_vector_driver())) {
++    if ((code = opvp_load_vector_driver(dev))) {
+         return code;
+     }
+
+@@ -2058,44 +2353,48 @@ opvp_open(gx_device *dev)
+     /* require version 1.0 */
+     apiVersion[0] = 1;
+     apiVersion[1] = 0;
+-    dc = OpenPrinterWrapper(outputFD,(opvp_char_t *)printerModel,
++    dc = OpenPrinterWrapper(dev, pdev->globals.outputFD, (opvp_char_t *)pdev->globals.printerModel,
+       apiVersion,&api_entry);
+-    if (!apiEntry) {
+-        if (!(apiEntry = calloc(sizeof(opvp_api_procs_t), 1))) {
++    if (!(pdev->globals.apiEntry)) {
++        if (!(pdev->globals.apiEntry = calloc(sizeof(opvp_api_procs_t), 1))) {
+             ecode = -1;
+         }
+     } else {
+-        memset(apiEntry, 0, sizeof(opvp_api_procs_t));
++        memset(pdev->globals.apiEntry, 0, sizeof(opvp_api_procs_t));
+     }
+     if (dc == -1) {
+         ecode =  -1;
+-        if (apiEntry) free(apiEntry);
+-        apiEntry = NULL;
+-        opvp_unload_vector_driver();
+-        if (inkjet) gdev_prn_close(dev);
++        if (pdev->globals.apiEntry)
++            free(pdev->globals.apiEntry);
++        pdev->globals.apiEntry = NULL;
++        opvp_unload_vector_driver(dev);
++        if (pdev->globals.inkjet)
++            gdev_prn_close(dev);
+         else gdev_vector_close_file((gx_device_vector *)pdev);
+         return ecode;
+     }
+-    printerContext = dc;
+-    nApiEntry = sizeof(opvp_api_procs_t)/sizeof(void *);
+-    memcpy(apiEntry, api_entry, nApiEntry*sizeof(void *));
++    pdev->globals.printerContext = dc;
++    pdev->globals.nApiEntry = sizeof(opvp_api_procs_t)/sizeof(void *);
++    memcpy(pdev->globals.apiEntry, api_entry, pdev->globals.nApiEntry*sizeof(void *));
+
+     /* initialize */
+-    if ((!ecode) && (!inkjet)) {
++    if ((!ecode) && (!(pdev->globals.inkjet))) {
+         pdev->vec_procs = &opvp_vector_procs;
+-        if (vector) gdev_vector_init((gx_device_vector *)pdev);
++        if (pdev->globals.vector)
++            gdev_vector_init((gx_device_vector *)pdev);
+     }
+
+-    if (apiEntry->opvpQueryColorSpace) {
++    if (pdev->globals.apiEntry->opvpQueryColorSpace ||
++        pdev->globals.apiEntry_0_2->QueryColorSpace) {
+         int n = sizeof(cspace_available);
+         int nn = n;
+         opvp_cspace_t *p = malloc(n*sizeof(opvp_cspace_t));
+
+-        if ((r = apiEntry->opvpQueryColorSpace(printerContext,&nn,p))
++        if ((r = gsopvpQueryColorSpace(dev, pdev->globals.printerContext,&nn,p))
+              == OPVP_PARAMERROR && nn > n) {
+             /* realloc buffer and retry */
+             p = realloc(p,nn*sizeof(opvp_cspace_t));
+-            r = apiEntry->opvpQueryColorSpace(printerContext,&nn,p);
++            r = gsopvpQueryColorSpace(dev, pdev->globals.printerContext,&nn,p);
+         }
+         if (r == OPVP_OK) {
+             int i;
+@@ -2111,12 +2410,12 @@ opvp_open(gx_device *dev)
+     /* start job */
+     if (!ecode) {
+         /* job info */
+-        if (jobInfo) {
+-            if (strlen(jobInfo) > 0) {
+-                job_info = opvp_alloc_string(&job_info,jobInfo);
++        if (pdev->globals.jobInfo) {
++            if (strlen(pdev->globals.jobInfo) > 0) {
++                job_info = opvp_alloc_string(&job_info, pdev->globals.jobInfo);
+             }
+         }
+-        tmp_info = opvp_alloc_string(&tmp_info,opvp_gen_job_info(dev));
++        tmp_info = opvp_alloc_string(&tmp_info, opvp_gen_job_info(dev));
+         if (tmp_info) {
+             if (strlen(tmp_info) > 0) {
+                 if (job_info) {
+@@ -2130,8 +2429,8 @@ opvp_open(gx_device *dev)
+         }
+
+         /* call StartJob */
+-        if (apiEntry->opvpStartJob) {
+-            r = apiEntry->opvpStartJob(printerContext,
++        if (pdev->globals.apiEntry->opvpStartJob) {
++            r = pdev->globals.apiEntry->opvpStartJob(pdev->globals.printerContext,
+               (opvp_char_t *)opvp_to_utf8(job_info));
+         }
+         if (r != OPVP_OK) {
+@@ -2142,9 +2441,9 @@ opvp_open(gx_device *dev)
+     /* start doc */
+     if (!ecode) {
+         /* doc info */
+-        if (docInfo) {
+-            if (strlen(docInfo) > 0) {
+-                doc_info = opvp_alloc_string(&doc_info,docInfo);
++        if (pdev->globals.docInfo) {
++            if (strlen(pdev->globals.docInfo) > 0) {
++                doc_info = opvp_alloc_string(&doc_info, pdev->globals.docInfo);
+             }
+         }
+         tmp_info = opvp_alloc_string(&tmp_info, opvp_gen_doc_info(dev));
+@@ -2161,8 +2460,8 @@ opvp_open(gx_device *dev)
+         }
+
+         /* call StartDoc */
+-        if (apiEntry->opvpStartDoc) {
+-            r = apiEntry->opvpStartDoc(printerContext,
++        if (pdev->globals.apiEntry->opvpStartDoc) {
++            r = pdev->globals.apiEntry->opvpStartDoc(pdev->globals.printerContext,
+               (opvp_char_t *)opvp_to_utf8(doc_info));
+         }
+         if (r != OPVP_OK) {
+@@ -2183,9 +2482,11 @@ opvp_open(gx_device *dev)
+ static  int
+ oprp_open(gx_device *dev)
+ {
++    gx_device_opvp *opdev = (gx_device_opvp*) dev;
++
+     /* set inkjet mode */
+-    vector = false;
+-    inkjet = true;
++    opdev->globals.vector = false;
++    opdev->globals.inkjet = true;
+
+     /* matrix */
+     dev->procs.get_initial_matrix = opvp_get_initial_matrix;
+@@ -2198,24 +2499,24 @@ oprp_open(gx_device *dev)
+ static  void
+ opvp_get_initial_matrix(gx_device *dev, gs_matrix *pmat)
+ {
+-    gx_device_opvp *pdev = (gx_device_opvp *)dev;
++    gx_device_opvp * opdev = (gx_device_opvp *)dev;
+     opvp_ctm_t omat;
+
+     gx_default_get_initial_matrix(dev,pmat);
+-    if (zooming) {
++    if (opdev->globals.zooming) {
+         /* gs matrix */
+-        pmat->xx *= zoom[0];
+-        pmat->xy *= zoom[1];
+-        pmat->yx *= zoom[0];
+-        pmat->yy *= zoom[1];
+-        pmat->tx = pmat->tx * zoom[0] + shift[0];
+-        pmat->ty = pmat->ty * zoom[1] + shift[1];
++        pmat->xx *= opdev->globals.zoom[0];
++        pmat->xy *= opdev->globals.zoom[1];
++        pmat->yx *= opdev->globals.zoom[0];
++        pmat->yy *= opdev->globals.zoom[1];
++        pmat->tx = pmat->tx * opdev->globals.zoom[0] + opdev->globals.shift[0];
++        pmat->ty = pmat->ty * opdev->globals.zoom[1] + opdev->globals.shift[1];
+     }
+
+-    if (pdev->is_open) {
++    if (opdev->is_open) {
+         /* call ResetCTM */
+-        if (apiEntry->opvpResetCTM) {
+-            apiEntry->opvpResetCTM(printerContext);
++        if (opdev->globals.apiEntry->opvpResetCTM) {
++            opdev->globals.apiEntry->opvpResetCTM(opdev->globals.printerContext);
+         } else {
+             /* call SetCTM */
+             omat.a = 1;
+@@ -2224,8 +2525,8 @@ opvp_get_initial_matrix(gx_device *dev, gs_matrix *pmat)
+             omat.d = 1;
+             omat.e = 0;
+             omat.f = 0;
+-            if (apiEntry->opvpSetCTM) {
+-                apiEntry->opvpSetCTM(printerContext, &omat);
++            if (opdev->globals.apiEntry->opvpSetCTM) {
++                opdev->globals.apiEntry->opvpSetCTM(opdev->globals.printerContext, &omat);
+             }
+         }
+     }
+@@ -2239,30 +2540,32 @@ opvp_get_initial_matrix(gx_device *dev, gs_matrix *pmat)
+ static  int
+ opvp_output_page(gx_device *dev, int num_copies, int flush)
+ {
+-    gx_device_opvp *pdev = (gx_device_opvp *)dev;
++    gx_device_opvp *opdev = (gx_device_opvp *)dev;
+     int ecode = 0;
+     int code = -1;
+
+-    if (inkjet) return gdev_prn_output_page(dev, num_copies, flush);
++    if (opdev->globals.inkjet)
++        return gdev_prn_output_page(dev, num_copies, flush);
+
+ #ifdef OPVP_IGNORE_BLANK_PAGE
+     if (pdev->in_page) {
+ #else
+     /* check page-in */
+-    if (opvp_check_in_page(pdev)) return -1;
++    if (opvp_check_in_page(opdev))
++        return -1;
+ #endif
+         /* end page */
+-        code = opvp_endpage();
++        code = opvp_endpage(dev);
+         if (code) ecode = code;
+
+-        pdev->in_page = false;
+-        beginPage = false;
++        opdev->in_page = false;
++        opdev->globals.beginPage = false;
+ #ifdef OPVP_IGNORE_BLANK_PAGE
+     }
+ #endif
+
+-    if (vector) {
+-        gdev_vector_reset((gx_device_vector *)pdev);
++    if (opdev->globals.vector) {
++        gdev_vector_reset((gx_device_vector *)dev);
+     }
+
+     code = gx_finish_output_page(dev, num_copies, flush);
+@@ -2289,6 +2592,7 @@ oprp_print_page(gx_device_printer *pdev, gp_file *prn_stream)
+     int rasterWidth;
+     bool start_page = false;
+     bool start_raster = false;
++    gx_device_opvp *opdev = (gx_device_opvp*)pdev;
+ #if ENABLE_SKIP_RASTER
+     int i;
+     byte check;
+@@ -2317,8 +2621,8 @@ oprp_print_page(gx_device_printer *pdev, gp_file *prn_stream)
+
+     /* call StartRaster */
+     if (!ecode) {
+-        if (apiEntry->opvpStartRaster) {
+-            r = apiEntry->opvpStartRaster(printerContext,rasterWidth);
++        if (opdev->globals.apiEntry->opvpStartRaster) {
++            r = opdev->globals.apiEntry->opvpStartRaster(opdev->globals.printerContext,rasterWidth);
+         }
+         if (r != OPVP_OK) {
+             ecode = r;
+@@ -2339,7 +2643,7 @@ oprp_print_page(gx_device_printer *pdev, gp_file *prn_stream)
+         }
+ #if ENABLE_SKIP_RASTER
+         /* check support SkipRaster */
+-        if (apiEntry->opvpSkipRaster) {
++        if (opdev->globals.apiEntry->opvpSkipRaster) {
+             /* check all white */
+             if (pdev->color_info.depth > 8) {
+                 for (check = 0xff, i = 0; i < raster_size; i++)
+@@ -2349,7 +2653,7 @@ oprp_print_page(gx_device_printer *pdev, gp_file *prn_stream)
+                 }
+                 /* if all white call SkipRaster */
+                 if (check == 0xff) {
+-                    r = apiEntry->opvpSkipRaster(printerContext, 1);
++                    r = opdev->globals.apiEntry->opvpSkipRaster(opdev->globals.printerContext, 1);
+                     if (r == OPVP_OK) continue;
+                 }
+             } else {
+@@ -2359,27 +2663,29 @@ oprp_print_page(gx_device_printer *pdev, gp_file *prn_stream)
+                 }
+                 /* if all zero call SkipRaster */
+                 if (check) {
+-                    r = apiEntry->opvpSkipRaster(printerContext, 1);
+-                    if (r == OPVP_OK) continue;
++                    r = opdev->globals.apiEntry->opvpSkipRaster(opdev->globals.printerContext, 1);
++                    if (r == OPVP_OK)
++                        continue;
+                 }
+             }
+         }
+ #endif
+         /* call TransferRasterData */
+         if (!ecode) {
+-            if (apiEntry->opvpTransferRasterData) {
+-                r = apiEntry->opvpTransferRasterData(printerContext,
++            if (opdev->globals.apiEntry->opvpTransferRasterData) {
++                r = opdev->globals.apiEntry->opvpTransferRasterData(opdev->globals.printerContext,
+                                                 raster_size,
+                                                 data);
+             }
+-            if (r != OPVP_OK) ecode = r;
++            if (r != OPVP_OK)
++                ecode = r;
+         }
+     }
+
+     /* call EndRaster */
+     if (start_raster) {
+-        if (apiEntry->opvpEndRaster) {
+-            r = apiEntry->opvpEndRaster(printerContext);
++        if (opdev->globals.apiEntry->opvpEndRaster) {
++            r = opdev->globals.apiEntry->opvpEndRaster(opdev->globals.printerContext);
+         }
+         if (r != OPVP_OK) ecode = r;
+         start_raster = false;
+@@ -2387,7 +2693,7 @@ oprp_print_page(gx_device_printer *pdev, gp_file *prn_stream)
+
+     /* end page */
+     if (start_page) {
+-        code = opvp_endpage();
++        code = opvp_endpage((gx_device*) pdev);
+         if (code) ecode = code;
+         start_page = false;
+     }
+@@ -2411,37 +2717,38 @@ opvp_close(gx_device *dev)
+     int ecode = 0;
+
+     /* finalize */
+-    if (printerContext != -1) {
++    if (pdev->globals.printerContext != -1) {
+         /* call EndDoc */
+-        if (apiEntry->opvpEndDoc) {
+-            apiEntry->opvpEndDoc(printerContext);
++        if (pdev->globals.apiEntry->opvpEndDoc) {
++            pdev->globals.apiEntry->opvpEndDoc(pdev->globals.printerContext);
+         }
+
+         /* call EndJob */
+-        if (apiEntry->opvpEndJob) {
+-            apiEntry->opvpEndJob(printerContext);
++        if (pdev->globals.apiEntry->opvpEndJob) {
++            pdev->globals.apiEntry->opvpEndJob(pdev->globals.printerContext);
+         }
+
+         /* call ClosePrinter */
+-        if (apiEntry->opvpClosePrinter) {
+-            apiEntry->opvpClosePrinter(printerContext);
++        if (pdev->globals.apiEntry->opvpClosePrinter) {
++            pdev->globals.apiEntry->opvpClosePrinter(pdev->globals.printerContext);
+         }
+-        printerContext = -1;
++        pdev->globals.printerContext = -1;
+     }
+
+     /* unload vector driver */
+-    if (apiEntry) free(apiEntry);
+-    apiEntry = NULL;
+-    opvp_unload_vector_driver();
++    if (pdev->globals.apiEntry)
++        free(pdev->globals.apiEntry);
++    pdev->globals.apiEntry = NULL;
++    opvp_unload_vector_driver(dev);
+
+-    if (inkjet) {
++    if (pdev->globals.inkjet) {
+         /* close printer */
+         gdev_prn_close(dev);
+     } else {
+         /* close output stream */
+         gdev_vector_close_file((gx_device_vector *)pdev);
+     }
+-    outputFD = -1;
++    pdev->globals.outputFD = -1;
+
+     return ecode;
+ }
+@@ -2455,6 +2762,7 @@ opvp_map_rgb_color(gx_device *dev,
+ {
+     opvp_cspace_t cs;
+     uint c, m, y, k;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+ #if !(ENABLE_SIMPLE_MODE)
+     gx_device_opvp *pdev;
+@@ -2467,16 +2775,15 @@ opvp_map_rgb_color(gx_device *dev,
+     b = prgb[2];
+
+ #if ENABLE_SIMPLE_MODE
+-    cs = colorSpace;
++    cs = opdev->globals.colorSpace;
+ #else
+     pdev = (gx_device_opvp *)dev;
+     r = -1;
+     cs = OPVP_CSPACE_STANDARDRGB;
+     if (pdev->is_open) {
+         /* call GetColorSpace */
+-        if (apiEntry->opvpGetColorSpace) {
+-            r = apiEntry->opvpGetColorSpace(printerContext, &cs);
+-        }
++
++        r = gsopvpGetColorSpace(dev, opdev->globals.printerContext, &cs);
+         if (r != OPVP_OK) {
+             if (pdev->color_info.depth > 32) {
+                     cs = OPVP_CSPACE_STANDARDRGB64;
+@@ -2555,15 +2862,14 @@ opvp_map_color_rgb(gx_device *dev, gx_color_index color,
+ #endif
+     opvp_cspace_t cs = OPVP_CSPACE_STANDARDRGB;
+     uint c, m, y, k;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+ #if ENABLE_SIMPLE_MODE
+-    cs = colorSpace;
++    cs = opdev->globals.colorSpace;
+ #else
+     /* call GetColorSpace */
+     if (pdev->is_open) {
+-        if (apiEntry->opvpGetColorSpace) {
+-            r = apiEntry->opvpGetColorSpace(printerContext, &cs);
+-        }
++        r = gsopvpGetColorSpace(dev, opdev->globals.printerContext, &cs);
+         if (r != OPVP_OK) {
+             if (pdev->color_info.depth > 32) {
+                 cs = OPVP_CSPACE_STANDARDRGB64;
+@@ -2635,44 +2941,44 @@ opvp_fill_rectangle(
+     int h,
+     gx_color_index color)
+ {
+-    gx_device_opvp *pdev = (gx_device_opvp *)dev;
++    gx_device_opvp *opdev = (gx_device_opvp *)dev;
+     byte data[8] = {0xC0, 0, 0, 0, 0xC0, 0, 0, 0};
+     int code = -1;
+     int ecode = 0;
+     opvp_brush_t brush;
+     opvp_point_t point;
+
+-    if (vector) {
+-        return gdev_vector_fill_rectangle( dev, x, y, w, h, color);
++    if (opdev->globals.vector) {
++        return gdev_vector_fill_rectangle(dev, x, y, w, h, color);
+     }
+
+     /* check page-in */
+-    if (opvp_check_in_page(pdev)) return -1;
++    if (opvp_check_in_page(opdev))
++        return -1;
+
+ #if !(ENABLE_SIMPLE_MODE)
+     /* call SaveGS */
+-    if (apiEntry->opvpSaveGS) {
+-        apiEntry->opvpSaveGS(printerContext);
++    if (pdev->globals.apiEntry->opvpSaveGS) {
++        pdev->globals.apiEntry->opvpSaveGS(printerContext);
+     }
+ #endif
+
+     /* one-color */
+-    opvp_set_brush_color(pdev, color, &brush);
++    opvp_set_brush_color(opdev, color, &brush);
+
+     /* call SetFillColor */
+-    if (apiEntry->opvpSetFillColor) {
+-        apiEntry->opvpSetFillColor(printerContext, &brush);
+-    }
++    gsopvpSetFillColor(dev, opdev->globals.printerContext, &brush);
++
+
+     /* call SetCurrentPoint */
+     OPVP_I2FIX(x, point.x);
+     OPVP_I2FIX(y, point.y);
+-    if (apiEntry->opvpSetCurrentPoint) {
+-        apiEntry->opvpSetCurrentPoint(printerContext,point.x, point.y);
++    if (opdev->globals.apiEntry->opvpSetCurrentPoint) {
++        opdev->globals.apiEntry->opvpSetCurrentPoint(opdev->globals.printerContext,point.x, point.y);
+     }
+
+     /* draw image */
+-    code = opvp_draw_image(pdev,
++    code = opvp_draw_image(opdev,
+                            1,
+                            2, 2,
+                            w, h,
+@@ -2684,17 +2990,15 @@ opvp_fill_rectangle(
+     }
+
+     /* restore fill color */
+-    if (vectorFillColor) {
++    if (opdev->globals.vectorFillColor) {
+         /* call SetFillColor */
+-        if (apiEntry->opvpSetFillColor) {
+-            apiEntry->opvpSetFillColor(printerContext,vectorFillColor);
+-        }
++        gsopvpSetFillColor(dev, opdev->globals.printerContext,opdev->globals.vectorFillColor);
+     }
+
+ #if !(ENABLE_SIMPLE_MODE)
+     /* call RestoreGS */
+-    if (apiEntry->opvpRestoreGS) {
+-        apiEntry->opvpRestoreGS(printerContext);
++    if (pdev->globals.apiEntry->opvpRestoreGS) {
++        pdev->globals.opdev->globals.apiEntry->opvpRestoreGS(printerContext);
+     }
+ #endif
+
+@@ -2718,7 +3022,7 @@ opvp_copy_mono(
+     gx_color_index zero,
+     gx_color_index one)
+ {
+-    gx_device_opvp *pdev = (gx_device_opvp *)dev;
++    gx_device_opvp *opdev = (gx_device_opvp *)dev;
+     int code = -1;
+     int ecode = 0;
+     opvp_brush_t brush;
+@@ -2736,7 +3040,8 @@ opvp_copy_mono(
+     bool reverse = false;
+
+     /* check page-in */
+-    if (opvp_check_in_page(pdev)) return -1;
++    if (opvp_check_in_page(opdev))
++        return -1;
+
+     /* data offset */
+     if (data_x) {
+@@ -2773,8 +3078,8 @@ opvp_copy_mono(
+
+ #if !(ENABLE_SIMPLE_MODE)
+     /* call SaveGS */
+-    if (apiEntry->opvpSaveGS) {
+-        apiEntry->opvpSaveGS(printerContext);
++    if (opdev->globals.apiEntry->opvpSaveGS) {
++        opdev->globals.apiEntry->opvpSaveGS(printerContext);
+     }
+ #endif
+     if (one == gx_no_color_index) {
+@@ -2789,25 +3094,22 @@ opvp_copy_mono(
+     if (zero != gx_no_color_index) {
+         /* not mask */
+         /* Set PaintMode */
+-        if (apiEntry->opvpSetPaintMode) {
+-            apiEntry->opvpSetPaintMode(printerContext,OPVP_PAINTMODE_OPAQUE);
++        if (opdev->globals.apiEntry->opvpSetPaintMode) {
++            opdev->globals.apiEntry->opvpSetPaintMode(opdev->globals.printerContext, OPVP_PAINTMODE_OPAQUE);
+         }
+         /* zero-color */
+-        opvp_set_brush_color(pdev, zero, &brush);
++        opvp_set_brush_color(opdev, zero, &brush);
+
+         /* call SetBgColor */
+-        if (apiEntry->opvpSetBgColor) {
+-            apiEntry->opvpSetBgColor(printerContext, &brush);
+-        }
++        gsopvpSetBgColor(dev, opdev->globals.printerContext, &brush);
++
+     }
+
+     /* one-color */
+-    opvp_set_brush_color(pdev, one, &brush);
++    opvp_set_brush_color(opdev, one, &brush);
+
+     /* call SetFillColor */
+-    if (apiEntry->opvpSetFillColor) {
+-        apiEntry->opvpSetFillColor(printerContext, &brush);
+-    }
++    gsopvpSetFillColor(dev, opdev->globals.printerContext, &brush);
+
+     if (reverse) {
+         /* 0/1 reverse image */
+@@ -2826,12 +3128,12 @@ opvp_copy_mono(
+     /* call SetCurrentPoint */
+     OPVP_I2FIX(x, point.x);
+     OPVP_I2FIX(y, point.y);
+-    if (apiEntry->opvpSetCurrentPoint) {
+-        apiEntry->opvpSetCurrentPoint(printerContext,point.x, point.y);
++    if (opdev->globals.apiEntry->opvpSetCurrentPoint) {
++        opdev->globals.apiEntry->opvpSetCurrentPoint(opdev->globals.printerContext,point.x, point.y);
+     }
+
+     /* draw image */
+-    code = opvp_draw_image(pdev,
++    code = opvp_draw_image(opdev,
+                            1,
+                            w, h,
+                            w, h,
+@@ -2844,23 +3146,21 @@ opvp_copy_mono(
+
+     if (zero != gx_no_color_index) {
+         /* restore PaintMode */
+-        if (apiEntry->opvpSetPaintMode) {
+-            apiEntry->opvpSetPaintMode(printerContext,
++        if (opdev->globals.apiEntry->opvpSetPaintMode) {
++            opdev->globals.apiEntry->opvpSetPaintMode(opdev->globals.printerContext,
+               OPVP_PAINTMODE_TRANSPARENT);
+         }
+     }
+     /* restore fill color */
+-    if (vectorFillColor) {
++    if (opdev->globals.vectorFillColor) {
+         /* call SetFillColor */
+-        if (apiEntry->opvpSetFillColor) {
+-            apiEntry->opvpSetFillColor(printerContext,vectorFillColor);
+-        }
++        gsopvpSetFillColor(dev, opdev->globals.printerContext,opdev->globals.vectorFillColor);
+     }
+
+ #if !(ENABLE_SIMPLE_MODE)
+     /* call RestoreGS */
+-    if (apiEntry->opvpRestoreGS) {
+-        apiEntry->opvpRestoreGS(printerContext);
++    if (opdev->globals.apiEntry->opvpRestoreGS) {
++        opdev->globals.apiEntry->opvpRestoreGS(opdev->globals.printerContext);
+     }
+ #endif
+
+@@ -2887,7 +3187,7 @@ opvp_copy_color(
+     int w,
+     int h)
+ {
+-    gx_device_opvp *pdev = (gx_device_opvp *)dev;
++    gx_device_opvp *opdev = (gx_device_opvp *)dev;
+     int code = -1;
+     int ecode = 0;
+     opvp_point_t point;
+@@ -2902,11 +3202,12 @@ opvp_copy_color(
+     int adj_raster = raster;
+
+     /* check page-in */
+-    if (opvp_check_in_page(pdev)) return -1;
++    if (opvp_check_in_page(opdev))
++        return -1;
+
+     /* data offset */
+     if (data_x) {
+-        depth = pdev->color_info.depth;
++        depth = opdev->color_info.depth;
+         pixel = (depth + 7) >> 3;
+         byte_length = pixel * w;
+         adj_raster = ((byte_length + 3) >> 2) << 2;
+@@ -2926,21 +3227,21 @@ opvp_copy_color(
+
+ #if !(ENABLE_SIMPLE_MODE)
+     /* call SaveGS */
+-    if (apiEntry->opvpSaveGS) {
+-        apiEntry->opvpSaveGS(printerContext);
++    if (opdev->globals.apiEntry->opvpSaveGS) {
++        opdev->globals.apiEntry->opvpSaveGS(opdev->globals.printerContext);
+     }
+ #endif
+
+     /* call SetCurrentPoint */
+     OPVP_I2FIX(x, point.x);
+     OPVP_I2FIX(y, point.y);
+-    if (apiEntry->opvpSetCurrentPoint) {
+-        apiEntry->opvpSetCurrentPoint(printerContext, point.x, point.y);
++    if (opdev->globals.apiEntry->opvpSetCurrentPoint) {
++        opdev->globals.apiEntry->opvpSetCurrentPoint(opdev->globals.printerContext, point.x, point.y);
+     }
+
+     /* draw image */
+-    code = opvp_draw_image(pdev,
+-                           pdev->color_info.depth,
++    code = opvp_draw_image(opdev,
++                           opdev->color_info.depth,
+                            w, h,
+                            w, h,
+                            adj_raster,
+@@ -2952,8 +3253,8 @@ opvp_copy_color(
+
+ #if !(ENABLE_SIMPLE_MODE)
+     /* call RestoreGS */
+-    if (apiEntry->opvpRestoreGS) {
+-        apiEntry->opvpRestoreGS(printerContext);
++    if (opdev->globals.apiEntry->opvpRestoreGS) {
++        opdev->globals.apiEntry->opvpRestoreGS(opdev->globals.printerContext);
+     }
+ #endif
+
+@@ -2969,7 +3270,7 @@ opvp_copy_color(
+  * get params
+  */
+ static  int
+-_get_params(gs_param_list *plist)
++_get_params(gx_device* dev, gs_param_list *plist)
+ {
+     int code;
+     int ecode = 0;
+@@ -2985,37 +3286,38 @@ _get_params(gs_param_list *plist)
+     gs_param_string mbps;
+     gs_param_string zmps;
+     char buff[OPVP_BUFF_SIZE];
++    gx_device_opvp* opdev = (gx_device_opvp*)dev;
+
+     /* get params */
+
+     /* vector driver name */
+     pname = "Driver";
+-    vdps.data = (byte *)vectorDriver;
+-    vdps.size = (vectorDriver ? strlen(vectorDriver) + 1 : 0);
++    vdps.data = (byte *)opdev->globals.vectorDriver;
++    vdps.size = (opdev->globals.vectorDriver ? strlen(opdev->globals.vectorDriver) + 1 : 0);
+     vdps.persistent = false;
+     code = param_write_string(plist, pname, &vdps);
+     if (code) ecode = code;
+
+     /* printer model name */
+     pname = "Model";
+-    pmps.data = (byte *)printerModel;
+-    pmps.size = (printerModel ? strlen(printerModel) + 1 : 0);
++    pmps.data = (byte *)opdev->globals.printerModel;
++    pmps.size = (opdev->globals.printerModel ? strlen(opdev->globals.printerModel) + 1 : 0);
+     pmps.persistent = false;
+     code = param_write_string(plist, pname, &pmps);
+     if (code) ecode = code;
+
+     /* job info */
+     pname = "JobInfo";
+-    jips.data = (byte *)jobInfo;
+-    jips.size = (jobInfo ? strlen(jobInfo) + 1 : 0);
++    jips.data = (byte *)opdev->globals.jobInfo;
++    jips.size = (opdev->globals.jobInfo ? strlen(opdev->globals.jobInfo) + 1 : 0);
+     jips.persistent = false;
+     code = param_write_string(plist, pname, &jips);
+     if (code) ecode = code;
+
+     /* doc info */
+     pname = "DocInfo";
+-    dips.data = (byte *)docInfo;
+-    dips.size = (docInfo ? strlen(docInfo) + 1 : 0);
++    dips.data = (byte *)opdev->globals.docInfo;
++    dips.size = (opdev->globals.docInfo ? strlen(opdev->globals.docInfo) + 1 : 0);
+     dips.persistent = false;
+     code = param_write_string(plist, pname, &dips);
+     if (code) ecode = code;
+@@ -3052,28 +3354,28 @@ _get_params(gs_param_list *plist)
+     /* margins */
+     memset((void*)buff, 0, OPVP_BUFF_SIZE);
+     pname = "MarginLeft";
+-    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",margins[0]);
++    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",opdev->globals.margins[0]);
+     mlps.data = (byte *)buff;
+     mlps.size = strlen(buff) + 1;
+     mlps.persistent = false;
+     code = param_write_string(plist, pname, &mlps);
+     if (code) ecode = code;
+     pname = "MarginTop";
+-    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",margins[3]);
++    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",opdev->globals.margins[3]);
+     mtps.data = (byte *)buff;
+     mtps.size = strlen(buff) + 1;
+     mtps.persistent = false;
+     code = param_write_string(plist, pname, &mtps);
+     if (code) ecode = code;
+     pname = "MarginRight";
+-    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",margins[2]);
++    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",opdev->globals.margins[2]);
+     mrps.data = (byte *)buff;
+     mrps.size = strlen(buff) + 1;
+     mrps.persistent = false;
+     code = param_write_string(plist, pname, &mrps);
+     if (code) ecode = code;
+     pname = "MarginBottom";
+-    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",margins[1]);
++    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",opdev->globals.margins[1]);
+     mbps.data = (byte *)buff;
+     mbps.size = strlen(buff) + 1;
+     mbps.persistent = false;
+@@ -3082,7 +3384,7 @@ _get_params(gs_param_list *plist)
+
+     /* zoom */
+     pname = "Zoom";
+-    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",zoom[0]);
++    snprintf(buff, OPVP_BUFF_SIZE - 1, "%f",opdev->globals.zoom[0]);
+     zmps.data = (byte *)buff;
+     zmps.size = strlen(buff) + 1;
+     zmps.persistent = false;
+@@ -3105,7 +3407,7 @@ opvp_get_params(gx_device *dev, gs_param_list *plist)
+     if (code) return code;
+
+     /* get params */
+-    return _get_params(plist);
++    return _get_params(dev, plist);
+ }
+
+ /*
+@@ -3121,14 +3423,14 @@ oprp_get_params(gx_device *dev, gs_param_list *plist)
+     if (code) return code;
+
+     /* get params */
+-    return _get_params(plist);
++    return _get_params(dev, plist);
+ }
+
+ /*
+  * put params
+  */
+ static  int
+-_put_params(gs_param_list *plist)
++_put_params(gx_device *dev, gs_param_list *plist)
+ {
+     int code;
+     int ecode = 0;
+@@ -3144,6 +3446,7 @@ _put_params(gs_param_list *plist)
+     gs_param_string mrps;
+     gs_param_string mbps;
+     gs_param_string zmps;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     /* vector driver name */
+     pname = "Driver";
+@@ -3153,10 +3456,10 @@ _put_params(gs_param_list *plist)
+         buff = realloc(buff, vdps.size + 1);
+         memcpy(buff, vdps.data, vdps.size);
+         buff[vdps.size] = 0;
+-        opvp_alloc_string(&vectorDriver, buff);
++        opvp_alloc_string(&(opdev->globals.vectorDriver), buff);
+         break;
+     case 1:
+-        /* opvp_alloc_string(&vectorDriver, NULL);*/
++        /* opvp_alloc_string(&(opdev->globals.vectorDriver), NULL);*/
+         break;
+     default:
+         ecode = code;
+@@ -3171,10 +3474,10 @@ _put_params(gs_param_list *plist)
+         buff = realloc(buff, pmps.size + 1);
+         memcpy(buff, pmps.data, pmps.size);
+         buff[pmps.size] = 0;
+-        opvp_alloc_string(&printerModel, buff);
++        opvp_alloc_string(&(opdev->globals.printerModel), buff);
+         break;
+     case 1:
+-        /*opvp_alloc_string(&printerModel, NULL);*/
++        /*opvp_alloc_string(&(opdev->globals.printerModel), NULL);*/
+         break;
+     default:
+         ecode = code;
+@@ -3189,10 +3492,10 @@ _put_params(gs_param_list *plist)
+         buff = realloc(buff, jips.size + 1);
+         memcpy(buff, jips.data, jips.size);
+         buff[jips.size] = 0;
+-        opvp_alloc_string(&jobInfo, buff);
++        opvp_alloc_string(&(opdev->globals.jobInfo), buff);
+         break;
+     case 1:
+-        /*opvp_alloc_string(&jobInfo, NULL);*/
++        /*opvp_alloc_string(&(opdev->globals.jobInfo), NULL);*/
+         break;
+     default:
+         ecode = code;
+@@ -3207,10 +3510,10 @@ _put_params(gs_param_list *plist)
+         buff = realloc(buff, dips.size + 1);
+         memcpy(buff, dips.data, dips.size);
+         buff[dips.size] = 0;
+-        opvp_alloc_string(&docInfo, buff);
++        opvp_alloc_string(&(opdev->globals.docInfo), buff);
+         break;
+     case 1:
+-        /*opvp_alloc_string(&docInfo, NULL);*/
++        /*opvp_alloc_string(&(opdev->globals.docInfo), NULL);*/
+         break;
+     default:
+         ecode = code;
+@@ -3256,7 +3559,7 @@ _put_params(gs_param_list *plist)
+         buff = realloc(buff, mlps.size + 1);
+         memcpy(buff, mlps.data, mlps.size);
+         buff[mlps.size] = 0;
+-        margins[0] = atof(buff);
++        opdev->globals.margins[0] = atof(buff);
+         break;
+     case 1:
+         break;
+@@ -3271,7 +3574,7 @@ _put_params(gs_param_list *plist)
+         buff = realloc(buff, mtps.size + 1);
+         memcpy(buff, mtps.data, mtps.size);
+         buff[mtps.size] = 0;
+-        margins[3] = atof(buff);
++        opdev->globals.margins[3] = atof(buff);
+         break;
+     case 1:
+         break;
+@@ -3286,7 +3589,7 @@ _put_params(gs_param_list *plist)
+         buff = realloc(buff, mrps.size + 1);
+         memcpy(buff, mrps.data, mrps.size);
+         buff[mrps.size] = 0;
+-        margins[2] = atof(buff);
++        opdev->globals.margins[2] = atof(buff);
+         break;
+     case 1:
+         break;
+@@ -3301,7 +3604,7 @@ _put_params(gs_param_list *plist)
+         buff = realloc(buff, mbps.size + 1);
+         memcpy(buff, mbps.data, mbps.size);
+         buff[mbps.size] = 0;
+-        margins[1] = atof(buff);
++        opdev->globals.margins[1] = atof(buff);
+         break;
+     case 1:
+         break;
+@@ -3319,15 +3622,15 @@ _put_params(gs_param_list *plist)
+         memcpy(buff, zmps.data, zmps.size);
+         buff[zmps.size] = 0;
+         if (strncasecmp(buff, "Auto", 4)) {
+-            zoom[0] = atof(buff);
+-            if (zoom[0] > 0) {
+-                zoom[1] = zoom[0];
++            opdev->globals.zoom[0] = atof(buff);
++            if (opdev->globals.zoom[0] > 0) {
++                opdev->globals.zoom[1] = opdev->globals.zoom[0];
+             } else {
+-                zoom[0] = zoom[1] = 1;
++                opdev->globals.zoom[0] = opdev->globals.zoom[1] = 1;
+             }
+         } else {
+-            zoom[0] = zoom[1] = 1;
+-            zoomAuto = true;
++            opdev->globals.zoom[0] = opdev->globals.zoom[1] = 1;
++            opdev->globals.zoomAuto = true;
+         }
+         break;
+     case 1:
+@@ -3351,7 +3654,7 @@ opvp_put_params(gx_device *dev, gs_param_list *plist)
+     int code;
+
+     /* put params */
+-    code = _put_params(plist);
++    code = _put_params(dev, plist);
+     if (code) return code;
+
+     /* put default params */
+@@ -3367,7 +3670,7 @@ oprp_put_params(gx_device *dev, gs_param_list *plist)
+     int code;
+
+     /* put params */
+-    code = _put_params(plist);
++    code = _put_params(dev, plist);
+     if (code) return code;
+
+     /* put default params */
+@@ -3444,13 +3747,14 @@ opvp_fill_path(
+ {
+     bool draw_image = false;
+     gs_fixed_rect inner, outer;
++    gx_device_opvp *opdev = (gx_device_opvp*)dev;
+
+     /* check if paths are too complex */
+     if (!checkPath(ppath) || !checkCPath(pxpath)) {
+         return gx_default_fill_path(dev, pgs, ppath, params, pdevc, pxpath);
+     }
+     /* check clippath support */
+-    if (!(apiEntry->opvpSetClipPath)) {
++    if (!(opdev->globals.apiEntry->opvpSetClipPath)) {
+         /* get clipping box area */
+         gx_cpath_inner_box(pxpath,&inner);
+         gx_cpath_outer_box(pxpath,&outer);
+@@ -3462,7 +3766,7 @@ opvp_fill_path(
+         }
+     }
+
+-    if (!vector || draw_image) {
++    if (!(opdev->globals.vector) || draw_image) {
+         return gx_default_fill_path(dev, pgs, ppath, params, pdevc, pxpath);
+     }
+
+@@ -3483,6 +3787,7 @@ opvp_stroke_path(
+ {
+     bool draw_image = false;
+     gs_fixed_rect inner, outer;
++    gx_device_opvp *opdev = (gx_device_opvp *) dev;
+
+     /* check if paths are too complex */
+     if (!checkPath(ppath) || !checkCPath(pxpath)) {
+@@ -3490,7 +3795,7 @@ opvp_stroke_path(
+                                       params, pdcolor, pxpath);
+     }
+     /* check clippath support */
+-    if (!(apiEntry->opvpSetClipPath)) {
++    if (!(opdev->globals.apiEntry->opvpSetClipPath)) {
+         /* get clipping box area */
+         gx_cpath_inner_box(pxpath,&inner);
+         gx_cpath_outer_box(pxpath,&outer);
+@@ -3502,7 +3807,7 @@ opvp_stroke_path(
+         }
+     }
+
+-    if (!vector || draw_image) {
++    if (!(opdev->globals.vector) || draw_image) {
+         return gx_default_stroke_path(dev, pgs, ppath,
+                                       params, pdcolor, pxpath);
+     }
+@@ -3530,7 +3835,9 @@ opvp_fill_mask(
+     gs_logical_operation_t lop,
+     const gx_clip_path *pcpath)
+ {
+-    if (vector) {
++    gx_device_opvp *opdev = (gx_device_opvp*) dev;
++
++    if (opdev->globals.vector) {
+         int code;
+         code = gdev_vector_update_fill_color((gx_device_vector *)dev, NULL, pdcolor);
+         if (code < 0)   return code;
+@@ -3574,6 +3881,7 @@ opvp_begin_typed_image(
+     int p;
+     float mag[2] = {1, 1};
+     const gs_color_space *pcs;
++    gx_device_opvp *opdev = (gx_device_opvp *)dev;
+
+     /* check if paths are too complex */
+     if (pic->type->index != 1 || !checkCPath(pcpath))
+@@ -3757,7 +4065,7 @@ opvp_begin_typed_image(
+                  * 3 planes 24 bits color image
+                  * (8 bits per plane)
+                  */
+-                if (apiEntry->opvpStartDrawImage) {
++                if (opdev->globals.apiEntry->opvpStartDrawImage) {
+                     draw_image = true;
+                 }
+             }
+@@ -3768,54 +4076,51 @@ opvp_begin_typed_image(
+         *pinfo = (gx_image_enum_common_t *)vinfo;
+
+         if (!ecode) {
++            opvp_cspace_t ncspace;
++
+             if (!pim->ImageMask) {
+                 /* call SetPaintMode */
+-                if (apiEntry->opvpSetPaintMode) {
+-                    apiEntry->opvpSetPaintMode(printerContext,
++                if (opdev->globals.apiEntry->opvpSetPaintMode) {
++                    opdev->globals.apiEntry->opvpSetPaintMode(opdev->globals.printerContext,
+                        OPVP_PAINTMODE_OPAQUE);
+                     change_paint_mode = true;
+                 }
+                 /* set color space */
+-                if (apiEntry->opvpSetColorSpace != NULL) {
+-                    opvp_cspace_t ncspace;
+-
+-                    savedColorSpace = colorSpace;
+-                    switch (bits_per_pixel) {
+-                    case 1:
+-                        ncspace = OPVP_CSPACE_DEVICEGRAY;
+-                        bits_per_pixel = 8;
+-                        if (!cspace_available[ncspace]) {
+-                            ncspace = OPVP_CSPACE_STANDARDRGB;
+-                            bits_per_pixel = 24;
+-                        }
+-                        break;
+-                    case 8:
+-                        ncspace = OPVP_CSPACE_DEVICEGRAY;
+-                        if (!cspace_available[ncspace]) {
+-                            ncspace = OPVP_CSPACE_STANDARDRGB;
+-                            bits_per_pixel = 24;
+-                        }
+-                        break;
+-                    case 24:
+-                        ncspace = OPVP_CSPACE_DEVICERGB;
+-                        if (!cspace_available[ncspace]) {
+-                            ncspace = OPVP_CSPACE_STANDARDRGB;
+-                        }
+-                        break;
+-                    default:
++                opdev->globals.savedColorSpace = opdev->globals.colorSpace;
++                switch (bits_per_pixel) {
++                case 1:
++                    ncspace = OPVP_CSPACE_DEVICEGRAY;
++                    bits_per_pixel = 8;
++                    if (!cspace_available[ncspace]) {
++                        ncspace = OPVP_CSPACE_STANDARDRGB;
++                        bits_per_pixel = 24;
++                    }
++                    break;
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

meta/recipes-extended/ghostscript/ghostscript/CVE-2024-33871-0002.patch new file +43 -0

43 lines not on this page · raw message

meta/recipes-extended/ghostscript/ghostscript_9.55.0.bb +2 -0
index 083ee4b337..36c5aa3285 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.34.1

Part of the diff is not shown here. View the raw message.

#4 lore raw

PATCH 4/7 ghostscript: fix CVE-2024-29510

In reply to Steve Sakoman

From: Archana Polampalli <[email protected]>

---
 .../ghostscript/CVE-2024-29510.patch          | 84 +++++++++++++++++++
 .../ghostscript/ghostscript_9.55.0.bb         |  1 +
 2 files changed, 85 insertions(+)
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2024-29510.patch
meta/recipes-extended/ghostscript/ghostscript/CVE-2024-29510.patch new file +84 -0
new file mode 100644
index 0000000000..0234c79c7d
@@ -0,0 +1,84 @@
+From 3b1735085ecef20b29e8db3416ab36de93e86d1f Mon Sep 17 00:00:00 2001
+From: Ken Sharp <[email protected]>
+Date: Thu, 21 Mar 2024 09:01:15 +0000
+Subject: [PATCH 4/5] Uniprint device - prevent string configuration changes
+ when SAFER
+
+Bug #707662
+
+We cannot sanitise the string arguments used by the Uniprint device
+because they can potentially include anything.
+
+This commit ensures that these strings are locked and cannot be
+changed by PostScript once SAFER is activated. Full configuration from
+the command line is still possible (see the *.upp files in lib).
+
+This addresses CVE-2024-29510
+
+CVE: CVE-2024-29510
+
+Upstream-Status: Backport [https://cgit.ghostscript.com/cgi-bin/cgit.cgi/ghostpdl.git/commit/?id=3b1735085ecef20b29e]
+
+Signed-off-by: Archana Polampalli <[email protected]>
+---
+ devices/gdevupd.c | 31 +++++++++++++++++++++++++++++++
+ 1 file changed, 31 insertions(+)
+
+diff --git a/devices/gdevupd.c b/devices/gdevupd.c
+index 6635984..7952165 100644
+--- a/devices/gdevupd.c
++++ b/devices/gdevupd.c
+@@ -1886,6 +1886,16 @@ out on this copies.
+       if(!upd_strings[i]) continue;
+       UPD_PARAM_READ(param_read_string,upd_strings[i],value,udev->memory);
+       if(0 == code) {
++        if (gs_is_path_control_active(udev->memory)) {
++            if (strings[i].size != value.size)
++              error = gs_error_invalidaccess;
++            else {
++                if (strings[i].data && memcmp(strings[i].data, value.data, strings[i].size) != 0)
++                    error = gs_error_invalidaccess;
++            }
++            if (error < 0)
++                goto exit;
++        }
+          if(0 <= error) error |= UPD_PUT_STRINGS;
+          UPD_MM_DEL_PARAM(udev->memory, strings[i]);
+          if(!value.size) {
+@@ -1903,6 +1913,26 @@ out on this copies.
+       if(!upd_string_a[i]) continue;
+       UPD_PARAM_READ(param_read_string_array,upd_string_a[i],value,udev->memory);
+       if(0 == code) {
++          if (gs_is_path_control_active(udev->memory)) {
++              if (string_a[i].size != value.size)
++                  error = gs_error_invalidaccess;
++              else {
++                  int loop;
++                  for (loop = 0;loop < string_a[i].size;loop++) {
++                      gs_param_string *tmp1 = (gs_param_string *)&(string_a[i].data[loop]);
++                      gs_param_string *tmp2 = (gs_param_string *)&value.data[loop];
++
++                      if (tmp1->size != tmp2->size)
++                          error = gs_error_invalidaccess;
++                      else {
++                          if (tmp1->data && memcmp(tmp1->data, tmp2->data, tmp1->size) != 0)
++                              error = gs_error_invalidaccess;
++                      }
++                  }
++              }
++            if (error < 0)
++                goto exit;
++          }
+          if(0 <= error) error |= UPD_PUT_STRING_A;
+          UPD_MM_DEL_APARAM(udev->memory, string_a[i]);
+          if(!value.size) {
+@@ -2097,6 +2127,7 @@ transferred into the device-structure. In the case of "uniprint", this may
+       if(0 > code) error = code;
+    }
+
++exit:
+    if(0 < error) { /* Actually something loaded without error */
+
+       if(!(upd = udev->upd)) {
+--
+2.40.0
meta/recipes-extended/ghostscript/ghostscript_9.55.0.bb +1 -0
index 36c5aa3285..1fd08d1cfe 100644
@@ -48,6 +48,7 @@ SRC_URI_BASE = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/d
                 file://CVE-2024-33869-0002.patch \
                 file://CVE-2024-33871-0001.patch \
                 file://CVE-2024-33871-0002.patch \
+                file://CVE-2024-29510.patch \
 "
 
 SRC_URI = "${SRC_URI_BASE} \
Signature · 1 line
2.34.1
#5 lore raw

PATCH 5/7 ghostscript: fix CVE-2023-52722

In reply to Steve Sakoman

From: Archana Polampalli <[email protected]>

---
 .../ghostscript/CVE-2023-52722.patch          | 43 +++++++++++++++++++
 .../ghostscript/ghostscript_9.55.0.bb         |  1 +
 2 files changed, 44 insertions(+)
 create mode 100644 meta/recipes-extended/ghostscript/ghostscript/CVE-2023-52722.patch
meta/recipes-extended/ghostscript/ghostscript/CVE-2023-52722.patch new file +43 -0
new file mode 100644
index 0000000000..8fbfc9ef09
@@ -0,0 +1,43 @@
+From 1ff9a695947967d2d327c45bf5145dd381fc1745 Mon Sep 17 00:00:00 2001
+From: Chris Liddell <[email protected]>
+Date: Tue, 12 Sep 2023 10:46:10 +0100
+Subject: [PATCH 5/5] In SAFER (default) don't allow eexec seeds other than the
+ Type 1 standard
+
+CVE: CVE-2023-52722
+
+Upstream-Status: Backport [https://cgit.ghostscript.com/cgi-bin/cgit.cgi/ghostpdl.git/commit/?id=1ff9a695947967d2d327]
+
+Signed-off-by: Archana Polampalli <[email protected]>
+---
+ psi/zmisc1.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/psi/zmisc1.c b/psi/zmisc1.c
+index 3c47e99..81556ac 100644
+--- a/psi/zmisc1.c
++++ b/psi/zmisc1.c
+@@ -93,6 +93,9 @@ zexE(i_ctx_t *i_ctx_p)
+
+     if (code < 0)
+         return code;
++    if (gs_is_path_control_active(imemory) != 0 && state.cstate != 55665) {
++        return_error(gs_error_rangecheck);
++    }
+     return filter_write(i_ctx_p, code, &s_exE_template, (stream_state *)&state, 0);
+ }
+
+@@ -130,6 +133,11 @@ zexD(i_ctx_t *i_ctx_p)
+     }
+     if (code < 0)
+         return code;
++
++    if (gs_is_path_control_active(imemory) != 0 && state.cstate != 55665) {
++        return_error(gs_error_rangecheck);
++    }
++
+     /*
+      * If we're reading a .PFB file, let the filter know about it,
+      * so it can read recklessly to the end of the binary section.
+--
+2.40.0
meta/recipes-extended/ghostscript/ghostscript_9.55.0.bb +1 -0
index 1fd08d1cfe..2e332b1589 100644
@@ -49,6 +49,7 @@ SRC_URI_BASE = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/d
                 file://CVE-2024-33871-0001.patch \
                 file://CVE-2024-33871-0002.patch \
                 file://CVE-2024-29510.patch \
+                file://CVE-2023-52722.patch \
 "
 
 SRC_URI = "${SRC_URI_BASE} \
Signature · 1 line
2.34.1
#6 lore raw

PATCH 6/7 util-linux: Fix CVE-2024-28085

In reply to Steve Sakoman

From: Soumya Sambu <[email protected]>

wall in util-linux through 2.40, often installed with setgid tty permissions, allows escape sequences to be sent to other users' terminals through argv. (Specifically, escape sequences received from stdin are blocked, but escape sequences received from argv are not blocked.) There may be plausible scenarios where this leads to account takeover.

CVE-2024-28085-0005 is the CVE fix and CVE-2024-28085-0001, CVE-2024-28085-0002, CVE-2024-28085-0003, CVE-2024-28085-0004 are dependent commits to fix the CVE.

References:
https://nvd.nist.gov/vuln/detail/CVE-2024-28085

---
 meta/recipes-core/util-linux/util-linux.inc   |   5 +
 .../util-linux/CVE-2024-28085-0001.patch      | 202 ++++++++++++++++
 .../util-linux/CVE-2024-28085-0002.patch      | 172 ++++++++++++++
 .../util-linux/CVE-2024-28085-0003.patch      | 223 ++++++++++++++++++
 .../util-linux/CVE-2024-28085-0004.patch      |  36 +++
 .../util-linux/CVE-2024-28085-0005.patch      |  34 +++
 6 files changed, 672 insertions(+)
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0001.patch
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0002.patch
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0003.patch
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0004.patch
 create mode 100644 meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0005.patch
meta/recipes-core/util-linux/util-linux.inc +5 -0
index 982ec669a2..f8841e6be0 100644
@@ -35,6 +35,11 @@ SRC_URI = "${KERNELORG_MIRROR}/linux/utils/util-linux/v${MAJOR_VERSION}/util-lin
            file://run-ptest \
            file://display_testname_for_subtest.patch \
            file://avoid_parallel_tests.patch \
+           file://CVE-2024-28085-0001.patch \
+           file://CVE-2024-28085-0002.patch \
+           file://CVE-2024-28085-0003.patch \
+           file://CVE-2024-28085-0004.patch \
+           file://CVE-2024-28085-0005.patch \
            "
 
 SRC_URI[sha256sum] = "634e6916ad913366c3536b6468e7844769549b99a7b2bf80314de78ab5655b83"
meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0001.patch new file +202 -0

202 lines not on this page · raw message

meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0002.patch new file +172 -0

172 lines not on this page · raw message

meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0003.patch new file +223 -0

223 lines not on this page · raw message

meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0004.patch new file +36 -0
new file mode 100644
index 0000000000..af39931b3f
@@ -0,0 +1,36 @@
+From 07f0f0f5bd1e5e2268257ae1ff6d76a9b6c6ea8b Mon Sep 17 00:00:00 2001
+From: Karel Zak <[email protected]>
+Date: Wed, 17 Jan 2024 12:37:08 +0100
+Subject: [PATCH] wall: fix calloc cal [-Werror=calloc-transposed-args]
+
+term-utils/wall.c:143:37: error: xcalloc sizes specified with sizeof in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
+  143 |         buf->groups = xcalloc(sizeof(*buf->groups), buf->ngroups);
+      |                                     ^
+term-utils/wall.c:143:37: note: earlier argument should specify number of elements, later size of each element
+
+Signed-off-by: Karel Zak <[email protected]>
+
+CVE: CVE-2024-28085
+
+Upstream-Status: Backport [https://github.com/util-linux/util-linux/commit/07f0f0f5bd1e5e2268257ae1ff6d76a9b6c6ea8b]
+
+Signed-off-by: Soumya Sambu <[email protected]>
+---
+ term-utils/wall.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/term-utils/wall.c b/term-utils/wall.c
+index 377db45..85c006a 100644
+--- a/term-utils/wall.c
++++ b/term-utils/wall.c
+@@ -135,7 +135,7 @@ static struct group_workspace *init_group_workspace(const char *group)
+
+	buf->requested_group = get_group_gid(group);
+	buf->ngroups = sysconf(_SC_NGROUPS_MAX) + 1;  /* room for the primary gid */
+-	buf->groups = xcalloc(sizeof(*buf->groups), buf->ngroups);
++	buf->groups = xcalloc(buf->ngroups, sizeof(*buf->groups));
+
+	return buf;
+ }
+--
+2.40.0
meta/recipes-core/util-linux/util-linux/CVE-2024-28085-0005.patch new file +34 -0
new file mode 100644
index 0000000000..a2b914d580
@@ -0,0 +1,34 @@
+From 404b0781f52f7c045ca811b2dceec526408ac253 Mon Sep 17 00:00:00 2001
+From: Karel Zak <[email protected]>
+Date: Thu, 21 Mar 2024 11:16:20 +0100
+Subject: [PATCH] wall: fix escape sequence Injection [CVE-2024-28085]
+
+Let's use for all cases the same output function.
+
+Reported-by: Skyler Ferrante <[email protected]>
+Signed-off-by: Karel Zak <[email protected]>
+
+CVE: CVE-2024-28085
+
+Upstream-Status: Backport [https://github.com/util-linux/util-linux/commit/404b0781f52f7c045ca811b2dceec526408ac253]
+
+Signed-off-by: Soumya Sambu <[email protected]>
+---
+ term-utils/wall.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/term-utils/wall.c b/term-utils/wall.c
+index 85c006a..0212c03 100644
+--- a/term-utils/wall.c
++++ b/term-utils/wall.c
+@@ -328,7 +328,7 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
+		int i;
+
+		for (i = 0; i < mvecsz; i++) {
+-			fputs(mvec[i], fs);
++			fputs_careful(mvec[i], fs, '^', true, TERM_WIDTH);
+			if (i < mvecsz - 1)
+				fputc(' ', fs);
+		}
+--
+2.40.0
Signature · 1 line
2.34.1
#7 lore raw

PATCH 7/7 git: Fix multiple CVEs

In reply to Steve Sakoman

From: Soumya Sambu <[email protected]>

CVE-2024-32002:
Git is a revision control system. Prior to versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4, repositories with submodules can be crafted in a way that exploits a bug in Git whereby it can be fooled into writing files not into the submodule's worktree but into a .git/ directory. This allows writing a hook that will be executed while the clone operation is still running, giving the user no opportunity to inspect the code that is being executed. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4. If symbolic link support is disabled in Git (e.g. via git config --global core.symlinks false), the described attack won't work. As always, it is best to avoid cloning repositories from untrusted sources.

CVE-2024-32004:
Git is a revision control system. Prior to versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4, an attacker can prepare a local repository in such a way that, when cloned, will execute arbitrary code during the operation. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4. As a workaround, avoid cloning repositories from untrusted sources.

CVE-2024-32020:
Git is a revision control system. Prior to versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4, local clones may end up hardlinking files into the target repository's object database when source and target repository reside on the same disk. If the source repository is owned by a different user, then those hardlinked files may be rewritten at any point in time by the untrusted user. Cloning local repositories will cause Git to either copy or hardlink files of the source repository into the target repository. This significantly speeds up such local clones compared to doing a "proper" clone and saves both disk space and compute time. When cloning a repository located on the same disk that is owned by a different user than the current user we also end up creating such hardlinks. These files will continue to be owned and controlled by the potentially-untrusted user and can be rewritten by them at will in the future. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4.

CVE-2024-32021:
Git is a revision control system. Prior to versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4, when cloning a local source repository that contains symlinks via the filesystem, Git may create hardlinks to arbitrary user-readable files on the same filesystem as the target repository in the objects/ directory. Cloning a local repository over the filesystem may creating hardlinks to arbitrary user-owned files on the same filesystem in the target Git repository's objects/ directory. When cloning a repository over the filesystem (without explicitly specifying the file:// protocol or --no-local), the optimizations for local cloning will be used, which include attempting to hard link the object files instead of copying them. While the code includes checks against symbolic links in the source repository, which were added during the fix for CVE-2022-39253, these checks can still be raced because the hard link operation ultimately follows symlinks. If the object on the filesystem appears as a file during the check, and then a symlink during the operation, this will allow the adversary to bypass the check and create hardlinks in the destination objects directory to arbitrary, user-readable files. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4.

CVE-2024-32465:
Git is a revision control system. The Git project recommends to avoid working in untrusted repositories, and instead to clone it first with git clone --no-local to obtain a clean copy. Git has specific protections to make that a safe operation even with an untrusted source repository, but vulnerabilities allow those protections to be bypassed. In the context of cloning local repositories owned by other users, this vulnerability has been covered in CVE-2024-32004. But there are circumstances where the fixes for CVE-2024-32004 are not enough: For example, when obtaining a .zip file containing a full copy of a Git repository, it should not be trusted by default to be safe, as e.g. hooks could be configured to run within the context of that repository. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4. As a workaround, avoid using Git in repositories that have been obtained via archives from untrusted sources.

References:
https://nvd.nist.gov/vuln/detail/CVE-2024-32002
https://nvd.nist.gov/vuln/detail/CVE-2024-32004
https://nvd.nist.gov/vuln/detail/CVE-2024-32020
https://nvd.nist.gov/vuln/detail/CVE-2024-32021
https://nvd.nist.gov/vuln/detail/CVE-2024-32465

---
 .../git/git/CVE-2024-32002-0001.patch         |  69 ++++++
 .../git/git/CVE-2024-32002-0002.patch         | 213 ++++++++++++++++++
 .../git/git/CVE-2024-32002-0003.patch         | 141 ++++++++++++
 .../git/git/CVE-2024-32002-0004.patch         | 150 ++++++++++++
 .../git/git/CVE-2024-32004-0001.patch         |  95 ++++++++
 .../git/git/CVE-2024-32004-0002.patch         | 187 +++++++++++++++
 .../git/git/CVE-2024-32004-0003.patch         | 158 +++++++++++++
 .../git/git/CVE-2024-32020.patch              | 114 ++++++++++
 .../git/git/CVE-2024-32021-0001.patch         |  89 ++++++++
 .../git/git/CVE-2024-32021-0002.patch         |  65 ++++++
 .../git/git/CVE-2024-32465.patch              | 206 +++++++++++++++++
 meta/recipes-devtools/git/git_2.35.7.bb       |  11 +
 12 files changed, 1498 insertions(+)
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32002-0001.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32002-0002.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32002-0003.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32002-0004.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32004-0001.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32004-0002.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32004-0003.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32020.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32021-0001.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32021-0002.patch
 create mode 100644 meta/recipes-devtools/git/git/CVE-2024-32465.patch
meta/recipes-devtools/git/git/CVE-2024-32002-0001.patch new file +69 -0
new file mode 100644
index 0000000000..c424562e05
@@ -0,0 +1,69 @@
+From 21496b4c60b2327417c63fc9762096037a185be3 Mon Sep 17 00:00:00 2001
+From: Ævar Arnfjörð Bjarmason <[email protected]>
+Date: Thu, 1 Sep 2022 01:17:54 +0200
+Subject: [PATCH] submodule--helper: use xstrfmt() in clone_submodule()
+
+Use xstrfmt() in clone_submodule() instead of a "struct strbuf" in two
+cases where we weren't getting anything out of using the "struct
+strbuf".
+
+This changes code that was was added along with other uses of "struct
+strbuf" in this function in ee8838d1577 (submodule: rewrite
+`module_clone` shell function in C, 2015-09-08).
+
+Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
+Reviewed-by: Glen Choo <[email protected]>
+Signed-off-by: Junio C Hamano <[email protected]>
+
+CVE: CVE-2024-32002
+
+Upstream-Status: Backport [https://github.com/git/git/commit/21496b4c60b2327417c63fc9762096037a185be3]
+
+Signed-off-by: Soumya Sambu <[email protected]>
+---
+ builtin/submodule--helper.c | 17 +++++++++--------
+ 1 file changed, 9 insertions(+), 8 deletions(-)
+
+diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
+index c5d3fc3..79868c3 100644
+--- a/builtin/submodule--helper.c
++++ b/builtin/submodule--helper.c
+@@ -1761,12 +1761,11 @@ static int clone_submodule(struct module_clone_data *clone_data)
+	sm_gitdir = absolute_pathdup(sb.buf);
+	strbuf_reset(&sb);
+
+-	if (!is_absolute_path(clone_data->path)) {
+-		strbuf_addf(&sb, "%s/%s", get_git_work_tree(), clone_data->path);
+-		clone_data->path = strbuf_detach(&sb, NULL);
+-	} else {
++	if (!is_absolute_path(clone_data->path))
++		clone_data->path = xstrfmt("%s/%s", get_git_work_tree(),
++					   clone_data->path);
++	else
+		clone_data->path = xstrdup(clone_data->path);
+-	}
+
+	if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0)
+		die(_("refusing to create/use '%s' in another submodule's "
+@@ -1813,14 +1812,16 @@ static int clone_submodule(struct module_clone_data *clone_data)
+			die(_("clone of '%s' into submodule path '%s' failed"),
+			    clone_data->url, clone_data->path);
+	} else {
++		char *path;
++
+		if (clone_data->require_init && !access(clone_data->path, X_OK) &&
+		    !is_empty_dir(clone_data->path))
+			die(_("directory not empty: '%s'"), clone_data->path);
+		if (safe_create_leading_directories_const(clone_data->path) < 0)
+			die(_("could not create directory '%s'"), clone_data->path);
+-		strbuf_addf(&sb, "%s/index", sm_gitdir);
+-		unlink_or_warn(sb.buf);
+-		strbuf_reset(&sb);
++		path = xstrfmt("%s/index", sm_gitdir);
++		unlink_or_warn(path);
++		free(path);
+	}
+
+	connect_work_tree_and_git_dir(clone_data->path, sm_gitdir, 0);
+--
+2.40.0
meta/recipes-devtools/git/git/CVE-2024-32002-0002.patch new file +213 -0

213 lines not on this page · raw message

meta/recipes-devtools/git/git/CVE-2024-32002-0003.patch new file +141 -0

141 lines not on this page · raw message

meta/recipes-devtools/git/git/CVE-2024-32002-0004.patch new file +150 -0

150 lines not on this page · raw message

meta/recipes-devtools/git/git/CVE-2024-32004-0001.patch new file +95 -0

95 lines not on this page · raw message

meta/recipes-devtools/git/git/CVE-2024-32004-0002.patch new file +187 -0

187 lines not on this page · raw message

meta/recipes-devtools/git/git/CVE-2024-32004-0003.patch new file +158 -0

158 lines not on this page · raw message

meta/recipes-devtools/git/git/CVE-2024-32020.patch new file +114 -0

114 lines not on this page · raw message

meta/recipes-devtools/git/git/CVE-2024-32021-0001.patch new file +89 -0

89 lines not on this page · raw message

meta/recipes-devtools/git/git/CVE-2024-32021-0002.patch new file +65 -0

65 lines not on this page · raw message

meta/recipes-devtools/git/git/CVE-2024-32465.patch new file +206 -0

206 lines not on this page · raw message

meta/recipes-devtools/git/git_2.35.7.bb +11 -0
index 9e7b0a8cff..94352d38ef 100644
@@ -12,6 +12,17 @@ SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
            file://0001-config.mak.uname-do-not-force-RHEL-7-specific-build-.patch \
            file://CVE-2023-29007.patch \
            file://CVE-2023-25652.patch \
+           file://CVE-2024-32002-0001.patch \
+           file://CVE-2024-32002-0002.patch \
+           file://CVE-2024-32002-0003.patch \
+           file://CVE-2024-32002-0004.patch \
+           file://CVE-2024-32004-0001.patch \
+           file://CVE-2024-32004-0002.patch \
+           file://CVE-2024-32004-0003.patch \
+           file://CVE-2024-32020.patch \
+           file://CVE-2024-32021-0001.patch \
+           file://CVE-2024-32021-0002.patch \
+           file://CVE-2024-32465.patch \
            "
 
 S = "${WORKDIR}/git-${PV}"
Signature · 1 line
2.34.1