From: Kees van Reeuwijk Date: Tue, 2 Mar 2010 23:12:13 +0000 (+0000) Subject: More correctly use cp_grant_id_t. X-Git-Tag: v3.1.7~262 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.dnssec-coverage.html?a=commitdiff_plain;h=bf7397b64efaabb7c4fde95e26b2c99cc36e4b0e;p=minix.git More correctly use cp_grant_id_t. More correctly use vir_bytes. More correctly use endpoint_t. --- diff --git a/include/minix/com.h b/include/minix/com.h index 8ff463d48..e9674d7c0 100644 --- a/include/minix/com.h +++ b/include/minix/com.h @@ -32,9 +32,9 @@ *===========================================================================*/ /* These may not be any valid endpoint (see ). */ -#define ANY 0x7ace /* used to indicate 'any process' */ -#define NONE 0x6ace /* used to indicate 'no process at all' */ -#define SELF 0x8ace /* used to indicate 'own process' */ +#define ANY ((endpoint_t) 0x7ace) /* used to indicate 'any process' */ +#define NONE ((endpoint_t) 0x6ace) /* used to indicate 'no process at all' */ +#define SELF ((endpoint_t) 0x8ace) /* used to indicate 'own process' */ #define _MAX_MAGIC_PROC (SELF) /* used by to determine generation size */ @@ -50,10 +50,10 @@ */ /* Kernel tasks. These all run in the same address space. */ -#define IDLE -4 /* runs when no one else can run */ -#define CLOCK -3 /* alarms and other clock functions */ -#define SYSTEM -2 /* request system functionality */ -#define KERNEL -1 /* pseudo-process for IPC and scheduling */ +#define IDLE ((endpoint_t) -4) /* runs when no one else can run */ +#define CLOCK ((endpoint_t) -3) /* alarms and other clock functions */ +#define SYSTEM ((endpoint_t) -2) /* request system functionality */ +#define KERNEL ((endpoint_t) -1) /* pseudo-process for IPC and scheduling */ #define HARDWARE KERNEL /* for hardware interrupt handlers */ /* Number of tasks. Note that NR_PROCS is defined in . */ @@ -61,25 +61,28 @@ #define NR_TASKS 4 /* User-space processes, that is, device drivers, servers, and INIT. */ -#define PM_PROC_NR 0 /* process manager */ -#define FS_PROC_NR 1 /* file system */ +#define PM_PROC_NR ((endpoint_t) 0) /* process manager */ +#define FS_PROC_NR ((endpoint_t) 1) /* file system */ #define VFS_PROC_NR FS_PROC_NR /* FS has been renamed to VFS. */ -#define RS_PROC_NR 2 /* reincarnation server */ -#define MEM_PROC_NR 3 /* memory driver (RAM disk, null, etc.) */ -#define LOG_PROC_NR 4 /* log device driver */ -#define TTY_PROC_NR 5 /* terminal (TTY) driver */ -#define DS_PROC_NR 6 /* data store server */ -#define MFS_PROC_NR 7 /* minix root filesystem */ -#define VM_PROC_NR 8 /* memory server */ -#define PFS_PROC_NR 9 /* pipe filesystem */ -#define INIT_PROC_NR 10 /* init -- goes multiuser */ +#define RS_PROC_NR ((endpoint_t) 2) /* reincarnation server */ +#define MEM_PROC_NR ((endpoint_t) 3) /* memory driver (RAM disk, null, etc.) */ +#define LOG_PROC_NR ((endpoint_t) 4) /* log device driver */ +#define TTY_PROC_NR ((endpoint_t) 5) /* terminal (TTY) driver */ +#define DS_PROC_NR ((endpoint_t) 6) /* data store server */ +#define MFS_PROC_NR ((endpoint_t) 7) /* minix root filesystem */ +#define VM_PROC_NR ((endpoint_t) 8) /* memory server */ +#define PFS_PROC_NR ((endpoint_t) 9) /* pipe filesystem */ +#define LAST_SPECIAL_PROC_NR 10 /* An untyped version for + computation in macros.*/ +#define INIT_PROC_NR ((endpoint_t) LAST_SPECIAL_PROC_NR) /* init + -- goes multiuser */ /* Root system process and root user process. */ #define ROOT_SYS_PROC_NR RS_PROC_NR #define ROOT_USR_PROC_NR INIT_PROC_NR /* Number of processes contained in the system image. */ -#define NR_BOOT_PROCS (NR_TASKS + INIT_PROC_NR + 1) +#define NR_BOOT_PROCS (NR_TASKS + LAST_SPECIAL_PROC_NR + 1) /*===========================================================================* * Kernel notification types * diff --git a/include/minix/safecopies.h b/include/minix/safecopies.h index 50b8623d7..477811414 100644 --- a/include/minix/safecopies.h +++ b/include/minix/safecopies.h @@ -57,7 +57,7 @@ struct vscp_vec { #define VMPTYPE_SUNMAP 4 /* Invalid grant number. */ -#define GRANT_INVALID -1 +#define GRANT_INVALID ((cp_grant_id_t) -1) #define GRANT_VALID(g) ((g) > GRANT_INVALID) /* Operations: any combination is ok. */ diff --git a/include/minix/sef.h b/include/minix/sef.h index df82afaad..7c07adf07 100644 --- a/include/minix/sef.h +++ b/include/minix/sef.h @@ -25,7 +25,7 @@ _PROTOTYPE( int sef_receive, (endpoint_t src, message *m_ptr) ); /* Type definitions. */ typedef struct { - int rproctab_gid; + cp_grant_id_t rproctab_gid; } sef_init_info_t; /* Callback type definitions. */ diff --git a/kernel/arch/i386/do_sdevio.c b/kernel/arch/i386/do_sdevio.c index 774cd3a8c..090b800ce 100644 --- a/kernel/arch/i386/do_sdevio.c +++ b/kernel/arch/i386/do_sdevio.c @@ -67,7 +67,7 @@ PUBLIC int do_sdevio(struct proc * caller, message *m_ptr) if((m_ptr->DIO_REQUEST & _DIO_SAFEMASK) == _DIO_SAFE) { /* Map grant address to physical address. */ if(verify_grant(proc_nr_e, caller->p_endpoint, - (vir_bytes) m_ptr->DIO_VEC_ADDR, + (cp_grant_id_t) m_ptr->DIO_VEC_ADDR, count, req_dir == _DIO_INPUT ? CPF_WRITE : CPF_READ, (vir_bytes) m_ptr->DIO_OFFSET, diff --git a/kernel/arch/i386/memory.c b/kernel/arch/i386/memory.c index 19bfb8d09..ac029776d 100644 --- a/kernel/arch/i386/memory.c +++ b/kernel/arch/i386/memory.c @@ -401,7 +401,7 @@ vir_bytes bytes; /* # of bytes to be copied */ u32_t phys = 0; if(seg == MEM_GRANT) { - return umap_grant(rp, vir_addr, bytes); + return umap_grant(rp, (cp_grant_id_t) vir_addr, bytes); } if(!(linear = umap_local(rp, seg, vir_addr, bytes))) { diff --git a/kernel/system/do_safecopy.c b/kernel/system/do_safecopy.c index ffb1613c4..e2bfb1d09 100644 --- a/kernel/system/do_safecopy.c +++ b/kernel/system/do_safecopy.c @@ -53,9 +53,14 @@ endpoint_t *e_granter; /* new granter (magic grants) */ /* Get granter process slot (if valid), and check range of * grant id. */ - if(!isokendpt(granter, &proc_nr) || !GRANT_VALID(grant)) { + if(!isokendpt(granter, &proc_nr) ) { kprintf( - "grant verify failed: invalid granter or grant\n"); + "grant verify failed: invalid granter %d\n", (int) granter); + return(EINVAL); + } + if(!GRANT_VALID(grant)) { + kprintf( + "grant verify failed: invalid grant %d\n", (int) grant); return(EINVAL); } granter_proc = proc_addr(proc_nr); @@ -348,8 +353,9 @@ PUBLIC int do_safecopy(struct proc * caller, message * m_ptr) } else minix_panic("Impossible system call nr. ", m_ptr->m_type); return safecopy(caller, m_ptr->SCP_FROM_TO, caller->p_endpoint, - m_ptr->SCP_GID, src_seg, dst_seg, m_ptr->SCP_BYTES, - m_ptr->SCP_OFFSET, (vir_bytes) m_ptr->SCP_ADDRESS, access); + (cp_grant_id_t) m_ptr->SCP_GID, src_seg, dst_seg, + m_ptr->SCP_BYTES, m_ptr->SCP_OFFSET, + (vir_bytes) m_ptr->SCP_ADDRESS, access); } /*===========================================================================* diff --git a/kernel/system/do_safemap.c b/kernel/system/do_safemap.c index c58011f7e..65629968b 100644 --- a/kernel/system/do_safemap.c +++ b/kernel/system/do_safemap.c @@ -22,7 +22,7 @@ struct map_info_s { /* Grantor. */ endpoint_t grantor; - int gid; + cp_grant_id_t gid; vir_bytes offset; vir_bytes address_Dseg; /* seg always is D */ @@ -41,7 +41,7 @@ static struct map_info_s map_info[MAX_MAP_INFO]; /*===========================================================================* * add_info * *===========================================================================*/ -static int add_info(endpoint_t grantor, endpoint_t grantee, int gid, +static int add_info(endpoint_t grantor, endpoint_t grantee, cp_grant_id_t gid, vir_bytes offset, vir_bytes address_Dseg, int seg, vir_bytes address, vir_bytes bytes) { @@ -105,11 +105,9 @@ static struct map_info_s *get_unmap_info(endpoint_t grantee, int seg, /*===========================================================================* * clear_info * *===========================================================================*/ -static int clear_info(struct map_info_s *p) +static void clear_info(struct map_info_s *p) { p->flag = 0; - - return 0; } /*===========================================================================* @@ -173,7 +171,7 @@ PUBLIC int map_invoke_vm(struct proc * caller, PUBLIC int do_safemap(struct proc * caller, message * m_ptr) { endpoint_t grantor = m_ptr->SMAP_EP; - cp_grant_id_t gid = m_ptr->SMAP_GID; + cp_grant_id_t gid = (cp_grant_id_t) m_ptr->SMAP_GID; vir_bytes offset = (vir_bytes) m_ptr->SMAP_OFFSET; int seg = (int) m_ptr->SMAP_SEG; vir_bytes address = (vir_bytes) m_ptr->SMAP_ADDRESS; @@ -267,7 +265,7 @@ PUBLIC int do_saferevmap(struct proc * caller, message * m_ptr) *===========================================================================*/ PUBLIC int do_safeunmap(struct proc * caller, message * m_ptr) { - vir_bytes address = m_ptr->SMAP_ADDRESS; + vir_bytes address = (vir_bytes) m_ptr->SMAP_ADDRESS; int seg = (int)m_ptr->SMAP_SEG; struct map_info_s *p; int r; diff --git a/kernel/system/do_umap.c b/kernel/system/do_umap.c index bd245ee9c..6638c2339 100644 --- a/kernel/system/do_umap.c +++ b/kernel/system/do_umap.c @@ -56,10 +56,12 @@ PUBLIC int do_umap(struct proc * caller, message * m_ptr) vir_bytes newoffset; endpoint_t newep; int new_proc_nr; + cp_grant_id_t grant = (cp_grant_id_t) offset; - if(verify_grant(targetpr->p_endpoint, ANY, offset, count, 0, 0, + if(verify_grant(targetpr->p_endpoint, ANY, grant, count, 0, 0, &newoffset, &newep) != OK) { - kprintf("SYSTEM: do_umap: verify_grant in %s, grant %d, bytes 0x%lx, failed, caller %s\n", targetpr->p_name, offset, count, caller->p_name); + kprintf("SYSTEM: do_umap: verify_grant in %s, grant %d, bytes 0x%lx, failed, caller %s\n", + targetpr->p_name, (int) grant, count, caller->p_name); proc_stacktrace(caller); return EFAULT; } diff --git a/servers/ds/store.c b/servers/ds/store.c index fdd185ac9..17e893d5c 100644 --- a/servers/ds/store.c +++ b/servers/ds/store.c @@ -342,8 +342,8 @@ PUBLIC int do_publish(message *m_ptr) } /* Copy the memory range. */ - r = sys_safecopyfrom(m_ptr->m_source, m_ptr->DS_VAL, 0, - (vir_bytes) dsp->u.mem.data, length, D); + r = sys_safecopyfrom(m_ptr->m_source, (cp_grant_id_t) m_ptr->DS_VAL, + 0, (vir_bytes) dsp->u.mem.data, length, D); if(r != OK) { printf("DS: publish: memory map/copy failed from %d: %d\n", m_ptr->m_source, r); @@ -360,7 +360,7 @@ PUBLIC int do_publish(message *m_ptr) dsp->u.map.data = (void*) CLICK_CEIL(dsp->u.map.realpointer); /* Map memory. */ - r = sys_safemap(m_ptr->m_source, m_ptr->DS_VAL, 0, + r = sys_safemap(m_ptr->m_source, (cp_grant_id_t) m_ptr->DS_VAL, 0, (vir_bytes) dsp->u.map.data, length, D, 0); if(r != OK) { printf("DS: publish: memory map/copy failed from %d: %d\n", @@ -420,7 +420,7 @@ PUBLIC int do_retrieve(message *m_ptr) break; case DSF_TYPE_MEM: length = MIN(m_ptr->DS_VAL_LEN, dsp->u.mem.length); - r = sys_safecopyto(m_ptr->m_source, m_ptr->DS_VAL, 0, + r = sys_safecopyto(m_ptr->m_source, (cp_grant_id_t) m_ptr->DS_VAL, 0, (vir_bytes) dsp->u.mem.data, length, D); if(r != OK) { printf("DS: retrieve: copy failed to %d: %d\n", @@ -458,7 +458,8 @@ PUBLIC int do_retrieve(message *m_ptr) } length = MIN(m_ptr->DS_VAL_LEN, dsp->u.map.length); - r = sys_safecopyto(m_ptr->m_source, m_ptr->DS_VAL, 0, + r = sys_safecopyto(m_ptr->m_source, + (cp_grant_id_t) m_ptr->DS_VAL, (vir_bytes) 0, (vir_bytes) data, length, D); if(r != OK) { printf("DS: retrieve: copy failed to %d: %d\n", @@ -492,7 +493,7 @@ PUBLIC int do_retrieve_label(message *m_ptr) /* Copy the key name. */ r = sys_safecopyto(m_ptr->m_source, - (cp_grant_id_t) m_ptr->DS_KEY_GRANT, 0, + (cp_grant_id_t) m_ptr->DS_KEY_GRANT, (vir_bytes) 0, (vir_bytes) dsp->key, strlen(dsp->key) + 1, D); if(r != OK) { printf("DS: copy failed from %d: %d\n", m_ptr->m_source, r); @@ -607,7 +608,7 @@ PUBLIC int do_check(message *m_ptr) /* Copy the key name. */ r = sys_safecopyto(m_ptr->m_source, - (cp_grant_id_t) m_ptr->DS_KEY_GRANT, 0, + (cp_grant_id_t) m_ptr->DS_KEY_GRANT, (vir_bytes) 0, (vir_bytes) ds_store[i].key, strlen(ds_store[i].key), D); if(r != OK) { printf("DS: check: copy failed from %d: %d\n", m_ptr->m_source, r);