kern_proc.c (65dcb5bcb1993631f47d8acc207904411e135758) kern_proc.c (e6b95927f39018d10fcfc39f8236525c72b84d06)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 2238 unchanged lines hidden (view full) ---

2247 }
2248 PA_UNLOCK_COND(locked_pa);
2249}
2250
2251/*
2252 * Must be called with the process locked and will return unlocked.
2253 */
2254int
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 2238 unchanged lines hidden (view full) ---

2247 }
2248 PA_UNLOCK_COND(locked_pa);
2249}
2250
2251/*
2252 * Must be called with the process locked and will return unlocked.
2253 */
2254int
2255kern_proc_vmmap_out(struct proc *p, struct sbuf *sb)
2255kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags)
2256{
2257 vm_map_entry_t entry, tmp_entry;
2258 struct vattr va;
2259 vm_map_t map;
2260 vm_object_t obj, tobj, lobj;
2261 char *fullpath, *freepath;
2262 struct kinfo_vmentry *kve;
2263 struct ucred *cred;

--- 7 unchanged lines hidden (view full) ---

2271
2272 _PHOLD(p);
2273 PROC_UNLOCK(p);
2274 vm = vmspace_acquire_ref(p);
2275 if (vm == NULL) {
2276 PRELE(p);
2277 return (ESRCH);
2278 }
2256{
2257 vm_map_entry_t entry, tmp_entry;
2258 struct vattr va;
2259 vm_map_t map;
2260 vm_object_t obj, tobj, lobj;
2261 char *fullpath, *freepath;
2262 struct kinfo_vmentry *kve;
2263 struct ucred *cred;

--- 7 unchanged lines hidden (view full) ---

2271
2272 _PHOLD(p);
2273 PROC_UNLOCK(p);
2274 vm = vmspace_acquire_ref(p);
2275 if (vm == NULL) {
2276 PRELE(p);
2277 return (ESRCH);
2278 }
2279 kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK);
2279 kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK | M_ZERO);
2280
2281 error = 0;
2282 map = &vm->vm_map;
2283 vm_map_lock_read(map);
2284 for (entry = map->header.next; entry != &map->header;
2285 entry = entry->next) {
2286 if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
2287 continue;

--- 118 unchanged lines hidden (view full) ---

2406 kve->kve_shadow_count = 0;
2407 }
2408
2409 strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path));
2410 if (freepath != NULL)
2411 free(freepath, M_TEMP);
2412
2413 /* Pack record size down */
2280
2281 error = 0;
2282 map = &vm->vm_map;
2283 vm_map_lock_read(map);
2284 for (entry = map->header.next; entry != &map->header;
2285 entry = entry->next) {
2286 if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
2287 continue;

--- 118 unchanged lines hidden (view full) ---

2406 kve->kve_shadow_count = 0;
2407 }
2408
2409 strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path));
2410 if (freepath != NULL)
2411 free(freepath, M_TEMP);
2412
2413 /* Pack record size down */
2414 kve->kve_structsize = offsetof(struct kinfo_vmentry, kve_path) +
2415 strlen(kve->kve_path) + 1;
2414 if ((flags & KERN_VMMAP_PACK_KINFO) != 0)
2415 kve->kve_structsize =
2416 offsetof(struct kinfo_vmentry, kve_path) +
2417 strlen(kve->kve_path) + 1;
2418 else
2419 kve->kve_structsize = sizeof(*kve);
2416 kve->kve_structsize = roundup(kve->kve_structsize,
2417 sizeof(uint64_t));
2420 kve->kve_structsize = roundup(kve->kve_structsize,
2421 sizeof(uint64_t));
2422
2423 /* Halt filling and truncate rather than exceeding maxlen */
2424 if (maxlen != -1 && maxlen < kve->kve_structsize) {
2425 error = 0;
2426 vm_map_lock_read(map);
2427 break;
2428 } else if (maxlen != -1)
2429 maxlen -= kve->kve_structsize;
2430
2418 if (sbuf_bcat(sb, kve, kve->kve_structsize) != 0)
2419 error = ENOMEM;
2420 vm_map_lock_read(map);
2421 if (error != 0)
2422 break;
2423 if (last_timestamp != map->timestamp) {
2424 vm_map_lookup_entry(map, addr - 1, &tmp_entry);
2425 entry = tmp_entry;

--- 16 unchanged lines hidden (view full) ---

2442 name = (int *)arg1;
2443 sbuf_new_for_sysctl(&sb, NULL, sizeof(struct kinfo_vmentry), req);
2444 sbuf_clear_flags(&sb, SBUF_INCLUDENUL);
2445 error = pget((pid_t)name[0], PGET_CANDEBUG | PGET_NOTWEXIT, &p);
2446 if (error != 0) {
2447 sbuf_delete(&sb);
2448 return (error);
2449 }
2431 if (sbuf_bcat(sb, kve, kve->kve_structsize) != 0)
2432 error = ENOMEM;
2433 vm_map_lock_read(map);
2434 if (error != 0)
2435 break;
2436 if (last_timestamp != map->timestamp) {
2437 vm_map_lookup_entry(map, addr - 1, &tmp_entry);
2438 entry = tmp_entry;

--- 16 unchanged lines hidden (view full) ---

2455 name = (int *)arg1;
2456 sbuf_new_for_sysctl(&sb, NULL, sizeof(struct kinfo_vmentry), req);
2457 sbuf_clear_flags(&sb, SBUF_INCLUDENUL);
2458 error = pget((pid_t)name[0], PGET_CANDEBUG | PGET_NOTWEXIT, &p);
2459 if (error != 0) {
2460 sbuf_delete(&sb);
2461 return (error);
2462 }
2450 error = kern_proc_vmmap_out(p, &sb);
2463 error = kern_proc_vmmap_out(p, &sb, -1, KERN_VMMAP_PACK_KINFO);
2451 error2 = sbuf_finish(&sb);
2452 sbuf_delete(&sb);
2453 return (error != 0 ? error : error2);
2454}
2455
2456#if defined(STACK) || defined(DDB)
2457static int
2458sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS)

--- 603 unchanged lines hidden ---
2464 error2 = sbuf_finish(&sb);
2465 sbuf_delete(&sb);
2466 return (error != 0 ? error : error2);
2467}
2468
2469#if defined(STACK) || defined(DDB)
2470static int
2471sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS)

--- 603 unchanged lines hidden ---