From: Ben Gras Date: Tue, 27 Jun 2006 12:19:45 +0000 (+0000) Subject: Add a flag to grants system indicating a slot is VALID; so a slot X-Git-Tag: v3.1.3~283 X-Git-Url: http://zhaoyanbai.com/repos/icons/debian/static/doxygen.log?a=commitdiff_plain;h=607fb6bf7ff8279b2cce75f817679c8e25b01ffb;p=minix.git Add a flag to grants system indicating a slot is VALID; so a slot can be reserved (USED), while toggling VALID on and off. --- diff --git a/include/minix/safecopies.h b/include/minix/safecopies.h index 083c7d979..53366e1d2 100644 --- a/include/minix/safecopies.h +++ b/include/minix/safecopies.h @@ -62,6 +62,7 @@ struct vscp_vec { #define CPF_DIRECT 0x000200 /* Grant from this process to another. */ #define CPF_INDIRECT 0x000400 /* Grant from grant to another. */ #define CPF_MAGIC 0x000800 /* Grant from any to any. */ +#define CPF_VALID 0x001000 /* Grant slot contains valid grant. */ /* Prototypes for functions in libsys. */ _PROTOTYPE( cp_grant_id_t cpf_grant_direct, (endpoint_t, vir_bytes, size_t, int)); @@ -78,6 +79,7 @@ _PROTOTYPE( int cpf_setgrant_indirect, (cp_grant_id_t g, endpoint_t who_to, endpoint_t who_from, cp_grant_id_t his_g)); _PROTOTYPE( int cpf_setgrant_magic, (cp_grant_id_t g, endpoint_t who_to, endpoint_t who_from, vir_bytes addr, size_t bytes, int access)); +_PROTOTYPE( int cpf_setgrant_disable, (cp_grant_id_t grant_id)); /* Set a process' grant table location and size (in-kernel only). */ #define _K_SET_GRANT_TABLE(rp, ptr, entries) \ diff --git a/kernel/system/do_safecopy.c b/kernel/system/do_safecopy.c index 0d46a96fa..41e3a7968 100644 --- a/kernel/system/do_safecopy.c +++ b/kernel/system/do_safecopy.c @@ -90,8 +90,8 @@ endpoint_t *e_granter; /* new granter (magic grants) */ phys_copy(phys_grant, vir2phys(&g), sizeof(g)); /* Check validity. */ - if(!(g.cp_flags & CPF_USED)) { - kprintf("grant verify failed: invalid\n"); + if((g.cp_flags & (CPF_USED | CPF_VALID)) != (CPF_USED | CPF_VALID)) { + kprintf("grant verify failed: unused or invalid\n"); return EPERM; } diff --git a/lib/syslib/safecopies.c b/lib/syslib/safecopies.c index af46c3197..d9edea8fa 100644 --- a/lib/syslib/safecopies.c +++ b/lib/syslib/safecopies.c @@ -305,7 +305,7 @@ int access; GID_CHECK(gid); ACCESS_CHECK(access); - grants[gid].cp_flags = access | CPF_DIRECT | CPF_USED; + grants[gid].cp_flags = access | CPF_DIRECT | CPF_USED | CPF_VALID; grants[gid].cp_u.cp_direct.cp_who_to = who; grants[gid].cp_u.cp_direct.cp_start = addr; grants[gid].cp_u.cp_direct.cp_len = bytes; @@ -322,7 +322,7 @@ cp_grant_id_t his_gid; GID_CHECK(gid); /* Fill in new slot data. */ - grants[gid].cp_flags = CPF_USED | CPF_INDIRECT; + grants[gid].cp_flags = CPF_USED | CPF_INDIRECT | CPF_VALID; grants[gid].cp_u.cp_indirect.cp_who_to = who_to; grants[gid].cp_u.cp_indirect.cp_who_from = who_from; grants[gid].cp_u.cp_indirect.cp_grant = his_gid; @@ -342,7 +342,7 @@ int access; ACCESS_CHECK(access); /* Fill in new slot data. */ - grants[gid].cp_flags = CPF_USED | CPF_MAGIC | access; + grants[gid].cp_flags = CPF_USED | CPF_MAGIC | CPF_VALID | access; grants[gid].cp_u.cp_magic.cp_who_to = who_to; grants[gid].cp_u.cp_magic.cp_who_from = who_from; grants[gid].cp_u.cp_magic.cp_start = addr; @@ -351,3 +351,15 @@ int access; return 0; } +PUBLIC int +cpf_setgrant_disable(gid) +cp_grant_id_t gid; +{ + GID_CHECK(gid); + + /* Grant is now no longer valid, but still in use. */ + grants[gid].cp_flags = CPF_USED; + + return 0; +} +