FreeBSD/sys/ddb/db_capture.c
/*
 * Run-time adjustment of the capture buffer.
 */
Run-time adjustment of the capture buffer.
Run - time adjustment of the capture buffer .
static int
sysctl_debug_ddb_capture_bufsize(SYSCTL_HANDLER_ARGS)
{
	u_int len, size;
	char *buf;
	int error;
	size = db_capture_bufsize;
	error = sysctl_handle_int(oidp, &size, 0, req);
	if (error || req->newptr == NULL)
		return (error);
	size = roundup(size, TEXTDUMP_BLOCKSIZE);
	if (size > db_capture_maxbufsize)
		return (EINVAL);
	sx_xlock(&db_capture_sx);
	if (size != 0) {
		buf = malloc(size, M_DDB_CAPTURE, M_NOWAIT);
		if (buf == NULL) {
			sx_xunlock(&db_capture_sx);
			return (ENOMEM);
		}
		len = min(db_capture_bufoff, size);
	} else {
		buf = NULL;
		len = 0;
	}
	if (db_capture_buf != NULL && buf != NULL)
		bcopy(db_capture_buf, buf, len);
	if (db_capture_buf != NULL)
		free(db_capture_buf, M_DDB_CAPTURE);
	db_capture_bufoff = len;
	db_capture_buf = buf;
	db_capture_bufsize = size;
	sx_xunlock(&db_capture_sx);
	KASSERT(db_capture_bufoff <= db_capture_bufsize,
	    ("sysctl_debug_ddb_capture_bufsize: bufoff > bufsize"));
	KASSERT(db_capture_bufsize <= db_capture_maxbufsize,
	    ("sysctl_debug_ddb_capture_maxbufsize: bufsize > maxbufsize"));
	return (0);
}
static int sysctl_debug_ddb_capture_bufsize ( SYSCTL_HANDLER_ARGS ) { u_int len , size ; char * buf ; int error ; size = db_capture_bufsize ; error = sysctl_handle_int ( oidp , & size , 0 , req ) ; if ( error || req -> newptr == NULL ) return ( error ) ; size = roundup ( size , TEXTDUMP_BLOCKSIZE ) ; if ( size > db_capture_maxbufsize ) return ( EINVAL ) ; sx_xlock ( & db_capture_sx ) ; if ( size != 0 ) { buf = malloc ( size , M_DDB_CAPTURE , M_NOWAIT ) ; if ( buf == NULL ) { sx_xunlock ( & db_capture_sx ) ; return ( ENOMEM ) ; } len = min ( db_capture_bufoff , size ) ; } else { buf = NULL ; len = 0 ; } if ( db_capture_buf != NULL && buf != NULL ) bcopy ( db_capture_buf , buf , len ) ; if ( db_capture_buf != NULL ) free ( db_capture_buf , M_DDB_CAPTURE ) ; db_capture_bufoff = len ; db_capture_buf = buf ; db_capture_bufsize = size ; sx_xunlock ( & db_capture_sx ) ; KASSERT ( db_capture_bufoff <= db_capture_bufsize , ( " " ) ) ; KASSERT ( db_capture_bufsize <= db_capture_maxbufsize , ( " " ) ) ; return ( 0 ) ; }
Run-time adjustment of the capture buffer.
Run - time adjustment of the capture buffer .
/*
		 * Potentially the buffer is quite large, so if we can't
		 * allocate it, fail rather than waiting.
		 */