Add _lwp_setname, _lwp_getname. Proposed on tech-kern.

This commit is contained in:
ad 2007-11-07 00:37:21 +00:00
parent 172e40df21
commit f1c6cfe4f6
2 changed files with 83 additions and 6 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_lwp.c,v 1.27 2007/11/06 00:42:44 ad Exp $ */
/* $NetBSD: sys_lwp.c,v 1.28 2007/11/07 00:37:23 ad Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.27 2007/11/06 00:42:44 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.28 2007/11/07 00:37:23 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -734,3 +734,78 @@ sys__lwp_unpark_all(struct lwp *l, void *v, register_t *retval)
return 0;
}
int
sys__lwp_setname(struct lwp *l, void *v, register_t *retval)
{
struct sys__lwp_setname_args /* {
syscallarg(lwpid_t) target;
syscallarg(const char *) name;
} */ *uap = v;
char *name, *oname;
proc_t *p;
lwp_t *t;
int error;
name = kmem_alloc(MAXCOMLEN, KM_SLEEP);
if (name == NULL)
return ENOMEM;
error = copyinstr(SCARG(uap, name), name, MAXCOMLEN, NULL);
switch (error) {
case ENAMETOOLONG:
case 0:
name[MAXCOMLEN - 1] = '\0';
break;
default:
kmem_free(name, MAXCOMLEN);
return error;
}
p = curproc;
mutex_enter(&p->p_smutex);
if ((t = lwp_find(p, SCARG(uap, target))) == NULL) {
mutex_exit(&p->p_smutex);
kmem_free(name, MAXCOMLEN);
return ESRCH;
}
lwp_lock(t);
oname = t->l_name;
t->l_name = name;
lwp_unlock(t);
mutex_exit(&p->p_smutex);
if (oname != NULL)
kmem_free(oname, MAXCOMLEN);
return 0;
}
int
sys__lwp_getname(struct lwp *l, void *v, register_t *retval)
{
struct sys__lwp_getname_args /* {
syscallarg(lwpid_t) target;
syscallarg(char *) name;
syscallarg(size_t) len;
} */ *uap = v;
char name[MAXCOMLEN];
proc_t *p;
lwp_t *t;
p = curproc;
mutex_enter(&p->p_smutex);
if ((t = lwp_find(p, SCARG(uap, target))) == NULL) {
mutex_exit(&p->p_smutex);
kmem_free(name, MAXCOMLEN);
return ESRCH;
}
lwp_lock(t);
if (t->l_name == NULL)
name[0] = '\0';
else
strcpy(name, t->l_name);
lwp_unlock(t);
mutex_exit(&p->p_smutex);
return copyoutstr(name, SCARG(uap, name), SCARG(uap, len), NULL);
}

View File

@ -1,4 +1,4 @@
$NetBSD: syscalls.master,v 1.177 2007/09/07 18:56:09 rmind Exp $
$NetBSD: syscalls.master,v 1.178 2007/11/07 00:37:21 ad Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@ -660,9 +660,11 @@
321 STD MPSAFE { int sys__lwp_unpark(lwpid_t target, const void *hint); }
322 STD MPSAFE { ssize_t sys__lwp_unpark_all(const lwpid_t *targets, \
size_t ntargets, const void *hint); }
; Syscalls 323-339 reserved for LWP syscalls.
323 UNIMPL
324 UNIMPL
323 STD { int sys__lwp_setname(lwpid_t target, \
const char *name); }
324 STD { int sys__lwp_getname(lwpid_t target, \
char *name, size_t len); }
; Syscalls 325-339 reserved for LWP syscalls.
325 UNIMPL
326 UNIMPL
327 UNIMPL