Skip to content

Instantly share code, notes, and snippets.

@nolta
Created May 5, 2012 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolta/2605833 to your computer and use it in GitHub Desktop.
Save nolta/2605833 to your computer and use it in GitHub Desktop.
// Test to understand what https://gist.github.com/2517475 is actually doing.
#include <stdio.h>
#define __AC(X,Y) (X##Y)
#define _AC(X,Y) __AC(X,Y)
#define BITS_PER_BYTE 8
#define PAGE_SHIFT 12
#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
#define __user
#define EINVAL 22 /* Invalid argument */
// extracted from <linux-kernel>/mm/mempolicy.c
static int get_nodes(const unsigned long __user *nmask,
unsigned long maxnode)
{
--maxnode;
if (maxnode == 0 || !nmask)
return 0;
if (maxnode > PAGE_SIZE*BITS_PER_BYTE)
return -EINVAL;
}
int
main(int argc, char *argv[])
{
unsigned long null_nodemask=0, maxnode=0;
printf("get_nodes(NULL,0) = %d\n", get_nodes(NULL,maxnode));
printf("get_nodes(&null_nodemask,0) = %d\n", get_nodes(&null_nodemask,maxnode));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment