site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com The following code, when made from within a kernel extension, results in the error variable being set to 1 (EPERM?): [...] SYSCTL_PROC(_sysctl, 3, name2oid, CTLFLAG_RW|CTLFLAG_ANYBODY, 0, 0, sysctl_sysctl_name2oid, "I", ""); S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Technical Support * Networking, Communications, Hardware kern_return_t sysctlbyname_start(kmod_info_t * ki, void * d) { int err; int numberOfCPUs; size_t size; int oid[2]; oid[0] = CTL_HW; oid[1] = HW_NCPU; numberOfCPUs = -1; size = sizeof(numberOfCPUs); At 12:23 -0600 8/11/04, Geoffrey Schmit wrote: Any ideas? The same code works fine from a user-mode console This is caused by a bug in the kernel. Specifically, the definition of the name2oid sysctl entry in "xnu/bsd/kern/kern_newsysctl.c": should include the CTLFLAG_KERN flag to allow the entry to be used by kernel code. The absence of this flag causes sysctlbyname to fail because it can't translate your name to an OID. See sysctlnametomib (in the same file) for background. This bug has already been fixed in Tiger. Until then you can work around it by using kernel_sysctl instead of sysctlbyname, as illustrated by the code below. err = kernel_sysctl( current_proc(), oid, sizeof(oid) / sizeof(*oid), &numberOfCPUs, &size, NULL, 0 ); if (err == 0) { assert(size == sizeof(numberOfCPUs)); printf("kernel_sysctl: numberOfCPUs = %d\n", numberOfCPUs); } else { printf("kernel_sysctl: failed with error %d\n", err); } return KERN_SUCCESS; } _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com
participants (1)
-
Quinn