Files
@ 052c0cbc4bbf
Branch filter:
Location: vmkdrivers/vmkdrivers/src_9/vmklinux_9/vmware/linux_signal.c
052c0cbc4bbf
12.6 KiB
text/x-csrc
ESXi-5.0-U3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | /* ****************************************************************
* Portions Copyright 2005, 2009, 2010 VMware, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* ****************************************************************/
/*
* VMKLinux supports a subset of the Linux signal-related operations and
* state. We only support signals for kernel threads (no user-level
* signal delivery). We only support pre-RT signals (signals 1 through
* 31). None of the "realtime" (i.e., POSIX signal queuing) signals are
* supported.
*
* Signals may not be ignored. Signals do not have handlers. (Kernel
* threads must explicitly check for pending signals, and flush all
* signals after handling any they are interested in.)
*
* While Linux's existing task_struct is used to store the signal state,
* we don't use much of it. Just the signal masks for pending and blocked
* low-numbered signals (task->pending.signal.sig[0] and
* task->blocked.sig[0]) are used.
*/
#include <linux/list.h>
#include <linux/version.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include "linux_task.h"
#include "linux_stubs.h"
#include "vmklinux_log.h"
#include "vmkapi.h"
/*
* Only support the first 32 signals (none of the queuing or real-time
* signals)
*/
#define LINUX_SIG_MAX 32
/*
*----------------------------------------------------------------------
*
* siginitsetinv --
*
* Initialize all entries in the signal set (we only have 1) to the
* *inverse* of the given mask.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
siginitsetinv(sigset_t *set,
unsigned long mask)
{
struct task_struct *task;
task = get_current();
if (task) {
unsigned long prevIRQL;
LinuxTaskExt *te;
te = container_of(task, LinuxTaskExt, task);
prevIRQL = LinuxTask_Lock(te);
/* Make sure the blocked signals array has only one element */
VMK_ASSERT_ON_COMPILE((sizeof(task->blocked.sig) /
sizeof(task->blocked.sig[0])) == 1);
task->blocked.sig[0] = ~mask;
LinuxTask_Unlock(te, prevIRQL);
}
}
/*
*----------------------------------------------------------------------
*
* LinuxSignalPendingInt --
*
* Same as signal_pending, but signal lock already held
*
* Results:
* 0 if no signals pending on given task, non-zero if any are.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
LinuxSignalPendingInt(const struct task_struct* task)
{
LinuxTask_AssertLocked(container_of(task, LinuxTaskExt, task));
/* Make sure there's only one element in the array of signals */
VMK_ASSERT_ON_COMPILE((sizeof(task->blocked.sig)/
sizeof(task->blocked.sig[0])) == 1);
VMK_ASSERT_ON_COMPILE((sizeof(task->pending.signal.sig)/
sizeof(task->pending.signal.sig)) == 1);
VMKLNX_DEBUG(3, "task=%p pending=%#lx blocked=%#lx",
task, task->pending.signal.sig[0], task->blocked.sig[0]);
return task->pending.signal.sig[0] & ~(task->blocked.sig[0]);
}
/**
* signal_pending - Test if any non-blocked signals are pending
* @task: pointer to struct task_struct
*
* Tests if any non-blocked signals are pending
*
* ESX Deviation Notes:
* @task must be current.
*
* RETURN VALUE:
* Return 0 if no signals are pending on given task,
* non-zero if any.
*/
/* _VMKLNX_CODECHECK_: signal_pending */
int
signal_pending(struct task_struct* task)
{
unsigned long prevIRQL;
LinuxTaskExt *te;
int rval;
VMK_ASSERT(task == current);
VMKLNX_DEBUG(4, "task=%p", task);
te = container_of(task, LinuxTaskExt, task);
prevIRQL = LinuxTask_Lock(te);
rval = LinuxSignalPendingInt(task);
LinuxTask_Unlock(te, prevIRQL);
return rval;
}
EXPORT_SYMBOL(signal_pending);
/*
*----------------------------------------------------------------------
*
* recalc_sigpending --
*
* Refresh signal pending bit in core vmkernel for the current task.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
recalc_sigpending(void)
{
struct task_struct* task = get_current();
unsigned long prevIRQL;
int pending;
LinuxTaskExt *te = container_of(task, LinuxTaskExt, task);
/*
* Since drivers may twiddle .pending or .blocked directly, we'll
* refresh the world-based signal pending bit.
*/
prevIRQL = LinuxTask_Lock(te);
pending = LinuxSignalPendingInt(task);
LinuxTask_Unlock(te, prevIRQL);
VMKLNX_DEBUG(4, "pending=%#x", pending);
}
/*
*----------------------------------------------------------------------
*
* flush_signals --
*
* Mark all signals as handled on given task (must map to current
* world).
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
flush_signals(struct task_struct* task)
{
LinuxTaskExt *te;
unsigned long prevIRQL;
VMK_ASSERT(task != NULL);
VMKLNX_DEBUG(1, "task=%p", task);
// Only on ourselves
VMK_ASSERT(get_current() == task);
te = container_of(task, LinuxTaskExt, task);
/* Ensure there is only 1 entry in the pending signal sig array */
VMK_ASSERT_ON_COMPILE((sizeof(task->pending.signal.sig)/
sizeof(task->pending.signal.sig[0])) == 1);
prevIRQL = LinuxTask_Lock(te);
task->pending.signal.sig[0] = 0;
LinuxTask_Unlock(te, prevIRQL);
}
EXPORT_SYMBOL(flush_signals);
/*
*----------------------------------------------------------------------
*
* block_all_signals --
*
* Unsupported
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
block_all_signals(int (*notifier)(void *priv),
void *priv,
sigset_t *mask)
{
VMKLNX_DEBUG(0, "not implemented. notifier=%p priv=%p mask=...",
notifier, priv);
}
/*
*----------------------------------------------------------------------
*
* unblock_all_signals --
*
* Unsupported.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
unblock_all_signals(void)
{
// Not used by ISCSI, so not implemented.
VMKLNX_DEBUG(0, "not implemented");
}
/*
*----------------------------------------------------------------------
*
* LinuxSignalSendByTask --
*
* Send the given signal to the given task.
*
* Results:
* 0 if signalled, -ESRCH otherwise.
*
* Side effects:
* Signal added to pending mask on target
*
*----------------------------------------------------------------------
*/
static int
LinuxSignalSendByTask(struct task_struct *task,
int sig)
{
LinuxTaskExt *te;
unsigned long prevIRQL;
int p;
VMK_ASSERT(task != NULL);
te = container_of(task, LinuxTaskExt, task);
VMK_ASSERT(LinuxTask_ValidTask(te) == VMK_TRUE);
prevIRQL = LinuxTask_Lock(te);
// Subtract 1 because signal 0 isn't valid, but bit 0 is
task->pending.signal.sig[0] |= (1UL << (sig - 1));
p = LinuxSignalPendingInt(task);
LinuxTask_Unlock(te, prevIRQL);
if (p != 0
&& (task->state == TASK_INTERRUPTIBLE)
&& (te->flags & LT_SUSPENDED)) {
/*
* Wake up task since the signal is not blocked and the task is
* suspended.
*/
LinuxTask_Resume(te);
}
return 0;
}
/*
*----------------------------------------------------------------------
*
* kill_proc --
*
* Send given signal to given pid. fromKernel must be 1.
*
* Results:
* 0 on OK, -<errno> on error
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
kill_proc(pid_t pid,
int sig,
int fromKernel) // sent by kernel or kernel-thread. Ignored.
{
LinuxTaskExt *te;
int status;
VMK_ASSERT(pid);
VMK_ASSERT(fromKernel == 1);
VMK_ASSERT(sig > 0);
VMK_ASSERT(sig < LINUX_SIG_MAX);
VMKLNX_DEBUG(0, "pid=%d, sig=%d", pid, sig);
if (unlikely(pid < 0)) {
VMKLNX_WARN("World %d tried to signal invalid pid (%d)...",
vmk_WorldGetID(), pid);
return -ESRCH;
}
te = LinuxTask_Find(pid);
if (unlikely(te == NULL)) {
VMKLNX_WARN("World %d tried to signal non-existing pid (%d)...",
vmk_WorldGetID(), pid);
return -ESRCH;
}
status = LinuxSignalSendByTask(&te->task, sig);
LinuxTask_Release(te);
return status;
}
/*
*----------------------------------------------------------------------
*
* kill_proc_info_as_uid --
*
* Send given signal to given pid.
*
* Results:
* 0 on OK, -<errno> on error
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
kill_proc_info_as_uid(int signum,
struct siginfo *sinfo,
pid_t pid,
uid_t uid,
uid_t euid,
u32 secid)
{
VMK_ASSERT(signum > 0);
VMK_ASSERT(signum < LINUX_SIG_MAX);
VMK_ASSERT(!uid);
VMK_ASSERT(!euid);
VMKLNX_DEBUG(0, "kill_proc_info_as_uid with signum=%d, "
"1st 8 bytes of siginfo=%llx, pid=%d",
signum,
*(unsigned long long *)sinfo, pid);
return kill_proc(pid, signum, 1);
}
EXPORT_SYMBOL(kill_proc_info_as_uid);
/*
*----------------------------------------------------------------------
*
* send_sig --
*
* Results:
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
send_sig(int signum,
struct task_struct *task,
int fromKernel)
{
VMK_ASSERT(signum > 0);
VMK_ASSERT(signum < LINUX_SIG_MAX);
VMK_ASSERT(fromKernel == 1);
return LinuxSignalSendByTask(task, signum);
}
EXPORT_SYMBOL(send_sig);
/*
*----------------------------------------------------------------------
*
* send_sig_info --
*
* Results:
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
send_sig_info(int signum,
struct siginfo *sinfo,
struct task_struct *task)
{
VMK_ASSERT(signum > 0);
VMK_ASSERT(signum < LINUX_SIG_MAX);
return LinuxSignalSendByTask(task, signum);
}
/**
* fasync_helper - Initialize an fasync_struct
* @fd: ignored
* @filep: ignored
* @on: ignored
* @fapp: ignored
*
* NOTE:
* This function is currently unsupported. This is a
* nonfunctional stub only. For notifications to user-space
* applications from character devices, use poll() instead.
*
* ESX Deviation Notes:
* This function is a placeholder only and does nothing.
*
* RETURN VALUES:
* 0 for success,
* -EFAULT if the given fapp is NULL
*/
/* _VMKLNX_CODECHECK_: fasync_helper */
int
fasync_helper(int fd, struct file *filep, int on, struct fasync_struct **fapp)
{
/*
* On Linux, this function saves the fd and filep in an fsync_struct
* and enqueues the struct in a linked list. This function is
* unsupported on vmklinux, however.
*/
if (fapp == NULL)
return -EFAULT;
return 0;
}
EXPORT_SYMBOL(fasync_helper);
/**
* kill_fasync - Send an fasync signal on behalf of a device
* @fapp: ignored
* @sig: ignored
* @band: ignored
*
* NOTE:
* This function is currently unsupported. This is a
* nonfunctional stub only. For notifications to user-space
* applications from character devices, use poll() instead.
*
* ESX Deviation Notes:
* This function is a placeholder only and does nothing.
*
* RETURN VALUE:
* This function does not return a value.
*/
/* _VMKLNX_CODECHECK_: kill_fasync */
void
kill_fasync(struct fasync_struct **fapp, int sig, int band)
{
return;
}
EXPORT_SYMBOL(kill_fasync);
|