Grant system dynamic-only.
This commit is contained in:
parent
b654c02f55
commit
1561067ee4
10 changed files with 33 additions and 78 deletions
|
@ -21,7 +21,7 @@ OBJ = main.o pci.o pci_table.o
|
|||
all build: $(DRIVER)
|
||||
$(DRIVER): $(OBJ)
|
||||
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
|
||||
install -S 4096 $(DRIVER)
|
||||
install -S 16k $(DRIVER)
|
||||
|
||||
# install with other drivers
|
||||
install: /usr/sbin/$(DRIVER)
|
||||
|
|
|
@ -212,6 +212,7 @@ PUBLIC void main(void)
|
|||
continue;
|
||||
}
|
||||
case DIAGNOSTICS: /* a server wants to print some */
|
||||
printf("WARNING: old DIAGNOSTICS from %d\n", tty_mess.m_source);
|
||||
do_diagnostics(&tty_mess, 0);
|
||||
continue;
|
||||
case DIAGNOSTICS_S:
|
||||
|
|
|
@ -69,7 +69,6 @@ _PROTOTYPE( cp_grant_id_t cpf_grant_direct, (endpoint_t, vir_bytes, size_t, int)
|
|||
_PROTOTYPE( cp_grant_id_t cpf_grant_indirect, (endpoint_t, endpoint_t, cp_grant_id_t));
|
||||
_PROTOTYPE( cp_grant_id_t cpf_grant_magic, (endpoint_t, endpoint_t, vir_bytes, size_t, int));
|
||||
_PROTOTYPE( int cpf_revoke, (cp_grant_id_t grant_id));
|
||||
_PROTOTYPE( int cpf_preallocate, (cp_grant_t *, int));
|
||||
_PROTOTYPE( int cpf_lookup, (cp_grant_id_t g, endpoint_t *ep, endpoint_t *ep2));
|
||||
|
||||
_PROTOTYPE( int cpf_getgrants, (cp_grant_id_t *grant_ids, int n));
|
||||
|
|
|
@ -6,6 +6,7 @@ LIBRARIES=libc
|
|||
|
||||
libc_FILES=" \
|
||||
_brk.c \
|
||||
_sbrk.c \
|
||||
_devctl.c \
|
||||
__pm_findproc.c \
|
||||
_getnpid.c \
|
||||
|
|
|
@ -27,18 +27,3 @@ char *addr;
|
|||
return(0);
|
||||
}
|
||||
|
||||
|
||||
PUBLIC char *sbrk(incr)
|
||||
int incr;
|
||||
{
|
||||
char *newsize, *oldsize;
|
||||
|
||||
oldsize = _brksize;
|
||||
newsize = _brksize + incr;
|
||||
if ((incr > 0 && newsize < oldsize) || (incr < 0 && newsize > oldsize))
|
||||
return( (char *) -1);
|
||||
if (brk(newsize) == 0)
|
||||
return(oldsize);
|
||||
else
|
||||
return( (char *) -1);
|
||||
}
|
||||
|
|
20
lib/other/_sbrk.c
Executable file
20
lib/other/_sbrk.c
Executable file
|
@ -0,0 +1,20 @@
|
|||
#include <lib.h>
|
||||
#define sbrk _sbrk
|
||||
#include <unistd.h>
|
||||
|
||||
extern char *_brksize;
|
||||
|
||||
PUBLIC char *sbrk(incr)
|
||||
int incr;
|
||||
{
|
||||
char *newsize, *oldsize;
|
||||
|
||||
oldsize = _brksize;
|
||||
newsize = _brksize + incr;
|
||||
if ((incr > 0 && newsize < oldsize) || (incr < 0 && newsize > oldsize))
|
||||
return( (char *) -1);
|
||||
if (brk(newsize) == 0)
|
||||
return(oldsize);
|
||||
else
|
||||
return( (char *) -1);
|
||||
}
|
|
@ -38,54 +38,16 @@
|
|||
}
|
||||
|
||||
PRIVATE cp_grant_t *grants = NULL;
|
||||
PRIVATE int ngrants = 0, dynamic = 1;
|
||||
|
||||
PUBLIC int
|
||||
cpf_preallocate(cp_grant_t *new_grants, int new_ngrants)
|
||||
{
|
||||
/* Use a statically allocated block of grants as our grant table.
|
||||
* This means we can't grow it dynamically any more.
|
||||
*
|
||||
* This function is used in processes that can't safely call realloc().
|
||||
*/
|
||||
int s;
|
||||
|
||||
/* If any table is already in place, we can't change it. */
|
||||
if(ngrants > 0) {
|
||||
errno = EBUSY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Update kernel about the table. */
|
||||
if((s=sys_setgrant(new_grants, new_ngrants))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Update internal data. dynamic = 0 means no realloc()ing will be done
|
||||
* and we can't grow beyond this size.
|
||||
*/
|
||||
grants = new_grants;
|
||||
ngrants = new_ngrants;
|
||||
dynamic = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
PRIVATE int ngrants = 0;
|
||||
|
||||
PRIVATE void
|
||||
cpf_grow(void)
|
||||
{
|
||||
/* Grow the grants table if possible. If a preallocated block has been
|
||||
* submitted ('dynamic' is clear), we can't grow it. Otherwise, realloc().
|
||||
* Caller is expected to check 'ngrants' to see if the call was successful.
|
||||
*/
|
||||
/* Grow the grants table if possible. */
|
||||
cp_grant_t *new_grants;
|
||||
cp_grant_id_t g;
|
||||
int new_size;
|
||||
|
||||
/* Can't grow if static block already assigned. */
|
||||
if(!dynamic)
|
||||
return;
|
||||
|
||||
new_size = (1+ngrants)*2;
|
||||
assert(new_size > ngrants);
|
||||
|
||||
|
|
|
@ -25,21 +25,24 @@ int c;
|
|||
#define PRINTPROCS (sizeof(procs)/sizeof(procs[0]))
|
||||
int procs[] = OUTPUT_PROCS_ARRAY;
|
||||
static int firstprint = 1;
|
||||
static cp_grant_t printgrant_buffer[PRINTPROCS];
|
||||
static cp_grant_id_t printgrants[PRINTPROCS];
|
||||
int p;
|
||||
|
||||
if(firstprint) {
|
||||
for(p = 0; procs[p] != NONE; p++) {
|
||||
printgrants[p] = GRANT_INVALID;
|
||||
}
|
||||
|
||||
firstprint = 0;
|
||||
|
||||
/* First time? Initialize grant table;
|
||||
* Grant printing processes read copy access to our
|
||||
* print buffer. (So buffer can't be on stack!)
|
||||
* print buffer forever. (So buffer can't be on stack!)
|
||||
*/
|
||||
cpf_preallocate(printgrant_buffer, PRINTPROCS);
|
||||
for(p = 0; procs[p] != NONE; p++) {
|
||||
printgrants[p] = cpf_grant_direct(procs[p], print_buf,
|
||||
sizeof(print_buf), CPF_READ);
|
||||
}
|
||||
firstprint = 0;
|
||||
}
|
||||
|
||||
for(p = 0; procs[p] != NONE; p++) {
|
||||
|
|
|
@ -22,7 +22,7 @@ OBJ = main.o open.o read.o write.o pipe.o dmap.o \
|
|||
install all build: $(SERVER)
|
||||
$(SERVER): $(OBJ)
|
||||
$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
|
||||
install -S 1024w $@
|
||||
install -S 16k $@
|
||||
|
||||
# clean up local files
|
||||
clean:
|
||||
|
|
|
@ -225,22 +225,6 @@ PRIVATE void fs_init()
|
|||
message mess;
|
||||
int s;
|
||||
|
||||
/* Maximum number of outstanding grants is one full i/o
|
||||
* vector, and all processes hanging on SUSPENDed i/o, and
|
||||
* grants for printf() to tty and log.
|
||||
*
|
||||
* Space is declared for it here, and cpf_preallocate()
|
||||
* uses it internally and internally tells the kernel
|
||||
* about it. FS then never touches the data again directly,
|
||||
* only through the cpf_* library routines.
|
||||
*/
|
||||
#define NGRANTS (NR_PROCS + NR_IOREQS + 10)
|
||||
static cp_grant_t grants[NGRANTS];
|
||||
|
||||
/* Set data copy grant table, as FS can't allocate it dynamically. */
|
||||
if(cpf_preallocate(grants, NGRANTS) != OK)
|
||||
panic(__FILE__,"cpf_preallocate failed", NO_NUM);
|
||||
|
||||
/* Initialize the process table with help of the process manager messages.
|
||||
* Expect one message for each system process with its slot number and pid.
|
||||
* When no more processes follow, the magic process number NONE is sent.
|
||||
|
|
Loading…
Reference in a new issue